Search in sources :

Example 1 with HashingScheme

use of org.apache.pulsar.client.api.HashingScheme in project pulsar by apache.

the class AbstractWebSocketHandlerTest method producerBuilderTest.

@Test
public void producerBuilderTest() throws IOException {
    String producerV2 = "/ws/v2/producer/persistent/my-property/my-ns/my-topic";
    // the params are all different with the default value
    Map<String, String[]> queryParams = new HashMap<String, String>() {

        {
            put("producerName", "my-producer");
            put("initialSequenceId", "1");
            put("hashingScheme", "Murmur3_32Hash");
            put("sendTimeoutMillis", "30001");
            put("batchingEnabled", "false");
            put("batchingMaxMessages", "1001");
            put("maxPendingMessages", "1001");
            put("batchingMaxPublishDelay", "2");
            put("messageRoutingMode", "RoundRobinPartition");
            put("compressionType", "LZ4");
        }
    }.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> new String[] { entry.getValue() }));
    httpServletRequest = mock(HttpServletRequest.class);
    when(httpServletRequest.getRequestURI()).thenReturn(producerV2);
    when(httpServletRequest.getParameterMap()).thenReturn(queryParams);
    WebSocketService service = mock(WebSocketService.class);
    when(service.isAuthenticationEnabled()).thenReturn(false);
    when(service.isAuthorizationEnabled()).thenReturn(false);
    when(service.getPulsarClient()).thenReturn(newPulsarClient());
    MockedServletUpgradeResponse response = new MockedServletUpgradeResponse(null);
    MockedProducerHandler producerHandler = new MockedProducerHandler(service, httpServletRequest, response);
    assertEquals(response.getStatusCode(), 500);
    assertTrue(response.getMessage().contains("Connection refused"));
    ProducerConfigurationData conf = producerHandler.getConf();
    assertEquals(conf.getProducerName(), "my-producer");
    assertEquals(conf.getInitialSequenceId().longValue(), 1L);
    assertEquals(conf.getHashingScheme(), HashingScheme.Murmur3_32Hash);
    assertEquals(conf.getSendTimeoutMs(), 30001);
    assertFalse(conf.isBatchingEnabled());
    assertEquals(conf.getBatchingMaxMessages(), 1001);
    assertEquals(conf.getMaxPendingMessages(), 1001);
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.RoundRobinPartition);
    assertEquals(conf.getCompressionType(), CompressionType.LZ4);
    producerHandler.clearQueryParams();
    conf = producerHandler.getConf();
    // The default message routing mode is SinglePartition, which is different with ProducerBuilder
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.SinglePartition);
    producerHandler.putQueryParam("messageRoutingMode", "CustomPartition");
    conf = producerHandler.getConf();
    // ProducerHandler doesn't support CustomPartition
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.SinglePartition);
}
Also used : TopicName(org.apache.pulsar.common.naming.TopicName) Getter(lombok.Getter) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) Mock(org.mockito.Mock) SubscriptionMode(org.apache.pulsar.client.api.SubscriptionMode) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) MessageRoutingMode(org.apache.pulsar.client.api.MessageRoutingMode) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) ProducerBuilderImpl(org.apache.pulsar.client.impl.ProducerBuilderImpl) ServletUpgradeResponse(org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse) PulsarClient(org.apache.pulsar.client.api.PulsarClient) ConsumerBuilderImpl(org.apache.pulsar.client.impl.ConsumerBuilderImpl) Assert.assertFalse(org.testng.Assert.assertFalse) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) AfterClass(org.testng.annotations.AfterClass) CompressionType(org.apache.pulsar.client.api.CompressionType) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) HashingScheme(org.apache.pulsar.client.api.HashingScheme) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) TimeUnit(java.util.concurrent.TimeUnit) URLEncoder(java.net.URLEncoder) List(java.util.List) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) HttpServletRequest(javax.servlet.http.HttpServletRequest) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 2 with HashingScheme

use of org.apache.pulsar.client.api.HashingScheme in project pulsar by yahoo.

the class AbstractWebSocketHandlerTest method producerBuilderTest.

