Java Code Examples for io.vlingo.actors.testkit.AccessSafely#readFrom()
The following examples show how to use
io.vlingo.actors.testkit.AccessSafely#readFrom() .
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 |
@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 2
Source File: ServerTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatServerHandlesThrowables() { System.out.println(">>>>>>>>>>>>>>>>>>>>> testThatServerHandlesThrowables"); if (skipTests) { System.out.println(">>>>>>>>>>>>>>>>>>>>> skipped"); return; } final String request = getExceptionRequest("1"); client.requestWith(toByteBuffer(request)); final AccessSafely consumeCalls = progress.expectConsumeTimes(1); while (consumeCalls.totalWrites() < 1) { client.probeChannel(); } consumeCalls.readFrom("completed"); final Response createdResponse = progress.responses.poll(); assertEquals(1, progress.consumeCount.get()); assertEquals(Response.Status.InternalServerError, createdResponse.status); }
Example 3
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 4
Source File: ServerTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatServerRespondsPermanentRedirectWithNoContentLengthHeader() { System.out.println(">>>>>>>>>>>>>>>>>>>>> testThatServerRespondsPermanentRedirectWithNoContentLengthHeader"); if (skipTests) { System.out.println(">>>>>>>>>>>>>>>>>>>>> skipped"); return; } final String request = putRequest("u-123", 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(PermanentRedirect.name(), response.status.name()); assertEquals(1, progress.consumeCount.get()); }
Example 5
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 6
Source File: StaticFilesResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatServesViewsSubDirectoryStaticFile() throws IOException { final String resource = "/views/About.vue"; 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 7
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 8
Source File: SseStreamResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatFeedWithInstantiatorFeeds() { final MockCompletesEventuallyResponse completes = new MockCompletesEventuallyResponse(); final AccessSafely respondWithSafely = context.channel.expectRespondWith(1); // NOTE: Any reference to AllSseFeedActor automatically // causes the AllSseFeedInstantiator to be registered // somehow the static initializer doesn't work for (this) JUnit tests @SuppressWarnings({ "unused", "rawtypes" }) final Class c = AllSseFeedActor.class; // not registered AllSseFeedActor.registerInstantiator(); // registered final Request request = Request .method(Method.GET) .uri("/eventstreams/all") .and(RequestHeader.host("StreamsRUs.co")) .and(RequestHeader.accept("text/event-stream")); final SseStreamResource sseStreamResource = new SseStreamResource(world); final Context requestContext = new Context(context, request, completes); sseStreamResource.__internal__test_set_up(requestContext, world.stage()); final ActorInstantiator<?> instantiator = ActorInstantiatorRegistry.instantiatorFor(AllSseFeedActor.class); instantiator.set("feedClass", AllSseFeedActor.class); instantiator.set("streamName", "all"); instantiator.set("feedPayload", 1); instantiator.set("feedDefaultId", "123"); sseStreamResource.subscribeToStream("all", AllSseFeedActor.class, 1, 100, "123"); final int completedCount = respondWithSafely.readFrom("count"); assertEquals(1, completedCount); }
Example 9
Source File: ServerTest.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatServerDispatchesManyRequests() throws Exception { System.out.println(">>>>>>>>>>>>>>>>>>>>> testThatServerDispatchesManyRequests"); if (skipTests) { System.out.println(">>>>>>>>>>>>>>>>>>>>> skipped"); return; } final long startTime = System.currentTimeMillis(); final AccessSafely consumeCalls = progress.expectConsumeTimes(TOTAL_REQUESTS_RESPONSES); final int totalPairs = TOTAL_REQUESTS_RESPONSES / 2; int currentConsumeCount = 0; for (int idx = 0; idx < totalPairs; ++idx) { client.requestWith(toByteBuffer(postRequest(uniqueJohnDoe()))); client.requestWith(toByteBuffer(postRequest(uniqueJaneDoe()))); final int expected = currentConsumeCount + 2; while (consumeCalls.totalWrites() < expected) { client.probeChannel(); } currentConsumeCount = expected; Thread.sleep(100); } while (consumeCalls.totalWrites() < TOTAL_REQUESTS_RESPONSES) { client.probeChannel(); } consumeCalls.readFrom("completed"); System.out.println("TOTAL REQUESTS-RESPONSES: " + TOTAL_REQUESTS_RESPONSES + " TIME: " + (System.currentTimeMillis() - startTime) + " ms"); assertTrue(TOTAL_REQUESTS_RESPONSES <= progress.consumeCount.get()); final Response createdResponse = progress.responses.peek(); assertNotNull(createdResponse.headers.headerOf(ResponseHeader.Location)); }
Example 10
Source File: InMemoryObjectStoreActorTest.java From vlingo-symbio with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatMultiPersistQueryResolves() { dispatcher.afterCompleting(3); final AccessSafely persistAllAccess = persistInterest.afterCompleting(1); final Person person1 = new Person("Tom Jones", 78); final Person person2 = new Person("Dean Martin", 78); final Person person3 = new Person("Sally Struthers", 71); objectStore.persistAll(Arrays.asList(StateSources.of(person1), StateSources.of(person2), StateSources.of(person3)), persistInterest); final int persistSize = persistAllAccess.readFrom("size"); assertEquals(3, persistSize); final AccessSafely queryAllAccess = queryResultInterest.afterCompleting(1); objectStore.queryAll(QueryExpression.using(Person.class, "findAll"), queryResultInterest, null); final int querySize = queryAllAccess.readFrom("size"); assertEquals(3, querySize); assertEquals(person1, queryAllAccess.readFrom("object", 0)); assertEquals(person2, queryAllAccess.readFrom("object", 1)); assertEquals(person3, queryAllAccess.readFrom("object", 2)); assertEquals(3, dispatcher.dispatchedCount()); Dispatchable<Entry<?>, State<?>> dispatched = dispatcher.getDispatched().get(0); validateDispatchedState(person1, dispatched); List<Entry<?>> dispatchedEntries = dispatched.entries(); Assert.assertTrue(dispatchedEntries.isEmpty()); dispatched = dispatcher.getDispatched().get(1); validateDispatchedState(person2, dispatched); dispatchedEntries = dispatched.entries(); Assert.assertTrue(dispatchedEntries.isEmpty()); dispatched = dispatcher.getDispatched().get(2); validateDispatchedState(person3, dispatched); dispatchedEntries = dispatched.entries(); Assert.assertTrue(dispatchedEntries.isEmpty()); }
Example 11
Source File: FeedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatDefaultFeedReadsFirstFeedItemArchivedSecondFeedItemIncomplete() { final Feed feed = Feed.defaultFeedWith(world.stage(), "test", TextEntryReaderFeeder.class, entryReader); final int extra = 3; final int entries = feed.messagesPerFeedItem() + extra; final AccessSafely dispatcherAccess = dispatcher.afterCompleting(entries); for (int idx = 0; idx < entries; ++idx) { journal.append("stream-" + idx, 1, new TestEvents.Event1(), interest, null); } final int count = dispatcherAccess.readFrom("entriesCount"); assertEquals(entries, count); final AccessSafely consumerAccess = consumer.afterCompleting(2); feed.feeder().feedItemTo(FeedItemId.with(1), consumer); feed.feeder().feedItemTo(FeedItemId.with(2), consumer); final Map<Long,FeedItem> feedItems = consumerAccess.readFrom("feedItems"); assertEquals(2, feedItems.size()); assertEquals(feed.messagesPerFeedItem(), feedItems.get(1L).messages.size()); assertTrue(feedItems.get(1L).archived); assertEquals(extra, feedItems.get(2L).messages.size()); assertFalse(feedItems.get(2L).archived); }
Example 12
Source File: SseClientTest.java From vlingo-http with Mozilla Public License 2.0 | 4 votes |
@Test public void testThatEndOfStreamSends() { final AccessSafely respondWithSafely = context.channel.expectRespondWith(1); final SseEvent event = SseEvent.Builder.instance().endOfStream().toEvent(); client.send(event); assertEquals(1, (int) respondWithSafely.readFrom("count")); assertEquals(1, context.channel.respondWithCount.get()); final Response response = context.channel.response.get(); assertNotNull(response); final Response eventsResponse = respondWithSafely.readFrom("eventsResponse"); final List<MessageEvent> messageEvents = MessageEvent.from(eventsResponse); assertEquals(1, messageEvents.size()); final MessageEvent messageEvent = messageEvents.get(0); assertTrue(messageEvent.endOfStream()); }
Example 13
Source File: StateStoreProjectionTest.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Test public void testThatProjectionsWriteStateBeforeHandlingNextEvent() { final CountingProjectionControl control = new CountingProjectionControl(); final AccessSafely accessControl = control.afterCompleting(3); projection.projectWith(textWarble("1", 1), control); projection.projectWith(textWarble("1", 2), control); projection.projectWith(textWarble("1", 3), control); final Map<String,Integer> confirmations = accessControl.readFrom("confirmations"); Assert.assertEquals(3, confirmations.size()); final CountingReadResultInterest interest = new CountingReadResultInterest(); final AccessSafely accessInterest = interest.afterCompleting(1); store.read("1", Warble.class, interest); final Warble warble = accessInterest.readFrom("warble", "1"); Assert.assertEquals(6, warble.count); }
Example 14
Source File: EventSourcedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Test public void testBaseClassBehavior() { final Product product = world.actorFor(Product.class, ProductEntity.class); final AccessSafely access = dispatcher.afterCompleting(4); product.define("dice", "fuz", "dice-fuz-1", "Fuzzy dice.", 999); product.declareType("Type1"); product.categorize("Category2"); product.changeName("Fuzzy, fuzzy dice!"); final List<Entry<String>> entries = access.readFrom("entries"); assertEquals("ProductDefined", innerToSimple(entries.get(0).typeName())); assertEquals("ProductTyped", innerToSimple(entries.get(1).typeName())); assertEquals("ProductCategorized", innerToSimple(entries.get(2).typeName())); assertEquals("ProductNameChanged", innerToSimple(entries.get(3).typeName())); }
Example 15
Source File: ClientTest.java From vlingo-http with Mozilla Public License 2.0 | 4 votes |
@Test public void testThatRoundRobinClientDelivers() throws Exception { final TestResponseConsumer safely = new TestResponseConsumer(); final AccessSafely access = safely.afterCompleting(10); final UnknownResponseConsumer unknown = new UnknownResponseConsumer(access); final KnownResponseConsumer known = new KnownResponseConsumer(access); final Address address = Address.from(Host.of("localhost"), portToUse, AddressType.NONE); final Configuration config = Client.Configuration.defaultedKeepAliveExceptFor(world.stage(), address, unknown); config.testInfo(true); final Client client = Client.using( config, Client.ClientConsumerType.RoundRobin, 5); for (int count = 0; count < 100; ++count) { final String user = count % 2 == 0 ? uniqueJohnDoe() : uniqueJaneDoe(); client.requestWith( Request .has(POST) .and(URI.create("/users")) .and(host("localhost")) .and(contentLength(user)) .and(keepAlive()) .and(Body.from(user))) .andFinallyConsume(response -> known.consume(response) ); } final int responseCount = access.readFromExpecting("responseCount", 100, 2000); final int total = access.readFrom("totalAllResponseCount"); final int unknownResponseCount = access.readFrom("unknownResponseCount"); final Map<String,Integer> clientCounts = access.readFrom("responseClientCounts"); assertEquals(100, total); assertEquals(100, responseCount); assertEquals(0, unknownResponseCount); for (final String id : clientCounts.keySet()) { final int clientCound = clientCounts.get(id); assertEquals(20, clientCound); } }
Example 16
Source File: FeedTest.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Test public void testThatDefaultFeedReadsFirstFeedItemIncomplete() { final Feed feed = Feed.defaultFeedWith(world.stage(), "test", TextEntryReaderFeeder.class, entryReader); final AccessSafely dispatcherAccess = dispatcher.afterCompleting(3); journal.append("stream-1", 1, new TestEvents.Event1(), interest, null); journal.append("stream-2", 1, new TestEvents.Event2(), interest, null); journal.append("stream-3", 1, new TestEvents.Event3(), interest, null); final int count = dispatcherAccess.readFrom("entriesCount"); assertEquals(3, count); final AccessSafely consumerAccess = consumer.afterCompleting(1); feed.feeder().feedItemTo(FeedItemId.with(1), consumer); final Map<Long,FeedItem> feedItems = consumerAccess.readFrom("feedItems"); assertEquals(1, feedItems.size()); assertFalse(feedItems.get(1L).archived); }
Example 17
Source File: ClientTest.java From vlingo-http with Mozilla Public License 2.0 | 4 votes |
@Test public void testThatLoadBalancingClientDelivers() throws Exception { final TestResponseConsumer safely = new TestResponseConsumer(); final AccessSafely access = safely.afterCompleting(100); final UnknownResponseConsumer unknown = new UnknownResponseConsumer(access); final KnownResponseConsumer known = new KnownResponseConsumer(access); final Address address = Address.from(Host.of("localhost"), portToUse, AddressType.NONE); final Configuration config = Client.Configuration.defaultedKeepAliveExceptFor(world.stage(), address, unknown); config.testInfo(true); final Client client = Client.using( config, Client.ClientConsumerType.LoadBalancing, 5); for (int count = 0; count < 100; ++count) { final String user = count % 2 == 0 ? uniqueJohnDoe() : uniqueJaneDoe(); client.requestWith( Request .has(POST) .and(URI.create("/users")) .and(host("localhost")) .and(contentLength(user)) .and(keepAlive()) .and(Body.from(user))) .andFinallyConsume(known::consume); } final int responseCount = access.readFromExpecting("responseCount", 100, 2000); final int total = access.readFrom("totalAllResponseCount"); final int unknownResponseCount = access.readFrom("unknownResponseCount"); final Map<String,Integer> clientCounts = access.readFrom("responseClientCounts"); assertEquals(100, total); assertEquals(100, responseCount); assertEquals(0, unknownResponseCount); int totalClientCounts = 0; for (final String id : clientCounts.keySet()) { final int clientCound = clientCounts.get(id); totalClientCounts += clientCound; } assertEquals(100, totalClientCounts); }
Example 18
Source File: ServerTest.java From vlingo-http with Mozilla Public License 2.0 | 4 votes |
@Test public void testThatServerDispatchesRequests() throws Exception { System.out.println(">>>>>>>>>>>>>>>>>>>>> testThatServerDispatchesRequests"); if (skipTests) { System.out.println(">>>>>>>>>>>>>>>>>>>>> skipped"); return; } final String request = postRequest(uniqueJohnDoe()); client.requestWith(toByteBuffer(request)); final AccessSafely consumeCalls = progress.expectConsumeTimes(1); while (consumeCalls.totalWrites() < 1) { client.probeChannel(); } consumeCalls.readFrom("completed"); final Response createdResponse = progress.responses.poll(); assertEquals(1, progress.consumeCount.get()); assertNotNull(createdResponse.headers.headerOf(ResponseHeader.Location)); final String getUserMessage = "GET " + createdResponse.headerOf(ResponseHeader.Location).value + " HTTP/1.1\nHost: vlingo.io\nConnection: keep-alive\n\n"; client.requestWith(toByteBuffer(getUserMessage)); final AccessSafely moreConsumeCalls = progress.expectConsumeTimes(1); while (moreConsumeCalls.totalWrites() < 1) { client.probeChannel(); } moreConsumeCalls.readFrom("completed"); final Response getResponse = progress.responses.poll(); assertEquals(2, progress.consumeCount.get()); assertEquals(Response.Status.Ok, getResponse.status); assertNotNull(getResponse.entity); assertNotNull(getResponse.entity.content()); assertTrue(getResponse.entity.hasContent()); }
Example 19
Source File: UUIDAddressTest.java From vlingo-actors with Mozilla Public License 2.0 | 3 votes |
@Test public void testThatActorsAreOperational() { final TestResults testResults = new TestResults(); final AccessSafely access = testResults.afterCompleting(MaxPings * 2); final Ping ping = world.actorFor(Ping.class, PingActor.class, testResults); ping.ping(); final int pingCount = access.readFrom("pingCount"); final int pongCount = access.readFrom("pongCount"); assertEquals(pingCount, pongCount); }
Example 20
Source File: ActorStopTest.java From vlingo-actors with Mozilla Public License 2.0 | 2 votes |
public void testStopActors() throws Exception { final TestResults results = new TestResults(); final AccessSafely beforeStartCountAccess = results.beforeStartCountAccessCompletes(12); world.defaultLogger().debug("Test: testStopActors: starting actors"); final ChildCreatingStoppable[] stoppables = setUpActors(world, results); for (int idx = 0; idx < stoppables.length; ++idx) { stoppables[idx].createChildren(); } final int beforeStartCount = beforeStartCountAccess.readFrom("value"); assertEquals(12, beforeStartCount); world.defaultLogger().debug("Test: testStopActors: stopping actors"); results.terminatingAccessCompletes(0).writeUsing("value", false); final AccessSafely stopCountAccess = results.stopCountAccessCompletes(12); for (int idx = 0; idx < stoppables.length; ++idx) { stoppables[idx].stop(); } final int stopCount = stopCountAccess.readFromExpecting("value", 12); assertEquals(12, stopCount); world.defaultLogger().debug("Test: testStopActors: stopped actors"); world.defaultLogger().debug("Test: testStopActors: terminating world"); results.terminatingStopCountAccessCompletes(0); results.terminatingAccessCompletes(0).writeUsing("value", true); world.terminate(); final int terminatingStopCount = results.terminatingStopCountAccess.readFrom("value"); assertEquals(0, terminatingStopCount); }