Search in sources :

Example 1 with OwnershipCache

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

the class NamespacesTest method testSplitBundles.

@Test
public void testSplitBundles() throws Exception {
    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);
    mockWebUrl(localWebServiceUrl, testNs);
    // split bundles
    try {
        namespaces.splitNamespaceBundle(testProperty, testLocalCluster, bundledNsLocal, "0x00000000_0xffffffff", false);
        // verify split bundles
        BundlesData bundlesData = namespaces.getBundlesData(testProperty, testLocalCluster, bundledNsLocal);
        assertNotNull(bundlesData);
        assertTrue(bundlesData.boundaries.size() == 3);
        assertTrue(bundlesData.boundaries.get(0).equals("0x00000000"));
        assertTrue(bundlesData.boundaries.get(1).equals("0x7fffffff"));
        assertTrue(bundlesData.boundaries.get(2).equals("0xffffffff"));
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
}
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) RestException(com.yahoo.pulsar.broker.web.RestException) URL(java.net.URL) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 2 with OwnershipCache

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

the class NamespacesTest method testRetention.

@Test
public void testRetention() 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);
        mockWebUrl(localWebServiceUrl, testNs);
        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);
        RetentionPolicies retention = new RetentionPolicies(10, 10);
        namespaces.setRetention(this.testProperty, this.testLocalCluster, bundledNsLocal, retention);
        RetentionPolicies retention2 = namespaces.getRetention(this.testProperty, this.testLocalCluster, bundledNsLocal);
        assertEquals(retention, retention2);
    } catch (RestException e) {
        fail("ValidateNamespaceOwnershipWithBundles failed");
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) RetentionPolicies(com.yahoo.pulsar.common.policies.data.RetentionPolicies) 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) RestException(com.yahoo.pulsar.broker.web.RestException) URL(java.net.URL) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 3 with OwnershipCache

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

the class NamespacesTest method testValidateNamespaceOwnershipWithBundles.

@Test
public void testValidateNamespaceOwnershipWithBundles() 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);
        mockWebUrl(localWebServiceUrl, testNs);
        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);
        namespaces.validateNamespaceOwnershipWithBundles(this.testProperty, this.testLocalCluster, bundledNsLocal, false, true, bundleData);
    } catch (RestException e) {
        fail("ValidateNamespaceOwnershipWithBundles 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) RestException(com.yahoo.pulsar.broker.web.RestException) URL(java.net.URL) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 4 with OwnershipCache

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

the class ReplicatorTest method testConfigChangeNegativeCases.

@Test(enabled = false)
public void testConfigChangeNegativeCases() throws Exception {
    log.info("--- Starting ReplicatorTest::testConfigChangeNegativeCases ---");
    // Negative test cases for global namespace config change. Verify that the namespace config change can not be
    // updated when the namespace is being unloaded.
    // Set up field access to internal namespace state in NamespaceService
    Field ownershipCacheField = NamespaceService.class.getDeclaredField("ownershipCache");
    ownershipCacheField.setAccessible(true);
    OwnershipCache ownerCache = (OwnershipCache) ownershipCacheField.get(pulsar1.getNamespaceService());
    Assert.assertNotNull(pulsar1, "pulsar1 is null");
    Assert.assertNotNull(pulsar1.getNamespaceService(), "pulsar1.getNamespaceService() is null");
    NamespaceBundle globalNsBundle = pulsar1.getNamespaceService().getNamespaceBundleFactory().getFullBundle(new NamespaceName("pulsar/global/ns"));
    ownerCache.tryAcquiringOwnership(globalNsBundle);
    Assert.assertNotNull(ownerCache.getOwnedBundle(globalNsBundle), "pulsar1.getNamespaceService().getOwnedServiceUnit(new NamespaceName(\"pulsar/global/ns\")) is null");
    Field stateField = OwnedBundle.class.getDeclaredField("isActive");
    stateField.setAccessible(true);
    // set the namespace to be disabled
    ownerCache.disableOwnership(globalNsBundle);
    // Make sure the namespace config update failed
    try {
        admin1.namespaces().setNamespaceReplicationClusters("pulsar/global/ns", Lists.newArrayList("r1"));
        fail("Should have raised exception");
    } catch (PreconditionFailedException pfe) {
    // OK
    }
    // restore the namespace state
    ownerCache.removeOwnership(globalNsBundle).get();
    ownerCache.tryAcquiringOwnership(globalNsBundle);
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) Field(java.lang.reflect.Field) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) OwnershipCache(com.yahoo.pulsar.broker.namespace.OwnershipCache) PreconditionFailedException(com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) Test(org.testng.annotations.Test)

Example 5 with OwnershipCache

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

the class BrokerClientIntegrationTest method testCloseBrokerService.

/**
     * Verifies: 1. Closing of Broker service unloads all bundle gracefully and there must not be any connected bundles
     * after closing broker service
     * 
     * @throws Exception
     */
@Test
public void testCloseBrokerService() throws Exception {
    final String ns1 = "my-property/use/brok-ns1";
    final String ns2 = "my-property/use/brok-ns2";
    admin.namespaces().createNamespace(ns1);
    admin.namespaces().createNamespace(ns2);
    final String dn1 = "persistent://" + ns1 + "/my-topic";
    final String dn2 = "persistent://" + ns2 + "/my-topic";
    ConsumerImpl consumer1 = (ConsumerImpl) pulsarClient.subscribe(dn1, "my-subscriber-name", new ConsumerConfiguration());
    ProducerImpl producer1 = (ProducerImpl) pulsarClient.createProducer(dn1, new ProducerConfiguration());
    ProducerImpl producer2 = (ProducerImpl) pulsarClient.createProducer(dn2, new ProducerConfiguration());
    // unload all other namespace
    pulsar.getBrokerService().close();
    // [1] OwnershipCache should not contain any more namespaces
    OwnershipCache ownershipCache = pulsar.getNamespaceService().getOwnershipCache();
    assertTrue(ownershipCache.getOwnedBundles().keySet().isEmpty());
    // [2] All clients must be disconnected and in connecting state
    // producer1 must not be able to connect again
    assertTrue(producer1.getClientCnx() == null);
    assertTrue(producer1.getState().equals(State.Connecting));
    // consumer1 must not be able to connect again
    assertTrue(consumer1.getClientCnx() == null);
    assertTrue(consumer1.getState().equals(State.Connecting));
    // producer2 must not be able to connect again
    assertTrue(producer2.getClientCnx() == null);
    assertTrue(producer2.getState().equals(State.Connecting));
    producer1.close();
    producer2.close();
    consumer1.close();
}
Also used : OwnershipCache(com.yahoo.pulsar.broker.namespace.OwnershipCache) ConsumerConfiguration(com.yahoo.pulsar.client.api.ConsumerConfiguration) ProducerConfiguration(com.yahoo.pulsar.client.api.ProducerConfiguration) Test(org.testng.annotations.Test)

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