public void testCountStoredEvents() throws Exception {
EventStore eventStore = this.eventStore();
long numberOfEvents = eventStore.countStoredEvents();
TestableDomainEvent lastDomainEvent = null;
for (int idx = 0; idx < 10; ++idx) {
TestableDomainEvent domainEvent = new TestableDomainEvent(10001 + idx, "testDomainEvent" + idx);
lastDomainEvent = domainEvent;
eventStore.append(domainEvent);
}
LevelDBUnitOfWork.current().commit();
assertEquals(numberOfEvents + 10, eventStore.countStoredEvents());
numberOfEvents = eventStore.countStoredEvents();
assertEquals(1, eventStore.allStoredEventsBetween(numberOfEvents, numberOfEvents + 1000).size());
StoredEvent storedEvent = eventStore.allStoredEventsBetween(numberOfEvents, numberOfEvents).get(0);
assertNotNull(storedEvent);
TestableDomainEvent reconstitutedDomainEvent = storedEvent.toDomainEvent();
assertNotNull(reconstitutedDomainEvent);
assertEquals(lastDomainEvent.id(), reconstitutedDomainEvent.id());
assertEquals(lastDomainEvent.name(), reconstitutedDomainEvent.name());
assertEquals(lastDomainEvent.occurredOn(), reconstitutedDomainEvent.occurredOn());
}