Search in sources :

Example 1 with HttpLookupService

use of org.apache.pulsar.client.impl.HttpLookupService in project pulsar by apache.

the class SimpleSchemaTest method testGetSchemaByVersion.

@Test
public void testGetSchemaByVersion() throws PulsarClientException, PulsarAdminException, ExecutionException, InterruptedException {
    final String topic = "persistent://my-property/my-ns/testGetSchemaByVersion";
    @Cleanup PulsarClientImpl httpProtocolClient = (PulsarClientImpl) PulsarClient.builder().serviceUrl(brokerUrl.toString()).build();
    PulsarClientImpl binaryProtocolClient = (PulsarClientImpl) pulsarClient;
    pulsarClient.newProducer(Schema.AVRO(V1Data.class)).topic(topic).create();
    pulsarClient.newProducer(Schema.AVRO(V2Data.class)).topic(topic).create();
    LookupService httpLookupService = httpProtocolClient.getLookup();
    LookupService binaryLookupService = binaryProtocolClient.getLookup();
    Assert.assertTrue(httpLookupService instanceof HttpLookupService);
    Assert.assertTrue(binaryLookupService instanceof BinaryProtoLookupService);
    Assert.assertEquals(admin.schemas().getAllSchemas(topic).size(), 2);
    Assert.assertTrue(httpLookupService.getSchema(TopicName.get(topic), ByteBuffer.allocate(8).putLong(0).array()).get().isPresent());
    Assert.assertTrue(httpLookupService.getSchema(TopicName.get(topic), ByteBuffer.allocate(8).putLong(1).array()).get().isPresent());
    Assert.assertTrue(binaryLookupService.getSchema(TopicName.get(topic), ByteBuffer.allocate(8).putLong(0).array()).get().isPresent());
    Assert.assertTrue(binaryLookupService.getSchema(TopicName.get(topic), ByteBuffer.allocate(8).putLong(1).array()).get().isPresent());
}
Also used : BinaryProtoLookupService(org.apache.pulsar.client.impl.BinaryProtoLookupService) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) LookupService(org.apache.pulsar.client.impl.LookupService) BinaryProtoLookupService(org.apache.pulsar.client.impl.BinaryProtoLookupService) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) Cleanup(lombok.Cleanup) Test(org.testng.annotations.Test)

Example 2 with HttpLookupService

use of org.apache.pulsar.client.impl.HttpLookupService in project pulsar by apache.

the class PulsarMultiListenersWithInternalListenerNameTest method testHttpLookupRedirect.

@Test
public void testHttpLookupRedirect() throws Exception {
    admin.clusters().createCluster("localhost", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
    TenantInfo tenantInfo = TenantInfo.builder().allowedClusters(Collections.singleton("localhost")).build();
    this.admin.tenants().createTenant("public", tenantInfo);
    this.admin.namespaces().createNamespace("public/default");
    ClientConfigurationData conf = new ClientConfigurationData();
    conf.setListenerName("internal");
    conf.setServiceUrl(pulsar.getWebServiceAddress());
    conf.setMaxLookupRedirects(10);
    @Cleanup HttpLookupService lookupService = new HttpLookupService(conf, eventExecutors);
    NamespaceService namespaceService = pulsar.getNamespaceService();
    LookupResult lookupResult = new LookupResult(pulsar.getWebServiceAddress(), null, pulsar.getBrokerServiceUrl(), null, true);
    Optional<LookupResult> optional = Optional.of(lookupResult);
    InetSocketAddress address = InetSocketAddress.createUnresolved("192.168.0.1", 8080);
    NamespaceEphemeralData namespaceEphemeralData = new NamespaceEphemeralData("pulsar://" + address.getHostName() + ":" + address.getPort(), null, "http://192.168.0.1:8081", null, false);
    LookupResult lookupResult2 = new LookupResult(namespaceEphemeralData);
    Optional<LookupResult> optional2 = Optional.of(lookupResult2);
    doReturn(CompletableFuture.completedFuture(optional), CompletableFuture.completedFuture(optional2)).when(namespaceService).getBrokerServiceUrlAsync(any(), any());
    CompletableFuture<Pair<InetSocketAddress, InetSocketAddress>> future = lookupService.getBroker(TopicName.get("persistent://public/default/test"));
    Pair<InetSocketAddress, InetSocketAddress> result = future.get(10, TimeUnit.SECONDS);
    Assert.assertEquals(result.getKey(), address);
    Assert.assertEquals(result.getValue(), address);
}
Also used : ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) InetSocketAddress(java.net.InetSocketAddress) LookupResult(org.apache.pulsar.broker.lookup.LookupResult) TenantInfo(org.apache.pulsar.common.policies.data.TenantInfo) Cleanup(lombok.Cleanup) NamespaceEphemeralData(org.apache.pulsar.broker.namespace.NamespaceEphemeralData) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 3 with HttpLookupService

