Search in sources :

Example 11 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class NamespacesTest method testValidateAdminAccessOnTenant.

@Test
public void testValidateAdminAccessOnTenant() throws Exception {
    try {
        final String tenant = "prop";
        pulsar.getConfiguration().setAuthenticationEnabled(true);
        pulsar.getConfiguration().setAuthorizationEnabled(true);
        pulsar.getPulsarResources().getTenantResources().createTenant(tenant, new TenantInfoImpl(Sets.newHashSet(namespaces.clientAppId()), Sets.newHashSet("use")));
        namespaces.validateTenantOperation(tenant, null);
    } finally {
        pulsar.getConfiguration().setAuthenticationEnabled(false);
        pulsar.getConfiguration().setAuthorizationEnabled(false);
    }
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 12 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class AdminApiSchemaAutoUpdateTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    super.internalSetup();
    // Setup namespaces
    admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
    TenantInfoImpl tenantInfo = new TenantInfoImpl(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test"));
    admin.tenants().createTenant("prop-xyz", tenantInfo);
    admin.namespaces().createNamespace("prop-xyz/ns1", Sets.newHashSet("test"));
    admin.namespaces().createNamespace("prop-xyz/test/ns1");
    admin.namespaces().createNamespace("prop-xyz/ns2", Sets.newHashSet("test"));
    admin.namespaces().createNamespace("prop-xyz/test/ns2");
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 13 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class AdminApiSchemaTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    super.internalSetup();
    // Setup namespaces
    admin.clusters().createCluster(cluster, ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
    TenantInfoImpl tenantInfo = new TenantInfoImpl(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test"));
    admin.tenants().createTenant("schematest", tenantInfo);
    admin.namespaces().createNamespace("schematest/test", Sets.newHashSet("test"));
    admin.namespaces().createNamespace("schematest/" + cluster + "/test", Sets.newHashSet("test"));
    admin.namespaces().createNamespace(schemaCompatibilityNamespace, Sets.newHashSet("test"));
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 14 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class PersistentTopicsTest method testPeekWithSubscriptionNameNotExist.

@Test
public void testPeekWithSubscriptionNameNotExist() throws Exception {
    TenantInfoImpl tenantInfo = new TenantInfoImpl(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test"));
    admin.tenants().createTenant("tenant-xyz", tenantInfo);
    admin.namespaces().createNamespace("tenant-xyz/ns-abc", Sets.newHashSet("test"));
    RetentionPolicies retention = new RetentionPolicies(10, 10);
    admin.namespaces().setRetention("tenant-xyz/ns-abc", retention);
    final String topic = "persistent://tenant-xyz/ns-abc/topic-testPeekWithSubscriptionNameNotExist";
    final String subscriptionName = "sub";
    ((TopicsImpl) admin.topics()).createPartitionedTopicAsync(topic, 3, true, null).get();
    final String partitionedTopic = topic + "-partition-0";
    Producer<String> producer = pulsarClient.newProducer(Schema.STRING).enableBatching(false).topic(topic).create();
    for (int i = 0; i < 10; ++i) {
        producer.send("test" + i);
    }
    List<Message<byte[]>> messages = admin.topics().peekMessages(partitionedTopic, subscriptionName, 3);
    Assert.assertEquals(messages.size(), 3);
    producer.close();
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Message(org.apache.pulsar.client.api.Message) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 15 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class PersistentTopicsTest method testExamineMessageMetadata.

@Test
public void testExamineMessageMetadata() throws Exception {
    TenantInfoImpl tenantInfo = new TenantInfoImpl(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test"));
    admin.tenants().createTenant("tenant-xyz", tenantInfo);
    admin.namespaces().createNamespace("tenant-xyz/ns-abc", Sets.newHashSet("test"));
    final String topicName = "persistent://tenant-xyz/ns-abc/topic-testExamineMessageMetadata";
    admin.topics().createPartitionedTopic(topicName, 2);
    @Cleanup Producer<String> producer = pulsarClient.newProducer(Schema.STRING).producerName("testExamineMessageMetadataProducer").compressionType(CompressionType.LZ4).topic(topicName + "-partition-0").create();
    producer.newMessage().keyBytes("partition123".getBytes()).orderingKey(new byte[] { 0 }).replicationClusters(Lists.newArrayList("a", "b")).sequenceId(112233).value("data").send();
    MessageImpl<byte[]> message = (MessageImpl<byte[]>) admin.topics().examineMessage(topicName + "-partition-0", "earliest", 1);
    // test long
    Assert.assertEquals(112233, message.getSequenceId());
    // test byte[]
    Assert.assertEquals(new byte[] { 0 }, message.getOrderingKey());
    // test bool and byte[]
    Assert.assertEquals("partition123".getBytes(), message.getKeyBytes());
    Assert.assertTrue(message.hasBase64EncodedKey());
    // test arrays
    Assert.assertEquals(Lists.newArrayList("a", "b"), message.getReplicateTo());
    // test string
    Assert.assertEquals(producer.getProducerName(), message.getProducerName());
    // test enum
    Assert.assertEquals(CompressionType.LZ4.ordinal(), message.getMessageBuilder().getCompression().ordinal());
    Assert.assertEquals("data", new String(message.getData()));
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) MessageImpl(org.apache.pulsar.client.impl.MessageImpl) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

TenantInfoImpl (org.apache.pulsar.common.policies.data.TenantInfoImpl)690 Test (org.testng.annotations.Test)458 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)211 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)146 BeforeMethod (org.testng.annotations.BeforeMethod)144 Cleanup (lombok.Cleanup)139 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)136 PulsarClient (org.apache.pulsar.client.api.PulsarClient)91 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)72 HashSet (java.util.HashSet)55 HashMap (java.util.HashMap)49 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)48 CompletableFuture (java.util.concurrent.CompletableFuture)41 List (java.util.List)38 PulsarService (org.apache.pulsar.broker.PulsarService)37 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)36 ArrayList (java.util.ArrayList)33 WebTarget (javax.ws.rs.client.WebTarget)33 Policies (org.apache.pulsar.common.policies.data.Policies)33 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)31