use of org.apache.pulsar.client.impl.ConsumerBuilderImpl in project pulsar-adapters by apache.
the class PulsarKafkaConsumerTest method testPulsarKafkaConsumerConfig.
@Test
public void testPulsarKafkaConsumerConfig() throws Exception {
// https://kafka.apache.org/08/documentation.html#consumerconfigs
Properties properties = new Properties();
properties.put("zookeeper.connect", "http://localhost:8080/");
properties.put("group.id", "group1");
properties.put("consumer.id", "cons1");
properties.put("auto.commit.enable", "true");
properties.put("auto.commit.interval.ms", "100");
properties.put("queued.max.message.chunks", "100");
ConsumerConfig config = new ConsumerConfig(properties);
ConsumerConnector connector = new ConsumerConnector(config);
ConsumerBuilderImpl<byte[]> consumerBuilder = (ConsumerBuilderImpl<byte[]>) connector.getConsumerBuilder();
Field confField = consumerBuilder.getClass().getDeclaredField("conf");
confField.setAccessible(true);
ConsumerConfigurationData conf = (ConsumerConfigurationData) confField.get(consumerBuilder);
assertEquals(conf.getSubscriptionName(), "group1");
assertEquals(conf.getReceiverQueueSize(), 100);
assertEquals(conf.getAcknowledgementsGroupTimeMicros(), TimeUnit.MILLISECONDS.toMicros(100));
System.out.println(conf);
}
use of org.apache.pulsar.client.impl.ConsumerBuilderImpl in project pulsar-adapters by apache.
the class PulsarKafkaConsumerTest method testPulsarKafkaConsumerWithDefaultConfig.
@Test
public void testPulsarKafkaConsumerWithDefaultConfig() throws Exception {
// https://kafka.apache.org/08/documentation.html#consumerconfigs
Properties properties = new Properties();
properties.put("zookeeper.connect", "http://localhost:8080/");
properties.put("group.id", "group1");
ConsumerConfig config = new ConsumerConfig(properties);
ConsumerConnector connector = new ConsumerConnector(config);
ConsumerBuilderImpl<byte[]> consumerBuilder = (ConsumerBuilderImpl<byte[]>) connector.getConsumerBuilder();
Field confField = consumerBuilder.getClass().getDeclaredField("conf");
confField.setAccessible(true);
ConsumerConfigurationData conf = (ConsumerConfigurationData) confField.get(consumerBuilder);
assertEquals(conf.getSubscriptionName(), "group1");
assertEquals(conf.getReceiverQueueSize(), 1000);
}
use of org.apache.pulsar.client.impl.ConsumerBuilderImpl in project pulsar-adapters by apache.
the class PulsarCliebtKafkaConfigTest method testPulsarKafkaProducer.
@Test
public void testPulsarKafkaProducer() {
ClientBuilder mockClientBuilder = mock(ClientBuilder.class);
ProducerBuilder mockProducerBuilder = mock(ProducerBuilder.class);
doAnswer(invocation -> {
Assert.assertEquals((int) invocation.getArguments()[0], 1000000, "Send time out is suppose to be 1000.");
return mockProducerBuilder;
}).when(mockProducerBuilder).sendTimeout(anyInt(), any(TimeUnit.class));
doReturn(mockClientBuilder).when(mockClientBuilder).serviceUrl(anyString());
doAnswer(invocation -> {
Assert.assertEquals((int) invocation.getArguments()[0], 1000, "Keep alive interval is suppose to be 1000.");
return mockClientBuilder;
}).when(mockClientBuilder).keepAliveInterval(anyInt(), any(TimeUnit.class));
// validate producer
Properties properties = new Properties();
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
properties.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, DefaultPartitioner.class);
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, Arrays.asList("pulsar://localhost:6650"));
properties.put(ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG, "1000000");
properties.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, "1000000");
properties.put(PulsarProducerKafkaConfig.CRYPTO_READER_FACTORY_CLASS_NAME, CryptoKeyReaderFactoryImpl.class.getName());
PulsarKafkaProducer producer = new PulsarKafkaProducer<>(properties);
ProducerBuilderImpl producerBuilder = (ProducerBuilderImpl) producer.pulsarProducerBuilder;
assertEquals(producerBuilder.getConf().getCryptoKeyReader(), CryptoKeyReaderFactoryImpl.reader);
assertEquals(producerBuilder.getConf().getEncryptionKeys(), CryptoKeyReaderFactoryImpl.encryptionKeys);
// validate consumer
properties = new Properties();
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, Arrays.asList("pulsar://localhost:6650"));
properties.put(PulsarProducerKafkaConfig.CRYPTO_READER_FACTORY_CLASS_NAME, CryptoKeyReaderFactoryImpl.class.getName());
PulsarClient client = mock(PulsarClient.class);
ConsumerBuilderImpl<byte[]> consumerBuilder = new ConsumerBuilderImpl<>(null, null);
doReturn(consumerBuilder).when(client).newConsumer();
PulsarConsumerKafkaConfig.getConsumerBuilder(client, properties);
assertEquals(consumerBuilder.getConf().getCryptoKeyReader(), CryptoKeyReaderFactoryImpl.reader);
}
Aggregations