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


Java Matchers.containsString方法代码示例

本文整理汇总了Java中org.hamcrest.Matchers.containsString方法的典型用法代码示例。如果您正苦于以下问题:Java Matchers.containsString方法的具体用法?Java Matchers.containsString怎么用?Java Matchers.containsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hamcrest.Matchers的用法示例。


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

示例1: testMasterFaultDetectionConnectOnDisconnect

import org.hamcrest.Matchers; //导入方法依赖的package包/类
public void testMasterFaultDetectionConnectOnDisconnect() throws InterruptedException {
    Settings.Builder settings = Settings.builder();
    boolean shouldRetry = randomBoolean();
    ClusterName clusterName = new ClusterName(randomAsciiOfLengthBetween(3, 20));

    // make sure we don't ping
    settings.put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry)
            .put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").put("cluster.name", clusterName.value());

    final ClusterState state = ClusterState.builder(clusterName).nodes(buildNodesForA(false)).build();
    setState(clusterServiceA, state);
    MasterFaultDetection masterFD = new MasterFaultDetection(settings.build(), threadPool, serviceA,
        clusterServiceA);
    masterFD.restart(nodeB, "test");

    final String[] failureReason = new String[1];
    final DiscoveryNode[] failureNode = new DiscoveryNode[1];
    final CountDownLatch notified = new CountDownLatch(1);
    masterFD.addListener((masterNode, cause, reason) -> {
        failureNode[0] = masterNode;
        failureReason[0] = reason;
        notified.countDown();
    });
    // will raise a disconnect on A
    serviceB.stop();
    notified.await(30, TimeUnit.SECONDS);

    CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
    assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));

    assertEquals(nodeB, failureNode[0]);
    Matcher<String> matcher = Matchers.containsString("verified");
    if (!shouldRetry) {
        matcher = Matchers.not(matcher);
    }

    assertThat(failureReason[0], matcher);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:ZenFaultDetectionTests.java

示例2: testNodesFaultDetectionConnectOnDisconnect

import org.hamcrest.Matchers; //导入方法依赖的package包/类
public void testNodesFaultDetectionConnectOnDisconnect() throws InterruptedException {
    boolean shouldRetry = randomBoolean();
    // make sure we don't ping again after the initial ping
    final Settings pingSettings = Settings.builder()
        .put(FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING.getKey(), shouldRetry)
        .put(FaultDetection.PING_INTERVAL_SETTING.getKey(), "5m").build();
    ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(buildNodesForA(true)).build();
    NodesFaultDetection nodesFDA = new NodesFaultDetection(Settings.builder().put(settingsA).put(pingSettings).build(),
        threadPool, serviceA, clusterState.getClusterName());
    nodesFDA.setLocalNode(nodeA);
    NodesFaultDetection nodesFDB = new NodesFaultDetection(Settings.builder().put(settingsB).put(pingSettings).build(),
        threadPool, serviceB, clusterState.getClusterName());
    nodesFDB.setLocalNode(nodeB);
    final CountDownLatch pingSent = new CountDownLatch(1);
    nodesFDB.addListener(new NodesFaultDetection.Listener() {
        @Override
        public void onPingReceived(NodesFaultDetection.PingRequest pingRequest) {
            pingSent.countDown();
        }
    });
    nodesFDA.updateNodesAndPing(clusterState);

    // wait for the first ping to go out, so we will really respond to a disconnect event rather then
    // the ping failing
    pingSent.await(30, TimeUnit.SECONDS);

    final String[] failureReason = new String[1];
    final DiscoveryNode[] failureNode = new DiscoveryNode[1];
    final CountDownLatch notified = new CountDownLatch(1);
    nodesFDA.addListener(new NodesFaultDetection.Listener() {
        @Override
        public void onNodeFailure(DiscoveryNode node, String reason) {
            failureNode[0] = node;
            failureReason[0] = reason;
            notified.countDown();
        }
    });
    // will raise a disconnect on A
    serviceB.stop();
    notified.await(30, TimeUnit.SECONDS);

    CircuitBreaker inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
    assertThat(inFlightRequestsBreaker.getTrippedCount(), equalTo(0L));

    assertEquals(nodeB, failureNode[0]);
    Matcher<String> matcher = Matchers.containsString("verified");
    if (!shouldRetry) {
        matcher = Matchers.not(matcher);
    }

    assertThat(failureReason[0], matcher);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:53,代码来源:ZenFaultDetectionTests.java


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