Search in sources :

Example 1 with HierarchyTopicPolicies

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

the class PersistentStickyKeyDispatcherMultipleConsumersTest method setup.

@BeforeMethod
public void setup() throws Exception {
    configMock = mock(ServiceConfiguration.class);
    doReturn(true).when(configMock).isSubscriptionRedeliveryTrackerEnabled();
    doReturn(100).when(configMock).getDispatcherMaxReadBatchSize();
    doReturn(true).when(configMock).isSubscriptionKeySharedUseConsistentHashing();
    doReturn(1).when(configMock).getSubscriptionKeySharedConsistentHashingReplicaPoints();
    pulsarMock = mock(PulsarService.class);
    doReturn(configMock).when(pulsarMock).getConfiguration();
    brokerMock = mock(BrokerService.class);
    doReturn(pulsarMock).when(brokerMock).pulsar();
    HierarchyTopicPolicies topicPolicies = new HierarchyTopicPolicies();
    topicPolicies.getMaxConsumersPerSubscription().updateBrokerValue(0);
    EventLoopGroup eventLoopGroup = mock(EventLoopGroup.class);
    doReturn(eventLoopGroup).when(brokerMock).executor();
    doAnswer(invocation -> {
        ((Runnable) invocation.getArguments()[0]).run();
        return null;
    }).when(eventLoopGroup).execute(any(Runnable.class));
    topicMock = mock(PersistentTopic.class);
    doReturn(brokerMock).when(topicMock).getBrokerService();
    doReturn(topicName).when(topicMock).getName();
    doReturn(topicPolicies).when(topicMock).getHierarchyTopicPolicies();
    cursorMock = mock(ManagedCursorImpl.class);
    doReturn(null).when(cursorMock).getLastIndividualDeletedRange();
    doReturn(subscriptionName).when(cursorMock).getName();
    consumerMock = mock(Consumer.class);
    channelMock = mock(ChannelPromise.class);
    doReturn("consumer1").when(consumerMock).consumerName();
    doReturn(1000).when(consumerMock).getAvailablePermits();
    doReturn(true).when(consumerMock).isWritable();
    doReturn(channelMock).when(consumerMock).sendMessages(anyList(), any(EntryBatchSizes.class), any(EntryBatchIndexesAcks.class), anyInt(), anyLong(), anyLong(), any(RedeliveryTracker.class));
    subscriptionMock = mock(PersistentSubscription.class);
    try (MockedStatic<DispatchRateLimiter> rateLimiterMockedStatic = mockStatic(DispatchRateLimiter.class)) {
        rateLimiterMockedStatic.when(() -> DispatchRateLimiter.isDispatchRateNeeded(any(BrokerService.class), any(Optional.class), anyString(), any(DispatchRateLimiter.Type.class))).thenReturn(false);
        persistentDispatcher = new PersistentStickyKeyDispatcherMultipleConsumers(topicMock, cursorMock, subscriptionMock, configMock, new KeySharedMeta().setKeySharedMode(KeySharedMode.AUTO_SPLIT));
    }
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) Optional(java.util.Optional) RedeliveryTracker(org.apache.pulsar.broker.service.RedeliveryTracker) EntryBatchSizes(org.apache.pulsar.broker.service.EntryBatchSizes) ChannelPromise(io.netty.channel.ChannelPromise) KeySharedMeta(org.apache.pulsar.common.api.proto.KeySharedMeta) HierarchyTopicPolicies(org.apache.pulsar.common.policies.data.HierarchyTopicPolicies) EventLoopGroup(io.netty.channel.EventLoopGroup) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) Consumer(org.apache.pulsar.broker.service.Consumer) EntryBatchIndexesAcks(org.apache.pulsar.broker.service.EntryBatchIndexesAcks) BrokerService(org.apache.pulsar.broker.service.BrokerService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with HierarchyTopicPolicies

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

the class NonPersistentStickyKeyDispatcherMultipleConsumersTest method setup.

@BeforeMethod
public void setup() throws Exception {
    configMock = mock(ServiceConfiguration.class);
    doReturn(true).when(configMock).isSubscriptionRedeliveryTrackerEnabled();
    doReturn(100).when(configMock).getDispatcherMaxReadBatchSize();
    doReturn(true).when(configMock).isSubscriptionKeySharedUseConsistentHashing();
    doReturn(1).when(configMock).getSubscriptionKeySharedConsistentHashingReplicaPoints();
    pulsarMock = mock(PulsarService.class);
    doReturn(configMock).when(pulsarMock).getConfiguration();
    brokerMock = mock(BrokerService.class);
    doReturn(pulsarMock).when(brokerMock).pulsar();
    HierarchyTopicPolicies topicPolicies = new HierarchyTopicPolicies();
    topicPolicies.getMaxConsumersPerSubscription().updateBrokerValue(0);
    topicMock = mock(NonPersistentTopic.class);
    doReturn(brokerMock).when(topicMock).getBrokerService();
    doReturn(topicName).when(topicMock).getName();
    doReturn(topicPolicies).when(topicMock).getHierarchyTopicPolicies();
    subscriptionMock = mock(NonPersistentSubscription.class);
    try (MockedStatic<DispatchRateLimiter> rateLimiterMockedStatic = mockStatic(DispatchRateLimiter.class)) {
        rateLimiterMockedStatic.when(() -> DispatchRateLimiter.isDispatchRateNeeded(any(BrokerService.class), any(Optional.class), anyString(), any(DispatchRateLimiter.Type.class))).thenReturn(false);
        nonpersistentDispatcher = new NonPersistentStickyKeyDispatcherMultipleConsumers(topicMock, subscriptionMock, new HashRangeAutoSplitStickyKeyConsumerSelector());
    }
}
Also used : HierarchyTopicPolicies(org.apache.pulsar.common.policies.data.HierarchyTopicPolicies) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) Optional(java.util.Optional) DispatchRateLimiter(org.apache.pulsar.broker.service.persistent.DispatchRateLimiter) BrokerService(org.apache.pulsar.broker.service.BrokerService) HashRangeAutoSplitStickyKeyConsumerSelector(org.apache.pulsar.broker.service.HashRangeAutoSplitStickyKeyConsumerSelector) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with HierarchyTopicPolicies

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

