当前位置: 首页>>代码示例>>Java>>正文


Java Duration类代码示例

本文整理汇总了Java中org.awaitility.Duration的典型用法代码示例。如果您正苦于以下问题:Java Duration类的具体用法?Java Duration怎么用?Java Duration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Duration类属于org.awaitility包,在下文中一共展示了Duration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyResponse

import org.awaitility.Duration; //导入依赖的package包/类
protected void verifyResponse(InputStream pis, String response) {
    StringBuilder sb = new StringBuilder();
    try {
        await().atMost(Duration.TWO_SECONDS).until(() -> {
            while (true) {
                sb.append((char) pis.read());
                String s = sb.toString();
                if (s.contains(response)) {
                    break;
                }
            }
            return true;
        });
    } finally {
        System.out.println(sb.toString());
    }
}
 
开发者ID:anand1st,项目名称:sshd-shell-spring-boot,代码行数:18,代码来源:AbstractSshSupport.java

示例2: testSimple

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testSimple() throws IOException, TException, Failure {
    TestService.Iface client = new TestService.Client(new HttpClientHandler(
            this::endpoint));

    when(impl.test(any(net.morimekta.test.thrift.client.Request.class)))
            .thenReturn(new net.morimekta.test.thrift.client.Response("response"));

    Response response = client.test(new Request("request"));

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).until(() -> contentTypes.size() > 0);

    verify(impl).test(any(net.morimekta.test.thrift.client.Request.class));
    verifyNoMoreInteractions(impl);

    assertThat(response, is(equalToMessage(new Response("response"))));
    assertThat(contentTypes, is(equalTo(ImmutableList.of("application/vnd.apache.thrift.binary"))));
}
 
开发者ID:morimekta,项目名称:providence,代码行数:19,代码来源:HttpClientHandlerTest.java

示例3: testSimpleRequest

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testSimpleRequest() throws IOException, TException, Failure {
    TestService.Iface client = new TestService.Client(new HttpClientHandler(
            this::endpoint, factory(), provider, instrumentation));

    when(impl.test(any(net.morimekta.test.thrift.client.Request.class)))
            .thenReturn(new net.morimekta.test.thrift.client.Response("response"));

    Response response = client.test(new Request("request"));
    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).until(() -> contentTypes.size() > 0);

    verify(impl).test(any(net.morimekta.test.thrift.client.Request.class));
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(impl, instrumentation);

    assertThat(response, is(equalToMessage(new Response("response"))));
    assertThat(contentTypes, is(equalTo(ImmutableList.of("application/vnd.apache.thrift.binary"))));
}
 
开发者ID:morimekta,项目名称:providence,代码行数:19,代码来源:HttpClientHandlerTest.java

示例4: testSimpleRequest_oneway

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testSimpleRequest_oneway() throws IOException, TException, Failure {
    TestService.Iface client = new TestService.Client(new HttpClientHandler(
            this::endpoint, factory(), provider, instrumentation));

    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        return null;
    }).when(impl).onewayMethod();

    client.onewayMethod();

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).until(() -> contentTypes.size() > 0);

    verify(impl).onewayMethod();
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), isNull());
    verifyNoMoreInteractions(impl, instrumentation);

    assertThat(contentTypes, is(equalTo(ImmutableList.of("application/vnd.apache.thrift.binary"))));
}
 
开发者ID:morimekta,项目名称:providence,代码行数:23,代码来源:HttpClientHandlerTest.java

示例5: testSimpleRequest

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testSimpleRequest() throws IOException, Failure {
    AtomicBoolean called = new AtomicBoolean();
    when(impl.test(any(Request.class))).thenAnswer(i -> {
        called.set(true);
        return new Response("response");
    });

    TestService.Iface client = new TestService.Client(new HttpClientHandler(
            this::endpoint, factory(), provider));

    Response response = client.test(new Request("request"));

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    assertNotNull(response);
    assertEquals("{text:\"response\"}", response.asString());
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(instrumentation);
}
 
