Build and freeze transaction events in bulk
This commit is contained in:
1 parent
e78c65a36c
commit
75fa1a4f31
10 files changed
+146
-22
No files matched your search
+32
@@ -0,0 +1,32 @@
|
||||
package com.minres.scviewer.database.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import com.minres.scviewer.database.*;
|
||||
|
||||
public class EventListBuilderTest {
|
||||
@Test
|
||||
public void sortsAndPreservesSameTimeInsertionOrder() {
|
||||
EventList.Builder builder = new EventList.Builder();
|
||||
TxTestSupport.Tx tx = new TxTestSupport.Tx(1, 0, 10);
|
||||
IEvent begin = new TxTestSupport.Event(tx, EventKind.BEGIN);
|
||||
IEvent end = new TxTestSupport.Event(tx, EventKind.END);
|
||||
builder.add(10, begin);builder.add(2, end);builder.add(10, end);
|
||||
builder.add(Long.MIN_VALUE, begin);builder.add(Long.MAX_VALUE, end);
|
||||
EventList list = builder.build();
|
||||
assertEquals(4, list.size());
|
||||
assertEquals(2, list.firstKey());
|
||||
assertArrayEquals(new IEvent[] {begin, end}, list.get(10));
|
||||
assertEquals(Long.MIN_VALUE, list.lastKey());
|
||||
try { list.put(5, begin); fail(); } catch (UnsupportedOperationException expected) { }
|
||||
try { builder.add(5, begin); fail(); } catch (IllegalStateException expected) { }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesManyEventsAtOneTimestampAndEmptyInput() {
|
||||
EventList.Builder builder = new EventList.Builder();
|
||||
for (int i = 0; i < 10000; ++i) builder.add(5, null);
|
||||
assertEquals(10000, builder.build().get(5).length);
|
||||
assertNull(new EventList.Builder().build().firstEntry());
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.minres.scviewer.database.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import com.minres.scviewer.database.*;
|
||||
import com.minres.scviewer.database.text.TextDbLoader;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
|
||||
public class TransactionReaderTest {
|
||||
@Test
|
||||
public void textAndTruncatedRecordingsHaveConsistentRows() throws Exception {
|
||||
for (String input : new String[] {"my_db.txlog", "my_db_truncated.txlog"}) {
|
||||
TextDbLoader loader = new TextDbLoader();
|
||||
try {
|
||||
loader.load(TxTestSupport.input(input));
|
||||
assertFalse(loader.getAllWaves().isEmpty());
|
||||
for (IWaveform wave : loader.getAllWaves()) {
|
||||
int rows = wave.getRowCount();
|
||||
Map<Long, Integer> begun = new HashMap<>();
|
||||
for (EventEntry entry : wave.getEvents()) for (IEvent raw : entry.events) {
|
||||
ITxEvent event = (ITxEvent) raw;
|
||||
assertTrue(event.getRowIndex() >= 0 && event.getRowIndex() < rows);
|
||||
assertTrue(event.getTransaction().getEndTime() >= event.getTransaction().getBeginTime());
|
||||
if (event.getKind() == EventKind.BEGIN)
|
||||
begun.put(event.getTransaction().getId(), event.getRowIndex());
|
||||
else if (event.getKind() == EventKind.END)
|
||||
assertEquals(begun.remove(event.getTransaction().getId()), Integer.valueOf(event.getRowIndex()));
|
||||
}
|
||||
assertTrue(begun.isEmpty());
|
||||
try { wave.getEvents().put(1, null); fail("Frozen event list"); }
|
||||
catch (UnsupportedOperationException expected) { }
|
||||
}
|
||||
} finally { loader.dispose(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user