Java Code Examples for io.vlingo.actors.testkit.AccessSafely#totalWrites()
The following examples show how to use
io.vlingo.actors.testkit.AccessSafely#totalWrites() .
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: 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 2
Source File: StaticFilesResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatServesCssSubDirectoryStaticFile() throws IOException { final String resource = "/css/styles.css"; 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: 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 4
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 5
Source File: FeedResourceTest.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatFeedResourceFeeds() { final String request = requestFor(FeedURI + "/100"); 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("events:100:1\n2\n3\n4\n5\n", contentResponse.entity.content()); }
Example 6
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 7
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 8
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 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: ServerTest.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatServerClosesChannelAfterSingleRequest() { System.out.println(">>>>>>>>>>>>>>>>>>>>> testThatServerClosesChannelAfterSingleRequest"); if (skipTests) { System.out.println(">>>>>>>>>>>>>>>>>>>>> skipped"); return; } int totalResponses = 0; final int maxRequests = 10; for (int count = 0; count < maxRequests; ++count) { final AccessSafely consumeCalls = progress.expectConsumeTimes(1); if (count % 2 == 0) { client.requestWith(toByteBuffer(postRequestCloseFollowing(uniqueJohnDoe()))); } else { client.requestWith(toByteBuffer(postRequestCloseFollowing(uniqueJaneDoe()))); } System.out.println("1"); while (consumeCalls.totalWrites() < 1) { client.probeChannel(); } totalResponses += (int) consumeCalls.readFrom("completed"); System.out.println("2: " + totalResponses); client.close(); client = new NettyClientRequestResponseChannel(Address.from(Host.of("localhost"), serverPort, AddressType.NONE), consumer, 100, 10240); } assertEquals(maxRequests, totalResponses); }
Example 11
Source File: OrganizationResourceTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
private Response pollClient() { final AccessSafely consumeCalls = progress.expectConsumeTimes(1); while (consumeCalls.totalWrites() < 1) { client.probeChannel(); } consumeCalls.readFrom("completed"); final Response response = progress.responses.poll(); return response; }
Example 12
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 13
Source File: MessageRouterTest.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
@Test public void testAlternatingRouteProcessorRuns() { final World world = World.startWithDefaults( WORLD_NAME ); world.defaultLogger().debug( "AlternatingRouteProcessor: is starting" ); final MessageRouterResults results = new MessageRouterResults(); final AccessSafely access = results.afterCompleting( ROUTES ); final Processor messageProcessor1 = world.actorFor(Processor.class, WorkerProcessor.class, "MP One" ); final Processor messageProcessor2 = world.actorFor(Processor.class, WorkerProcessor.class, "MP Two" ); final Processor alternatingRouter = world.actorFor(Processor.class, AlternatingRouteProcessor.class, results, messageProcessor1, messageProcessor2 ); int routeCount = 0; int j = 0; while ( true ) { int remaining = ROUTES - access.totalWrites(); if ( routeCount < ROUTES ) { alternatingRouter.process( routeCount ); routeCount++; } if ( j != remaining ) { world.defaultLogger().debug( String.format( "Count: %d", remaining )); j = remaining; } if ( remaining == 0 ) break; } Assert.assertEquals(10, (int) access.readFrom("afterMessageProcessedByFirstProcessorCount")); Assert.assertEquals(10, (int) access.readFrom("afterMessageProcessedBySecondProcessorCount")); world.defaultLogger().debug( "AlternatingRouteProcessor: is completed" ); world.terminate(); }