protected RandomClockFactory _randClockFactory = new RandomClockFactory(2);
public void testApiBasics() {
EventBatch<String> batch;
long origin = _rand.nextInt(Integer.MAX_VALUE);
Clock clock = _randClockFactory.next();
int capacity = Math.max(EventBatch.MINIMUM_BATCH_SIZE, _rand.nextInt(2000));
batch = new SimpleEventBatch<String>(origin, clock, capacity);
assertEquals(EventBatch.VERSION, batch.getVersion());
assertEquals(0, batch.getSize());
assertEquals(origin, batch.getOrigin());
assertEquals(Occurred.EQUICONCURRENTLY, clock.compareTo(batch.getMinClock()));
assertEquals(Occurred.EQUICONCURRENTLY, clock.compareTo(batch.getMaxClock()));
// Add the first event
clock = _randClockFactory.next();
batch.put(new SimpleEvent<String>("Event." + clock, clock));
assertTrue(clock.compareTo(batch.getMinClock()) == Occurred.EQUICONCURRENTLY);
assertTrue(clock.compareTo(batch.getMaxClock()) == Occurred.EQUICONCURRENTLY);
assertEquals(1, batch.getSize());
// Add the second event
clock = _randClockFactory.next();
batch.put(new SimpleEvent<String>("Event." + clock, clock));
assertTrue(clock.after(batch.getMinClock()));
assertTrue(clock.compareTo(batch.getMaxClock()) == Occurred.EQUICONCURRENTLY);
assertEquals(2, batch.getSize());
do {
clock = _randClockFactory.next();
} while(batch.put(new SimpleEvent<String>("Event." + clock, clock)));
assertTrue(clock.after(batch.getMinClock()));
assertTrue(clock.after(batch.getMaxClock()));
assertEquals(capacity, batch.getSize());
batch.setCompletionTime(System.currentTimeMillis() + 1);
assertTrue(batch.getCreationTime() < batch.getCompletionTime());