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);
}
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));
}
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));
}
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);
}
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);
}
Aggregations