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

The following examples show how to use io.vlingo.actors.testkit.AccessSafely#afterCompleting() . 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: StateStoreProjectionTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int times) {
  access = AccessSafely.afterCompleting(times);

  access.writingWith("confirmations", (String projectionId) -> {
    final int count = confirmations.getOrDefault(projectionId, 0);
    confirmations.put(projectionId, count + 1);
  });

  access.readingWith("confirmations", () -> confirmations);

  access.readingWith("sum", () -> confirmations.values().stream().mapToInt(i -> i).sum());

  return access;
}
 
Example 3
Source File: TestResponseConsumer.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int happenings) {
  access = AccessSafely.afterCompleting(happenings);

  access.writingWith("response", (Response response) -> {
    final String testId = response.headerValueOr(Client.ClientIdCustomHeader, "");

    System.out.println("ID: " + testId);

    if (testId.isEmpty()) {
      System.out.println("Expected header missing: " + Client.ClientIdCustomHeader);
      //throw new IllegalStateException("Expected header missing: " + Client.ClientIdCustomHeader);
    }

    final Integer existingCount = clientCounts.getOrDefault(testId, 0);

    responseHolder.set(response);

    clientCounts.put(testId, existingCount + 1);

    responseCount.incrementAndGet();
  });
  access.readingWith("response", () -> responseHolder.get());
  access.readingWith("responseCount", () -> responseCount.get());
  access.readingWith("responseClientCounts", () -> clientCounts);

  access.writingWith("unknownResponseCount", (Integer increment) -> unknownResponseCount.incrementAndGet());
  access.readingWith("unknownResponseCount", () -> unknownResponseCount.get());

  access.readingWith("totalAllResponseCount", () -> responseCount.get() + unknownResponseCount.get());

  return access;
}
 
Example 4
Source File: TestResponseChannelConsumer.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Answer with an AccessSafely which writes responses to "consume" and reads the write count from "completed".
 * <p>
 * Note: Clients can replace the default lambdas with their own via readingWith/writingWith.
 *
 * @param n Number of times consume(response) must be called before readFrom(...) will return.
 * @return
 */
public AccessSafely expectConsumeTimes(final int n) {
  consumeCalls = AccessSafely.afterCompleting(n);

  consumeCalls
      .writingWith("consume", response -> {
        responses.add((Response) response);
        consumeCount.incrementAndGet();
      })
      .readingWith("completed", () -> consumeCalls.totalWrites())
      ;

  return consumeCalls;
}
 
Example 5
Source File: MockParent.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int happenings) {
  access = AccessSafely.afterCompleting(happenings);
  
  access
    .writingWith("events", (Event event) -> events.add(event))
    .readingWith("events", () -> events);
  
  return access;
}
 
Example 6
Source File: StateProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int times) {
  access = AccessSafely.afterCompleting(times);
  access
    .writingWith("filterCount", (Integer increment) -> filterCount.addAndGet(increment))
    .readingWith("filterCount", () -> filterCount.get());

  return access;
}
 
Example 7
Source File: JournalProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
private AccessSafely accessProjectionFor(final int times) {
  accessProjection = AccessSafely.afterCompleting(times);

  accessProjection.writingWith(AccessProjection, (x) -> accessProjectionCount.incrementAndGet());
  accessProjection.readingWith(AccessProjection, () -> accessProjectionCount.get());

  return accessProjection;
}
 
Example 8
Source File: JournalProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
private AccessSafely accessJournalFor(final int times) {
  accessJournal = AccessSafely.afterCompleting(times);

  accessJournal.writingWith(AccessJournal, (x) -> accessJournalCount.incrementAndGet());
  accessJournal.readingWith(AccessJournal, () -> accessJournalCount.get());

  return accessJournal;
}
 
Example 9
Source File: DescribedProjection.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int times) {
  access = AccessSafely.afterCompleting(times);
  access
    .writingWith("count", (Integer increment) -> count.addAndGet(increment))
    .readingWith("count", () -> count.get());

  return access;
}
 
