Search in sources :

Example 1 with CuratorZookeeperClient

use of org.apache.curator.CuratorZookeeperClient in project hadoop by apache.

the class TestLeaderElectorService method testExpireCurrentZKSession.

// 1. rm1 active
// 2. kill the zk session between the rm and zk cluster.
// 3. rm1 will first relinquish leadership and re-acquire leadership
@Test
public void testExpireCurrentZKSession() throws Exception {
    rm1 = startRM("rm1", HAServiceState.ACTIVE);
    CuratorBasedElectorService service = (CuratorBasedElectorService) rm1.getRMContext().getLeaderElectorService();
    CuratorZookeeperClient client = service.getCuratorClient().getZookeeperClient();
    // this will expire current curator client session. curator will re-establish
    // the session. RM will first relinquish leadership and re-acquire leadership
    KillSession.kill(client.getZooKeeper(), client.getCurrentConnectionString());
    waitFor(rm1, HAServiceState.ACTIVE);
}
Also used : CuratorZookeeperClient(org.apache.curator.CuratorZookeeperClient) Test(org.junit.Test)

Example 2 with CuratorZookeeperClient

use of org.apache.curator.CuratorZookeeperClient in project nakadi by zalando.

the class KafkaRepositoryAT method createKafkaTopicRepository.

private KafkaTopicRepository createKafkaTopicRepository() {
    final CuratorZookeeperClient zookeeperClient = mock(CuratorZookeeperClient.class);
    when(zookeeperClient.getCurrentConnectionString()).thenReturn(ZOOKEEPER_URL);
    final CuratorFramework curatorFramework = mock(CuratorFramework.class);
    when(curatorFramework.getZookeeperClient()).thenReturn(zookeeperClient);
    final ZooKeeperHolder zooKeeperHolder = mock(ZooKeeperHolder.class);
    when(zooKeeperHolder.get()).thenReturn(curatorFramework);
    final Consumer<byte[], byte[]> consumer = mock(Consumer.class);
    when(consumer.partitionsFor(any())).thenReturn(new ArrayList<>());
    final KafkaFactory factory = mock(KafkaFactory.class);
    when(factory.getConsumer()).thenReturn(consumer);
    Mockito.doReturn(kafkaHelper.createProducer()).when(factory).takeProducer();
    return new KafkaTopicRepository(zooKeeperHolder, factory, nakadiSettings, kafkaSettings, zookeeperSettings, new UUIDGenerator());
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorZookeeperClient(org.apache.curator.CuratorZookeeperClient) UUIDGenerator(org.zalando.nakadi.util.UUIDGenerator) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder)

Example 3 with CuratorZookeeperClient

use of org.apache.curator.CuratorZookeeperClient in project xian by happyyangyuan.

the class TestExhibitorEnsembleProvider method testChanging.

@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();
            // create situation where the current zookeeper gets a sys-disconnected
            server.stop();
            Stat stat = RetryLoop.callWithRetry(client, new Callable<Stat>() {

                @Override
                public Stat call() throws Exception {
                    return client.getZooKeeper().exists("/test", false);
                }
            });
            // it's a different server so should be null
            Assert.assertNull(stat);
        } finally {
            client.close();
        }
    } finally {
        CloseableUtils.closeQuietly(secondServer);
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) RetryOneTime(org.apache.curator.retry.RetryOneTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) Stat(org.apache.zookeeper.data.Stat) CuratorZookeeperClient(org.apache.curator.CuratorZookeeperClient) Timing(org.apache.curator.test.Timing) Test(org.testng.annotations.Test)

Example 4 with CuratorZookeeperClient

use of org.apache.curator.CuratorZookeeperClient in project xian by happyyangyuan.

the class TestExhibitorEnsembleProvider method testSimple.

@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();
    }
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CuratorZookeeperClient(org.apache.curator.CuratorZookeeperClient) Timing(org.apache.curator.test.Timing) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 5 with CuratorZookeeperClient

use of org.apache.curator.CuratorZookeeperClient in project phoenix by apache.

the class LoadBalancerEnd2EndIT method testZookeeperDown.

@Test(expected = Exception.class)
public void testZookeeperDown() throws Exception {
    testingServer.stop();
    CuratorZookeeperClient zookeeperClient = curatorFramework.getZookeeperClient();
    // check to see if zookeeper is really down.
    while (zookeeperClient.isConnected()) {
        Thread.sleep(1000);
    }
    ;
    loadBalancer.getSingleServiceLocation();
}
Also used : CuratorZookeeperClient(org.apache.curator.CuratorZookeeperClient)

Aggregations

CuratorZookeeperClient (org.apache.curator.CuratorZookeeperClient)10 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 Stat (org.apache.zookeeper.data.Stat)3 IOException (java.io.IOException)2 Listenable (org.apache.curator.framework.listen.Listenable)2 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)2 RetryOneTime (org.apache.curator.retry.RetryOneTime)2 Timing (org.apache.curator.test.Timing)2 ZooKeeper (org.apache.zookeeper.ZooKeeper)2 Test (org.junit.Test)2 Test (org.testng.annotations.Test)2 UnavailableException (alluxio.exception.status.UnavailableException)1 EventStreamClientFactory (io.pravega.client.EventStreamClientFactory)1 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)1 EventProcessorConfig (io.pravega.controller.eventProcessor.EventProcessorConfig)1 EventProcessorGroup (io.pravega.controller.eventProcessor.EventProcessorGroup)1 EventProcessorSystem (io.pravega.controller.eventProcessor.EventProcessorSystem)1 ContainerBalancer (io.pravega.controller.fault.ContainerBalancer)1 SegmentContainerMonitor (io.pravega.controller.fault.SegmentContainerMonitor)1 CheckpointStore (io.pravega.controller.store.checkpoint.CheckpointStore)1