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());
}
}
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");
}
}
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");
}
}
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);
}
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();
}
Aggregations