Search in sources :

Example 1 with TopicHashPositions

use of org.apache.pulsar.common.policies.data.TopicHashPositions in project pulsar by yahoo.

the class AdminApiTest method testNamespacesGetTopicHashPositions.

@Test
public void testNamespacesGetTopicHashPositions() throws Exception {
    // Force to create a namespace with only one bundle and create a topic
    final String namespace = "prop-xyz/ns-one-bundle";
    final String topic = "persistent://" + namespace + "/topic";
    final int topicPartitionNumber = 4;
    Policies policies = new Policies();
    policies.bundles = PoliciesUtil.getBundles(1);
    admin.namespaces().createNamespace(namespace, policies);
    admin.topics().createPartitionedTopic(topic, topicPartitionNumber);
    admin.lookups().lookupPartitionedTopic(topic);
    // check bundles and bundle boundaries
    BundlesData bundleData = admin.namespaces().getBundles(namespace);
    assertEquals(bundleData.getNumBundles(), 1);
    assertEquals(bundleData.getBoundaries().size(), 2);
    assertEquals(bundleData.getBoundaries().get(0), "0x00000000");
    assertEquals(bundleData.getBoundaries().get(1), "0xffffffff");
    // test get topic position for partitioned-topic name
    String bundleRange = "0x00000000_0xffffffff";
    TopicHashPositions topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, Collections.singletonList(topic));
    assertEquals(topicHashPositions.getNamespace(), "prop-xyz/ns-one-bundle");
    assertEquals(topicHashPositions.getBundle(), "0x00000000_0xffffffff");
    assertEquals(topicHashPositions.getTopicHashPositions().size(), topicPartitionNumber);
    final HashFunction hashFunction = Hashing.crc32();
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-0"), hashFunction.hashString(topic + "-partition-0", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-1"), hashFunction.hashString(topic + "-partition-1", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-2"), hashFunction.hashString(topic + "-partition-2", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-3"), hashFunction.hashString(topic + "-partition-3", Charsets.UTF_8).padToLong());
    // test get hash position for topic partition
    List<String> partitions = new ArrayList<>();
    partitions.add(topic + "-partition-0");
    partitions.add(topic + "-partition-1");
    partitions.add(topic + "-partition-2");
    partitions.add(topic + "-partition-3");
    topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, partitions);
    assertEquals(topicHashPositions.getNamespace(), "prop-xyz/ns-one-bundle");
    assertEquals(topicHashPositions.getBundle(), "0x00000000_0xffffffff");
    assertEquals(topicHashPositions.getTopicHashPositions().size(), topicPartitionNumber);
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-0"), hashFunction.hashString(topic + "-partition-0", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-1"), hashFunction.hashString(topic + "-partition-1", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-2"), hashFunction.hashString(topic + "-partition-2", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-3"), hashFunction.hashString(topic + "-partition-3", Charsets.UTF_8).padToLong());
    // test non-exist topic
    topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, Collections.singletonList(topic + "no-exist"));
    assertEquals(topicHashPositions.getTopicHashPositions().size(), 0);
    // test topics is null
    topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, null);
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-0"), hashFunction.hashString(topic + "-partition-0", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-1"), hashFunction.hashString(topic + "-partition-1", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-2"), hashFunction.hashString(topic + "-partition-2", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-3"), hashFunction.hashString(topic + "-partition-3", Charsets.UTF_8).padToLong());
    // test topics is empty
    topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, new ArrayList<>());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-0"), hashFunction.hashString(topic + "-partition-0", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-1"), hashFunction.hashString(topic + "-partition-1", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-2"), hashFunction.hashString(topic + "-partition-2", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-3"), hashFunction.hashString(topic + "-partition-3", Charsets.UTF_8).padToLong());
}
Also used : PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Policies(org.apache.pulsar.common.policies.data.Policies) HashFunction(com.google.common.hash.HashFunction) TopicHashPositions(org.apache.pulsar.common.policies.data.TopicHashPositions) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 2 with TopicHashPositions

use of org.apache.pulsar.common.policies.data.TopicHashPositions in project pulsar by yahoo.

the class NamespacesImpl method getTopicHashPositionsAsync.