@Test
public void producerBuilderTest() throws IOException {
    String producerV2 = "/ws/v2/producer/persistent/my-property/my-ns/my-topic";
    // the params are all different with the default value
    Map<String, String[]> queryParams = new HashMap<String, String>() {

        {
            put("producerName", "my-producer");
            put("initialSequenceId", "1");
            put("hashingScheme", "Murmur3_32Hash");
            put("sendTimeoutMillis", "30001");
            put("batchingEnabled", "true");
            put("batchingMaxMessages", "1001");
            put("maxPendingMessages", "1001");
            put("batchingMaxPublishDelay", "2");
            put("messageRoutingMode", "RoundRobinPartition");
            put("compressionType", "LZ4");
        }
    }.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> new String[] { entry.getValue() }));
    httpServletRequest = mock(HttpServletRequest.class);
    when(httpServletRequest.getRequestURI()).thenReturn(producerV2);
    when(httpServletRequest.getParameterMap()).thenReturn(queryParams);
    WebSocketService service = mock(WebSocketService.class);
    when(service.isAuthenticationEnabled()).thenReturn(false);
    when(service.isAuthorizationEnabled()).thenReturn(false);
    when(service.getPulsarClient()).thenReturn(newPulsarClient());
    MockedServletUpgradeResponse response = new MockedServletUpgradeResponse(null);
    MockedProducerHandler producerHandler = new MockedProducerHandler(service, httpServletRequest, response);
    assertEquals(response.getStatusCode(), 500);
    assertTrue(response.getMessage().contains("Connection refused"));
    ProducerConfigurationData conf = producerHandler.getConf();
    assertEquals(conf.getProducerName(), "my-producer");
    assertEquals(conf.getInitialSequenceId().longValue(), 1L);
    assertEquals(conf.getHashingScheme(), HashingScheme.Murmur3_32Hash);
    assertEquals(conf.getSendTimeoutMs(), 30001);
    assertTrue(conf.isBatchingEnabled());
    assertEquals(conf.getBatchingMaxMessages(), 1001);
    assertEquals(conf.getMaxPendingMessages(), 1001);
    assertEquals(conf.getBatchingMaxPublishDelayMicros(), 2000);
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.RoundRobinPartition);
    assertEquals(conf.getCompressionType(), CompressionType.LZ4);
    producerHandler.clearQueryParams();
    conf = producerHandler.getConf();
    // By default batching is disabled, which is different with ProducerBuilder
    assertFalse(conf.isBatchingEnabled());
    // The default message routing mode is SinglePartition, which is different with ProducerBuilder
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.SinglePartition);
    producerHandler.putQueryParam("messageRoutingMode", "CustomPartition");
    conf = producerHandler.getConf();
    // ProducerHandler doesn't support CustomPartition
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.SinglePartition);
}
Also used : TopicName(org.apache.pulsar.common.naming.TopicName) Getter(lombok.Getter) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) Mock(org.mockito.Mock) SubscriptionMode(org.apache.pulsar.client.api.SubscriptionMode) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) MessageRoutingMode(org.apache.pulsar.client.api.MessageRoutingMode) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) ProducerBuilderImpl(org.apache.pulsar.client.impl.ProducerBuilderImpl) ServletUpgradeResponse(org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse) PulsarClient(org.apache.pulsar.client.api.PulsarClient) ConsumerBuilderImpl(org.apache.pulsar.client.impl.ConsumerBuilderImpl) Assert.assertFalse(org.testng.Assert.assertFalse) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) AfterClass(org.testng.annotations.AfterClass) CompressionType(org.apache.pulsar.client.api.CompressionType) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) HashingScheme(org.apache.pulsar.client.api.HashingScheme) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) TimeUnit(java.util.concurrent.TimeUnit) URLEncoder(java.net.URLEncoder) List(java.util.List) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) HttpServletRequest(javax.servlet.http.HttpServletRequest) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 3 with HashingScheme

use of org.apache.pulsar.client.api.HashingScheme in project incubator-pulsar by apache.

the class AbstractWebSocketHandlerTest method producerBuilderTest.

