Search in sources :

Example 36 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData 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);
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Example 37 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class BrokerServiceLookupTest method testPartitionedMetadataWithDeprecatedVersion.

@Test
public void testPartitionedMetadataWithDeprecatedVersion() throws Exception {
    final String cluster = "use2";
    final String property = "my-property2";
    final String namespace = "my-ns";
    final String topicName = "my-partitioned";
    final int totalPartitions = 10;
    final TopicName dest = TopicName.get("persistent", property, cluster, namespace, topicName);
    admin.clusters().createCluster(cluster, new ClusterData("http://127.0.0.1:" + BROKER_WEBSERVICE_PORT, null, null, null));
    admin.properties().createProperty(property, new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet(cluster)));
    admin.namespaces().createNamespace(property + "/" + cluster + "/" + namespace);
    admin.persistentTopics().createPartitionedTopic(dest.toString(), totalPartitions);
    stopBroker();
    conf.setClientLibraryVersionCheckEnabled(true);
    startBroker();
    URI brokerServiceUrl = new URI(pulsar.getWebServiceAddress());
    URL url = brokerServiceUrl.toURL();
    String path = String.format("admin/%s/partitions", dest.getLookupName());
    AsyncHttpClient httpClient = getHttpClient("Pulsar-Java-1.20");
    PartitionedTopicMetadata metadata = getPartitionedMetadata(httpClient, url, path);
    assertEquals(metadata.partitions, totalPartitions);
    httpClient.close();
    httpClient = getHttpClient("Pulsar-CPP-v1.21");
    metadata = getPartitionedMetadata(httpClient, url, path);
    assertEquals(metadata.partitions, totalPartitions);
    httpClient.close();
    httpClient = getHttpClient("Pulsar-CPP-v1.21-SNAPSHOT");
    metadata = getPartitionedMetadata(httpClient, url, path);
    assertEquals(metadata.partitions, totalPartitions);
    httpClient.close();
    httpClient = getHttpClient("");
    try {
        metadata = getPartitionedMetadata(httpClient, url, path);
        fail("should have failed due to invalid version");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof PulsarClientException);
    }
    httpClient.close();
    httpClient = getHttpClient("Pulsar-CPP-v1.20-SNAPSHOT");
    try {
        metadata = getPartitionedMetadata(httpClient, url, path);
        fail("should have failed due to invalid version");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof PulsarClientException);
    }
    httpClient.close();
    httpClient = getHttpClient("Pulsar-CPP-v1.20");
    try {
        metadata = getPartitionedMetadata(httpClient, url, path);
        fail("should have failed due to invalid version");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof PulsarClientException);
    }
    httpClient.close();
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) URL(java.net.URL) TopicName(org.apache.pulsar.common.naming.TopicName) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Example 38 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class BrokerTestBase method baseSetup.

public void baseSetup() throws Exception {
    super.internalSetup();
    admin.clusters().createCluster("use", new ClusterData(brokerUrl.toString()));
    admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("prop/use/ns-abc");
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin)

Example 39 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class CompactedTopicTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    super.internalSetup();
    admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1:" + BROKER_WEBSERVICE_PORT));
    admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("my-property/use/my-ns");
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 40 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class CompactionTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    super.internalSetup();
    admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1:" + BROKER_WEBSERVICE_PORT));
    admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("my-property/use/my-ns");
    compactionScheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("compaction-%d").setDaemon(true).build());
    bk = pulsar.getBookKeeperClientFactory().create(this.conf, null);
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ClusterData (org.apache.pulsar.common.policies.data.ClusterData)53 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)30 Test (org.testng.annotations.Test)23 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)13 BeforeMethod (org.testng.annotations.BeforeMethod)13 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)11 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)10 URL (java.net.URL)9 PulsarService (org.apache.pulsar.broker.PulsarService)9 RestException (org.apache.pulsar.broker.web.RestException)8 KeeperException (org.apache.zookeeper.KeeperException)8 IOException (java.io.IOException)7 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)7 URI (java.net.URI)6 AuthenticationTls (org.apache.pulsar.client.impl.auth.AuthenticationTls)6 Authentication (org.apache.pulsar.client.api.Authentication)5 Field (java.lang.reflect.Field)4 ExecutionException (java.util.concurrent.ExecutionException)4 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)4 Policies (org.apache.pulsar.common.policies.data.Policies)4