io.vlingo.actors.testkit.AccessSafely Java Examples
The following examples show how to use
io.vlingo.actors.testkit.AccessSafely.
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: ExecutorDispatcherTest.java From vlingo-actors with Mozilla Public License 2.0 | 6 votes |
private TestResults(final int happenings, boolean shouldLog) { final List<Integer> counts = new CopyOnWriteArrayList<>(); final AtomicInteger highest = new AtomicInteger(0); this.shouldLog = shouldLog; this.accessSafely = AccessSafely .afterCompleting(happenings) .writingWith("results", (BiConsumer<Integer, Logger>) (count, logger) -> { if (shouldLog) { logger.debug("CountTakerActor: take: " + count); } if (count > highest.get()) { if (shouldLog) { logger.debug("CountTakerActor: take: " + count + " > " + highest.get()); } highest.set(count); } counts.add(highest.get()); }) .readingWith("results", () -> counts) .readingWith("highest", highest::get); }
Example #2
Source File: StaticFilesResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatServesJsSubDirectoryStaticFile() throws IOException { final String resource = "/js/vuetify.js"; final String content = readTextFile(contentRoot + resource); final String request = getRequest(resource); client.requestWith(toByteBuffer(request)); final AccessSafely consumeCalls = progress.expectConsumeTimes(1); while (consumeCalls.totalWrites() < 1) { client.probeChannel(); } consumeCalls.readFrom("completed"); final Response contentResponse = progress.responses.poll(); assertEquals(1, progress.consumeCount.get()); assertEquals(Response.Status.Ok, contentResponse.status); assertEquals(content, contentResponse.entity.content()); }
Example #3
Source File: InMemoryEventJournalActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatStreamReaderReadsFromBeyondSnapshot() { dispatcher.afterCompleting(5); interest.afterCompleting(5); journal.append("123", 1, new Test1Source(), interest, object); journal.append("123", 2, new Test1Source(), interest, object); journal.appendWith("123", 3, new Test1Source(), new SnapshotState(), interest, object); journal.append("123", 4, new Test1Source(), interest, object); journal.append("123", 5, new Test1Source(), interest, object); final AccessSafely accessResults = new TestResults().afterCompleting(1); journal.streamReader("test").andThenTo(reader -> reader.streamFor("123", 4)).andThenConsume(eventStream -> { accessResults.writeUsing("addAll", eventStream.entries); assertNull(eventStream.snapshot); }); assertEquals(2, (int) accessResults.readFrom("size")); assertEquals("4", accessResults.readFrom("entryId", 0)); assertEquals("5", accessResults.readFrom("entryId", 1)); }
Example #4
Source File: InMemoryEventJournalActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatStreamReaderReadsFiveEventsWithSnapshot() { dispatcher.afterCompleting(5); interest.afterCompleting(5); journal.append("123", 1, new Test1Source(), interest, object); journal.append("123", 2, new Test1Source(), interest, object); journal.appendWith("123", 3, new Test1Source(), new SnapshotState(), interest, object); journal.append("123", 4, new Test1Source(), interest, object); journal.append("123", 5, new Test1Source(), interest, object); final AccessSafely accessResults = new TestResults().afterCompleting(1); journal.streamReader("test").andThenTo(reader -> reader.streamFor("123")).andThenConsume(eventStream -> { accessResults.writeUsing("addAll", eventStream.entries); }); assertEquals(3, (int) accessResults.readFrom("size")); assertEquals("3", accessResults.readFrom("entryId", 0)); assertEquals("4", accessResults.readFrom("entryId", 1)); assertEquals("5", accessResults.readFrom("entryId", 2)); }
Example #5
Source File: InMemoryStateStoreTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatStateStoreWritesAndReadsObject() { final AccessSafely access1 = interest.afterCompleting(2); dispatcher.afterCompleting(2); final Entity1 entity = new Entity1("123", 5); store.write(entity.id, entity, 1, interest); store.read(entity.id, Entity1.class, interest); assertEquals(1, (int) access1.readFrom("readObjectResultedIn")); assertEquals(1, (int) access1.readFrom("writeObjectResultedIn")); assertEquals(Result.Success, access1.readFrom("objectReadResult")); assertEquals(entity, access1.readFrom("objectState")); final Entity1 readEntity = (Entity1) access1.readFrom("objectState"); assertEquals("123", readEntity.id); assertEquals(5, readEntity.value); }
Example #6
Source File: InMemoryEventJournalActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatJournalReaderReadsThreeEvents() { interest.afterCompleting(1); dispatcher.afterCompleting(1); final List<Source<String>> three = Arrays.asList(new Test1Source(), new Test2Source(), new Test1Source()); journal.appendAll("123", 1, three, interest, object); final AccessSafely accessResults = new TestResults().afterCompleting(1); journal.journalReader("test").andThenTo(reader -> reader.readNext(5)).andThenConsume(entries -> { accessResults.writeUsing("addAll", entries); }); assertEquals(3, (int) accessResults.readFrom("size")); assertEquals("1", accessResults.readFrom("entryId", 0)); assertEquals("2", accessResults.readFrom("entryId", 1)); assertEquals("3", accessResults.readFrom("entryId", 2)); }
Example #7
Source File: InMemoryStateStoreTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatStateStoreWritesAndReadsMetadataValue() { final AccessSafely access1 = interest.afterCompleting(2); dispatcher.afterCompleting(2); final Entity1 entity = new Entity1("123", 5); final Metadata sourceMetadata = Metadata.withValue("value"); store.write(entity.id, entity, 1, sourceMetadata, interest); store.read(entity.id, Entity1.class, interest); assertEquals(1, (int) access1.readFrom("readObjectResultedIn")); assertEquals(1, (int) access1.readFrom("writeObjectResultedIn")); assertEquals(Result.Success, access1.readFrom("objectReadResult")); assertEquals(entity, access1.readFrom("objectState")); assertNotNull(access1.readFrom("metadataHolder")); final Metadata metadata = access1.readFrom("metadataHolder"); assertTrue(metadata.hasValue()); assertEquals("value", metadata.value); final Entity1 readEntity = (Entity1) access1.readFrom("objectState"); assertEquals("123", readEntity.id); assertEquals(5, readEntity.value); }
Example #8
Source File: InMemoryStateStoreTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatStateStoreWritesAndReadsMetadataOperation() { final AccessSafely access1 = interest.afterCompleting(2); dispatcher.afterCompleting(2); final Entity1 entity = new Entity1("123", 5); final Metadata sourceMetadata = Metadata.with("value", "operation"); store.write(entity.id, entity, 1, sourceMetadata, interest); store.read(entity.id, Entity1.class, interest); assertEquals(1, (int) access1.readFrom("readObjectResultedIn")); assertEquals(1, (int) access1.readFrom("writeObjectResultedIn")); assertEquals(Result.Success, access1.readFrom("objectReadResult")); assertEquals(entity, access1.readFrom("objectState")); final Metadata metadata = access1.readFrom("metadataHolder"); assertNotNull(metadata); assertTrue(metadata.hasOperation()); assertEquals("operation", metadata.operation); final Entity1 readEntity = (Entity1) access1.readFrom("objectState"); assertEquals("123", readEntity.id); assertEquals(5, readEntity.value); }
Example #9
Source File: ConfigurationResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatGetUserDispatches() { System.out.println("testThatGetUserDispatches()"); final Request postRequest = Request.from(toByteBuffer(postJohnDoeUserMessage)); final MockCompletesEventuallyResponse postCompletes = new MockCompletesEventuallyResponse(); final AccessSafely postCompletesWithCalls = postCompletes.expectWithTimes(1); dispatcher.dispatchFor(new Context(postRequest, postCompletes)); postCompletesWithCalls.readFrom("completed"); assertNotNull(postCompletes.response); final String getUserMessage = "GET " + postCompletes.response.get().headerOf(Location).value + " HTTP/1.1\nHost: vlingo.io\n\n"; final Request getRequest = Request.from(toByteBuffer(getUserMessage)); final MockCompletesEventuallyResponse getCompletes = new MockCompletesEventuallyResponse(); final AccessSafely getCompletesWithCalls = getCompletes.expectWithTimes(1); dispatcher.dispatchFor(new Context(getRequest, getCompletes)); getCompletesWithCalls.readFrom("completed"); assertNotNull(getCompletes.response); assertEquals(Ok, getCompletes.response.get().status); final UserData getUserData = deserialized(getCompletes.response.get().entity.content(), UserData.class); assertNotNull(getUserData); assertEquals(johnDoeUserData.nameData.given, getUserData.nameData.given); assertEquals(johnDoeUserData.nameData.family, getUserData.nameData.family); assertEquals(johnDoeUserData.contactData.emailAddress, getUserData.contactData.emailAddress); assertEquals(johnDoeUserData.contactData.telephoneNumber, getUserData.contactData.telephoneNumber); }
Example #10
Source File: StaticFilesResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatServesRootStaticFile() throws IOException { final String resource = "/index.html"; final String content = readTextFile(contentRoot + resource); final String request = getRequest(resource); client.requestWith(toByteBuffer(request)); final AccessSafely consumeCalls = progress.expectConsumeTimes(1); while (consumeCalls.totalWrites() < 1) { client.probeChannel(); } consumeCalls.readFrom("completed"); final Response contentResponse = progress.responses.poll(); assertEquals(1, progress.consumeCount.get()); assertEquals(Response.Status.Ok, contentResponse.status); assertEquals(content, contentResponse.entity.content()); }
Example #11
Source File: InMemoryStateStoreEntryReaderActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatEntryReaderReadsOne() { final AccessSafely access = interest.afterCompleting(3); dispatcher.afterCompleting(0); store.write(Id1, new Entity1(Id1, 10), 1, Arrays.asList(new Event1()), interest); store.write(Id2, new Entity2(Id2, "20"), 1, Arrays.asList(new Event2()), interest); store.write(Id3, new Entity1(Id3, 30), 1, Arrays.asList(new Event3()), interest); assertEquals(new Event1(), access.readFrom("sources")); assertEquals(new Event2(), access.readFrom("sources")); assertEquals(new Event3(), access.readFrom("sources")); final TextEntry entry1 = reader.readNext().await(); assertEquals(entryAdapterProvider.asEntry(new Event1(), 1, Metadata.nullMetadata()).withId("0"), entry1); final TextEntry entry2 = reader.readNext().await(); assertEquals(entryAdapterProvider.asEntry(new Event2(), 1, Metadata.nullMetadata()).withId("1"), entry2); final TextEntry entry3 = reader.readNext().await(); assertEquals(entryAdapterProvider.asEntry(new Event3(), 1, Metadata.nullMetadata()).withId("2"), entry3); reader.rewind(); assertEquals(Arrays.asList(entry1, entry2, entry3), reader.readNext(3).await()); }
Example #12
Source File: InMemoryStateStoreRedispatchControlTest.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
@Test public void testRedispatch() { final AccessSafely accessDispatcher = dispatcher.afterCompleting(3); final Entity1 entity = new Entity1("123", 5); accessDispatcher.writeUsing("processDispatch", false); store.write(entity.id, entity, 1, interest); try { Thread.sleep(3000); } catch (InterruptedException ex) { //ignored } accessDispatcher.writeUsing("processDispatch", true); int dispatchedStateCount = accessDispatcher.readFrom("dispatchedStateCount"); assertTrue("dispatchedStateCount", dispatchedStateCount == 1); int dispatchAttemptCount = accessDispatcher.readFrom("dispatchAttemptCount"); assertTrue("dispatchAttemptCount", dispatchAttemptCount > 1); }
Example #13
Source File: StateStoreProjectionTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatProjectionsProject() { final CountingProjectionControl control = new CountingProjectionControl(); final AccessSafely access = control.afterCompleting(3); projection.projectWith(textWarble("1", 1), control); projection.projectWith(textWarble("2", 2), control); projection.projectWith(textWarble("3", 3), control); final Map<String,Integer> confirmations = access.readFrom("confirmations"); Assert.assertEquals(3, confirmations.size()); Assert.assertEquals(1, valueOfProjectionIdFor("1", confirmations)); Assert.assertEquals(1, valueOfProjectionIdFor("2", confirmations)); Assert.assertEquals(1, valueOfProjectionIdFor("3", confirmations)); Assert.assertEquals(3, (int) access.readFrom("sum")); }
Example #14
Source File: BasicSupervisionTest.java From vlingo-actors with Mozilla Public License 2.0 | 6 votes |
@Test public void testStoppingSupervisor() { final TestActor<Supervisor> supervisor = testWorld.actorFor( Supervisor.class, Definition.has(StoppingSupervisorActor.class, Definition.NoParameters, "stopping-supervisor")); final FailureControlTestResults failureControlTestResults = new FailureControlTestResults(); final TestActor<FailureControl> failure = testWorld.actorFor( FailureControl.class, Definition.has(FailureControlActor.class, Definition.parameters(failureControlTestResults), supervisor.actorInside(), "failure-for-stop")); AccessSafely access = failureControlTestResults.afterCompleting(2); failure.actor().failNow(); assertEquals(1, (int) access.readFrom("failNowCount")); failure.actor().afterFailure(); assertEquals(1, (int) access.readFrom("stoppedCount")); assertEquals(0, (int) access.readFrom("afterFailureCount")); }
Example #15
Source File: CompetingConsumerTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatConsumersCompete() { final World world = World.startWithDefaults("competing-consumer-test"); final int poolSize = 4; final int messagesToSend = 8; final CompetingConsumerResults results = new CompetingConsumerResults(); final WorkConsumer workConsumer = world.actorFor(WorkConsumer.class, WorkRouterActor.class, poolSize, results); final AccessSafely access = results.afterCompleting(messagesToSend); for (int i = 0; i < messagesToSend; i++) { workConsumer.consumeWork(new WorkItem(i)); } Assert.assertEquals(8, (int) access.readFrom("afterItemConsumedCount")); }
Example #16
Source File: StateProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatTextStateDataProjects() { final StateStore store = store(); final MockResultInterest interest = new MockResultInterest(0); final MockProjection projection = new MockProjection(); final AccessSafely access = projection.afterCompleting(2); projectionDispatcher.projectTo(projection, new String[] { "op1" }); projectionDispatcher.projectTo(projection, new String[] { "op2" }); final Entity1 entity1 = new Entity1("123-1", 1); final Entity1 entity2 = new Entity1("123-2", 2); store.write(entity1.id, entity1, 1, Metadata.with("value1", "op1"), interest); store.write(entity2.id, entity2, 1, Metadata.with("value2", "op2"), interest); assertEquals(2, (int) access.readFrom("projections")); assertEquals("123-1", access.readFrom("projectionId", 0)); assertEquals("123-2", access.readFrom("projectionId", 1)); }
Example #17
Source File: CommandSourcedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatEventEmits() { final AccessSafely access = result.afterCompleting(2); entity.doTest1(); assertTrue(access.readFrom("tested1")); assertFalse(access.readFrom("tested2")); assertEquals(1, (int) access.readFrom("appliedCount")); Object appliedAt0 = access.readFrom("appliedAt", 0); assertNotNull(appliedAt0); assertEquals(DoCommand1.class, appliedAt0.getClass()); final AccessSafely access2 = result.afterCompleting(2); entity.doTest2(); assertEquals(2, (int) access2.readFrom("appliedCount")); Object appliedAt1 = access2.readFrom("appliedAt", 1); assertNotNull(appliedAt1); assertEquals(DoCommand2.class, appliedAt1.getClass()); }
Example #18
Source File: EventSourcedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatCtorEmits() { final AccessSafely resultAccess = result.afterCompleting(2); final AccessSafely dispatcherAccess = dispatcher.afterCompleting(1); entity.doTest1(); assertTrue(resultAccess.readFrom("tested1")); assertEquals(1, (int) resultAccess.readFrom("appliedCount")); assertEquals(1, (int) dispatcherAccess.readFrom("entriesCount")); Object appliedAt0 = resultAccess.readFrom("appliedAt", 0); assertNotNull(appliedAt0); assertEquals(Test1Happened.class, appliedAt0.getClass()); BaseEntry<String> appendeAt0 = dispatcherAccess.readFrom("appendedAt", 0); assertNotNull(appendeAt0); assertEquals(Test1Happened.class.getName(), appendeAt0.typeName()); assertFalse(resultAccess.readFrom("tested2")); }
Example #19
Source File: ServerTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatServerRespondsOkWithNoContentLengthHeader() { System.out.println(">>>>>>>>>>>>>>>>>>>>> testThatServerRespondsOkWithNoContentLengthHeader"); if (skipTests) { System.out.println(">>>>>>>>>>>>>>>>>>>>> skipped"); return; } final String request = putRequest("u-456", uniqueJohnDoe()); client.requestWith(toByteBuffer(request)); final AccessSafely consumeCalls = progress.expectConsumeTimes(1); while (consumeCalls.totalWrites() < 1) { client.probeChannel(); } consumeCalls.readFrom("completed"); final Response response = progress.responses.poll(); assertNotNull(response); assertEquals(Ok.name(), response.status.name()); assertEquals(1, progress.consumeCount.get()); }
Example #20
Source File: ConfigurationResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatPostRegisterUserDispatches() { System.out.println("testThatPostRegisterUserDispatches()"); final Request request = Request.from(toByteBuffer(postJohnDoeUserMessage)); final MockCompletesEventuallyResponse completes = new MockCompletesEventuallyResponse(); final AccessSafely withCalls = completes.expectWithTimes(1); dispatcher.dispatchFor(new Context(request, completes)); withCalls.readFrom("completed"); assertNotNull(completes.response.get()); assertEquals(Created, completes.response.get().status); assertEquals(2, completes.response.get().headers.size()); assertEquals(Location, completes.response.get().headers.get(0).name); assertTrue(Location, completes.response.get().headerOf(Location).value.startsWith("/users/")); assertNotNull(completes.response.get().entity); final UserData createdUserData = deserialized(completes.response.get().entity.content(), UserData.class); assertNotNull(createdUserData); assertEquals(johnDoeUserData.nameData.given, createdUserData.nameData.given); assertEquals(johnDoeUserData.nameData.family, createdUserData.nameData.family); assertEquals(johnDoeUserData.contactData.emailAddress, createdUserData.contactData.emailAddress); assertEquals(johnDoeUserData.contactData.telephoneNumber, createdUserData.contactData.telephoneNumber); }
Example #21
Source File: SseStreamResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatClientUnsubscribes() { final Request subscribe = Request .method(Method.GET) .uri("/eventstreams/all") .and(RequestHeader.host("StreamsRUs.co")) .and(RequestHeader.accept("text/event-stream")); final AccessSafely respondWithSafely = resource.requestResponseContext.channel.expectRespondWith(10); resource.nextRequest(subscribe); resource.subscribeToStream("all", AllSseFeedActor.class, 1, 10, "1"); assertTrue(1 <= (int) respondWithSafely.readFrom("count")); assertTrue(1 <= resource.requestResponseContext.channel.respondWithCount.get()); final String clientId = resource.requestResponseContext.id(); final Request unsubscribe = Request .method(Method.DELETE) .uri("/eventstreams/all/" + clientId) .and(RequestHeader.host("StreamsRUs.co")) .and(RequestHeader.accept("text/event-stream")); final AccessSafely abandonSafely = resource.requestResponseContext.channel.expectAbandon(1); resource.nextRequest(unsubscribe); resource.unsubscribeFromStream("all", clientId); assertEquals(1, (int) abandonSafely.readFrom("count")); assertEquals(1, resource.requestResponseContext.channel.abandonCount.get()); }
Example #22
Source File: MockProjection.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
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 #23
Source File: PongSupervisorActor.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
public AccessSafely afterCompleting(final int times) { access = AccessSafely.afterCompleting(times) .writingWith("informedCount", (Integer increment) -> informedCount.incrementAndGet()) .readingWith("informedCount", () -> informedCount.get()); return access; }
Example #24
Source File: CommonSupervisionTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
@Test public void testPongSupervisor() { final PongTestResults testResults = new PongTestResults(); final TestActor<Pong> pong = testWorld.actorFor( Pong.class, Definition.has(PongActor.class, Definition.parameters(testResults), "pong")); PongSupervisorTestResults supervisorResults = PongSupervisorActor.instance.get().testResults; AccessSafely pongAccess = testResults.afterCompleting(10); AccessSafely supervisorAccess = supervisorResults.afterCompleting(10); for (int idx = 1; idx <= 10; ++idx) { pong.actor().pong(); } assertEquals(10, (int) pongAccess.readFrom("pongCount")); assertEquals(10, (int) supervisorAccess.readFrom("informedCount")); assertFalse(pong.actorInside().isStopped()); assertFalse(pong.actorInside().isStopped()); pongAccess = testResults.afterCompleting(2); supervisorAccess = supervisorResults.afterCompleting(1); pong.actor().pong(); assertEquals(11, (int) pongAccess.readFrom("pongCount")); assertEquals(11, (int) supervisorAccess.readFrom("informedCount")); assertTrue(pong.actorInside().isStopped()); }
Example #25
Source File: ContentBasedRouterTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
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 #26
Source File: StateStoreProjectionTest.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
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 #27
Source File: DescribedProjection.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
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 #28
Source File: SchedulerTest.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
private CounterHolder(final int times) { final AtomicInteger counter = new AtomicInteger(0); this.safely = AccessSafely .afterCompleting(times) .writingWith("counter", (Integer ignored) -> counter.incrementAndGet()) .readingWith("counter", counter::get); }
Example #29
Source File: ClientTest.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatCorrelatingClientDelivers() throws Exception { final String user = johnDoeUserSerialized; final TestResponseConsumer safely = new TestResponseConsumer(); final AccessSafely access = safely.afterCompleting(1); final UnknownResponseConsumer unknown = new UnknownResponseConsumer(access); final KnownResponseConsumer known = new KnownResponseConsumer(access); final Address address = Address.from(Host.of("localhost"), portToUse, AddressType.NONE); client = Client.using(Configuration.defaultedKeepAliveExceptFor(world.stage(), address, unknown)); client.requestWith( Request .has(POST) .and(URI.create("/users")) .and(host("localhost")) .and(contentLength(user)) .and(keepAlive()) .and(Body.from(user))) .andThenConsume(5000, Response.of(RequestTimeout), response -> expectedResponse = response) .andThenConsume(response -> expectedHeaderCount = response.headers.size()) .andThenConsume(response -> location = response.headers.headerOf(Location)) .andFinallyConsume(known::consume); final int responseCount = access.readFrom("responseCount"); final int unknownResponseCount = access.readFrom("unknownResponseCount"); assertEquals(1, responseCount); assertNotNull(expectedResponse); assertEquals(Created, expectedResponse.status); assertEquals(3, expectedHeaderCount); assertNotNull(location); assertEquals(0, unknownResponseCount); }
Example #30
Source File: PublishSubscribeTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testThatPublishSubscribeRuns() { System.out.println("Publish Subscribe: is starting."); final World world = World.startWithDefaults("publish-subscribe-test"); final MarketQuotationResults results = new MarketQuotationResults(); final AccessSafely access = results.afterCompleting(6); final Subscriber<PriceQuoted> allMarketsSubscriber = world.actorFor(Subscriber.class, AllMarketsSubscriber.class, results); final Subscriber<PriceQuoted> nasdaqSubscriber = world.actorFor(Subscriber.class, NASDAQSubscriber.class, results); final Subscriber<PriceQuoted> nyseSubscriber = world.actorFor(Subscriber.class, NYSESubscriber.class, results); final Publisher publisher = new DefaultPublisher(); publisher.subscribe(new Market("quotes"), allMarketsSubscriber); publisher.subscribe(new Market("quotes/NASDAQ"), nasdaqSubscriber); publisher.subscribe(new Market("quotes/NYSE"), nyseSubscriber); publisher.publish(new Market("quotes/NYSE"), new PriceQuoted("ORCL", new Money("121.13"))); publisher.publish(new Market("quotes/NASDAQ"), new PriceQuoted( "MSFT", new Money("1099.76"))); publisher.publish(new Market("quotes/DAX"), new PriceQuoted("SAP:GR", new Money("885.00"))); publisher.publish(new Market("quotes/NKY"), new PriceQuoted("6701:JP", new Money("131.12"))); Assert.assertEquals(4, (int) access.readFrom("afterQuotationReceivedAtGeneralSubscriberCount")); Assert.assertEquals(1, (int) access.readFrom("afterQuotationReceivedAtNASDAQSubscriberCount")); Assert.assertEquals(1, (int) access.readFrom("afterQuotationReceivedAtNYSESubscriberCount")); }