Search in sources :

Example 1 with LookupService

use of org.apache.pulsar.client.impl.LookupService in project 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));
}
Also used : LookupService(org.apache.pulsar.client.impl.LookupService) SchemaData(org.apache.pulsar.common.protocol.schema.SchemaData) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) ToString(lombok.ToString) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) Cleanup(lombok.Cleanup) Test(org.testng.annotations.Test)

Example 2 with LookupService

use of org.apache.pulsar.client.impl.LookupService 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 3 with LookupService

use of org.apache.pulsar.client.impl.LookupService 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 LookupService

use of org.apache.pulsar.client.impl.LookupService 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 LookupService

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

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));
}
Also used : LookupService(org.apache.pulsar.client.impl.LookupService) SchemaData(org.apache.pulsar.common.protocol.schema.SchemaData) PulsarClientImpl(org.apache.pulsar.client.impl.PulsarClientImpl) ToString(lombok.ToString) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) Cleanup(lombok.Cleanup) Test(org.testng.annotations.Test)

Aggregations

Cleanup (lombok.Cleanup)9 LookupService (org.apache.pulsar.client.impl.LookupService)9 PulsarClientImpl (org.apache.pulsar.client.impl.PulsarClientImpl)9 BinaryProtoLookupService (org.apache.pulsar.client.impl.BinaryProtoLookupService)6 HttpLookupService (org.apache.pulsar.client.impl.HttpLookupService)6 Test (org.testng.annotations.Test)6 InetSocketAddress (java.net.InetSocketAddress)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ToString (lombok.ToString)3 Pair (org.apache.commons.lang3.tuple.Pair)3 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)3 ClientConfigurationData (org.apache.pulsar.client.impl.conf.ClientConfigurationData)3 SchemaData (org.apache.pulsar.common.protocol.schema.SchemaData)3