use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method throw_ISE_if_unable_to_load_entity_by_id_from_storage_index.
@Test(expected = IllegalStateException.class)
public void throw_ISE_if_unable_to_load_entity_by_id_from_storage_index() {
// Store a valid aggregate.
givenStoredAggregate();
// Store a troublesome entity, which cannot be loaded.
final TenantAwareOperation op = new TenantAwareOperation(newUuid()) {
@Override
public void run() {
givenStoredAggregateWithId(ProjectAggregateRepository.troublesome.getId());
}
};
op.execute();
final Iterator<ProjectAggregate> iterator = repository.iterator(Predicates.<ProjectAggregate>alwaysTrue());
// This should iterate through all and fail.
Lists.newArrayList(iterator);
}
use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method restore_aggregate_using_snapshot.
@Test
public void restore_aggregate_using_snapshot() {
final ProjectId id = Sample.messageOfType(ProjectId.class);
final ProjectAggregate expected = GivenAggregate.withUncommittedEvents(id);
repository.setSnapshotTrigger(expected.uncommittedEventsCount());
repository.store(expected);
final ProjectAggregate actual = repository.find(id).get();
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getState(), actual.getState());
}
use of io.spine.server.aggregate.given.AggregateRepositoryTestEnv.ProjectAggregate in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method store_snapshot_and_set_event_count_to_zero_if_needed.
@Test
public void store_snapshot_and_set_event_count_to_zero_if_needed() {
final ProjectAggregate aggregate = GivenAggregate.withUncommittedEvents();
// This should make the repository write the snapshot.
repository.setSnapshotTrigger(aggregate.uncommittedEventsCount());
repository.store(aggregate);
final AggregateStateRecord record = readRecord(aggregate);
assertTrue(record.hasSnapshot());
assertEquals(0, repository.aggregateStorage().readEventCountAfterLastSnapshot(aggregate.getId()));
}
Aggregations