Java Code Examples for org.apache.curator.CuratorZookeeperClient#start()

The following examples show how to use org.apache.curator.CuratorZookeeperClient#start() . 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: MetricCollectorHATest.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmbeddedModeCollectorZK() throws Exception {


  BoundedExponentialBackoffRetry retryPolicyMock = PowerMock.createMock(BoundedExponentialBackoffRetry.class);
  expectNew(BoundedExponentialBackoffRetry.class, 1000, 10000, 1).andReturn(retryPolicyMock);

  CuratorZookeeperClient clientMock = PowerMock.createMock(CuratorZookeeperClient.class);
  expectNew(CuratorZookeeperClient.class, "zkQ", 10000, 2000, null, retryPolicyMock)
    .andReturn(clientMock);

  clientMock.start();
  expectLastCall().once();

  clientMock.close();
  expectLastCall().once();

  ZooKeeper zkMock = PowerMock.createMock(ZooKeeper.class);
  expect(clientMock.getZooKeeper()).andReturn(zkMock).once();

  expect(zkMock.exists("/ambari-metrics-cluster", false)).andReturn(null).once();

  replayAll();
  MetricCollectorHAHelper metricCollectorHAHelper = new MetricCollectorHAHelper("zkQ", 1, 1000);
  Collection<String> liveInstances = metricCollectorHAHelper.findLiveCollectorHostsFromZNode();
  verifyAll();
  Assert.assertTrue(liveInstances.isEmpty());
}
 
Example 2
Source File: TestExhibitorEnsembleProvider.java    From xian with Apache License 2.0 5 votes vote down vote up
@Test
public void     testSimple() throws Exception
{
    Exhibitors                  exhibitors = new Exhibitors(Lists.newArrayList("foo", "bar"), 1000, dummyConnectionStringProvider);
    ExhibitorRestClient         mockRestClient = new ExhibitorRestClient()
    {
        @Override
        public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception
        {
            return "count=1&port=" + server.getPort() + "&server0=localhost";
        }
    };
    ExhibitorEnsembleProvider   provider = new ExhibitorEnsembleProvider(exhibitors, mockRestClient, "/foo", 10, new RetryOneTime(1));
    provider.pollForInitialEnsemble();

    Timing                      timing = new Timing();
    CuratorZookeeperClient      client = new CuratorZookeeperClient(provider, timing.session(), timing.connection(), null, new ExponentialBackoffRetry(timing.milliseconds(), 3));
    client.start();
    try
    {
        client.blockUntilConnectedOrTimedOut();
        client.getZooKeeper().exists("/", false);
    }
    catch ( Exception e )
    {
        Assert.fail("provider.getConnectionString(): " + provider.getConnectionString() + " server.getPort(): " + server.getPort(), e);
    }
    finally
    {
        client.close();
    }
}
 
Example 3
Source File: ZooKeeperServerResource.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected void before() throws Throwable {
  testingServer = new TestingServer(true);
  zkClient = new CuratorZookeeperClient(testingServer.getConnectString(), 5000, 5000, null, new RetryOneTime(1000));
  zkClient.start();
  zkClient.blockUntilConnectedOrTimedOut();
}
 
Example 4
Source File: TestExhibitorEnsembleProvider.java    From xian with Apache License 2.0 4 votes vote down vote up
@Test
public void     testChanging() throws Exception
{
    TestingServer               secondServer = new TestingServer();
    try
    {
        String                          mainConnectionString = "count=1&port=" + server.getPort() + "&server0=localhost";
        String                          secondConnectionString = "count=1&port=" + secondServer.getPort() + "&server0=localhost";

        final Semaphore                 semaphore = new Semaphore(0);
        final AtomicReference<String>   connectionString = new AtomicReference<String>(mainConnectionString);
        Exhibitors                      exhibitors = new Exhibitors(Lists.newArrayList("foo", "bar"), 1000, dummyConnectionStringProvider);
        ExhibitorRestClient             mockRestClient = new ExhibitorRestClient()
        {
            @Override
            public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception
            {
                semaphore.release();
                return connectionString.get();
            }
        };
        ExhibitorEnsembleProvider   provider = new ExhibitorEnsembleProvider(exhibitors, mockRestClient, "/foo", 10, new RetryOneTime(1));
        provider.pollForInitialEnsemble();

        Timing                          timing = new Timing().multiple(4);
        final CuratorZookeeperClient    client = new CuratorZookeeperClient(provider, timing.session(), timing.connection(), null, new RetryOneTime(2));
        client.start();
        try
        {
            RetryLoop.callWithRetry
            (
                client,
                new Callable<Object>()
                {
                    @Override
                    public Object call() throws Exception
                    {
                        client.getZooKeeper().create("/test", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                        return null;
                    }
                }
            );

            connectionString.set(secondConnectionString);
            semaphore.drainPermits();
            semaphore.acquire();

            server.stop();  // create situation where the current zookeeper gets a sys-disconnected

            Stat        stat = RetryLoop.callWithRetry
            (
                client,
                new Callable<Stat>()
                {
                    @Override
                    public Stat call() throws Exception
                    {
                        return client.getZooKeeper().exists("/test", false);
                    }
                }
            );
            Assert.assertNull(stat);    // it's a different server so should be null
        }
        finally
        {
            client.close();
        }
    }
    finally
    {
        CloseableUtils.closeQuietly(secondServer);
    }
}