okhttp3.mockwebserver.QueueDispatcher Java Examples

The following examples show how to use okhttp3.mockwebserver.QueueDispatcher. 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: DigdagClientTest.java    From digdag with Apache License 2.0 6 votes vote down vote up
@Test
public void getLogFileFailsAfter10Attempts()
        throws Exception
{
    QueueDispatcher dispatcher = new QueueDispatcher();
    dispatcher.setFailFast(new MockResponse().setResponseCode(500));
    mockWebServer.setDispatcher(dispatcher);

    try {
        client.getLogFile(Id.of("17"), RestLogFileHandle.builder()
                .agentId("test-agent")
                .fileName("test-task-1.log")
                .fileSize(4711)
                .fileTime(Instant.now().truncatedTo(SECONDS))
                .taskName("test-task-1")
                .build());
        fail();
    }
    catch (InternalServerErrorException ignore) {
    }

    assertThat(mockWebServer.getRequestCount(), is(10));
}
 
Example #2
Source File: MockWebServerPlusTest.java    From mockwebserverplus with Apache License 2.0 5 votes vote down vote up
@Test public void enqueueSocketPolicy() throws IOException {
  server.enqueue(SocketPolicy.KEEP_OPEN);
  QueueDispatcher dispatcher = new QueueDispatcher();
  server.setDispatcher(dispatcher);

  MockResponse mockResponse = dispatcher.peek();

  assertThat(mockResponse.getSocketPolicy()).isEqualTo(SocketPolicy.KEEP_OPEN);
}
 
Example #3
Source File: MockWebServerPlusTest.java    From mockwebserverplus with Apache License 2.0 5 votes vote down vote up
@Test public void interceptDispatch() throws InterruptedException, IOException {
  Dispatcher dispatcher = spy(new QueueDispatcher());
  server.setDispatcher(dispatcher);
  server.enqueue(new MockResponse());

  execute();

  verify(dispatcher).dispatch(any(RecordedRequest.class));
}
 
Example #4
Source File: HttpCallIT.java    From digdag with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp()
        throws Exception
{
    httpMockWebServer = startMockWebServer();
    httpMockWebServer.setDispatcher(new QueueDispatcher());
    httpsMockWebServer = startMockWebServer(true);
    requests = new ConcurrentHashMap<>();
}
 
Example #5
Source File: SlaIT.java    From digdag with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyAlertIsRetried()
        throws Exception
{
    mockWebServer.setDispatcher(new QueueDispatcher());
    mockWebServer.enqueue(new MockResponse().setResponseCode(500).setBody("FAIL"));
    mockWebServer.enqueue(new MockResponse().setResponseCode(200));
    Id attemptId = pushAndStart("duration_alert_enabled.dig", Duration.ofSeconds(5));
    RecordedRequest recordedRequest1 = mockWebServer.takeRequest(30, TimeUnit.SECONDS);
    RecordedRequest recordedRequest2 = mockWebServer.takeRequest(30, TimeUnit.SECONDS);
    verifyNotification(attemptId, recordedRequest1);
    verifyNotification(attemptId, recordedRequest2);
}
 
Example #6
Source File: HttpIT.java    From digdag with Apache License 2.0 5 votes vote down vote up
@Test
public void testForEach()
        throws Exception
{
    String uri = "http://localhost:" + httpMockWebServer.getPort() + "/";
    httpMockWebServer.setDispatcher(new QueueDispatcher());
    String content = DigdagClient.objectMapper().writeValueAsString(
            ImmutableList.of("foo", "bar", "baz"));
    httpMockWebServer.enqueue(new MockResponse().setBody(content));
    runWorkflow(folder, "acceptance/http/http_for_each.dig", ImmutableMap.of("test_uri", uri));
    assertThat(httpMockWebServer.getRequestCount(), is(1));
}
 
Example #7
Source File: BaseLogicTest.java    From mockstar with MIT License 4 votes vote down vote up
protected MockWebServer getErrorMockWebServer() {
    mockWebServer.setDispatcher(new QueueDispatcher());
    return mockWebServer;
}
 
Example #8
Source File: WebServerBuilder.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public WebServerBuilder() {
  server = new MockWebServer();
  QueueDispatcher dispatcher = new QueueDispatcher();
  dispatcher.setFailFast(new MockResponse().setResponseCode(400));
  server.setDispatcher(dispatcher);
}