@Test
public void producerBuilderTest() throws IOException {
    String producerV2 = "/ws/v2/producer/persistent/my-property/my-ns/my-topic";
    // the params are all different with the default value
    Map<String, String[]> queryParams = new HashMap<String, String>() {

        {
            put("producerName", "my-producer");
            put("initialSequenceId", "1");
            put("hashingScheme", "Murmur3_32Hash");
            put("sendTimeoutMillis", "30001");
            put("batchingEnabled", "true");
            put("batchingMaxMessages", "1001");
            put("maxPendingMessages", "1001");
            put("batchingMaxPublishDelay", "2");
            put("messageRoutingMode", "RoundRobinPartition");
            put("compressionType", "LZ4");
        }
    }.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> new String[] { entry.getValue() }));
    httpServletRequest = mock(HttpServletRequest.class);
    when(httpServletRequest.getRequestURI()).thenReturn(producerV2);
    when(httpServletRequest.getParameterMap()).thenReturn(queryParams);
    WebSocketService service = mock(WebSocketService.class);
    when(service.isAuthenticationEnabled()).thenReturn(false);
    when(service.isAuthorizationEnabled()).thenReturn(false);
    when(service.getPulsarClient()).thenReturn(newPulsarClient());
    MockedServletUpgradeResponse response = new MockedServletUpgradeResponse(null);
    MockedProducerHandler producerHandler = new MockedProducerHandler(service, httpServletRequest, response);
    assertEquals(response.getStatusCode(), 500);
    assertTrue(response.getMessage().contains("Connection refused"));
    ProducerConfigurationData conf = producerHandler.getConf();
    assertEquals(conf.getProducerName(), "my-producer");
    assertEquals(conf.getInitialSequenceId().longValue(), 1L);
    assertEquals(conf.getHashingScheme(), HashingScheme.Murmur3_32Hash);
    assertEquals(conf.getSendTimeoutMs(), 30001);
    assertTrue(conf.isBatchingEnabled());
    assertEquals(conf.getBatchingMaxMessages(), 1001);
    assertEquals(conf.getMaxPendingMessages(), 1001);
    assertEquals(conf.getBatchingMaxPublishDelayMicros(), 2000);
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.RoundRobinPartition);
    assertEquals(conf.getCompressionType(), CompressionType.LZ4);
    producerHandler.clearQueryParams();
    conf = producerHandler.getConf();
    // By default batching is disabled, which is different with ProducerBuilder
    assertFalse(conf.isBatchingEnabled());
    // The default message routing mode is SinglePartition, which is different with ProducerBuilder
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.SinglePartition);
    producerHandler.putQueryParam("messageRoutingMode", "CustomPartition");
    conf = producerHandler.getConf();
    // ProducerHandler doesn't support CustomPartition
    assertEquals(conf.getMessageRoutingMode(), MessageRoutingMode.SinglePartition);
}
Also used : TopicName(org.apache.pulsar.common.naming.TopicName) Getter(lombok.Getter) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) Mock(org.mockito.Mock) SubscriptionMode(org.apache.pulsar.client.api.SubscriptionMode) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) MessageRoutingMode(org.apache.pulsar.client.api.MessageRoutingMode) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) ProducerBuilderImpl(org.apache.pulsar.client.impl.ProducerBuilderImpl) ServletUpgradeResponse(org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse) PulsarClient(org.apache.pulsar.client.api.PulsarClient) ConsumerBuilderImpl(org.apache.pulsar.client.impl.ConsumerBuilderImpl) Assert.assertFalse(org.testng.Assert.assertFalse) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) AfterClass(org.testng.annotations.AfterClass) CompressionType(org.apache.pulsar.client.api.CompressionType) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) HashingScheme(org.apache.pulsar.client.api.HashingScheme) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) TimeUnit(java.util.concurrent.TimeUnit) URLEncoder(java.net.URLEncoder) List(java.util.List) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) HttpServletRequest(javax.servlet.http.HttpServletRequest) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

IOException (java.io.IOException)3 URLEncoder (java.net.URLEncoder)3 StandardCharsets (java.nio.charset.StandardCharsets)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Getter (lombok.Getter)3 AuthenticationDataSource (org.apache.pulsar.broker.authentication.AuthenticationDataSource)3 CompressionType (org.apache.pulsar.client.api.CompressionType)3 HashingScheme (org.apache.pulsar.client.api.HashingScheme)3 MessageRoutingMode (org.apache.pulsar.client.api.MessageRoutingMode)3 PulsarClient (org.apache.pulsar.client.api.PulsarClient)3 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)3 SubscriptionMode (org.apache.pulsar.client.api.SubscriptionMode)3