use of org.apache.pulsar.client.impl.LookupService 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());
}
use of org.apache.pulsar.client.impl.LookupService 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.LookupService in project incubator-pulsar by apache.
the class PersistentTopicE2ETest method testDeleteSchema.
@Test
public void testDeleteSchema() throws Exception {
@Cleanup PulsarClientImpl httpProtocolClient = (PulsarClientImpl) PulsarClient.builder().serviceUrl(brokerUrl.toString()).build();
PulsarClientImpl binaryProtocolClient = (PulsarClientImpl) pulsarClient;
LookupService binaryLookupService = binaryProtocolClient.getLookup();
LookupService httpLookupService = httpProtocolClient.getLookup();
String topicName = "persistent://prop/ns-abc/topic-1";
// Topic is not GCed with live connection
@Cleanup Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).create();
Optional<Topic> topic = getTopic(topicName);
assertTrue(topic.isPresent());
byte[] data = JSONSchema.of(SchemaDefinition.builder().withPojo(Foo.class).build()).getSchemaInfo().getSchema();
SchemaData schemaData = SchemaData.builder().data(data).type(SchemaType.BYTES).user("foo").build();
topic.get().addSchema(schemaData).join();
assertTrue(topicHasSchema(topicName));
Assert.assertEquals(admin.schemas().getAllSchemas(topicName).size(), 1);
assertTrue(httpLookupService.getSchema(TopicName.get(topicName), ByteBuffer.allocate(8).putLong(0).array()).get().isPresent());
assertTrue(binaryLookupService.getSchema(TopicName.get(topicName), ByteBuffer.allocate(8).putLong(0).array()).get().isPresent());
topic.get().deleteSchema().join();
Assert.assertEquals(admin.schemas().getAllSchemas(topicName).size(), 0);
assertFalse(httpLookupService.getSchema(TopicName.get(topicName), ByteBuffer.allocate(8).putLong(0).array()).get().isPresent());
assertFalse(binaryLookupService.getSchema(TopicName.get(topicName), ByteBuffer.allocate(8).putLong(0).array()).get().isPresent());
assertFalse(topicHasSchema(topicName));
}
use of org.apache.pulsar.client.impl.LookupService 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());
}
Aggregations