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