use of org.apache.pulsar.client.impl.HttpLookupService in project pulsar by apache.

the class PulsarMultiListenersWithInternalListenerNameTest method doFindBrokerWithListenerName.

private void doFindBrokerWithListenerName(boolean useHttp) throws Exception {
    ClientConfigurationData conf = new ClientConfigurationData();
    conf.setListenerName("internal");
    conf.setServiceUrl(pulsar.getWebServiceAddress());
    conf.setMaxLookupRedirects(10);
    @Cleanup LookupService lookupService = useHttp ? new HttpLookupService(conf, eventExecutors) : new BinaryProtoLookupService((PulsarClientImpl) this.pulsarClient, lookupUrl.toString(), "internal", false, this.executorService);
    // test request 1
    {
        CompletableFuture<Pair<InetSocketAddress, InetSocketAddress>> future = lookupService.getBroker(TopicName.get("persistent://public/default/test"));
        Pair<InetSocketAddress, InetSocketAddress> result = future.get(10, TimeUnit.SECONDS);
        Assert.assertEquals(result.getKey(), brokerAddress);
        Assert.assertEquals(result.getValue(), brokerAddress);
    }
    // test request 2
    {
        CompletableFuture<Pair<InetSocketAddress, InetSocketAddress>> future = lookupService.getBroker(TopicName.get("persistent://public/default/test"));
        Pair<InetSocketAddress, InetSocketAddress> result = future.get(10, TimeUnit.SECONDS);
        Assert.assertEquals(result.getKey(), brokerAddress);
        Assert.assertEquals(result.getValue(), brokerAddress);
    }
}
Also used : ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) BinaryProtoLookupService(org.apache.pulsar.client.impl.BinaryProtoLookupService) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) CompletableFuture(java.util.concurrent.CompletableFuture) LookupService(org.apache.pulsar.client.impl.LookupService) BinaryProtoLookupService(org.apache.pulsar.client.impl.BinaryProtoLookupService) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) InetSocketAddress(java.net.InetSocketAddress) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) Cleanup(lombok.Cleanup) Pair(org.apache.commons.lang3.tuple.Pair)

Example 4 with HttpLookupService

use of org.apache.pulsar.client.impl.HttpLookupService in project pulsar by yahoo.

the class PulsarMultiListenersWithInternalListenerNameTest method doFindBrokerWithListenerName.

private void doFindBrokerWithListenerName(boolean useHttp) throws Exception {
    ClientConfigurationData conf = new ClientConfigurationData();
    conf.setListenerName("internal");
    conf.setServiceUrl(pulsar.getWebServiceAddress());
    conf.setMaxLookupRedirects(10);
    @Cleanup LookupService lookupService = useHttp ? new HttpLookupService(conf, eventExecutors) : new BinaryProtoLookupService((PulsarClientImpl) this.pulsarClient, lookupUrl.toString(), "internal", false, this.executorService);
    // test request 1
    {
        CompletableFuture<Pair<InetSocketAddress, InetSocketAddress>> future = lookupService.getBroker(TopicName.get("persistent://public/default/test"));
        Pair<InetSocketAddress, InetSocketAddress> result = future.get(10, TimeUnit.SECONDS);
        Assert.assertEquals(result.getKey(), brokerAddress);
        Assert.assertEquals(result.getValue(), brokerAddress);
    }
    // test request 2
    {
        CompletableFuture<Pair<InetSocketAddress, InetSocketAddress>> future = lookupService.getBroker(TopicName.get("persistent://public/default/test"));
        Pair<InetSocketAddress, InetSocketAddress> result = future.get(10, TimeUnit.SECONDS);
        Assert.assertEquals(result.getKey(), brokerAddress);
        Assert.assertEquals(result.getValue(), brokerAddress);
    }
}
Also used : ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) BinaryProtoLookupService(org.apache.pulsar.client.impl.BinaryProtoLookupService) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) CompletableFuture(java.util.concurrent.CompletableFuture) LookupService(org.apache.pulsar.client.impl.LookupService) BinaryProtoLookupService(org.apache.pulsar.client.impl.BinaryProtoLookupService) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) InetSocketAddress(java.net.InetSocketAddress) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) Cleanup(lombok.Cleanup) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with HttpLookupService

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

