Search in sources :

Example 1 with PersistentTopics

use of org.apache.pulsar.broker.admin.v1.PersistentTopics in project incubator-pulsar by apache.

the class NamespacesTest method testValidateTopicOwnership.

@Test
public void testValidateTopicOwnership() throws Exception {
    try {
        URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
        String bundledNsLocal = "test-bundled-namespace-1";
        BundlesData bundleData = new BundlesData(Lists.newArrayList("0x00000000", "0xffffffff"));
        createBundledTestNamespaces(this.testProperty, this.testLocalCluster, bundledNsLocal, bundleData);
        final NamespaceName testNs = NamespaceName.get(this.testProperty, this.testLocalCluster, bundledNsLocal);
        OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
        doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
        Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
        ownership.setAccessible(true);
        ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
        TopicName topicName = TopicName.get(testNs.getPersistentTopicName("my-topic"));
        PersistentTopics topics = spy(new PersistentTopics());
        topics.setServletContext(new MockServletContext());
        topics.setPulsar(pulsar);
        doReturn(false).when(topics).isRequestHttps();
        doReturn("test").when(topics).clientAppId();
        mockWebUrl(localWebServiceUrl, testNs);
        doReturn("persistent").when(topics).domain();
        try {
            topics.validateTopicName(topicName.getProperty(), topicName.getCluster(), topicName.getNamespacePortion(), topicName.getEncodedLocalName());
            topics.validateAdminOperationOnTopic(false);
        } catch (RestException e) {
            fail("validateAdminAccessOnProperty failed");
        }
    } catch (RestException e) {
        fail("validateAdminAccessOnProperty failed");
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) Field(java.lang.reflect.Field) OwnershipCache(org.apache.pulsar.broker.namespace.OwnershipCache) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) RestException(org.apache.pulsar.broker.web.RestException) PersistentTopics(org.apache.pulsar.broker.admin.v1.PersistentTopics) URL(java.net.URL) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

Field (java.lang.reflect.Field)1 URL (java.net.URL)1 PersistentTopics (org.apache.pulsar.broker.admin.v1.PersistentTopics)1 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)1 OwnershipCache (org.apache.pulsar.broker.namespace.OwnershipCache)1 RestException (org.apache.pulsar.broker.web.RestException)1 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)1 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)1 TopicName (org.apache.pulsar.common.naming.TopicName)1 BundlesData (org.apache.pulsar.common.policies.data.BundlesData)1 Test (org.testng.annotations.Test)1