use of org.apache.pulsar.client.impl.HttpLookupService in project incubator-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);
}
}
use of org.apache.pulsar.client.impl.HttpLookupService in project incubator-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);
}
use of org.apache.pulsar.client.impl.HttpLookupService in project pulsar by yahoo.
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());
}
use of org.apache.pulsar.client.impl.HttpLookupService in project pulsar by yahoo.
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);
}
Aggregations