[GitHub] [pulsar] MarvinCai commented on a change in pull request #3753: Add support for Kafka's ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG (#1090)

2019-03-06 Thread GitBox
MarvinCai commented on a change in pull request #3753: Add support for Kafka's 
ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG (#1090)
URL: https://github.com/apache/pulsar/pull/3753#discussion_r263226100
 
 

 ##
 File path: 
pulsar-client-kafka-compat/pulsar-client-kafka/src/main/java/org/apache/kafka/clients/producer/PulsarKafkaProducer.java
 ##
 @@ -34,6 +34,7 @@
 import java.util.concurrent.TimeoutException;
 import java.util.stream.Collectors;
 
+import com.sun.javaws.exceptions.InvalidArgumentException;
 
 Review comment:
   Removed unused import.
   Also added document that merlimat mentioned.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] MarvinCai commented on a change in pull request #3753: Add support for Kafka's ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG (#1090)

2019-03-05 Thread GitBox
MarvinCai commented on a change in pull request #3753: Add support for Kafka's 
ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG (#1090)
URL: https://github.com/apache/pulsar/pull/3753#discussion_r262794932
 
 

 ##
 File path: 
pulsar-client-kafka-compat/pulsar-client-kafka/src/main/java/org/apache/kafka/clients/producer/PulsarKafkaProducer.java
 ##
 @@ -114,7 +114,11 @@ private PulsarKafkaProducer(Map conf, 
Properties properties, Ser
 
 String serviceUrl = 
producerConfig.getList(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG).get(0);
 try {
-client = 
PulsarClientKafkaConfig.getClientBuilder(properties).serviceUrl(serviceUrl).build();
+// Support Kafka's ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG 
in ms.
+long keepAliveIntervalMs = 
Long.parseLong(properties.getProperty(ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG,
 "3"));
+// If passed in value is greater than Integer.MAX_VALUE in second 
will throw ArithmeticException.
+int keepAliveInterval = Math.toIntExact(keepAliveIntervalMs / 
1000);
 
 Review comment:
   Done, catch ArithmeticException, log error message and throw 
IllegalArgumentException with same error message.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [pulsar] MarvinCai commented on a change in pull request #3753: Add support for Kafka's ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG (#1090)

2019-03-05 Thread GitBox
MarvinCai commented on a change in pull request #3753: Add support for Kafka's 
ProducerConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG (#1090)
URL: https://github.com/apache/pulsar/pull/3753#discussion_r262794702
 
 

 ##
 File path: 
pulsar-client-kafka-compat/pulsar-client-kafka/src/test/java/org/apache/kafka/clients/producer/PulsarKafkaProducerTest.java
 ##
 @@ -0,0 +1,48 @@
+package org.apache.kafka.clients.producer;
+
+import org.apache.kafka.clients.producer.internals.DefaultPartitioner;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.pulsar.client.api.ClientBuilder;
+import org.apache.pulsar.client.kafka.compat.PulsarClientKafkaConfig;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+public class PulsarKafkaProducerTest {
+
+@Test
+public void testPulsarKafkaProducer() {
+ClientBuilder mockClientBuilder = mock(ClientBuilder.class);
+
doReturn(mockClientBuilder).when(mockClientBuilder).serviceUrl(anyString());
+doAnswer(new Answer() {
+@Override
+public Object answer(InvocationOnMock invocation) throws Throwable 
{
+Assert.assertEquals((int)invocation.getArguments()[0], 1000, 
"Keep alive interval is suppose to be 1000.");
+return mockClientBuilder;
+}
+}).when(mockClientBuilder).keepAliveInterval(anyInt(), 
any(TimeUnit.class));
+
+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, 
"100");
+
+PulsarKafkaProducer pulsarKafkaProducer = new 
PulsarKafkaProducer<>(properties, null, null);
 
 Review comment:
   Verified mockClientBuilder.keepAliveInterval is called exactly once with 
expected value.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services