Search in sources :

Example 6 with OwnershipCache

use of com.yahoo.pulsar.broker.namespace.OwnershipCache in project pulsar by yahoo.

the class NamespacesTest method testValidateDestinationOwnership.

@Test
public void testValidateDestinationOwnership() 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 = new NamespaceName(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);
        DestinationName topicName = DestinationName.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);
        try {
            topics.validateAdminOperationOnDestination(topicName, false);
        } catch (RestException e) {
            fail("validateAdminAccessOnProperty failed");
        }
        try {
            topics.validateAdminOperationOnDestination(DestinationName.get(""), false);
            fail("validateAdminAccessOnProperty failed");
        } catch (Exception e) {
        // OK
        }
    } catch (RestException e) {
        fail("validateAdminAccessOnProperty failed");
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Field(java.lang.reflect.Field) OwnershipCache(com.yahoo.pulsar.broker.namespace.OwnershipCache) BundlesData(com.yahoo.pulsar.common.policies.data.BundlesData) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) RestException(com.yahoo.pulsar.broker.web.RestException) URL(java.net.URL) RestException(com.yahoo.pulsar.broker.web.RestException) ClientErrorException(javax.ws.rs.ClientErrorException) WebApplicationException(javax.ws.rs.WebApplicationException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

OwnershipCache (com.yahoo.pulsar.broker.namespace.OwnershipCache)6 Test (org.testng.annotations.Test)6 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)5 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)5 Field (java.lang.reflect.Field)5 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)4 RestException (com.yahoo.pulsar.broker.web.RestException)4 BundlesData (com.yahoo.pulsar.common.policies.data.BundlesData)4 URL (java.net.URL)4 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)1 PreconditionFailedException (com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)1 ConsumerConfiguration (com.yahoo.pulsar.client.api.ConsumerConfiguration)1 ProducerConfiguration (com.yahoo.pulsar.client.api.ProducerConfiguration)1 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)1 RetentionPolicies (com.yahoo.pulsar.common.policies.data.RetentionPolicies)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1