本文整理汇总了Java中org.apache.zookeeper.client.HostProvider.onConnected方法的典型用法代码示例。如果您正苦于以下问题:Java HostProvider.onConnected方法的具体用法?Java HostProvider.onConnected怎么用?Java HostProvider.onConnected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.client.HostProvider
的用法示例。
在下文中一共展示了HostProvider.onConnected方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testOnConnectDoesNotReset
import org.apache.zookeeper.client.HostProvider; //导入方法依赖的package包/类
@Test
public void testOnConnectDoesNotReset() throws UnknownHostException {
HostProvider hostProvider = getHostProvider((byte) 2);
InetSocketAddress first = hostProvider.next(0);
hostProvider.onConnected();
InetSocketAddress second = hostProvider.next(0);
assertNotSame(first, second);
}
示例2: testOnConnectDoesNotReset
import org.apache.zookeeper.client.HostProvider; //导入方法依赖的package包/类
@Test
public void testOnConnectDoesNotReset() {
HostProvider hostProvider = getHostProvider((byte) 2);
InetSocketAddress first = hostProvider.next(0);
hostProvider.onConnected();
InetSocketAddress second = hostProvider.next(0);
assertNotSame(first, second);
}
示例3: testOnConnectDoesNotReset
import org.apache.zookeeper.client.HostProvider; //导入方法依赖的package包/类
@Test
public void testOnConnectDoesNotReset() throws UnknownHostException {
HostProvider hostProvider = getHostProvider(2);
InetSocketAddress first = hostProvider.next(0);
hostProvider.onConnected();
InetSocketAddress second = hostProvider.next(0);
assertNotSame(first, second);
}
示例4: testUpdateClientMigrateOrNot
import org.apache.zookeeper.client.HostProvider; //导入方法依赖的package包/类
@Test
public void testUpdateClientMigrateOrNot() throws UnknownHostException {
HostProvider hostProvider = getHostProvider((byte) 4); // 10.10.10.4:1238, 10.10.10.3:1237, 10.10.10.2:1236, 10.10.10.1:1235
Collection<InetSocketAddress> newList = getServerAddresses((byte) 3); // 10.10.10.3:1237, 10.10.10.2:1236, 10.10.10.1:1235
InetSocketAddress myServer = new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, 3}), 1237);
// Number of machines becomes smaller, my server is in the new cluster
boolean disconnectRequired = hostProvider.updateServerList(newList, myServer);
assertTrue(!disconnectRequired);
hostProvider.onConnected();
// Number of machines stayed the same, my server is in the new cluster
disconnectRequired = hostProvider.updateServerList(newList, myServer);
assertTrue(!disconnectRequired);
hostProvider.onConnected();
// Number of machines became smaller, my server is not in the new
// cluster
newList = getServerAddresses((byte) 2); // 10.10.10.2:1236, 10.10.10.1:1235
disconnectRequired = hostProvider.updateServerList(newList, myServer);
assertTrue(disconnectRequired);
hostProvider.onConnected();
// Number of machines stayed the same, my server is not in the new
// cluster
disconnectRequired = hostProvider.updateServerList(newList, myServer);
assertTrue(disconnectRequired);
hostProvider.onConnected();
// Number of machines increased, my server is not in the new cluster
newList = new ArrayList<InetSocketAddress>(3);
for (byte i = 4; i > 1; i--) { // 10.10.10.4:1238, 10.10.10.3:1237, 10.10.10.2:1236
newList.add(new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, i}), 1234 + i));
}
myServer = new InetSocketAddress(InetAddress.getByAddress(new byte[]{10, 10, 10, 1}), 1235);
disconnectRequired = hostProvider.updateServerList(newList, myServer);
assertTrue(disconnectRequired);
hostProvider.onConnected();
// Number of machines increased, my server is in the new cluster
// Here whether to move or not depends on the difference of cluster
// sizes
// With probability 1 - |old|/|new} the client disconnects
// In the test below 1-9/10 = 1/10 chance of disconnecting
HostProvider[] hostProviderArray = new HostProvider[numClients];
newList = getServerAddresses((byte) 10);
int numDisconnects = 0;
for (int i = 0; i < numClients; i++) {
hostProviderArray[i] = getHostProvider((byte) 9);
disconnectRequired = hostProviderArray[i].updateServerList(newList, myServer);
if (disconnectRequired)
numDisconnects++;
}
hostProvider.onConnected();
// should be numClients/10 in expectation, we test that its numClients/10 +- slackPercent
assertTrue(numDisconnects < upperboundCPS(numClients, 10));
}