• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Duration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: doWorkInThread

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void doWorkInThread() throws Exception {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();

    Assert.assertEquals(0, blockchain.getBestBlock().getNumber());

    MinerServerImpl minerServer = getMinerServer(blockchain);
    MinerClientImpl minerClient = getMinerClient(minerServer);

    minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
    Thread thread = minerClient.createDoWorkThread();
    thread.start();
    try {

        Awaitility.await().timeout(Duration.FIVE_SECONDS).until(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                return minerClient.isMining();
            }
        });

        Assert.assertTrue(minerClient.isMining());
    } finally {
        thread.interrupt(); // enought ?
        minerClient.stop();
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:29,代码来源:MinerManagerTest.java


示例17: contextTransfersOneHopAsync

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void contextTransfersOneHopAsync() throws Exception {
    Metadata.Key<String> ctxKey = Metadata.Key.of("ctx-context-key", Metadata.ASCII_STRING_MARSHALLER);
    String expectedCtxValue = "context-value";
    AtomicReference<String> ctxValue = new AtomicReference<>();

    // Service
    GreeterGrpc.GreeterImplBase svc = new GreeterGrpc.GreeterImplBase() {
        @Override
        public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
            ctxValue.set(AmbientContext.current().get(ctxKey));
            responseObserver.onNext(HelloResponse.newBuilder().setMessage("Hello " + request.getName()).build());
            responseObserver.onCompleted();
        }
    };

    // Plumbing
    serverRule1.getServiceRegistry().addService(ServerInterceptors
            .intercept(svc, new AmbientContextServerInterceptor("ctx-")));
    GreeterGrpc.GreeterFutureStub stub = GreeterGrpc
            .newFutureStub(serverRule1.getChannel())
            .withInterceptors(new AmbientContextClientInterceptor("ctx-"));

    // Test
    AmbientContext.initialize(Context.current()).run(() -> {
        AmbientContext.current().put(ctxKey, expectedCtxValue);
        ListenableFuture<HelloResponse> futureResponse = stub.sayHello(HelloRequest.newBuilder().setName("world").build());

        // Verify response callbacks still have context
        MoreFutures.onSuccess(
                futureResponse,
                response -> assertThat(AmbientContext.current().get(ctxKey)).isEqualTo(expectedCtxValue),
                Context.currentContextExecutor(Executors.newSingleThreadExecutor()));

        await().atMost(Duration.ONE_SECOND).until(futureResponse::isDone);
    });

    assertThat(ctxValue.get()).isEqualTo(expectedCtxValue);
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:40,代码来源:AmbientContextTransferTest.java


示例18: after

import org.awaitility.Duration; //导入依赖的package包/类
@Override
protected void after() {
    server.stop();
    // server.stop is not instantaneous
    Awaitility.await().atMost(Duration.FIVE_SECONDS).until(() -> {
        try {
            getTarget("/").request().get();
        } catch (ProcessingException e) {
            return true;
        }
        return false;
    });
    client.close();
    CookieHandler.setDefault(null);
}
 
开发者ID:pac4j,项目名称:jax-rs-pac4j,代码行数:16,代码来源:RestEasyUndertowServletRule.java


示例19: test_metric_field_does_not_exist_is_not_stored

import org.awaitility.Duration; //导入依赖的package包/类
@Test
public void test_metric_field_does_not_exist_is_not_stored() {
  json ()
    .remove ("@metric") // Remove field that is used to create metric
    .<JsonEvent>toObservable ()
    .flatMap (graphite ("@timestamp", "ISO_8601"))
    .toBlocking ().subscribe ();

  await ().timeout (Duration.ONE_SECOND).until (() -> receivedMetrics.size () == 0);
}
 
开发者ID:sonyxperiadev,项目名称:lumber-mill,代码行数:11,代码来源:GraphiteCarbonTest.java


示例20: waitUntilReady

import org.awaitility.Duration; //导入依赖的package包/类
void waitUntilReady()
{
    System.out.println( ">> Riak HealthCheck BEGIN" );
    Instant start = Instant.now();
    Awaitility.await()
              .pollDelay( Duration.ZERO )
              .pollInterval( Duration.ONE_SECOND )
              .timeout( Duration.ONE_MINUTE )
              .until( new HealthCheck() );
    System.out.println( ">> Riak HealthCheck END, took " + java.time.Duration.between( start, Instant.now() ) );
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:12,代码来源:RiakFixture.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CloudantClient类代码示例发布时间:2022-05-21
下一篇:
Java RSASSAVerifier类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap