use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.
the class NamespacesImpl method clearNamespaceBundleBacklogForSubscription.
@Override
public void clearNamespaceBundleBacklogForSubscription(String namespace, String bundle, String subscription) throws PulsarAdminException {
try {
NamespaceName ns = NamespaceName.get(namespace);
WebTarget path = namespacePath(ns, bundle, "clearBacklog", subscription);
request(path).post(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class);
} catch (Exception e) {
throw getApiException(e);
}
}
use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.
the class PersistentTopicE2ETest method testTopicDeleteWithDisconnectedSubscription.
@Test
public void testTopicDeleteWithDisconnectedSubscription() throws Exception {
final String topicName = "persistent://prop/use/ns-abc/topic8";
final String subName = "sub1";
// 1. client connect
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).subscribe();
PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName);
PersistentSubscription subRef = topicRef.getSubscription(subName);
assertNotNull(topicRef);
assertNotNull(subRef);
assertTrue(subRef.getDispatcher().isConsumerConnected());
// 2. client disconnect
consumer.close();
assertFalse(subRef.getDispatcher().isConsumerConnected());
// 3. delete topic
admin.persistentTopics().delete(topicName);
try {
admin.persistentTopics().getStats(topicName);
} catch (PulsarAdminException e) {
// ok
}
}
use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.
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 topic = "persistent://" + namespace + "1/topic1";
// this will cause NPE and it should throw 500
mockZookKeeper.shutdown();
pulsar.getConfiguration().setSuperUserRoles(Sets.newHashSet());
try {
admin.persistentTopics().getPartitionedTopicMetadata(topic);
} catch (PulsarAdminException e) {
Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
}
try {
admin.lookups().lookupTopic(topic);
} catch (PulsarAdminException e) {
Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
}
}
use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.
the class AuthenticatedProducerConsumerTest method testAuthenticationFilterNegative.
/**
* Verifies: on 500 server error, broker invalidates session and client receives 500 correctly.
*
* @throws Exception
*/
@Test
public void testAuthenticationFilterNegative() 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);
final String cluster = "use";
final ClusterData clusterData = new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), "pulsar://localhost:" + BROKER_PORT, "pulsar+ssl://localhost:" + BROKER_PORT_TLS);
// this will cause NPE and it should throw 500
doReturn(null).when(pulsar).getGlobalZkCache();
try {
admin.clusters().createCluster(cluster, clusterData);
} catch (PulsarAdminException e) {
Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
}
log.info("-- Exiting {} test --", methodName);
}
use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.
the class PulsarBrokerStatsClientTest method testServiceException.
@Test
public void testServiceException() throws Exception {
URL url = new URL("http://localhost:15000");
PulsarAdmin admin = new PulsarAdmin(url, (Authentication) null);
BrokerStatsImpl client = (BrokerStatsImpl) spy(admin.brokerStats());
try {
client.getLoadReport();
} catch (PulsarAdminException e) {
// Ok
}
try {
client.getPendingBookieOpsStats();
} catch (PulsarAdminException e) {
// Ok
}
try {
client.getBrokerResourceAvailability("prop/cluster/ns");
} catch (PulsarAdminException e) {
// Ok
}
assertTrue(client.getApiException(new ClientErrorException(403)) instanceof NotAuthorizedException);
assertTrue(client.getApiException(new ClientErrorException(404)) instanceof NotFoundException);
assertTrue(client.getApiException(new ClientErrorException(409)) instanceof ConflictException);
assertTrue(client.getApiException(new ClientErrorException(412)) instanceof PreconditionFailedException);
assertTrue(client.getApiException(new ClientErrorException(400)) instanceof PulsarAdminException);
assertTrue(client.getApiException(new ServerErrorException(500)) instanceof ServerSideErrorException);
assertTrue(client.getApiException(new ServerErrorException(503)) instanceof PulsarAdminException);
log.info("Client: ", client);
admin.close();
}
Aggregations