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