Search in sources :

Example 1 with AbstractMetadataStore

use of org.apache.pulsar.metadata.impl.AbstractMetadataStore in project pulsar by apache.

the class NamespacesTest method testGetNamespaces.

@Test
public void testGetNamespaces() throws Exception {
    List<String> expectedList = Lists.newArrayList(this.testLocalNamespaces.get(0).toString(), this.testLocalNamespaces.get(1).toString());
    expectedList.sort(null);
    assertEquals(namespaces.getNamespacesForCluster(this.testTenant, this.testLocalCluster), expectedList);
    expectedList = Lists.newArrayList(this.testLocalNamespaces.get(0).toString(), this.testLocalNamespaces.get(1).toString(), this.testLocalNamespaces.get(2).toString(), this.testGlobalNamespaces.get(0).toString());
    expectedList.sort(null);
    assertEquals(namespaces.getTenantNamespaces(this.testTenant), expectedList);
    try {
        // check the tenant name is valid
        namespaces.getTenantNamespaces(this.testTenant + "/default");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    try {
        namespaces.getTenantNamespaces("non-existing-tenant");
        fail("should have failed");
    } catch (RestException e) {
    // Ok, does not exist
    }
    try {
        namespaces.getNamespacesForCluster(this.testTenant, "other-cluster");
        fail("should have failed");
    } catch (RestException e) {
    // Ok, does not exist
    }
    // ZK Errors
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/policies/my-tenant");
    });
    // clear caches to load data from metadata-store again
    MetadataCacheImpl<TenantInfo> tenantCache = (MetadataCacheImpl<TenantInfo>) pulsar.getPulsarResources().getTenantResources().getCache();
    AbstractMetadataStore store = (AbstractMetadataStore) tenantCache.getStore();
    tenantCache.invalidateAll();
    store.invalidateAll();
    try {
        namespaces.getTenantNamespaces(this.testTenant);
        fail("should have failed");
    } catch (RestException e) {
    // Ok
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/policies/my-tenant/use");
    });
    try {
        namespaces.getNamespacesForCluster(this.testTenant, this.testLocalCluster);
        fail("should have failed");
    } catch (RestException e) {
    // Ok
    }
}
Also used : AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) RestException(org.apache.pulsar.broker.web.RestException) TenantInfo(org.apache.pulsar.common.policies.data.TenantInfo) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 2 with AbstractMetadataStore

use of org.apache.pulsar.metadata.impl.AbstractMetadataStore in project pulsar by apache.

the class AdminTest method clusters.

