當前位置: 首頁>>代碼示例>>Java>>正文


Java RetryOneTime類代碼示例

本文整理匯總了Java中org.apache.curator.retry.RetryOneTime的典型用法代碼示例。如果您正苦於以下問題:Java RetryOneTime類的具體用法?Java RetryOneTime怎麽用?Java RetryOneTime使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RetryOneTime類屬於org.apache.curator.retry包,在下文中一共展示了RetryOneTime類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: assertPersistEphemeralSequential

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void assertPersistEphemeralSequential() throws Exception {
    zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
    zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    List<String> actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
    assertThat(actual.size(), is(2));
    for (String each : actual) {
        assertThat(each, startsWith("test_ephemeral_sequential"));
    }
    zkRegCenter.close();
    actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
    assertTrue(actual.isEmpty());
    zkRegCenter.init();
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:18,代碼來源:ZookeeperRegistryCenterModifyTest.java

示例2: assertContend

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
@Ignore
public void assertContend() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    ZookeeperElectionService service = new ZookeeperElectionService(HOST_AND_PORT, client, ELECTION_PATH, electionCandidate);
    service.start();
    ElectionCandidate anotherElectionCandidate = mock(ElectionCandidate.class);
    CuratorFramework anotherClient = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    ZookeeperElectionService anotherService = new ZookeeperElectionService("ANOTHER_CLIENT:8899", anotherClient, ELECTION_PATH, anotherElectionCandidate);
    anotherClient.start();
    anotherClient.blockUntilConnected();
    anotherService.start();
    KillSession.kill(client.getZookeeperClient().getZooKeeper(), EmbedTestingServer.getConnectionString());
    service.stop();
    verify(anotherElectionCandidate).startLeadership();
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:19,代碼來源:ZookeeperElectionServiceTest.java

示例3: testZkHealth

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void testZkHealth() throws Exception {

    final CuratorFramework client = newClient(zk.getConnectString(), new RetryOneTime(100));
    client.start();
    client.blockUntilConnected();

    final HealthCheck check = new KafkaHealthCheck(client);
    final HealthCheck.Result res = check.execute();
    assertFalse(res.isHealthy());
    assertTrue(res.getMessage().contains("Error fetching kafka broker list"));

    client.createContainers("/brokers/ids");

    final HealthCheck.Result res2 = check.execute();
    assertFalse(res2.isHealthy());
    assertEquals("No Kafka brokers are connected.", res2.getMessage());

    client.createContainers("/brokers/ids/1");

    final HealthCheck.Result res3 = check.execute();
    assertTrue(res3.isHealthy());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:24,代碼來源:KafkaHealthCheckTest.java

示例4: testZkHealth

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void testZkHealth() throws Exception {
    final CuratorFramework client = newClient(zk.getConnectString(), new RetryOneTime(100));
    client.start();
    client.blockUntilConnected();

    final HealthCheck check = new ZookeeperHealthCheck(client);
    final HealthCheck.Result res = check.execute();
    assertFalse(res.isHealthy());
    assertEquals("Zookeeper not properly initialized", res.getMessage());

    client.createContainers(ZNODE_COORDINATION);

    final HealthCheck.Result res2 = check.execute();
    assertTrue(res2.isHealthy());
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:17,代碼來源:ZookeeperHealthCheckTest.java

示例5: doEvaluate

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
void doEvaluate(Statement base) throws Throwable {
  try {
    cluster = new TestingCluster(3);
    cluster.start();

    client = newClient(cluster.getConnectString(), new RetryOneTime(200 /* ms */));
    client.start();

    checkState(client.blockUntilConnected(5, TimeUnit.SECONDS),
        "failed to connect to zookeeper in 5 seconds");

    base.evaluate();
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw new IllegalStateException("Interrupted while connecting to ZooKeeper", e);
  } finally {
    client.close();
    cluster.close();
  }
}
 
開發者ID:liaominghua,項目名稱:zipkin,代碼行數:21,代碼來源:ZooKeeperRule.java

示例6: startZookeeper

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Before
public void startZookeeper() throws Exception {
  zkTestServer = new TestingServer(2181);
  cli = CuratorFrameworkFactory.newClient(zkTestServer.getConnectString(), new RetryOneTime(2000));
  cli.start();

  discovery = ServiceDiscoveryBuilder.builder(String.class)
      .client(cli)
      .basePath("/discovery")
      .watchInstances(true)
      .build();

  discovery.start();
  vertx = Vertx.vertx();
  sd = io.vertx.servicediscovery.ServiceDiscovery.create(vertx);
}
 
開發者ID:vert-x3,項目名稱:vertx-service-discovery,代碼行數:17,代碼來源:ZookeeperBridgeTest.java

示例7: assertPersistEphemeralSequential

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void assertPersistEphemeralSequential() throws Exception {
    zkRegCenter.persistEphemeralSequential("/sequential/test_sequential");
    zkRegCenter.persistEphemeralSequential("/sequential/test_sequential");
    CuratorFramework client = CuratorFrameworkFactory.newClient(ZK_CONNECTION_STRING, new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    List<String> actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
    assertThat(actual.size(), is(2));
    for (String each : actual) {
        assertThat(each, startsWith("test_sequential"));
    }
    zkRegCenter.close();
    actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
    assertTrue(actual.isEmpty());
    zkRegCenter.init();
}
 
開發者ID:artoderk,項目名稱:elastic-jobx,代碼行數:18,代碼來源:ZookeeperRegistryCenterModifyTest.java

示例8: run

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Override
public void run(T configuration, Environment environment) throws Exception
{
    CuratorConfiguration curatorConfiguration = ComposedConfigurationAccessor.access(configuration, environment, CuratorConfiguration.class);
    // TODO more config
    final CuratorFramework curator = CuratorFrameworkFactory.newClient(curatorConfiguration.getConnectionString(), new RetryOneTime(1));

    Managed managed = new Managed()
    {
        @Override
        public void start() throws Exception
        {
            curator.start();
        }

        @Override
        public void stop() throws Exception
        {
            CloseableUtils.closeQuietly(curator);
        }
    };
    environment.lifecycle().manage(managed);

    SoaBundle.getFeatures(environment).putNamed(curator, CuratorFramework.class, curatorConfiguration.getCuratorName());
}
 
開發者ID:soabase,項目名稱:soabase,代碼行數:26,代碼來源:CuratorBundle.java

示例9: testSetSerializer

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void testSetSerializer() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    ServiceDiscoveryBuilder<Object> builder = ServiceDiscoveryBuilder.builder(Object.class).client(client);
    builder.serializer(new InstanceSerializer<Object>()
    {
        @Override
        public byte[] serialize(ServiceInstance<Object> instance)
        {
            return null;
        }

        @Override
        public ServiceInstance<Object> deserialize(byte[] bytes)
        {
            return null;
        }
    });

    ServiceDiscoveryImpl<?> discovery = (ServiceDiscoveryImpl<?>) builder.basePath("/path").build();
    Assert.assertNotNull(discovery.getSerializer(), "default serializer not set");
    Assert.assertFalse(discovery.getSerializer() instanceof JsonInstanceSerializer, "set serializer is JSON");
}
 
開發者ID:apache,項目名稱:curator,代碼行數:25,代碼來源:TestServiceDiscoveryBuilder.java

示例10: testBasic

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void    testBasic() throws Exception
{
    ZooKeeper               client = mock(ZooKeeper.class, Mockito.RETURNS_MOCKS);
    CuratorZookeeperClient  curator = mock(CuratorZookeeperClient.class);
    RetryPolicy             retryPolicy = new RetryOneTime(1);
    RetryLoop               retryLoop = new RetryLoop(retryPolicy, null);
    when(curator.getConnectionHandlingPolicy()).thenReturn(new StandardConnectionHandlingPolicy());
    when(curator.getZooKeeper()).thenReturn(client);
    when(curator.getRetryPolicy()).thenReturn(retryPolicy);
    when(curator.newRetryLoop()).thenReturn(retryLoop);

    Stat                    fakeStat = mock(Stat.class);
    when(client.exists(Mockito.<String>any(), anyBoolean())).thenReturn(fakeStat);
    
    EnsurePath      ensurePath = new EnsurePath("/one/two/three");
    ensurePath.ensure(curator);

    verify(client, times(3)).exists(Mockito.<String>any(), anyBoolean());

    ensurePath.ensure(curator);
    verifyNoMoreInteractions(client);
    ensurePath.ensure(curator);
    verifyNoMoreInteractions(client);
}
 
開發者ID:apache,項目名稱:curator,代碼行數:26,代碼來源:TestEnsurePath.java

示例11: testSimultaneous

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void     testSimultaneous() throws Exception
{
    CuratorFramework    client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        CuratorFramework fooClient = client.usingNamespace("foo");
        CuratorFramework barClient = client.usingNamespace("bar");

        fooClient.create().forPath("/one");
        barClient.create().forPath("/one");

        Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/foo/one", false));
        Assert.assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/bar/one", false));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:23,代碼來源:TestNamespaceFacade.java

示例12: testBasic

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void testBasic() throws Exception
{
    CuratorTempFramework        client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).buildTemp();
    try
    {
        client.inTransaction().create().forPath("/foo", "data".getBytes()).and().commit();

        byte[] bytes = client.getData().forPath("/foo");
        Assert.assertEquals(bytes, "data".getBytes());
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:17,代碼來源:TestTempFramework.java

示例13: testSetData

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void testSetData() throws Exception
{
    final byte[]            data = "here's a string".getBytes();

    CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        client.create().creatingParentsIfNeeded().forPath("/a/b/c", data);
        Assert.assertEquals(data, client.getData().forPath("/a/b/c"));

        client.setData().compressed().forPath("/a/b/c", data);
        Assert.assertEquals(data.length, client.getData().decompressed().forPath("/a/b/c").length);
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:22,代碼來源:TestCompression.java

示例14: testQuickCloseNodeExists

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void testQuickCloseNodeExists() throws Exception
{
    Timing timing = new Timing();
    PersistentNode pen = null;
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    try
    {
        client.start();
        client.create().creatingParentsIfNeeded().forPath("/test/one/two");

        pen = new PersistentNode(client, CreateMode.PERSISTENT, false, "/test/one/two", new byte[0]);
        pen.start();
        pen.close();
        timing.sleepABit();
        Assert.assertNull(client.checkExists().forPath("/test/one/two"));
    }
    finally
    {
        CloseableUtils.closeQuietly(pen);
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:24,代碼來源:TestPersistentNode.java

示例15: testZKWatcher

import org.apache.curator.retry.RetryOneTime; //導入依賴的package包/類
@Test
public void testZKWatcher() throws Exception
{
    Timing timing = new Timing();
    CountZKWatcher watcher = new CountZKWatcher();
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    try
    {
        client.start();
        client.create().forPath(PATH);
        // Add twice the same watcher on the same path
        client.getData().usingWatcher(watcher).forPath(PATH);
        client.getData().usingWatcher(watcher).forPath(PATH);
        // Ok, let's test it
        client.setData().forPath(PATH, new byte[]{});
        timing.sleepABit();
        Assert.assertEquals(1, watcher.count.get());
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:24,代碼來源:TestWatcherIdentity.java


注:本文中的org.apache.curator.retry.RetryOneTime類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。