Java Code Examples for io.vlingo.actors.testkit.AccessSafely#readingWith()

The following examples show how to use io.vlingo.actors.testkit.AccessSafely#readingWith() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemoryStateStoreTest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatAllOfTypeStreams() {
  for (int count = 1; count <= 200; ++count) {
    final Entity1 entity1 = new Entity1("" + count, count);
    store.write(entity1.id, entity1, 1, interest);
  }

  final Stream all = store.streamAllOf(Entity1.class).await();

  final AccessSafely access = AccessSafely.afterCompleting(200);

  access.writingWith("stateCounter", (state) -> { totalStates.incrementAndGet(); });
  access.readingWith("stateCount", () -> totalStates.get());

  all.flowInto(new ConsumerSink<>((state) -> access.writeUsing("stateCounter", 1)), 10);

  final int stateCount = access.readFromExpecting("stateCount", 200);

  Assert.assertEquals(totalStates.get(), 200);
  Assert.assertEquals(totalStates.get(), stateCount);
}
 
Example 2
Source File: InMemoryEventJournalActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 3 votes vote down vote up
@Test
public void testThatJournalReaderStreams() {
  final int limit = 1000;

  dispatcher.afterCompleting(0);
  interest.afterCompleting(0);

  for (int count = 0; count < limit; ++count) {
    journal.append("123-" + count, 1, new Test1Source(count), interest, object);
  }

  final AccessSafely access = AccessSafely.afterCompleting(limit);

  access.writingWith("sourcesCounter", (state) -> { totalSources.incrementAndGet(); });
  access.readingWith("sourcesCount", () -> totalSources.get());

  final Stream all = journal.journalReader("test").andThenTo(reader -> reader.streamAll()).await();

  final Consumer<EntryBundle> bundles = (bundle) -> access.writeUsing("sourcesCounter", 1);

  sink = new ConsumerSink<>(bundles);

  all.flowInto(sink, 100);

  final int sourcesCount = access.readFromExpecting("sourcesCount", limit);

  Assert.assertEquals(limit, totalSources.get());
  Assert.assertEquals(totalSources.get(), sourcesCount);
}