@Test
public void clusters() throws Exception {
    assertEquals(clusters.getClusters(), Lists.newArrayList());
    verify(clusters, never()).validateSuperUserAccess();
    clusters.createCluster("use", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.use.example.com:8080").build());
    verify(clusters, times(1)).validateSuperUserAccess();
    // ensure to read from ZooKeeper directly
    // clusters.clustersListCache().clear();
    assertEquals(clusters.getClusters(), Lists.newArrayList("use"));
    // Check creating existing cluster
    try {
        clusters.createCluster("use", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.use.example.com:8080").build());
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.CONFLICT.getStatusCode());
    }
    // Check deleting non-existing cluster
    try {
        clusters.deleteCluster("usc");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    assertEquals(clusters.getCluster("use"), ClusterDataImpl.builder().serviceUrl("http://broker.messaging.use.example.com:8080").build());
    verify(clusters, times(4)).validateSuperUserAccess();
    clusters.updateCluster("use", ClusterDataImpl.builder().serviceUrl("http://new-broker.messaging.use.example.com:8080").build());
    verify(clusters, times(5)).validateSuperUserAccess();
    assertEquals(clusters.getCluster("use"), ClusterData.builder().serviceUrl("http://new-broker.messaging.use.example.com:8080").build());
    verify(clusters, times(6)).validateSuperUserAccess();
    try {
        clusters.getNamespaceIsolationPolicies("use");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 404);
    }
    Map<String, String> parameters1 = new HashMap<>();
    parameters1.put("min_limit", "1");
    parameters1.put("usage_threshold", "90");
    NamespaceIsolationDataImpl policyData = NamespaceIsolationDataImpl.builder().namespaces(Collections.singletonList("dummy/colo/ns")).primary(Collections.singletonList("localhost" + ":" + pulsar.getListenPortHTTP())).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters1).build()).build();
    AsyncResponse response = mock(AsyncResponse.class);
    clusters.setNamespaceIsolationPolicy(response, "use", "policy1", policyData);
    clusters.getNamespaceIsolationPolicies("use");
    try {
        clusters.deleteCluster("use");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 412);
    }
    clusters.deleteNamespaceIsolationPolicy("use", "policy1");
    assertTrue(clusters.getNamespaceIsolationPolicies("use").isEmpty());
    clusters.deleteCluster("use");
    verify(clusters, times(13)).validateSuperUserAccess();
    assertEquals(clusters.getClusters(), Lists.newArrayList());
    try {
        clusters.getCluster("use");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 404);
    }
    try {
        clusters.updateCluster("use", ClusterDataImpl.builder().build());
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 404);
    }
    try {
        clusters.getNamespaceIsolationPolicies("use");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 404);
    }
    // Test zk failures
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/clusters");
    });
    // clear caches to load data from metadata-store again
    MetadataCacheImpl<ClusterData> clusterCache = (MetadataCacheImpl<ClusterData>) pulsar.getPulsarResources().getClusterResources().getCache();
    MetadataCacheImpl isolationPolicyCache = (MetadataCacheImpl) pulsar.getPulsarResources().getNamespaceResources().getIsolationPolicies().getCache();
    AbstractMetadataStore store = (AbstractMetadataStore) clusterCache.getStore();
    clusterCache.invalidateAll();
    store.invalidateAll();
    try {
        clusters.getClusters();
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.CREATE && path.equals("/admin/clusters/test");
    });
    try {
        clusters.createCluster("test", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.test.example.com:8080").build());
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/clusters/test");
    });
    clusterCache.invalidateAll();
    store.invalidateAll();
    try {
        clusters.updateCluster("test", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.test.example.com").build());
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/clusters/test");
    });
    try {
        clusters.getCluster("test");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/policies");
    });
    try {
        clusters.deleteCluster("use");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/clusters/use/namespaceIsolationPolicies");
    });
    clusterCache.invalidateAll();
    isolationPolicyCache.invalidateAll();
    store.invalidateAll();
    try {
        clusters.deleteCluster("use");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    // Check name validations
    try {
        clusters.createCluster("bf@", ClusterDataImpl.builder().serviceUrl("http://dummy.messaging.example.com").build());
        fail("should have filed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    // Check authentication and listener name
    try {
        clusters.createCluster("auth", ClusterDataImpl.builder().serviceUrl("http://dummy.web.example.com").serviceUrlTls("").brokerServiceUrl("http://dummy.messaging.example.com").brokerServiceUrlTls("").authenticationPlugin("authenticationPlugin").authenticationParameters("authenticationParameters").listenerName("listenerName").build());
        ClusterData cluster = clusters.getCluster("auth");
        assertEquals(cluster.getAuthenticationPlugin(), "authenticationPlugin");
        assertEquals(cluster.getAuthenticationParameters(), "authenticationParameters");
        assertEquals(cluster.getListenerName(), "listenerName");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) HashMap(java.util.HashMap) RestException(org.apache.pulsar.broker.web.RestException) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) NamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.NamespaceIsolationDataImpl) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 3 with AbstractMetadataStore

use of org.apache.pulsar.metadata.impl.AbstractMetadataStore in project pulsar by yahoo.

the class AdminTest method clusters.

@Test
@SuppressWarnings("unchecked")
public void clusters() throws Exception {
    assertEquals(asyncRequests(ctx -> clusters.getClusters(ctx)), Sets.newHashSet());
    verify(clusters, never()).validateSuperUserAccessAsync();
    asyncRequests(ctx -> clusters.createCluster(ctx, "use", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.use.example.com:8080").build()));
    // ensure to read from ZooKeeper directly
    // clusters.clustersListCache().clear();
    assertEquals(asyncRequests(ctx -> clusters.getClusters(ctx)), Sets.newHashSet("use"));
    // Check creating existing cluster
    try {
        asyncRequests(ctx -> clusters.createCluster(ctx, "use", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.use.example.com:8080").build()));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.CONFLICT.getStatusCode());
    }
    // Check deleting non-existing cluster
    try {
        asyncRequests(ctx -> clusters.deleteCluster(ctx, "usc"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    assertEquals(asyncRequests(ctx -> clusters.getCluster(ctx, "use")), ClusterDataImpl.builder().serviceUrl("http://broker.messaging.use.example.com:8080").build());
    asyncRequests(ctx -> clusters.updateCluster(ctx, "use", ClusterDataImpl.builder().serviceUrl("http://new-broker.messaging.use.example.com:8080").build()));
    assertEquals(asyncRequests(ctx -> clusters.getCluster(ctx, "use")), ClusterData.builder().serviceUrl("http://new-broker.messaging.use.example.com:8080").build());
    try {
        asyncRequests(ctx -> clusters.getNamespaceIsolationPolicies(ctx, "use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 404);
    }
    Map<String, String> parameters1 = new HashMap<>();
    parameters1.put("min_limit", "1");
    parameters1.put("usage_threshold", "90");
    NamespaceIsolationDataImpl policyData = NamespaceIsolationDataImpl.builder().namespaces(Collections.singletonList("dummy/colo/ns")).primary(Collections.singletonList("localhost" + ":" + pulsar.getListenPortHTTP())).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters1).build()).build();
    asyncRequests(ctx -> clusters.setNamespaceIsolationPolicy(ctx, "use", "policy1", policyData));
    asyncRequests(ctx -> clusters.getNamespaceIsolationPolicies(ctx, "use"));
    try {
        asyncRequests(ctx -> clusters.deleteCluster(ctx, "use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 412);
    }
    asyncRequests(ctx -> clusters.deleteNamespaceIsolationPolicy(ctx, "use", "policy1"));
    assertTrue(((Map<String, NamespaceIsolationDataImpl>) asyncRequests(ctx -> clusters.getNamespaceIsolationPolicies(ctx, "use"))).isEmpty());
    asyncRequests(ctx -> clusters.deleteCluster(ctx, "use"));
    assertEquals(asyncRequests(ctx -> clusters.getClusters(ctx)), Sets.newHashSet());
    try {
        asyncRequests(ctx -> clusters.getCluster(ctx, "use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 404);
    }
    try {
        asyncRequests(ctx -> clusters.updateCluster(ctx, "use", ClusterDataImpl.builder().build()));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 404);
    }
    try {
        asyncRequests(ctx -> clusters.getNamespaceIsolationPolicies(ctx, "use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 404);
    }
    // Test zk failures
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/clusters");
    });
    // clear caches to load data from metadata-store again
    MetadataCacheImpl<ClusterData> clusterCache = (MetadataCacheImpl<ClusterData>) pulsar.getPulsarResources().getClusterResources().getCache();
    MetadataCacheImpl isolationPolicyCache = (MetadataCacheImpl) pulsar.getPulsarResources().getNamespaceResources().getIsolationPolicies().getCache();
    AbstractMetadataStore store = (AbstractMetadataStore) clusterCache.getStore();
    clusterCache.invalidateAll();
    store.invalidateAll();
    try {
        asyncRequests(ctx -> clusters.getClusters(ctx));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.CREATE && path.equals("/admin/clusters/test");
    });
    try {
        asyncRequests(ctx -> clusters.createCluster(ctx, "test", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.test.example.com:8080").build()));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/clusters/test");
    });
    clusterCache.invalidateAll();
    store.invalidateAll();
    try {
        asyncRequests(ctx -> clusters.updateCluster(ctx, "test", ClusterDataImpl.builder().serviceUrl("http://broker.messaging.test.example.com").build()));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/clusters/test");
    });
    try {
        asyncRequests(ctx -> clusters.getCluster(ctx, "test"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/policies");
    });
    try {
        asyncRequests(ctx -> clusters.deleteCluster(ctx, "use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/clusters/use/namespaceIsolationPolicies");
    });
    clusterCache.invalidateAll();
    isolationPolicyCache.invalidateAll();
    store.invalidateAll();
    try {
        asyncRequests(ctx -> clusters.deleteCluster(ctx, "use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    // Check name validations
    try {
        asyncRequests(ctx -> clusters.createCluster(ctx, "bf@", ClusterDataImpl.builder().serviceUrl("http://dummy.messaging.example.com").build()));
        fail("should have filed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    // Check authentication and listener name
    try {
        asyncRequests(ctx -> clusters.createCluster(ctx, "auth", ClusterDataImpl.builder().serviceUrl("http://dummy.web.example.com").serviceUrlTls("").brokerServiceUrl("http://dummy.messaging.example.com").brokerServiceUrlTls("").authenticationPlugin("authenticationPlugin").authenticationParameters("authenticationParameters").listenerName("listenerName").build()));
        ClusterData cluster = (ClusterData) asyncRequests(ctx -> clusters.getCluster(ctx, "auth"));
        assertEquals(cluster.getAuthenticationPlugin(), "authenticationPlugin");
        assertEquals(cluster.getAuthenticationParameters(), "authenticationParameters");
        assertEquals(cluster.getListenerName(), "listenerName");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    verify(clusters, times(24)).validateSuperUserAccessAsync();
}
Also used : ClusterDataImpl(org.apache.pulsar.common.policies.data.ClusterDataImpl) Metrics(org.apache.pulsar.common.stats.Metrics) AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) Test(org.testng.annotations.Test) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) BrokerStats(org.apache.pulsar.broker.admin.v1.BrokerStats) AfterMethod(org.testng.annotations.AfterMethod) Namespaces(org.apache.pulsar.broker.admin.v1.Namespaces) AuthenticationDataHttps(org.apache.pulsar.broker.authentication.AuthenticationDataHttps) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) Brokers(org.apache.pulsar.broker.admin.v1.Brokers) PendingBookieOpsStats(org.apache.bookkeeper.mledger.proto.PendingBookieOpsStats) Collection(java.util.Collection) AsyncResponse(javax.ws.rs.container.AsyncResponse) BrokerInfo(org.apache.pulsar.common.policies.data.BrokerInfo) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) PersistentTopics(org.apache.pulsar.broker.admin.v1.PersistentTopics) StreamingOutput(javax.ws.rs.core.StreamingOutput) MockZooKeeper(org.apache.zookeeper.MockZooKeeper) Mockito.doNothing(org.mockito.Mockito.doNothing) Assert.assertNotNull(org.testng.Assert.assertNotNull) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) Sets(com.google.common.collect.Sets) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest) List(java.util.List) SchemasResource(org.apache.pulsar.broker.admin.v2.SchemasResource) Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) LeaderBroker(org.apache.pulsar.broker.loadbalance.LeaderBroker) Awaitility(org.awaitility.Awaitility) Mockito.mock(org.mockito.Mockito.mock) Code(org.apache.zookeeper.KeeperException.Code) TopicName(org.apache.pulsar.common.naming.TopicName) NamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.NamespaceIsolationDataImpl) Properties(org.apache.pulsar.broker.admin.v1.Properties) CommandGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) Mockito.spy(org.mockito.Mockito.spy) Mockito.timeout(org.mockito.Mockito.timeout) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) Assert.assertNotSame(org.testng.Assert.assertNotSame) Assert(org.testng.Assert) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) Clusters(org.apache.pulsar.broker.admin.v1.Clusters) TenantInfo(org.apache.pulsar.common.policies.data.TenantInfo) Status(javax.ws.rs.core.Response.Status) AllocatorStats(org.apache.pulsar.common.stats.AllocatorStats) ResourceQuota(org.apache.pulsar.common.policies.data.ResourceQuota) PulsarWebResource(org.apache.pulsar.broker.web.PulsarWebResource) AutoFailoverPolicyType(org.apache.pulsar.common.policies.data.AutoFailoverPolicyType) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) Assert.fail(org.testng.Assert.fail) Mockito.times(org.mockito.Mockito.times) Field(java.lang.reflect.Field) ResourceQuotas(org.apache.pulsar.broker.admin.v1.ResourceQuotas) Mockito.verify(org.mockito.Mockito.verify) Policies(org.apache.pulsar.common.policies.data.Policies) Mockito.never(org.mockito.Mockito.never) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) InternalConfigurationData(org.apache.pulsar.common.conf.InternalConfigurationData) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) AutoFailoverPolicyData(org.apache.pulsar.common.policies.data.AutoFailoverPolicyData) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) HashMap(java.util.HashMap) RestException(org.apache.pulsar.broker.web.RestException) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) NamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.NamespaceIsolationDataImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 4 with AbstractMetadataStore