the class SimpleSchemaTest method testGetSchemaByVersion.

@Test
public void testGetSchemaByVersion() throws PulsarClientException, PulsarAdminException, ExecutionException, InterruptedException {
    final String topic = "persistent://my-property/my-ns/testGetSchemaByVersion";
    @Cleanup PulsarClientImpl httpProtocolClient = (PulsarClientImpl) PulsarClient.builder().serviceUrl(brokerUrl.toString()).build();
    PulsarClientImpl binaryProtocolClient = (PulsarClientImpl) pulsarClient;
    pulsarClient.newProducer(Schema.AVRO(V1Data.class)).topic(topic).create();
    pulsarClient.newProducer(Schema.AVRO(V2Data.class)).topic(topic).create();
    LookupService httpLookupService = httpProtocolClient.getLookup();
    LookupService binaryLookupService = binaryProtocolClient.getLookup();
    Assert.assertTrue(httpLookupService instanceof HttpLookupService);
    Assert.assertTrue(binaryLookupService instanceof BinaryProtoLookupService);
    Assert.assertEquals(admin.schemas().getAllSchemas(topic).size(), 2);
    Assert.assertTrue(httpLookupService.getSchema(TopicName.get(topic), ByteBuffer.allocate(8).putLong(0).array()).get().isPresent());
    Assert.assertTrue(httpLookupService.getSchema(TopicName.get(topic), ByteBuffer.allocate(8).putLong(1).array()).get().isPresent());
    Assert.assertTrue(binaryLookupService.getSchema(TopicName.get(topic), ByteBuffer.allocate(8).putLong(0).array()).get().isPresent());
    Assert.assertTrue(binaryLookupService.getSchema(TopicName.get(topic), ByteBuffer.allocate(8).putLong(1).array()).get().isPresent());
}
Also used : BinaryProtoLookupService(org.apache.pulsar.client.impl.BinaryProtoLookupService) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) LookupService(org.apache.pulsar.client.impl.LookupService) BinaryProtoLookupService(org.apache.pulsar.client.impl.BinaryProtoLookupService) HttpLookupService(org.apache.pulsar.client.impl.HttpLookupService) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) Cleanup(lombok.Cleanup) Test(org.testng.annotations.Test)

Aggregations

Cleanup (lombok.Cleanup)9 HttpLookupService (org.apache.pulsar.client.impl.HttpLookupService)9 InetSocketAddress (java.net.InetSocketAddress)6 Pair (org.apache.commons.lang3.tuple.Pair)6 BinaryProtoLookupService (org.apache.pulsar.client.impl.BinaryProtoLookupService)6 LookupService (org.apache.pulsar.client.impl.LookupService)6 PulsarClientImpl (org.apache.pulsar.client.impl.PulsarClientImpl)6 ClientConfigurationData (org.apache.pulsar.client.impl.conf.ClientConfigurationData)6 Test (org.testng.annotations.Test)6 CompletableFuture (java.util.concurrent.CompletableFuture)3 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)3 LookupResult (org.apache.pulsar.broker.lookup.LookupResult)3 NamespaceEphemeralData (org.apache.pulsar.broker.namespace.NamespaceEphemeralData)3 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)3 TenantInfo (org.apache.pulsar.common.policies.data.TenantInfo)3