the class PersistentStickyKeyDispatcherMultipleConsumersTest method setup.

@BeforeMethod
public void setup() throws Exception {
    configMock = mock(ServiceConfiguration.class);
    doReturn(true).when(configMock).isSubscriptionRedeliveryTrackerEnabled();
    doReturn(100).when(configMock).getDispatcherMaxReadBatchSize();
    doReturn(true).when(configMock).isSubscriptionKeySharedUseConsistentHashing();
    doReturn(1).when(configMock).getSubscriptionKeySharedConsistentHashingReplicaPoints();
    pulsarMock = mock(PulsarService.class);
    doReturn(configMock).when(pulsarMock).getConfiguration();
    brokerMock = mock(BrokerService.class);
    doReturn(pulsarMock).when(brokerMock).pulsar();
    HierarchyTopicPolicies topicPolicies = new HierarchyTopicPolicies();
    topicPolicies.getMaxConsumersPerSubscription().updateBrokerValue(0);
    EventLoopGroup eventLoopGroup = mock(EventLoopGroup.class);
    doReturn(eventLoopGroup).when(brokerMock).executor();
    doAnswer(invocation -> {
        ((Runnable) invocation.getArguments()[0]).run();
        return null;
    }).when(eventLoopGroup).execute(any(Runnable.class));
    topicMock = mock(PersistentTopic.class);
    doReturn(brokerMock).when(topicMock).getBrokerService();
    doReturn(topicName).when(topicMock).getName();
    doReturn(topicPolicies).when(topicMock).getHierarchyTopicPolicies();
    cursorMock = mock(ManagedCursorImpl.class);
    doReturn(null).when(cursorMock).getLastIndividualDeletedRange();
    doReturn(subscriptionName).when(cursorMock).getName();
    consumerMock = mock(Consumer.class);
    channelMock = mock(ChannelPromise.class);
    doReturn("consumer1").when(consumerMock).consumerName();
    doReturn(1000).when(consumerMock).getAvailablePermits();
    doReturn(true).when(consumerMock).isWritable();
    doReturn(channelMock).when(consumerMock).sendMessages(anyList(), any(EntryBatchSizes.class), any(EntryBatchIndexesAcks.class), anyInt(), anyLong(), anyLong(), any(RedeliveryTracker.class));
    subscriptionMock = mock(PersistentSubscription.class);
    try (MockedStatic<DispatchRateLimiter> rateLimiterMockedStatic = mockStatic(DispatchRateLimiter.class)) {
        rateLimiterMockedStatic.when(() -> DispatchRateLimiter.isDispatchRateNeeded(any(BrokerService.class), any(Optional.class), anyString(), any(DispatchRateLimiter.Type.class))).thenReturn(false);
        persistentDispatcher = new PersistentStickyKeyDispatcherMultipleConsumers(topicMock, cursorMock, subscriptionMock, configMock, new KeySharedMeta().setKeySharedMode(KeySharedMode.AUTO_SPLIT));
    }
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) Optional(java.util.Optional) RedeliveryTracker(org.apache.pulsar.broker.service.RedeliveryTracker) EntryBatchSizes(org.apache.pulsar.broker.service.EntryBatchSizes) ChannelPromise(io.netty.channel.ChannelPromise) KeySharedMeta(org.apache.pulsar.common.api.proto.KeySharedMeta) HierarchyTopicPolicies(org.apache.pulsar.common.policies.data.HierarchyTopicPolicies) EventLoopGroup(io.netty.channel.EventLoopGroup) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) Consumer(org.apache.pulsar.broker.service.Consumer) EntryBatchIndexesAcks(org.apache.pulsar.broker.service.EntryBatchIndexesAcks) BrokerService(org.apache.pulsar.broker.service.BrokerService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with HierarchyTopicPolicies

use of org.apache.pulsar.common.policies.data.HierarchyTopicPolicies in project aop by streamnative.

the class AmqpProtocolTestBase method initMockAmqpTopicManager.

private void initMockAmqpTopicManager() {
    CompletableFuture<Topic> completableFuture = new CompletableFuture<>();
    PersistentTopic persistentTopic = mock(PersistentTopic.class);
    CompletableFuture<Subscription> subFuture = new CompletableFuture<>();
    Subscription subscription = mock(Subscription.class);
    Mockito.when(subscription.getTopic()).thenReturn(persistentTopic);
    subFuture.complete(subscription);
    Mockito.when(persistentTopic.createSubscription(Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())).thenReturn(subFuture);
    Mockito.when(subscription.getDispatcher()).thenReturn(mock(MockDispatcher.class));
    Mockito.when(persistentTopic.getSubscriptions()).thenReturn(new ConcurrentOpenHashMap<>());
    Mockito.when(persistentTopic.getManagedLedger()).thenReturn(new MockManagedLedger());
    Mockito.when(persistentTopic.getBrokerService()).thenReturn(brokerService);
    CompletableFuture deleteCpm = new CompletableFuture<>();
    Mockito.when(persistentTopic.delete()).thenReturn(deleteCpm);
    deleteCpm.complete(null);
    Mockito.when(persistentTopic.getHierarchyTopicPolicies()).thenReturn(spy(new HierarchyTopicPolicies()));
    completableFuture.complete(persistentTopic);
    NamespaceService namespaceService = mock(NamespaceService.class);
    CompletableFuture<Optional<LookupResult>> lookupCompletableFuture = new CompletableFuture<>();
    LookupResult lookupResult = mock(LookupResult.class);
    lookupCompletableFuture.complete(Optional.of(lookupResult));
    Mockito.when(connection.getPulsarService().getNamespaceService()).thenReturn(namespaceService);
    Mockito.when(namespaceService.getBrokerServiceUrlAsync(Mockito.any(TopicName.class), Mockito.any(LookupOptions.class))).then(invocationOnMock -> {
        Object[] args = invocationOnMock.getArguments();
        Mockito.when(persistentTopic.getName()).thenReturn(args[0].toString());
        return lookupCompletableFuture;
    });
    LookupData lookupData = mock(LookupData.class);
    Mockito.when(lookupResult.getLookupData()).thenReturn(lookupData);
    Mockito.when(lookupResult.getLookupData().getBrokerUrl()).thenReturn("127.0.0.1");
    CompletableFuture<Optional<Topic>> topicCompletableFuture = new CompletableFuture<>();
    topicCompletableFuture.complete(Optional.of(persistentTopic));
    Mockito.when(connection.getPulsarService().getBrokerService()).thenReturn(brokerService);
    Mockito.when(brokerService.getTopic(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(topicCompletableFuture);
    ManagedLedger managedLedger = mock(ManagedLedgerImpl.class);
    Mockito.when(persistentTopic.getManagedLedger()).thenReturn(managedLedger);
    Mockito.when(managedLedger.getCursors()).thenReturn(new ManagedCursorContainer());
}
Also used : Optional(java.util.Optional) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) MockManagedLedger(io.streamnative.pulsar.handlers.amqp.test.mock.MockManagedLedger) MockDispatcher(io.streamnative.pulsar.handlers.amqp.test.mock.MockDispatcher) MockManagedLedger(io.streamnative.pulsar.handlers.amqp.test.mock.MockManagedLedger) LookupData(org.apache.pulsar.common.lookup.data.LookupData) TopicName(org.apache.pulsar.common.naming.TopicName) HierarchyTopicPolicies(org.apache.pulsar.common.policies.data.HierarchyTopicPolicies) CompletableFuture(java.util.concurrent.CompletableFuture) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) LookupOptions(org.apache.pulsar.broker.namespace.LookupOptions) ManagedCursorContainer(org.apache.bookkeeper.mledger.impl.ManagedCursorContainer) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) LookupResult(org.apache.pulsar.broker.lookup.LookupResult) Topic(org.apache.pulsar.broker.service.Topic) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) Subscription(org.apache.pulsar.broker.service.Subscription)