use of org.apache.pulsar.metadata.impl.AbstractMetadataStore in project pulsar by yahoo.

the class AdminTest method properties.

@Test
public void properties() throws Throwable {
    Object response = asyncRequests(ctx -> properties.getTenants(ctx));
    assertEquals(response, Lists.newArrayList());
    verify(properties, times(1)).validateSuperUserAccessAsync();
    // create local cluster
    asyncRequests(ctx -> clusters.createCluster(ctx, configClusterName, ClusterDataImpl.builder().build()));
    Set<String> allowedClusters = Sets.newHashSet();
    allowedClusters.add(configClusterName);
    TenantInfoImpl tenantInfo = TenantInfoImpl.builder().adminRoles(Sets.newHashSet("role1", "role2")).allowedClusters(allowedClusters).build();
    response = asyncRequests(ctx -> properties.createTenant(ctx, "test-property", tenantInfo));
    verify(properties, times(2)).validateSuperUserAccessAsync();
    response = asyncRequests(ctx -> properties.getTenants(ctx));
    assertEquals(response, Lists.newArrayList("test-property"));
    verify(properties, times(3)).validateSuperUserAccessAsync();
    response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "test-property"));
    assertEquals(response, tenantInfo);
    verify(properties, times(4)).validateSuperUserAccessAsync();
    final TenantInfoImpl newPropertyAdmin = TenantInfoImpl.builder().adminRoles(Sets.newHashSet("role1", "other-role")).allowedClusters(allowedClusters).build();
    response = asyncRequests(ctx -> properties.updateTenant(ctx, "test-property", newPropertyAdmin));
    verify(properties, times(5)).validateSuperUserAccessAsync();
    // Wait for updateTenant to take effect
    Thread.sleep(100);
    response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "test-property"));
    assertEquals(response, newPropertyAdmin);
    response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "test-property"));
    assertNotSame(response, tenantInfo);
    verify(properties, times(7)).validateSuperUserAccessAsync();
    // Check creating existing property
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "test-property", tenantInfo));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.CONFLICT.getStatusCode());
    }
    // Check non-existing property
    try {
        response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "non-existing"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    try {
        response = asyncRequests(ctx -> properties.updateTenant(ctx, "xxx-non-existing", newPropertyAdmin));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    // Check deleting non-existing property
    try {
        response = asyncRequests(ctx -> properties.deleteTenant(ctx, "non-existing", false));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    // clear caches to load data from metadata-store again
    MetadataCacheImpl<TenantInfo> cache = (MetadataCacheImpl<TenantInfo>) pulsar.getPulsarResources().getTenantResources().getCache();
    AbstractMetadataStore store = (AbstractMetadataStore) cache.getStore();
    cache.invalidateAll();
    store.invalidateAll();
    // Test zk failures
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/policies");
    });
    try {
        response = asyncRequests(ctx -> properties.getTenants(ctx));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/policies/my-tenant");
    });
    try {
        response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "my-tenant"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/policies/my-tenant");
    });
    try {
        response = asyncRequests(ctx -> properties.updateTenant(ctx, "my-tenant", newPropertyAdmin));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.CREATE && path.equals("/admin/policies/test");
    });
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "test", tenantInfo));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/policies/test-property");
    });
    try {
        cache.invalidateAll();
        store.invalidateAll();
        response = asyncRequests(ctx -> properties.deleteTenant(ctx, "test-property", false));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    response = asyncRequests(ctx -> properties.createTenant(ctx, "error-property", tenantInfo));
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.DELETE && path.equals("/admin/policies/error-property");
    });
    try {
        response = asyncRequests(ctx -> properties.deleteTenant(ctx, "error-property", false));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    response = asyncRequests(ctx -> properties.deleteTenant(ctx, "test-property", false));
    response = asyncRequests(ctx -> properties.deleteTenant(ctx, "error-property", false));
    response = Lists.newArrayList();
    response = asyncRequests(ctx -> properties.getTenants(ctx));
    assertEquals(response, Lists.newArrayList());
    // Create a namespace to test deleting a non-empty property
    TenantInfoImpl newPropertyAdmin2 = TenantInfoImpl.builder().adminRoles(Sets.newHashSet("role1", "other-role")).allowedClusters(Sets.newHashSet("use")).build();
    response = asyncRequests(ctx -> properties.createTenant(ctx, "my-tenant", newPropertyAdmin2));
    response = asyncRequests(ctx -> namespaces.createNamespace(ctx, "my-tenant", "use", "my-namespace", BundlesData.builder().build()));
    try {
        response = asyncRequests(ctx -> properties.deleteTenant(ctx, "my-tenant", false));
        fail("should have failed");
    } catch (RestException e) {
    // Ok
    }
    // Check name validation
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "test&", tenantInfo));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    // Check tenantInfo is null
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "tenant-config-is-null", null));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    // Check tenantInfo with empty cluster
    String blankCluster = "";
    Set<String> blankClusters = Sets.newHashSet(blankCluster);
    TenantInfoImpl tenantWithEmptyCluster = TenantInfoImpl.builder().adminRoles(Sets.newHashSet("role1", "role2")).allowedClusters(blankClusters).build();
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "tenant-config-is-empty", tenantWithEmptyCluster));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    // Check tenantInfo contains empty cluster
    Set<String> containBlankClusters = Sets.newHashSet(blankCluster);
    containBlankClusters.add(configClusterName);
    TenantInfoImpl tenantContainEmptyCluster = TenantInfoImpl.builder().adminRoles(Sets.newHashSet()).allowedClusters(containBlankClusters).build();
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "tenant-config-contain-empty", tenantContainEmptyCluster));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    AsyncResponse response2 = mock(AsyncResponse.class);
    namespaces.deleteNamespace(response2, "my-tenant", "use", "my-namespace", false, false);
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    verify(response2, timeout(5000).times(1)).resume(captor.capture());
    assertEquals(captor.getValue().getStatus(), Status.NO_CONTENT.getStatusCode());
    response = asyncRequests(ctx -> properties.deleteTenant(ctx, "my-tenant", false));
}
Also used : ClusterDataImpl(org.apache.pulsar.common.policies.data.ClusterDataImpl) Metrics(org.apache.pulsar.common.stats.Metrics) AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) Test(org.testng.annotations.Test) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) BrokerStats(org.apache.pulsar.broker.admin.v1.BrokerStats) AfterMethod(org.testng.annotations.AfterMethod) Namespaces(org.apache.pulsar.broker.admin.v1.Namespaces) AuthenticationDataHttps(org.apache.pulsar.broker.authentication.AuthenticationDataHttps) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) Brokers(org.apache.pulsar.broker.admin.v1.Brokers) PendingBookieOpsStats(org.apache.bookkeeper.mledger.proto.PendingBookieOpsStats) Collection(java.util.Collection) AsyncResponse(javax.ws.rs.container.AsyncResponse) BrokerInfo(org.apache.pulsar.common.policies.data.BrokerInfo) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) PersistentTopics(org.apache.pulsar.broker.admin.v1.PersistentTopics) StreamingOutput(javax.ws.rs.core.StreamingOutput) MockZooKeeper(org.apache.zookeeper.MockZooKeeper) Mockito.doNothing(org.mockito.Mockito.doNothing) Assert.assertNotNull(org.testng.Assert.assertNotNull) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) Sets(com.google.common.collect.Sets) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest) List(java.util.List) SchemasResource(org.apache.pulsar.broker.admin.v2.SchemasResource) Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) LeaderBroker(org.apache.pulsar.broker.loadbalance.LeaderBroker) Awaitility(org.awaitility.Awaitility) Mockito.mock(org.mockito.Mockito.mock) Code(org.apache.zookeeper.KeeperException.Code) TopicName(org.apache.pulsar.common.naming.TopicName) NamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.NamespaceIsolationDataImpl) Properties(org.apache.pulsar.broker.admin.v1.Properties) CommandGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) Mockito.spy(org.mockito.Mockito.spy) Mockito.timeout(org.mockito.Mockito.timeout) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) Assert.assertNotSame(org.testng.Assert.assertNotSame) Assert(org.testng.Assert) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) Clusters(org.apache.pulsar.broker.admin.v1.Clusters) TenantInfo(org.apache.pulsar.common.policies.data.TenantInfo) Status(javax.ws.rs.core.Response.Status) AllocatorStats(org.apache.pulsar.common.stats.AllocatorStats) ResourceQuota(org.apache.pulsar.common.policies.data.ResourceQuota) PulsarWebResource(org.apache.pulsar.broker.web.PulsarWebResource) AutoFailoverPolicyType(org.apache.pulsar.common.policies.data.AutoFailoverPolicyType) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) Assert.fail(org.testng.Assert.fail) Mockito.times(org.mockito.Mockito.times) Field(java.lang.reflect.Field) ResourceQuotas(org.apache.pulsar.broker.admin.v1.ResourceQuotas) Mockito.verify(org.mockito.Mockito.verify) Policies(org.apache.pulsar.common.policies.data.Policies) Mockito.never(org.mockito.Mockito.never) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) InternalConfigurationData(org.apache.pulsar.common.conf.InternalConfigurationData) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) AutoFailoverPolicyData(org.apache.pulsar.common.policies.data.AutoFailoverPolicyData) AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) RestException(org.apache.pulsar.broker.web.RestException) TenantInfo(org.apache.pulsar.common.policies.data.TenantInfo) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 5 with AbstractMetadataStore

