Search in sources :

Example 6 with ClientConfigurationData

use of org.apache.pulsar.client.impl.conf.ClientConfigurationData in project incubator-pulsar by apache.

the class ClientCnxTest method testClientCnxTimeout.

@Test
public void testClientCnxTimeout() throws Exception {
    EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, new DefaultThreadFactory("testClientCnxTimeout"));
    ClientConfigurationData conf = new ClientConfigurationData();
    conf.setOperationTimeoutMs(10);
    ClientCnx cnx = new ClientCnx(conf, eventLoop);
    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    ChannelFuture listenerFuture = mock(ChannelFuture.class);
    when(listenerFuture.addListener(anyObject())).thenReturn(listenerFuture);
    when(ctx.writeAndFlush(anyObject())).thenReturn(listenerFuture);
    Field ctxField = PulsarHandler.class.getDeclaredField("ctx");
    ctxField.setAccessible(true);
    ctxField.set(cnx, ctx);
    try {
        cnx.newLookup(null, 123).get();
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof PulsarClientException.TimeoutException);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) ChannelFuture(io.netty.channel.ChannelFuture) Field(java.lang.reflect.Field) EventLoopGroup(io.netty.channel.EventLoopGroup) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) Test(org.testng.annotations.Test)

Example 7 with ClientConfigurationData

use of org.apache.pulsar.client.impl.conf.ClientConfigurationData in project incubator-pulsar by apache.

the class ConnectionPoolTest method testSingleIpAddress.

@Test
public void testSingleIpAddress() throws Exception {
    ClientConfigurationData conf = new ClientConfigurationData();
    EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, new DefaultThreadFactory("test"));
    ConnectionPool pool = Mockito.spy(new ConnectionPool(conf, eventLoop));
    conf.setServiceUrl(serviceUrl);
    PulsarClientImpl client = new PulsarClientImpl(conf, eventLoop, pool);
    List<InetAddress> result = Lists.newArrayList();
    result.add(InetAddress.getByName("127.0.0.1"));
    Mockito.when(pool.resolveName("non-existing-dns-name")).thenReturn(CompletableFuture.completedFuture(result));
    client.createProducer("persistent://sample/standalone/ns/my-topic");
    client.close();
}
Also used : ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) EventLoopGroup(io.netty.channel.EventLoopGroup) InetAddress(java.net.InetAddress) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

ClientConfigurationData (org.apache.pulsar.client.impl.conf.ClientConfigurationData)7 Test (org.testng.annotations.Test)4 EventLoopGroup (io.netty.channel.EventLoopGroup)3 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)3 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)3 Field (java.lang.reflect.Field)2 InetAddress (java.net.InetAddress)2 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)2 PulsarAdminWithFunctions (org.apache.pulsar.client.admin.PulsarAdminWithFunctions)2 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Properties (java.util.Properties)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 CreateFunction (org.apache.pulsar.admin.cli.CmdFunctions.CreateFunction)1