Example 5 with HierarchyTopicPolicies

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

the class PersistentStickyKeyDispatcherMultipleConsumersTest method setup.

@BeforeMethod
public void setup() throws Exception {
    configMock = mock(ServiceConfiguration.class);
    doReturn(true).when(configMock).isSubscriptionRedeliveryTrackerEnabled();
    doReturn(100).when(configMock).getDispatcherMaxReadBatchSize();
    doReturn(true).when(configMock).isSubscriptionKeySharedUseConsistentHashing();
    doReturn(1).when(configMock).getSubscriptionKeySharedConsistentHashingReplicaPoints();
    pulsarMock = mock(PulsarService.class);
    doReturn(configMock).when(pulsarMock).getConfiguration();
    brokerMock = mock(BrokerService.class);
    doReturn(pulsarMock).when(brokerMock).pulsar();
    HierarchyTopicPolicies topicPolicies = new HierarchyTopicPolicies();
    topicPolicies.getMaxConsumersPerSubscription().updateBrokerValue(0);
    EventLoopGroup eventLoopGroup = mock(EventLoopGroup.class);
    doReturn(eventLoopGroup).when(brokerMock).executor();
    doAnswer(invocation -> {
        ((Runnable) invocation.getArguments()[0]).run();
        return null;
    }).when(eventLoopGroup).execute(any(Runnable.class));
    topicMock = mock(PersistentTopic.class);
    doReturn(brokerMock).when(topicMock).getBrokerService();
    doReturn(topicName).when(topicMock).getName();
    doReturn(topicPolicies).when(topicMock).getHierarchyTopicPolicies();
    cursorMock = mock(ManagedCursorImpl.class);
    doReturn(null).when(cursorMock).getLastIndividualDeletedRange();
    doReturn(subscriptionName).when(cursorMock).getName();
    consumerMock = mock(Consumer.class);
    channelMock = mock(ChannelPromise.class);
    doReturn("consumer1").when(consumerMock).consumerName();
    doReturn(1000).when(consumerMock).getAvailablePermits();
    doReturn(true).when(consumerMock).isWritable();
    doReturn(channelMock).when(consumerMock).sendMessages(anyList(), any(EntryBatchSizes.class), any(EntryBatchIndexesAcks.class), anyInt(), anyLong(), anyLong(), any(RedeliveryTracker.class));
    subscriptionMock = mock(PersistentSubscription.class);
    try (MockedStatic<DispatchRateLimiter> rateLimiterMockedStatic = mockStatic(DispatchRateLimiter.class)) {
        rateLimiterMockedStatic.when(() -> DispatchRateLimiter.isDispatchRateNeeded(any(BrokerService.class), any(Optional.class), anyString(), any(DispatchRateLimiter.Type.class))).thenReturn(false);
        persistentDispatcher = new PersistentStickyKeyDispatcherMultipleConsumers(topicMock, cursorMock, subscriptionMock, configMock, new KeySharedMeta().setKeySharedMode(KeySharedMode.AUTO_SPLIT));
    }
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) Optional(java.util.Optional) RedeliveryTracker(org.apache.pulsar.broker.service.RedeliveryTracker) EntryBatchSizes(org.apache.pulsar.broker.service.EntryBatchSizes) ChannelPromise(io.netty.channel.ChannelPromise) KeySharedMeta(org.apache.pulsar.common.api.proto.KeySharedMeta) HierarchyTopicPolicies(org.apache.pulsar.common.policies.data.HierarchyTopicPolicies) EventLoopGroup(io.netty.channel.EventLoopGroup) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) Consumer(org.apache.pulsar.broker.service.Consumer) EntryBatchIndexesAcks(org.apache.pulsar.broker.service.EntryBatchIndexesAcks) BrokerService(org.apache.pulsar.broker.service.BrokerService) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Optional (java.util.Optional)7 HierarchyTopicPolicies (org.apache.pulsar.common.policies.data.HierarchyTopicPolicies)7 PulsarService (org.apache.pulsar.broker.PulsarService)6 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)6 BrokerService (org.apache.pulsar.broker.service.BrokerService)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 ChannelPromise (io.netty.channel.ChannelPromise)3 EventLoopGroup (io.netty.channel.EventLoopGroup)3 ManagedCursorImpl (org.apache.bookkeeper.mledger.impl.ManagedCursorImpl)3 Consumer (org.apache.pulsar.broker.service.Consumer)3 EntryBatchIndexesAcks (org.apache.pulsar.broker.service.EntryBatchIndexesAcks)3 EntryBatchSizes (org.apache.pulsar.broker.service.EntryBatchSizes)3 HashRangeAutoSplitStickyKeyConsumerSelector (org.apache.pulsar.broker.service.HashRangeAutoSplitStickyKeyConsumerSelector)3 RedeliveryTracker (org.apache.pulsar.broker.service.RedeliveryTracker)3 DispatchRateLimiter (org.apache.pulsar.broker.service.persistent.DispatchRateLimiter)3 KeySharedMeta (org.apache.pulsar.common.api.proto.KeySharedMeta)3 MockDispatcher (io.streamnative.pulsar.handlers.amqp.test.mock.MockDispatcher)1 MockManagedLedger (io.streamnative.pulsar.handlers.amqp.test.mock.MockManagedLedger)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)1