当前位置: 首页>>代码示例>>Java>>正文


Java HostProvider.onConnected方法代码示例

本文整理汇总了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);
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:9,代码来源:StaticHostProviderTest.java

示例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);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:9,代码来源:StaticHostProviderTest.java

示例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);
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:9,代码来源:StaticHostProviderTest.java

示例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));
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:60,代码来源:StaticHostProviderTest.java


注:本文中的org.apache.zookeeper.client.HostProvider.onConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。