@Override
public CompletableFuture<TopicHashPositions> getTopicHashPositionsAsync(String namespace, String bundle, List<String> topics) {
    NamespaceName ns = NamespaceName.get(namespace);
    WebTarget path = namespacePath(ns, bundle, "topicHashPositions");
    if (topics != null && topics.size() > 0) {
        path = path.queryParam("topics", topics.stream().map(Codec::encode).toArray());
    }
    final CompletableFuture<TopicHashPositions> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<TopicHashPositions>() {

        @Override
        public void completed(TopicHashPositions topicHashPositions) {
            future.complete(topicHashPositions);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) TopicHashPositions(org.apache.pulsar.common.policies.data.TopicHashPositions) WebTarget(javax.ws.rs.client.WebTarget) AutoTopicCreationOverride(org.apache.pulsar.common.policies.data.AutoTopicCreationOverride) AutoSubscriptionCreationOverride(org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride) AutoTopicCreationOverride(org.apache.pulsar.common.policies.data.AutoTopicCreationOverride) AutoSubscriptionCreationOverride(org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride)

Example 3 with TopicHashPositions

use of org.apache.pulsar.common.policies.data.TopicHashPositions in project incubator-pulsar by apache.

the class NamespacesBase method internalGetTopicHashPositions.

protected void internalGetTopicHashPositions(AsyncResponse asyncResponse, String bundleRange, List<String> topics) {
    if (log.isDebugEnabled()) {
        log.debug("[{}] Getting hash position for topic list {}, bundle {}", clientAppId(), topics, bundleRange);
    }
    validateNamespacePolicyOperation(namespaceName, PolicyName.PERSISTENCE, PolicyOperation.READ);
    Policies policies = getNamespacePolicies(namespaceName);
    NamespaceBundle bundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange, false, true);
    pulsar().getNamespaceService().getOwnedTopicListForNamespaceBundle(bundle).whenComplete((allTopicsInThisBundle, throwable) -> {
        if (throwable != null) {
            log.error("[{}] {} Failed to get topic list for bundle {}.", clientAppId(), namespaceName, bundle);
            asyncResponse.resume(new RestException(throwable));
        }
        // if topics is empty, return all topics' hash position in this bundle
        Map<String, Long> topicHashPositions = new HashMap<>();
        if (topics == null || topics.size() == 0) {
            allTopicsInThisBundle.forEach(t -> {
                topicHashPositions.put(t, pulsar().getNamespaceService().getNamespaceBundleFactory().getLongHashCode(t));
            });
        } else {
            for (String topic : topics.stream().map(Codec::decode).collect(Collectors.toList())) {
                TopicName topicName = TopicName.get(topic);
                // partitioned topic
                if (topicName.getPartitionIndex() == -1) {
                    allTopicsInThisBundle.stream().filter(t -> TopicName.get(t).getPartitionedTopicName().equals(TopicName.get(topic).getPartitionedTopicName())).forEach(partition -> {
                        topicHashPositions.put(partition, pulsar().getNamespaceService().getNamespaceBundleFactory().getLongHashCode(partition));
                    });
                } else {
                    // topic partition
                    if (allTopicsInThisBundle.contains(topicName.toString())) {
                        topicHashPositions.put(topic, pulsar().getNamespaceService().getNamespaceBundleFactory().getLongHashCode(topic));
                    }
                }
            }
        }
        asyncResponse.resume(new TopicHashPositions(namespaceName.toString(), bundleRange, topicHashPositions));
    });
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) SortedSet(java.util.SortedSet) Topic(org.apache.pulsar.broker.service.Topic) MutableObject(org.apache.commons.lang.mutable.MutableObject) URL(java.net.URL) AdminResource(org.apache.pulsar.broker.admin.AdminResource) BundleType(org.apache.pulsar.common.policies.data.Policies.BundleType) LoggerFactory(org.slf4j.LoggerFactory) TopicHashPositions(org.apache.pulsar.common.policies.data.TopicHashPositions) LedgerOffloader(org.apache.bookkeeper.mledger.LedgerOffloader) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) StringUtils(org.apache.commons.lang3.StringUtils) NamespaceBundleSplitAlgorithm(org.apache.pulsar.common.naming.NamespaceBundleSplitAlgorithm) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) NamespaceBundles(org.apache.pulsar.common.naming.NamespaceBundles) PoliciesUtil.defaultBundle(org.apache.pulsar.common.policies.data.PoliciesUtil.defaultBundle) PoliciesUtil.getBundles(org.apache.pulsar.common.policies.data.PoliciesUtil.getBundles) BacklogQuotaType(org.apache.pulsar.common.policies.data.BacklogQuota.BacklogQuotaType) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) PolicyOperation(org.apache.pulsar.common.policies.data.PolicyOperation) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceOperation(org.apache.pulsar.common.policies.data.NamespaceOperation) NamedEntity(org.apache.pulsar.common.naming.NamedEntity) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) UriBuilder(javax.ws.rs.core.UriBuilder) BookieAffinityGroupData(org.apache.pulsar.common.policies.data.BookieAffinityGroupData) URI(java.net.URI) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) SchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) AsyncResponse(javax.ws.rs.container.AsyncResponse) OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) Set(java.util.Set) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) List(java.util.List) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Response(javax.ws.rs.core.Response) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) PolicyName(org.apache.pulsar.common.policies.data.PolicyName) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) TenantOperation(org.apache.pulsar.common.policies.data.TenantOperation) Subscription(org.apache.pulsar.broker.service.Subscription) TopicName(org.apache.pulsar.common.naming.TopicName) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) TopicType(org.apache.pulsar.common.policies.data.TopicType) Lists(com.google.common.collect.Lists) AutoTopicCreationOverride(org.apache.pulsar.common.policies.data.AutoTopicCreationOverride) AutoTopicCreationOverrideImpl(org.apache.pulsar.common.policies.data.impl.AutoTopicCreationOverrideImpl) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) Status(javax.ws.rs.core.Response.Status) DispatchRate(org.apache.pulsar.common.policies.data.DispatchRate) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) PersistentReplicator(org.apache.pulsar.broker.service.persistent.PersistentReplicator) Logger(org.slf4j.Logger) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) AutoSubscriptionCreationOverride(org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride) Field(java.lang.reflect.Field) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Policies(org.apache.pulsar.common.policies.data.Policies) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) SchemaAutoUpdateCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaAutoUpdateCompatibilityStrategy) SubscriptionAuthMode(org.apache.pulsar.common.policies.data.SubscriptionAuthMode) ValidateResult(org.apache.pulsar.common.policies.data.ValidateResult) Codec(org.apache.pulsar.common.util.Codec) BadVersionException(org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) Collections(java.util.Collections) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Policies(org.apache.pulsar.common.policies.data.Policies) HashMap(java.util.HashMap) TopicHashPositions(org.apache.pulsar.common.policies.data.TopicHashPositions) RestException(org.apache.pulsar.broker.web.RestException) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 4 with TopicHashPositions