Example 10
Source File: StateStoreProjectionTest.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int times) {
  access = AccessSafely.afterCompleting(times);

  access.writingWith("warble", (Warble warble) -> {
    sum.addAndGet(warble.count);
    warbles.put(warble.name, warble);
  });

  access.readingWith("sum", () -> sum.get());
  access.readingWith("warble", (id) -> warbles.get(id));

  return access;
}
 
Example 11
Source File: MockProjection.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int times) {
  access = AccessSafely.afterCompleting(times);

  access
    .writingWith("projections", (Integer val, String id) -> {
      projections.set(projections.get() + val);
      projectedDataIds.add(id);
    })
    .readingWith("projections", () -> projections.get())
    .readingWith("projectionId", (Integer index) -> projectedDataIds.get(index));

  return access;
}
 
Example 12
Source File: CharactersTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
Results(final int times) {
  final AtomicInteger one = new AtomicInteger(0);
  final AtomicInteger two = new AtomicInteger(0);
  final AtomicInteger three = new AtomicInteger(0);
  counters = AccessSafely.afterCompleting(times);
  counters.writingWith("one" , one::addAndGet);
  counters.readingWith("one" , one::get);
  counters.writingWith("two" , two::addAndGet);
  counters.readingWith("two" , two::get);
  counters.writingWith("three" , three::addAndGet);
  counters.readingWith("three" , three::get);
}
 
Example 13
Source File: TestExchangeReceiver1.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int times) {
  access = AccessSafely.afterCompleting(times);
  access
    .writingWith("addMessage", (LocalType1 message) -> results.add(message))
    .readingWith("getMessage", () -> results.poll());

  return access;
}
 
Example 14
Source File: ContentBasedRouterTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
private TestResults(int times) {
  final Map<ERPSystemCode, List<Invoice>> invoices = new ConcurrentHashMap<>(times);
  this.submittedInvoices = AccessSafely.afterCompleting(times);
  this.submittedInvoices.writingWith("submittedInvoices",
          (ERPSystemCode key, Invoice value) -> invoices.computeIfAbsent(key, (code) ->  new ArrayList<>()).add(value));
  this.submittedInvoices.readingWith("submittedInvoices",
          (Function<ERPSystemCode, List<Invoice>>) invoices::get);
}
 
Example 15
Source File: TestExchange.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public AccessSafely afterCompleting(final int times) {
  access = AccessSafely.afterCompleting(times);
  access
      .writingWith("sentCount", (Integer increment) -> sentCount.addAndGet(increment))
      .readingWith("sentCount", () -> sentCount.get());

  return access;
}
 
Example 16
Source File: DescribedProjection.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
public Outcome(final int testUntilHappenings) {
  this.count = new AtomicInteger(0);
  this.access = AccessSafely.afterCompleting(testUntilHappenings);
}
 
Example 17
Source File: LocalMessageTest.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
private SimpleTestResults(final int times) {
  final AtomicInteger deliveries = new AtomicInteger(0);
  this.deliveries = AccessSafely.afterCompleting(times);
  this.deliveries.writingWith("deliveries", (Integer i)-> deliveries.incrementAndGet());
  this.deliveries.readingWith("deliveries", deliveries::get);
}
 
Example 18
Source File: TestExchange.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
public TestExchange(final MessageQueue queue) {
  this.queue = queue;
  queue.registerListener(this);
  this.forwarder = new Forwarder();
  this.access = AccessSafely.afterCompleting(0);
}
 
Example 19
Source File: MockStateStoreDispatcher.java    From vlingo-symbio with Mozilla Public License 2.0 4 votes vote down vote up
public MockStateStoreDispatcher(final ConfirmDispatchedResultInterest confirmDispatchedResultInterest) {
  this.confirmDispatchedResultInterest = confirmDispatchedResultInterest;
  this.access = AccessSafely.afterCompleting(0);
}
 
Example 20
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);
}