use of org.apache.pulsar.metadata.impl.AbstractMetadataStore in project pulsar by yahoo.

the class NamespacesTest method testGlobalNamespaceReplicationConfiguration.

@Test
public void testGlobalNamespaceReplicationConfiguration() throws Exception {
    assertEquals(namespaces.getNamespaceReplicationClusters(this.testGlobalNamespaces.get(0).getTenant(), this.testGlobalNamespaces.get(0).getCluster(), this.testGlobalNamespaces.get(0).getLocalName()), Sets.newHashSet());
    namespaces.setNamespaceReplicationClusters(this.testGlobalNamespaces.get(0).getTenant(), this.testGlobalNamespaces.get(0).getCluster(), this.testGlobalNamespaces.get(0).getLocalName(), Lists.newArrayList("use", "usw"));
    assertEquals(namespaces.getNamespaceReplicationClusters(this.testGlobalNamespaces.get(0).getTenant(), this.testGlobalNamespaces.get(0).getCluster(), this.testGlobalNamespaces.get(0).getLocalName()), Lists.newArrayList("use", "usw"));
    try {
        namespaces.setNamespaceReplicationClusters(this.testGlobalNamespaces.get(0).getTenant(), this.testGlobalNamespaces.get(0).getCluster(), this.testGlobalNamespaces.get(0).getLocalName(), Lists.newArrayList("use", "invalid-cluster"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.FORBIDDEN.getStatusCode());
    }
    try {
        namespaces.setNamespaceReplicationClusters(this.testGlobalNamespaces.get(0).getTenant(), this.testGlobalNamespaces.get(0).getCluster(), this.testGlobalNamespaces.get(0).getLocalName(), Lists.newArrayList("use", "global"));
        fail("should have failed");
    } catch (RestException e) {
        // Ok, global should not be allowed in the list of replication clusters
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    try {
        namespaces.setNamespaceReplicationClusters(this.testTenant, "global", this.testGlobalNamespaces.get(0).getLocalName(), Lists.newArrayList("use", "invalid-cluster"));
        fail("should have failed");
    } catch (RestException e) {
        // Ok, invalid-cluster is an invalid cluster id
        assertEquals(e.getResponse().getStatus(), Status.FORBIDDEN.getStatusCode());
    }
    admin.tenants().updateTenant(testTenant, new TenantInfoImpl(Sets.newHashSet("role1", "role2"), Sets.newHashSet("use", "usc")));
    try {
        namespaces.setNamespaceReplicationClusters(this.testTenant, "global", this.testGlobalNamespaces.get(0).getLocalName(), Lists.newArrayList("use", "usw"));
        fail("should have failed");
    } catch (RestException e) {
        // Ok, usw was not configured in the list of allowed clusters
        assertEquals(e.getResponse().getStatus(), Status.FORBIDDEN.getStatusCode());
    }
    // Sometimes watcher event consumes scheduled exception, so set to always fail to ensure exception is
    // thrown for api call.
    mockZooKeeperGlobal.setAlwaysFail(Code.SESSIONEXPIRED);
    try {
        namespaces.setNamespaceReplicationClusters(this.testTenant, "global", this.testGlobalNamespaces.get(0).getLocalName(), Lists.newArrayList("use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    } finally {
        mockZooKeeperGlobal.unsetAlwaysFail();
    }
    // clear caches to load data from metadata-store again
    MetadataCacheImpl<Policies> policiesCache = (MetadataCacheImpl<Policies>) pulsar.getPulsarResources().getNamespaceResources().getCache();
    AbstractMetadataStore store = (AbstractMetadataStore) policiesCache.getStore();
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.SET && path.equals("/admin/policies/my-tenant/global/test-global-ns1");
    });
    policiesCache.invalidateAll();
    store.invalidateAll();
    try {
        namespaces.setNamespaceReplicationClusters(this.testTenant, "global", this.testGlobalNamespaces.get(0).getLocalName(), Lists.newArrayList("use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 500);
    }
    try {
        namespaces.getNamespaceReplicationClusters(this.testTenant, "global", "non-existing-ns");
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    try {
        namespaces.setNamespaceReplicationClusters(this.testTenant, "global", "non-existing-ns", Lists.newArrayList("use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/policies/my-tenant/global/test-global-ns1");
    });
    policiesCache.invalidateAll();
    store.invalidateAll();
    // ensure the ZooKeeper read happens, bypassing the cache
    try {
        namespaces.getNamespaceReplicationClusters(this.testTenant, "global", this.testGlobalNamespaces.get(0).getLocalName());
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), 500);
    }
    try {
        namespaces.getNamespaceReplicationClusters(this.testTenant, this.testLocalCluster, this.testLocalNamespaces.get(0).getLocalName());
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    try {
        namespaces.setNamespaceReplicationClusters(this.testTenant, this.testLocalCluster, this.testLocalNamespaces.get(0).getLocalName(), Lists.newArrayList("use"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
}
Also used : PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Policies(org.apache.pulsar.common.policies.data.Policies) AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) RestException(org.apache.pulsar.broker.web.RestException) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)12 RestException (org.apache.pulsar.broker.web.RestException)12 MetadataCacheImpl (org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl)12 AbstractMetadataStore (org.apache.pulsar.metadata.impl.AbstractMetadataStore)12 Test (org.testng.annotations.Test)12 AsyncResponse (javax.ws.rs.container.AsyncResponse)9 TenantInfo (org.apache.pulsar.common.policies.data.TenantInfo)9 Response (javax.ws.rs.core.Response)8 Policies (org.apache.pulsar.common.policies.data.Policies)8 TenantInfoImpl (org.apache.pulsar.common.policies.data.TenantInfoImpl)8 List (java.util.List)7 Lists (com.google.common.collect.Lists)6 Sets (com.google.common.collect.Sets)6 Field (java.lang.reflect.Field)6 URI (java.net.URI)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Set (java.util.Set)6 Status (javax.ws.rs.core.Response.Status)6 UriInfo (javax.ws.rs.core.UriInfo)6