use of org.apache.pulsar.common.policies.data.TopicHashPositions in project incubator-pulsar by apache.

the class NamespacesImpl method getTopicHashPositionsAsync.

@Override
public CompletableFuture<TopicHashPositions> getTopicHashPositionsAsync(String namespace, String bundle, List<String> topics) {
    NamespaceName ns = NamespaceName.get(namespace);
    WebTarget path = namespacePath(ns, bundle, "topicHashPositions");
    if (topics != null && topics.size() > 0) {
        path = path.queryParam("topics", topics.stream().map(Codec::encode).toArray());
    }
    final CompletableFuture<TopicHashPositions> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<TopicHashPositions>() {

        @Override
        public void completed(TopicHashPositions topicHashPositions) {
            future.complete(topicHashPositions);
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) TopicHashPositions(org.apache.pulsar.common.policies.data.TopicHashPositions) WebTarget(javax.ws.rs.client.WebTarget) AutoTopicCreationOverride(org.apache.pulsar.common.policies.data.AutoTopicCreationOverride) AutoSubscriptionCreationOverride(org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride) AutoTopicCreationOverride(org.apache.pulsar.common.policies.data.AutoTopicCreationOverride) AutoSubscriptionCreationOverride(org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride)

Example 5 with TopicHashPositions

use of org.apache.pulsar.common.policies.data.TopicHashPositions in project incubator-pulsar by apache.

the class AdminApiTest method testNamespacesGetTopicHashPositions.

@Test
public void testNamespacesGetTopicHashPositions() throws Exception {
    // Force to create a namespace with only one bundle and create a topic
    final String namespace = "prop-xyz/ns-one-bundle";
    final String topic = "persistent://" + namespace + "/topic";
    final int topicPartitionNumber = 4;
    Policies policies = new Policies();
    policies.bundles = PoliciesUtil.getBundles(1);
    admin.namespaces().createNamespace(namespace, policies);
    admin.topics().createPartitionedTopic(topic, topicPartitionNumber);
    admin.lookups().lookupPartitionedTopic(topic);
    // check bundles and bundle boundaries
    BundlesData bundleData = admin.namespaces().getBundles(namespace);
    assertEquals(bundleData.getNumBundles(), 1);
    assertEquals(bundleData.getBoundaries().size(), 2);
    assertEquals(bundleData.getBoundaries().get(0), "0x00000000");
    assertEquals(bundleData.getBoundaries().get(1), "0xffffffff");
    // test get topic position for partitioned-topic name
    String bundleRange = "0x00000000_0xffffffff";
    TopicHashPositions topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, Collections.singletonList(topic));
    assertEquals(topicHashPositions.getNamespace(), "prop-xyz/ns-one-bundle");
    assertEquals(topicHashPositions.getBundle(), "0x00000000_0xffffffff");
    assertEquals(topicHashPositions.getTopicHashPositions().size(), topicPartitionNumber);
    final HashFunction hashFunction = Hashing.crc32();
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-0"), hashFunction.hashString(topic + "-partition-0", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-1"), hashFunction.hashString(topic + "-partition-1", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-2"), hashFunction.hashString(topic + "-partition-2", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-3"), hashFunction.hashString(topic + "-partition-3", Charsets.UTF_8).padToLong());
    // test get hash position for topic partition
    List<String> partitions = new ArrayList<>();
    partitions.add(topic + "-partition-0");
    partitions.add(topic + "-partition-1");
    partitions.add(topic + "-partition-2");
    partitions.add(topic + "-partition-3");
    topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, partitions);
    assertEquals(topicHashPositions.getNamespace(), "prop-xyz/ns-one-bundle");
    assertEquals(topicHashPositions.getBundle(), "0x00000000_0xffffffff");
    assertEquals(topicHashPositions.getTopicHashPositions().size(), topicPartitionNumber);
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-0"), hashFunction.hashString(topic + "-partition-0", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-1"), hashFunction.hashString(topic + "-partition-1", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-2"), hashFunction.hashString(topic + "-partition-2", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-3"), hashFunction.hashString(topic + "-partition-3", Charsets.UTF_8).padToLong());
    // test non-exist topic
    topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, Collections.singletonList(topic + "no-exist"));
    assertEquals(topicHashPositions.getTopicHashPositions().size(), 0);
    // test topics is null
    topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, null);
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-0"), hashFunction.hashString(topic + "-partition-0", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-1"), hashFunction.hashString(topic + "-partition-1", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-2"), hashFunction.hashString(topic + "-partition-2", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-3"), hashFunction.hashString(topic + "-partition-3", Charsets.UTF_8).padToLong());
    // test topics is empty
    topicHashPositions = admin.namespaces().getTopicHashPositions(namespace, bundleRange, new ArrayList<>());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-0"), hashFunction.hashString(topic + "-partition-0", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-1"), hashFunction.hashString(topic + "-partition-1", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-2"), hashFunction.hashString(topic + "-partition-2", Charsets.UTF_8).padToLong());
    assertEquals((long) topicHashPositions.getTopicHashPositions().get(topic + "-partition-3"), hashFunction.hashString(topic + "-partition-3", Charsets.UTF_8).padToLong());
}
Also used : PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) Policies(org.apache.pulsar.common.policies.data.Policies) HashFunction(com.google.common.hash.HashFunction) TopicHashPositions(org.apache.pulsar.common.policies.data.TopicHashPositions) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

TopicHashPositions (org.apache.pulsar.common.policies.data.TopicHashPositions)9 CompletableFuture (java.util.concurrent.CompletableFuture)6 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)6 AutoSubscriptionCreationOverride (org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride)6 AutoTopicCreationOverride (org.apache.pulsar.common.policies.data.AutoTopicCreationOverride)6 BundlesData (org.apache.pulsar.common.policies.data.BundlesData)6 PersistencePolicies (org.apache.pulsar.common.policies.data.PersistencePolicies)6 Policies (org.apache.pulsar.common.policies.data.Policies)6 RetentionPolicies (org.apache.pulsar.common.policies.data.RetentionPolicies)6 Lists (com.google.common.collect.Lists)3 Sets (com.google.common.collect.Sets)3 Field (java.lang.reflect.Field)3 URI (java.net.URI)3 URL (java.net.URL)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3