use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class AdminApiTest method testNamespaceBundleUnload.
@Test(dataProvider = "numBundles")
public void testNamespaceBundleUnload(Integer numBundles) throws Exception {
admin.namespaces().createNamespace("prop-xyz/use/ns1-bundles", numBundles);
assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1-bundles"), Lists.newArrayList());
// Force to create a destination
publishMessagesOnPersistentTopic("persistent://prop-xyz/use/ns1-bundles/ds2", 0);
assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1-bundles"), Lists.newArrayList("persistent://prop-xyz/use/ns1-bundles/ds2"));
// create consumer and subscription
ConsumerConfiguration conf = new ConsumerConfiguration();
Consumer consumer = pulsarClient.subscribe("persistent://prop-xyz/use/ns1-bundles/ds2", "my-sub", conf);
assertEquals(admin.persistentTopics().getSubscriptions("persistent://prop-xyz/use/ns1-bundles/ds2"), Lists.newArrayList("my-sub"));
// Create producer
Producer producer = pulsarClient.createProducer("persistent://prop-xyz/use/ns1-bundles/ds2");
for (int i = 0; i < 10; i++) {
String message = "message-" + i;
producer.send(message.getBytes());
}
NamespaceBundle bundle = (NamespaceBundle) pulsar.getNamespaceService().getBundle(DestinationName.get("persistent://prop-xyz/use/ns1-bundles/ds2"));
consumer.close();
producer.close();
admin.namespaces().unloadNamespaceBundle("prop-xyz/use/ns1-bundles", bundle.getBundleRange());
// check that no one owns the namespace bundle
assertFalse(pulsar.getNamespaceService().isServiceUnitOwned(bundle));
assertFalse(otherPulsar.getNamespaceService().isServiceUnitOwned(bundle));
LOG.info("--- RELOAD ---");
// Force reload of namespace and wait for topic to be ready
for (int i = 0; i < 30; i++) {
try {
admin.persistentTopics().getStats("persistent://prop-xyz/use/ns1-bundles/ds2");
break;
} catch (PulsarAdminException e) {
LOG.warn("Failed to get topic stats.. {}", e.getMessage());
Thread.sleep(1000);
}
}
admin.persistentTopics().deleteSubscription("persistent://prop-xyz/use/ns1-bundles/ds2", "my-sub");
admin.persistentTopics().delete("persistent://prop-xyz/use/ns1-bundles/ds2");
}
use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class AdminApiTest method clusters.
@Test
public void clusters() throws Exception {
admin.clusters().createCluster("usw", new ClusterData("http://broker.messaging.use.example.com" + ":" + BROKER_WEBSERVICE_PORT));
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
assertEquals(admin.clusters().getCluster("use"), new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
admin.clusters().updateCluster("usw", new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT));
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
assertEquals(admin.clusters().getCluster("usw"), new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT));
admin.clusters().updateCluster("usw", new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT, "https://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT_TLS));
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
assertEquals(admin.clusters().getCluster("usw"), new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT, "https://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT_TLS));
admin.clusters().deleteCluster("usw");
Thread.sleep(300);
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use"));
admin.namespaces().deleteNamespace("prop-xyz/use/ns1");
admin.clusters().deleteCluster("use");
assertEquals(admin.clusters().getClusters(), Lists.newArrayList());
// Check name validation
try {
admin.clusters().createCluster("bf!", new ClusterData("http://dummy.messaging.example.com"));
fail("should have failed");
} catch (PulsarAdminException e) {
assertTrue(e instanceof PreconditionFailedException);
}
}
use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class ZooKeeperSessionExpireRecoveryTest method testSessionExpired.
/**
* Verify we are able to recover when receiving a SessionExpired event on global ZK session
*/
@Test
public void testSessionExpired() throws Exception {
admin.clusters().createCluster("my-cluster", new ClusterData("test-url"));
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("my-cluster"));
mockZookKeeper.failNow(Code.SESSIONEXPIRED);
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("my-cluster"));
try {
admin.clusters().createCluster("my-cluster-2", new ClusterData("test-url"));
fail("Should have failed, because global zk is down");
} catch (PulsarAdminException e) {
// Ok
}
admin.clusters().createCluster("cluster-2", new ClusterData("test-url"));
}
use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class AuthenticatedProducerConsumerTest method testInternalServerExceptionOnLookup.
/**
* verifies that topicLookup/PartitionMetadataLookup gives InternalServerError(500) instead 401(auth_failed) on
* unknown-exception failure
*
* @throws Exception
*/
@Test
public void testInternalServerExceptionOnLookup() throws Exception {
log.info("-- Starting {} test --", methodName);
Map<String, String> authParams = new HashMap<>();
authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
Authentication authTls = new AuthenticationTls();
authTls.configure(authParams);
internalSetup(authTls);
admin.clusters().createCluster("use", new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), "pulsar://localhost:" + BROKER_PORT, "pulsar+ssl://localhost:" + BROKER_PORT_TLS));
admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
String namespace = "my-property/use/my-ns";
admin.namespaces().createNamespace(namespace);
String destination = "persistent://" + namespace + "1/topic1";
// this will cause NPE and it should throw 500
mockZookKeeper.shutdown();
pulsar.getConfiguration().setSuperUserRoles(Sets.newHashSet());
try {
admin.persistentTopics().getPartitionedTopicMetadata(destination);
} catch (PulsarAdminException e) {
Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
}
try {
admin.lookups().lookupDestination(destination);
} catch (PulsarAdminException e) {
Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
}
}
use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class MessageIdTest method partitionedProducerSendAsync.
@Test(timeOut = 10000)
public void partitionedProducerSendAsync() throws PulsarClientException, PulsarAdminException {
// 1. Basic Config
String key = "partitionedProducerSendAsync";
final String topicName = "persistent://prop/cluster/namespace/topic-" + key;
final String subscriptionName = "my-subscription-" + key;
final String messagePredicate = "my-message-" + key + "-";
final int numberOfMessages = 30;
int numberOfPartitions = 3;
admin.persistentTopics().createPartitionedTopic(topicName, numberOfPartitions);
// 2. Create Producer
Producer producer = pulsarClient.createProducer(topicName);
// 3. Create Consumer
Consumer consumer = pulsarClient.subscribe(topicName, subscriptionName);
// 4. Publish message and get message id
Set<MessageId> messageIds = new HashSet();
Set<Future<MessageId>> futures = new HashSet();
for (int i = 0; i < numberOfMessages; i++) {
String message = messagePredicate + i;
futures.add(producer.sendAsync(message.getBytes()));
}
futures.forEach(f -> {
try {
messageIds.add(f.get());
} catch (Exception e) {
Assert.fail("Failed to publish message, Exception: " + e.getMessage());
}
});
// 4. Check if message Ids are correct
log.info("Message IDs = " + messageIds);
Assert.assertEquals(messageIds.size(), numberOfMessages, "Not all messages published successfully");
for (int i = 0; i < numberOfMessages; i++) {
MessageId messageId = consumer.receive().getMessageId();
log.info("Message ID Received = " + messageId);
Assert.assertTrue(messageIds.remove(messageId), "Failed to receive Message");
}
log.info("Message IDs = " + messageIds);
Assert.assertEquals(messageIds.size(), 0, "Not all messages received successfully");
consumer.unsubscribe();
}
Aggregations