开发者ID:morimekta,项目名称:providence,代码行数:21,代码来源:ProvidenceServletTest.java

示例6: testSimpleRequest_exception

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testSimpleRequest_exception() throws IOException, Failure {
    AtomicBoolean called = new AtomicBoolean();
    when(impl.test(any(Request.class))).thenAnswer(i -> {
        called.set(true);
        throw Failure.builder()
               .setText("failure")
               .build();
    });

    TestService.Iface client = new TestService.Client(new HttpClientHandler(this::endpoint,
                                                                            factory(),
                                                                            provider));

    try {
        client.test(new Request("request"));
        fail("No exception");
    } catch (Failure ex) {
        assertEquals("failure", ex.getText());
    }

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(instrumentation);
}
 
开发者ID:morimekta,项目名称:providence,代码行数:27,代码来源:ProvidenceServletTest.java

示例7: testThriftClient_void

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testThriftClient_void() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client =
            new net.morimekta.test.thrift.service.TestService.Client(protocol);

    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        return null;
    }).when(impl).voidMethod(55);

    client.voidMethod(55);

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(impl).voidMethod(55);
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(impl, instrumentation);
}
 
开发者ID:morimekta,项目名称:providence,代码行数:23,代码来源:ProvidenceServlet_ThriftClientTest.java

示例8: testThriftClient_oneway

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testThriftClient_oneway() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client =
            new net.morimekta.test.thrift.service.TestService.Client(protocol);

    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        return null;
    }).when(impl).ping();

    client.ping();

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(impl).ping();
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), isNull());
    verifyNoMoreInteractions(impl, instrumentation);
}
 
开发者ID:morimekta,项目名称:providence,代码行数:23,代码来源:ProvidenceServlet_ThriftClientTest.java

示例9: testThriftClient_failure

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testThriftClient_failure() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client =
            new net.morimekta.test.thrift.service.TestService.Client(protocol);

    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        throw new Failure("test");
    }).when(impl).voidMethod(55);

    try {
        client.voidMethod(55);
    } catch (net.morimekta.test.thrift.service.Failure e) {
        assertEquals("test", e.getText());
    }

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(impl).voidMethod(55);
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(impl, instrumentation);
}
 
开发者ID:morimekta,项目名称:providence,代码行数:27,代码来源:ProvidenceServlet_ThriftClientTest.java

示例10: testSimpleRequest

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testSimpleRequest() throws IOException, TException, Failure {
    AtomicBoolean called = new AtomicBoolean();
    when(impl.test(new net.morimekta.test.thrift.thrift.service.Request("test")))
            .thenAnswer(i -> {
                called.set(true);
                return new net.morimekta.test.thrift.thrift.service.Response("response");
            });

    MyService.Iface client = new MyService.Client(new SocketClientHandler(serializer, address));

    Response response = client.test(new Request("test"));

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
    verify(impl).test(any(net.morimekta.test.thrift.thrift.service.Request.class));

    assertThat(response, is(equalToMessage(new Response("response"))));
}
 
开发者ID:morimekta,项目名称:providence,代码行数:19,代码来源:SocketClientHandlerTest.java

示例11: testOnewayRequest

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testOnewayRequest() throws IOException, TException, Failure {
    MyService.Iface client = new MyService.Client(new SocketClientHandler(serializer, address));

    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        return null;
    }).when(impl).ping();

    client.ping();

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(impl).ping();
}
 
开发者ID:morimekta,项目名称:providence,代码行数:17,代码来源:SocketClientHandlerTest.java

示例12: testOnewayRequest

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testOnewayRequest()
        throws IOException, TException, net.morimekta.test.providence.thrift.service.Failure, InterruptedException {
    MyService.Iface client = new MyService.Client(new NonblockingSocketClientHandler(serializer, address));

    AtomicBoolean called = new AtomicBoolean(false);
    doAnswer(i -> {
        called.set(true);
        return null;
    }).when(impl).ping();

    client.ping();

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(impl).ping();
}
 
