use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class NamespaceBundlesTest method testSplitBundleInTwo.
@Test
public void testSplitBundleInTwo() throws Exception {
final int NO_BUNDLES = 2;
NamespaceName nsname = NamespaceName.get("pulsar/global/ns1");
TopicName topicName = TopicName.get("persistent://pulsar/global/ns1/topic-1");
NamespaceBundles bundles = factory.getBundles(nsname);
NamespaceBundle bundle = bundles.findBundle(topicName);
// (1) split : [0x00000000,0xffffffff] => [0x00000000_0x7fffffff,0x7fffffff_0xffffffff]
Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles = factory.splitBundles(bundle, NO_BUNDLES);
assertNotNull(splitBundles);
assertBundleDivideInTwo(bundle, splitBundles.getRight(), NO_BUNDLES);
// (2) split: [0x00000000,0x7fffffff] => [0x00000000_0x3fffffff,0x3fffffff_0x7fffffff],
// [0x7fffffff,0xffffffff] => [0x7fffffff_0xbfffffff,0xbfffffff_0xffffffff]
NamespaceBundleFactory utilityFactory = getNamespaceBundleFactory();
assertBundles(utilityFactory, nsname, bundle, splitBundles, NO_BUNDLES);
// (3) split: [0x00000000,0x3fffffff] => [0x00000000_0x1fffffff,0x1fffffff_0x3fffffff],
// [0x3fffffff,0x7fffffff] => [0x3fffffff_0x5fffffff,0x5fffffff_0x7fffffff]
Pair<NamespaceBundles, List<NamespaceBundle>> splitChildBundles = splitBundlesUtilFactory(utilityFactory, nsname, splitBundles.getLeft(), splitBundles.getRight().get(0), NO_BUNDLES);
assertBundles(utilityFactory, nsname, splitBundles.getRight().get(0), splitChildBundles, NO_BUNDLES);
// (4) split: [0x7fffffff,0xbfffffff] => [0x7fffffff_0x9fffffff,0x9fffffff_0xbfffffff],
// [0xbfffffff,0xffffffff] => [0xbfffffff_0xdfffffff,0xdfffffff_0xffffffff]
splitChildBundles = splitBundlesUtilFactory(utilityFactory, nsname, splitBundles.getLeft(), splitBundles.getRight().get(1), NO_BUNDLES);
assertBundles(utilityFactory, nsname, splitBundles.getRight().get(1), splitChildBundles, NO_BUNDLES);
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class CliCommand method validateNonPersistentTopic.
String validateNonPersistentTopic(List<String> params) {
String topic = checkArgument(params);
TopicName topicName = TopicName.get(topic);
if (topicName.getDomain() != TopicDomain.non_persistent) {
throw new ParameterException("Need to provide a non-persistent topic name");
}
return topicName.toString();
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class NonPersistentTopicsImpl method getPartitionedTopicMetadataAsync.
@Override
public CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadataAsync(String topic) {
TopicName topicName = validateTopic(topic);
final CompletableFuture<PartitionedTopicMetadata> future = new CompletableFuture<>();
WebTarget path = topicPath(topicName, "partitions");
asyncGetRequest(path, new InvocationCallback<PartitionedTopicMetadata>() {
@Override
public void completed(PartitionedTopicMetadata response) {
future.complete(response);
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class NonPersistentTopicsImpl method createPartitionedTopicAsync.
@Override
public CompletableFuture<Void> createPartitionedTopicAsync(String topic, int numPartitions) {
checkArgument(numPartitions > 1, "Number of partitions should be more than 1");
TopicName topicName = validateTopic(topic);
WebTarget path = topicPath(topicName, "partitions");
return asyncPutRequest(path, Entity.entity(numPartitions, MediaType.APPLICATION_JSON));
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class NonPersistentTopicsImpl method unloadAsync.
@Override
public CompletableFuture<Void> unloadAsync(String topic) {
TopicName topicName = validateTopic(topic);
WebTarget path = topicPath(topicName, "unload");
return asyncPutRequest(path, Entity.entity("", MediaType.APPLICATION_JSON));
}
Aggregations