use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class PartitionedProducerConsumerTest method testPartitionedTopicNameWithSpecialCharacter.
@Test(timeOut = 30000)
public void testPartitionedTopicNameWithSpecialCharacter() throws Exception {
log.info("-- Starting {} test --", methodName);
int numPartitions = 4;
final String specialCharacter = "! * ' ( ) ; : @ & = + $ , /\\ ? % # [ ]";
TopicName topicName = TopicName.get("persistent://my-property/use/my-ns/my-partitionedtopic1" + specialCharacter);
admin.persistentTopics().createPartitionedTopic(topicName.toString(), numPartitions);
// Try to create producer which does lookup and create connection with broker
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName.toString()).messageRoutingMode(MessageRoutingMode.RoundRobinPartition).create();
producer.close();
admin.persistentTopics().deletePartitionedTopic(topicName.toString());
log.info("-- Exiting {} test --", methodName);
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class PartitionedProducerConsumerTest method testAsyncPartitionedProducerConsumer.
@Test(timeOut = 30000)
public void testAsyncPartitionedProducerConsumer() throws Exception {
log.info("-- Starting {} test --", methodName);
final int totalMsg = 100;
final Set<String> produceMsgs = Sets.newHashSet();
final Set<String> consumeMsgs = Sets.newHashSet();
int numPartitions = 4;
TopicName topicName = TopicName.get("persistent://my-property/use/my-ns/my-partitionedtopic1");
admin.persistentTopics().createPartitionedTopic(topicName.toString(), numPartitions);
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName.toString()).messageRoutingMode(MessageRoutingMode.RoundRobinPartition).create();
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName.toString()).subscriptionName("my-partitioned-subscriber").subscriptionType(SubscriptionType.Shared).subscribe();
// produce messages
for (int i = 0; i < totalMsg; i++) {
String message = "my-message-" + i;
produceMsgs.add(message);
producer.send(message.getBytes());
}
log.info(" start receiving messages :");
// receive messages
CountDownLatch latch = new CountDownLatch(totalMsg);
receiveAsync(consumer, totalMsg, 0, latch, consumeMsgs, executor);
latch.await();
// verify message produced correctly
assertEquals(produceMsgs.size(), totalMsg);
// verify produced and consumed messages must be exactly same
produceMsgs.removeAll(consumeMsgs);
assertTrue(produceMsgs.isEmpty());
producer.close();
consumer.unsubscribe();
consumer.close();
admin.persistentTopics().deletePartitionedTopic(topicName.toString());
log.info("-- Exiting {} test --", methodName);
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class AuthorizationProducerConsumerTest method testGrantPermission.
@Test
public void testGrantPermission() throws Exception {
log.info("-- Starting {} test --", methodName);
conf.setAuthorizationProvider(TestAuthorizationProviderWithGrantPermission.class.getName());
setup();
AuthorizationService authorizationService = new AuthorizationService(conf, null);
TopicName topicName = TopicName.get("persistent://prop/cluster/ns/t1");
String role = "test-role";
Assert.assertFalse(authorizationService.canProduce(topicName, role, null));
Assert.assertFalse(authorizationService.canConsume(topicName, role, null, "sub1"));
authorizationService.grantPermissionAsync(topicName, null, role, "auth-json").get();
Assert.assertTrue(authorizationService.canProduce(topicName, role, null));
Assert.assertTrue(authorizationService.canConsume(topicName, role, null, "sub1"));
log.info("-- Exiting {} test --", methodName);
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class AuthorizationProducerConsumerTest method testAuthData.
@Test
public void testAuthData() throws Exception {
log.info("-- Starting {} test --", methodName);
conf.setAuthorizationProvider(TestAuthorizationProviderWithGrantPermission.class.getName());
setup();
AuthorizationService authorizationService = new AuthorizationService(conf, null);
TopicName topicName = TopicName.get("persistent://prop/cluster/ns/t1");
String role = "test-role";
authorizationService.grantPermissionAsync(topicName, null, role, "auth-json").get();
Assert.assertEquals(TestAuthorizationProviderWithGrantPermission.authDataJson, "auth-json");
Assert.assertTrue(authorizationService.canProduce(topicName, role, new AuthenticationDataCommand("prod-auth")));
Assert.assertEquals(TestAuthorizationProviderWithGrantPermission.authenticationData.getCommandData(), "prod-auth");
Assert.assertTrue(authorizationService.canConsume(topicName, role, new AuthenticationDataCommand("cons-auth"), "sub1"));
Assert.assertEquals(TestAuthorizationProviderWithGrantPermission.authenticationData.getCommandData(), "cons-auth");
log.info("-- Exiting {} test --", methodName);
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class NamespaceServiceTest method testIsServiceUnitDisabled.
@Test
public void testIsServiceUnitDisabled() throws Exception {
OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
ManagedLedger ledger = mock(ManagedLedger.class);
when(ledger.getCursors()).thenReturn(Lists.newArrayList());
doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
ownership.setAccessible(true);
ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
NamespaceService namespaceService = pulsar.getNamespaceService();
NamespaceName nsname = NamespaceName.get("pulsar/global/ns1");
TopicName topicName = TopicName.get("persistent://pulsar/global/ns1/topic-1");
NamespaceBundles bundles = namespaceService.getNamespaceBundleFactory().getBundles(nsname);
NamespaceBundle originalBundle = bundles.findBundle(topicName);
assertFalse(namespaceService.isNamespaceBundleDisabled(originalBundle));
}
Aggregations