开发者ID:morimekta,项目名称:providence,代码行数:18,代码来源:NonblockingSocketClientHandlerTest.java

示例13: testOneway

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testOneway() throws IOException, TException, Failure, InterruptedException {
    try (TSocket socket = new TSocket("localhost", port)) {
        socket.open();
        TProtocol protocol = new TBinaryProtocol(socket);
        Client client = new Client(protocol);

        AtomicBoolean called = new AtomicBoolean();
        doAnswer(i -> {
            called.set(true);
            return null;
        }).when(impl).ping();

        client.ping();

        waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

        verify(impl).ping();
        verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), isNull());
        verifyNoMoreInteractions(impl, instrumentation);
    }
}
 
开发者ID:morimekta,项目名称:providence,代码行数:23,代码来源:SocketServerTest.java

示例14: testExpiry

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void testExpiry() throws Exception {
  pipelineStoreTask.create("user", "aaaa", "label","blah", false, false);
  Runner runner = pipelineManager.getRunner("aaaa", "0");
  pipelineStateStore.saveState("user", "aaaa", "0", PipelineStatus.RUNNING_ERROR, "blah", null, ExecutionMode.STANDALONE, null, 0, 0);
  assertEquals(PipelineStatus.RUNNING_ERROR, runner.getState().getStatus());
  pipelineStateStore.saveState("user", "aaaa", "0", PipelineStatus.RUN_ERROR, "blah", null, ExecutionMode.STANDALONE, null, 0, 0);

  pipelineManager.stop();
  pipelineStoreTask.stop();

  pipelineStateStore.saveState("user", "aaaa", "0", PipelineStatus.RUNNING_ERROR, "blah", null, ExecutionMode
      .STANDALONE, null, 0, 0);
  pipelineManager = null;
  setUpManager(100, 0, false);
  await().atMost(Duration.FIVE_SECONDS).until(new Callable<Boolean>() {
    @Override
    public Boolean call() throws Exception {
      return !((StandaloneAndClusterPipelineManager) pipelineManager).isRunnerPresent("aaaa", "0");
    }
  });
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:23,代码来源:TestStandalonePipelineManager.java

示例15: loginAndLogout

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void loginAndLogout() throws Exception {
    final int baselineReplicationLogCount = replicationLogCount();

    // Log in from the 1st replica.
    final AggregatedHttpMessage loginRes = login(replica1, USERNAME, PASSWORD);
    assertThat(loginRes.status()).isEqualTo(HttpStatus.OK);

    // Ensure that only one replication log is produced.
    assertThat(replicationLogCount()).isEqualTo(baselineReplicationLogCount + 1);

    // Ensure authorization works at the 2nd replica.
    final String sessionId = loginRes.content().toStringAscii();
    await().pollDelay(Duration.TWO_HUNDRED_MILLISECONDS)
           .pollInterval(Duration.ONE_SECOND)
           .untilAsserted(() -> assertThat(usersMe(replica2, sessionId).status()).isEqualTo(HttpStatus.OK));

    // Ensure that no replication log is produced.
    assertThat(replicationLogCount()).isEqualTo(baselineReplicationLogCount + 1);

    // Log out from the 1st replica.
    assertThat(logout(replica1, sessionId).status()).isEqualTo(HttpStatus.OK);

    // Ensure that only one replication log is produced.
    assertThat(replicationLogCount()).isEqualTo(baselineReplicationLogCount + 2);

    // Ensure authorization fails at the 2nd replica.
    await().pollDelay(Duration.TWO_HUNDRED_MILLISECONDS)
           .pollInterval(Duration.ONE_SECOND)
           .untilAsserted(() -> assertThat(usersMe(replica2, sessionId).status())
                   .isEqualTo(HttpStatus.UNAUTHORIZED));
}
 
开发者ID:line,项目名称:centraldogma,代码行数:33,代码来源:ReplicatedLoginAndLogoutTest.java


注:本文中的org.awaitility.Duration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。