Search in sources :

Example 1 with HostProvider

use of org.apache.zookeeper.client.HostProvider in project zookeeper by apache.

the class CustomHostProviderTest method testZooKeeperWithCustomHostProvider.

@Test
public void testZooKeeperWithCustomHostProvider() throws IOException, InterruptedException {
    final int CLIENT_PORT = PortAssignment.unique();
    final HostProvider specialHostProvider = new SpecialHostProvider();
    int expectedCounter = 3;
    counter.set(expectedCounter);
    ZooKeeper zkDefaults = new ZooKeeper("127.0.0.1:" + CLIENT_PORT, ClientBase.CONNECTION_TIMEOUT, this, false);
    ZooKeeper zkSpecial = new ZooKeeper("127.0.0.1:" + CLIENT_PORT, ClientBase.CONNECTION_TIMEOUT, this, false, specialHostProvider);
    Assert.assertTrue(counter.get() == expectedCounter);
    zkDefaults.updateServerList("127.0.0.1:" + PortAssignment.unique());
    Assert.assertTrue(counter.get() == expectedCounter);
    zkSpecial.updateServerList("127.0.0.1:" + PortAssignment.unique());
    expectedCounter--;
    Assert.assertTrue(counter.get() == expectedCounter);
}
Also used : HostProvider(org.apache.zookeeper.client.HostProvider) Test(org.junit.Test)

Example 2 with HostProvider

use of org.apache.zookeeper.client.HostProvider in project zookeeper by apache.

the class StaticHostProviderTest method testNextGoesRound.

@Test
public void testNextGoesRound() {
    HostProvider hostProvider = getHostProvider((byte) 2);
    InetSocketAddress first = hostProvider.next(0);
    assertTrue(first != null);
    hostProvider.next(0);
    assertEquals(first, hostProvider.next(0));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) StaticHostProvider(org.apache.zookeeper.client.StaticHostProvider) HostProvider(org.apache.zookeeper.client.HostProvider) Test(org.junit.Test)

Example 3 with HostProvider

use of org.apache.zookeeper.client.HostProvider in project zookeeper by apache.

the class StaticHostProviderTest method testTwoConsequitiveCallsToNextReturnDifferentElement.

@Test
public void testTwoConsequitiveCallsToNextReturnDifferentElement() {
    HostProvider hostProvider = getHostProvider((byte) 2);
    assertNotSame(hostProvider.next(0), hostProvider.next(0));
}
Also used : StaticHostProvider(org.apache.zookeeper.client.StaticHostProvider) HostProvider(org.apache.zookeeper.client.HostProvider) Test(org.junit.Test)

Example 4 with HostProvider

use of org.apache.zookeeper.client.HostProvider in project zookeeper by apache.

the class StaticHostProviderTest method testNextDoesNotSleepForZero.

@Test
public void testNextDoesNotSleepForZero() {
    byte size = 2;
    HostProvider hostProvider = getHostProvider(size);
    while (size > 0) {
        hostProvider.next(0);
        --size;
    }
    long start = Time.currentElapsedTime();
    hostProvider.next(0);
    long stop = Time.currentElapsedTime();
    assertTrue(5 > stop - start);
}
Also used : StaticHostProvider(org.apache.zookeeper.client.StaticHostProvider) HostProvider(org.apache.zookeeper.client.HostProvider) Test(org.junit.Test)

Example 5 with HostProvider

use of org.apache.zookeeper.client.HostProvider in project zookeeper by apache.

the class StaticHostProviderTest method testNextGoesRoundAndSleeps.

@Test
public void testNextGoesRoundAndSleeps() {
    byte size = 2;
    HostProvider hostProvider = getHostProvider(size);
    while (size > 0) {
        hostProvider.next(0);
        --size;
    }
    long start = Time.currentElapsedTime();
    hostProvider.next(1000);
    long stop = Time.currentElapsedTime();
    assertTrue(900 <= stop - start);
}
Also used : StaticHostProvider(org.apache.zookeeper.client.StaticHostProvider) HostProvider(org.apache.zookeeper.client.HostProvider) Test(org.junit.Test)

Aggregations

HostProvider (org.apache.zookeeper.client.HostProvider)14 StaticHostProvider (org.apache.zookeeper.client.StaticHostProvider)12 Test (org.junit.Test)11 InetSocketAddress (java.net.InetSocketAddress)10 IOException (java.io.IOException)3 List (java.util.List)3 ClientCnxn (org.apache.zookeeper.ClientCnxn)3 KeeperException (org.apache.zookeeper.KeeperException)3 ZkException (org.I0Itec.zkclient.exception.ZkException)2 ConnectStringParser (org.apache.zookeeper.client.ConnectStringParser)2 BaseOtterTest (com.alibaba.otter.shared.arbitrate.BaseOtterTest)1 ZkClientx (com.alibaba.otter.shared.common.utils.zookeeper.ZkClientx)1 ZooKeeperx (com.alibaba.otter.shared.common.utils.zookeeper.ZooKeeperx)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 WatchedEvent (org.apache.zookeeper.WatchedEvent)1 Watcher (org.apache.zookeeper.Watcher)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 ZKClientConfig (org.apache.zookeeper.client.ZKClientConfig)1 Stat (org.apache.zookeeper.data.Stat)1