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);
}
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);
}
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);
}
Aggregations