Search in sources :

Example 41 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class BrokerServiceTest method testTopicLoadingOnDisableNamespaceBundle.

@Test
public void testTopicLoadingOnDisableNamespaceBundle() throws Exception {
    final String namespace = "prop/use/disableBundle";
    admin.namespaces().createNamespace(namespace);
    // own namespace bundle
    final String topicName = "persistent://" + namespace + "/my-topic";
    TopicName topic = TopicName.get(topicName);
    Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).create();
    producer.close();
    // disable namespace-bundle
    NamespaceBundle bundle = pulsar.getNamespaceService().getBundle(topic);
    pulsar.getNamespaceService().getOwnershipCache().updateBundleState(bundle, false);
    // try to create topic which should fail as bundle is disable
    CompletableFuture<Topic> futureResult = pulsar.getBrokerService().createPersistentTopic(topicName);
    try {
        futureResult.get();
        fail("Topic creation should fail due to disable bundle");
    } catch (Exception e) {
        if (!(e.getCause() instanceof BrokerServiceException.ServiceUnitNotReadyException)) {
            fail("Topic creation should fail with ServiceUnitNotReadyException");
        }
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) TimeoutException(java.util.concurrent.TimeoutException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) IOException(java.io.IOException) PersistenceException(org.apache.pulsar.broker.service.BrokerServiceException.PersistenceException) ExecutionException(java.util.concurrent.ExecutionException) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Example 42 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class NamespaceBundleTest method testEquals.

@Test
public void testEquals() throws Exception {
    NamespaceBundle bundle = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    NamespaceBundle bundle2 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0x20000000l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    assertTrue(!bundle.equals(bundle2));
    NamespaceBundle bundle0 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    assertTrue(bundle0.equals(bundle));
    NamespaceBundle otherBundle = factory.getBundle(NamespaceName.get("pulsar/use/ns2"), Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    assertTrue(!otherBundle.equals(bundle));
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Test(org.testng.annotations.Test)

Example 43 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class NamespaceBundleTest method testIncludes.

@Test
public void testIncludes() throws Exception {
    TopicName topicName = TopicName.get("persistent://pulsar/use/ns1/topic-1");
    Long hashKey = factory.getLongHashCode(topicName.toString());
    Long upper = Math.max(hashKey + 1, NamespaceBundles.FULL_UPPER_BOUND);
    BoundType upperType = upper.equals(NamespaceBundles.FULL_UPPER_BOUND) ? BoundType.CLOSED : BoundType.OPEN;
    NamespaceBundle bundle = factory.getBundle(topicName.getNamespaceObject(), Range.range(hashKey / 2, BoundType.CLOSED, upper, upperType));
    assertTrue(bundle.includes(topicName));
    bundle = factory.getBundle(NamespaceName.get("pulsar/use/ns1"), Range.range(upper, BoundType.CLOSED, NamespaceBundles.FULL_UPPER_BOUND, BoundType.CLOSED));
    assertTrue(!bundle.includes(topicName));
    NamespaceBundle otherBundle = factory.getBundle(NamespaceName.get("pulsar/use/ns2"), Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    assertTrue(!otherBundle.includes(topicName));
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) BoundType(com.google.common.collect.BoundType) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Example 44 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class NamespaceBundlesTest method testFindBundle.

@Test
public void testFindBundle() throws Exception {
    SortedSet<Long> partitions = Sets.newTreeSet();
    partitions.add(0l);
    partitions.add(0x40000000l);
    partitions.add(0xa0000000l);
    partitions.add(0xb0000000l);
    partitions.add(0xc0000000l);
    partitions.add(0xffffffffl);
    NamespaceBundles bundles = new NamespaceBundles(NamespaceName.get("pulsar/global/ns1"), partitions, factory);
    TopicName topicName = TopicName.get("persistent://pulsar/global/ns1/topic-1");
    NamespaceBundle bundle = bundles.findBundle(topicName);
    assertTrue(bundle.includes(topicName));
    topicName = TopicName.get("persistent://pulsar/use/ns2/topic-2");
    try {
        bundles.findBundle(topicName);
        fail("Should have failed due to mismatched namespace name");
    } catch (IllegalArgumentException iae) {
    // OK, expected
    }
    Long hashKey = factory.getLongHashCode(topicName.toString());
    // The following code guarantees that we have at least two ranges after the hashKey till the end
    SortedSet<Long> tailSet = partitions.tailSet(hashKey);
    tailSet.add(hashKey);
    // Now, remove the first range to ensure the hashKey is not included in <code>newPar</code>
    Iterator<Long> iter = tailSet.iterator();
    iter.next();
    SortedSet<Long> newPar = tailSet.tailSet(iter.next());
    try {
        bundles = new NamespaceBundles(topicName.getNamespaceObject(), newPar, factory);
        bundles.findBundle(topicName);
        fail("Should have failed due to out-of-range");
    } catch (ArrayIndexOutOfBoundsException iae) {
    // OK, expected
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) NamespaceBundles(org.apache.pulsar.common.naming.NamespaceBundles) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Example 45 with NamespaceBundle

use of org.apache.pulsar.common.naming.NamespaceBundle in project incubator-pulsar by apache.

the class NamespaceBundlesTest method validateSplitBundlesRange.

private void validateSplitBundlesRange(NamespaceBundle fullBundle, List<NamespaceBundle> splitBundles) {
    assertNotNull(fullBundle);
    assertNotNull(splitBundles);
    Range<Long> fullRange = fullBundle.getKeyRange();
    Range<Long> span = splitBundles.get(0).getKeyRange();
    for (NamespaceBundle bundle : splitBundles) {
        span = span.span(bundle.getKeyRange());
    }
    assertTrue(fullRange.equals(span));
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle)

Aggregations

NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)66 Test (org.testng.annotations.Test)42 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)23 NamespaceBundles (org.apache.pulsar.common.naming.NamespaceBundles)18 TopicName (org.apache.pulsar.common.naming.TopicName)18 KeeperException (org.apache.zookeeper.KeeperException)17 Field (java.lang.reflect.Field)14 RestException (org.apache.pulsar.broker.web.RestException)14 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)13 Policies (org.apache.pulsar.common.policies.data.Policies)13 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)11 ExecutionException (java.util.concurrent.ExecutionException)10 URL (java.net.URL)9 List (java.util.List)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 URI (java.net.URI)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 LoadManager (org.apache.pulsar.broker.loadbalance.LoadManager)7 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)7