Search in sources :

Example 1 with ZKClientConfig

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

the class ClientCnxnSocketTest method testWhenInvalidJuteMaxBufferIsConfiguredIOExceptionIsThrown.

@Test
public void testWhenInvalidJuteMaxBufferIsConfiguredIOExceptionIsThrown() {
    ZKClientConfig clientConfig = new ZKClientConfig();
    String value = "SomeInvalidInt";
    clientConfig.setProperty(ZKConfig.JUTE_MAXBUFFER, value);
    // verify ClientCnxnSocketNIO creation
    try {
        new ClientCnxnSocketNIO(clientConfig);
        fail("IOException is expected.");
    } catch (IOException e) {
        assertTrue(e.getMessage().contains(value));
    }
    // verify ClientCnxnSocketNetty creation
    try {
        new ClientCnxnSocketNetty(clientConfig);
        fail("IOException is expected.");
    } catch (IOException e) {
        assertTrue(e.getMessage().contains(value));
    }
}
Also used : ZKClientConfig(org.apache.zookeeper.client.ZKClientConfig) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with ZKClientConfig

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

the class ClientReconnectTest method testClientReconnect.

@Test
public void testClientReconnect() throws IOException, InterruptedException {
    HostProvider hostProvider = mock(HostProvider.class);
    when(hostProvider.size()).thenReturn(1);
    InetSocketAddress inaddr = new InetSocketAddress("127.0.0.1", 1111);
    when(hostProvider.next(anyLong())).thenReturn(inaddr);
    ZooKeeper zk = mock(ZooKeeper.class);
    when(zk.getClientConfig()).thenReturn(new ZKClientConfig());
    sc = SocketChannel.open();
    ClientCnxnSocketNIO nioCnxn = new MockCnxn();
    ClientWatchManager watcher = mock(ClientWatchManager.class);
    ClientCnxn clientCnxn = new ClientCnxn("tmp", hostProvider, 5000, zk, watcher, nioCnxn, false);
    clientCnxn.start();
    countDownLatch.await(5000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(countDownLatch.getCount() == 0);
    clientCnxn.close();
}
Also used : ZKClientConfig(org.apache.zookeeper.client.ZKClientConfig) InetSocketAddress(java.net.InetSocketAddress) HostProvider(org.apache.zookeeper.client.HostProvider) Test(org.junit.Test)

Aggregations

ZKClientConfig (org.apache.zookeeper.client.ZKClientConfig)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 HostProvider (org.apache.zookeeper.client.HostProvider)1