Search in sources :

Example 1 with TransactionPendingAckStoreProvider

use of org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider in project pulsar by apache.

the class TransactionTest method testEndTPRecoveringWhenManagerLedgerDisReadable.

@Test
public void testEndTPRecoveringWhenManagerLedgerDisReadable() throws Exception {
    String topic = NAMESPACE1 + "/testEndTPRecoveringWhenManagerLedgerDisReadable";
    admin.topics().createNonPartitionedTopic(topic);
    @Cleanup Producer<String> producer = pulsarClient.newProducer(Schema.STRING).producerName("test").enableBatching(false).sendTimeout(0, TimeUnit.SECONDS).topic(topic).create();
    producer.newMessage().send();
    PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic(topic, false).get().get();
    persistentTopic.getManagedLedger().getConfig().setAutoSkipNonRecoverableData(true);
    PersistentSubscription persistentSubscription = (PersistentSubscription) persistentTopic.createSubscription("test", CommandSubscribe.InitialPosition.Earliest, false).get();
    ManagedCursorImpl managedCursor = mock(ManagedCursorImpl.class);
    doReturn(true).when(managedCursor).hasMoreEntries();
    doReturn(false).when(managedCursor).isClosed();
    doReturn(new PositionImpl(-1, -1)).when(managedCursor).getMarkDeletedPosition();
    doAnswer(invocation -> {
        AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
        callback.readEntriesFailed(new ManagedLedgerException.NonRecoverableLedgerException("No ledger exist"), null);
        return null;
    }).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
    TransactionPendingAckStoreProvider pendingAckStoreProvider = mock(TransactionPendingAckStoreProvider.class);
    doReturn(CompletableFuture.completedFuture(new MLPendingAckStore(persistentTopic.getManagedLedger(), managedCursor, null))).when(pendingAckStoreProvider).newPendingAckStore(any());
    doReturn(CompletableFuture.completedFuture(true)).when(pendingAckStoreProvider).checkInitializedBefore(any());
    Class<PulsarService> pulsarServiceClass = PulsarService.class;
    Field field = pulsarServiceClass.getDeclaredField("transactionPendingAckStoreProvider");
    field.setAccessible(true);
    field.set(getPulsarServiceList().get(0), pendingAckStoreProvider);
    PendingAckHandleImpl pendingAckHandle1 = new PendingAckHandleImpl(persistentSubscription);
    Awaitility.await().untilAsserted(() -> assertEquals(pendingAckHandle1.getStats().state, "Ready"));
    doAnswer(invocation -> {
        AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
        callback.readEntriesFailed(new ManagedLedgerException.ManagedLedgerFencedException(), null);
        return null;
    }).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
    PendingAckHandleImpl pendingAckHandle2 = new PendingAckHandleImpl(persistentSubscription);
    Awaitility.await().untilAsserted(() -> assertEquals(pendingAckHandle2.getStats().state, "Ready"));
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) PendingAckHandleImpl(org.apache.pulsar.broker.transaction.pendingack.impl.PendingAckHandleImpl) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) Cleanup(lombok.Cleanup) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) MLPendingAckStore(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStore) Field(java.lang.reflect.Field) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PulsarService(org.apache.pulsar.broker.PulsarService) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) TransactionPendingAckStoreProvider(org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider) Test(org.testng.annotations.Test)

Example 2 with TransactionPendingAckStoreProvider

use of org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider in project pulsar by yahoo.

the class TransactionTest method testEndTPRecoveringWhenManagerLedgerDisReadable.

@Test
public void testEndTPRecoveringWhenManagerLedgerDisReadable() throws Exception {
    String topic = NAMESPACE1 + "/testEndTPRecoveringWhenManagerLedgerDisReadable";
    admin.topics().createNonPartitionedTopic(topic);
    @Cleanup Producer<String> producer = pulsarClient.newProducer(Schema.STRING).producerName("test").enableBatching(false).sendTimeout(0, TimeUnit.SECONDS).topic(topic).create();
    producer.newMessage().send();
    PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic(topic, false).get().get();
    persistentTopic.getManagedLedger().getConfig().setAutoSkipNonRecoverableData(true);
    PersistentSubscription persistentSubscription = (PersistentSubscription) persistentTopic.createSubscription("test", CommandSubscribe.InitialPosition.Earliest, false, null).get();
    ManagedCursorImpl managedCursor = mock(ManagedCursorImpl.class);
    doReturn(true).when(managedCursor).hasMoreEntries();
    doReturn(false).when(managedCursor).isClosed();
    doReturn(new PositionImpl(-1, -1)).when(managedCursor).getMarkDeletedPosition();
    doAnswer(invocation -> {
        AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
        callback.readEntriesFailed(new ManagedLedgerException.NonRecoverableLedgerException("No ledger exist"), null);
        return null;
    }).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
    TransactionPendingAckStoreProvider pendingAckStoreProvider = mock(TransactionPendingAckStoreProvider.class);
    doReturn(CompletableFuture.completedFuture(new MLPendingAckStore(persistentTopic.getManagedLedger(), managedCursor, null, 500))).when(pendingAckStoreProvider).newPendingAckStore(any());
    doReturn(CompletableFuture.completedFuture(true)).when(pendingAckStoreProvider).checkInitializedBefore(any());
    Class<PulsarService> pulsarServiceClass = PulsarService.class;
    Field field = pulsarServiceClass.getDeclaredField("transactionPendingAckStoreProvider");
    field.setAccessible(true);
    field.set(getPulsarServiceList().get(0), pendingAckStoreProvider);
    PendingAckHandleImpl pendingAckHandle1 = new PendingAckHandleImpl(persistentSubscription);
    Awaitility.await().untilAsserted(() -> assertEquals(pendingAckHandle1.getStats().state, "Ready"));
    doAnswer(invocation -> {
        AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
        callback.readEntriesFailed(new ManagedLedgerException.ManagedLedgerFencedException(), null);
        return null;
    }).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
    PendingAckHandleImpl pendingAckHandle2 = new PendingAckHandleImpl(persistentSubscription);
    Awaitility.await().untilAsserted(() -> assertEquals(pendingAckHandle2.getStats().state, "Ready"));
    doAnswer(invocation -> {
        AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
        callback.readEntriesFailed(new ManagedLedgerException.CursorAlreadyClosedException("test"), null);
        return null;
    }).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
    PendingAckHandleImpl pendingAckHandle3 = new PendingAckHandleImpl(persistentSubscription);
    Awaitility.await().untilAsserted(() -> assertEquals(pendingAckHandle3.getStats().state, "Ready"));
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) PendingAckHandleImpl(org.apache.pulsar.broker.transaction.pendingack.impl.PendingAckHandleImpl) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) Cleanup(lombok.Cleanup) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) MLPendingAckStore(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStore) Field(java.lang.reflect.Field) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PulsarService(org.apache.pulsar.broker.PulsarService) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) TransactionPendingAckStoreProvider(org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider) Test(org.testng.annotations.Test)

Example 3 with TransactionPendingAckStoreProvider

use of org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider in project incubator-pulsar by apache.

the class TransactionTest method testEndTPRecoveringWhenManagerLedgerDisReadable.

@Test
public void testEndTPRecoveringWhenManagerLedgerDisReadable() throws Exception {
    String topic = NAMESPACE1 + "/testEndTPRecoveringWhenManagerLedgerDisReadable";
    admin.topics().createNonPartitionedTopic(topic);
    @Cleanup Producer<String> producer = pulsarClient.newProducer(Schema.STRING).producerName("test").enableBatching(false).sendTimeout(0, TimeUnit.SECONDS).topic(topic).create();
    producer.newMessage().send();
    PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic(topic, false).get().get();
    persistentTopic.getManagedLedger().getConfig().setAutoSkipNonRecoverableData(true);
    PersistentSubscription persistentSubscription = (PersistentSubscription) persistentTopic.createSubscription("test", CommandSubscribe.InitialPosition.Earliest, false, null).get();
    ManagedCursorImpl managedCursor = mock(ManagedCursorImpl.class);
    doReturn(true).when(managedCursor).hasMoreEntries();
    doReturn(false).when(managedCursor).isClosed();
    doReturn(new PositionImpl(-1, -1)).when(managedCursor).getMarkDeletedPosition();
    doAnswer(invocation -> {
        AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
        callback.readEntriesFailed(new ManagedLedgerException.NonRecoverableLedgerException("No ledger exist"), null);
        return null;
    }).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
    TransactionPendingAckStoreProvider pendingAckStoreProvider = mock(TransactionPendingAckStoreProvider.class);
    doReturn(CompletableFuture.completedFuture(new MLPendingAckStore(persistentTopic.getManagedLedger(), managedCursor, null, 500))).when(pendingAckStoreProvider).newPendingAckStore(any());
    doReturn(CompletableFuture.completedFuture(true)).when(pendingAckStoreProvider).checkInitializedBefore(any());
    Class<PulsarService> pulsarServiceClass = PulsarService.class;
    Field field = pulsarServiceClass.getDeclaredField("transactionPendingAckStoreProvider");
    field.setAccessible(true);
    field.set(getPulsarServiceList().get(0), pendingAckStoreProvider);
    PendingAckHandleImpl pendingAckHandle1 = new PendingAckHandleImpl(persistentSubscription);
    Awaitility.await().untilAsserted(() -> assertEquals(pendingAckHandle1.getStats().state, "Ready"));
    doAnswer(invocation -> {
        AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
        callback.readEntriesFailed(new ManagedLedgerException.ManagedLedgerFencedException(), null);
        return null;
    }).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
    PendingAckHandleImpl pendingAckHandle2 = new PendingAckHandleImpl(persistentSubscription);
    Awaitility.await().untilAsserted(() -> assertEquals(pendingAckHandle2.getStats().state, "Ready"));
    doAnswer(invocation -> {
        AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
        callback.readEntriesFailed(new ManagedLedgerException.CursorAlreadyClosedException("test"), null);
        return null;
    }).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
    PendingAckHandleImpl pendingAckHandle3 = new PendingAckHandleImpl(persistentSubscription);
    Awaitility.await().untilAsserted(() -> assertEquals(pendingAckHandle3.getStats().state, "Ready"));
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) PendingAckHandleImpl(org.apache.pulsar.broker.transaction.pendingack.impl.PendingAckHandleImpl) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) Cleanup(lombok.Cleanup) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) MLPendingAckStore(org.apache.pulsar.broker.transaction.pendingack.impl.MLPendingAckStore) Field(java.lang.reflect.Field) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) PulsarService(org.apache.pulsar.broker.PulsarService) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) TransactionPendingAckStoreProvider(org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider) Test(org.testng.annotations.Test)

Example 4 with TransactionPendingAckStoreProvider

use of org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider in project incubator-pulsar by apache.

the class PersistentSubscriptionTest method setup.

@BeforeMethod
public void setup() throws Exception {
    executor = OrderedExecutor.newBuilder().numThreads(1).name("persistent-subscription-test").build();
    eventLoopGroup = new NioEventLoopGroup();
    ServiceConfiguration svcConfig = spy(ServiceConfiguration.class);
    svcConfig.setBrokerShutdownTimeoutMs(0L);
    svcConfig.setLoadBalancerOverrideBrokerNicSpeedGbps(Optional.of(1.0d));
    svcConfig.setTransactionCoordinatorEnabled(true);
    svcConfig.setClusterName("pulsar-cluster");
    pulsarMock = spyWithClassAndConstructorArgs(PulsarService.class, svcConfig);
    PulsarResources pulsarResources = mock(PulsarResources.class);
    doReturn(pulsarResources).when(pulsarMock).getPulsarResources();
    NamespaceResources namespaceResources = mock(NamespaceResources.class);
    doReturn(namespaceResources).when(pulsarResources).getNamespaceResources();
    doReturn(Optional.of(new Policies())).when(namespaceResources).getPoliciesIfCached(any());
    doReturn(new InMemTransactionBufferProvider()).when(pulsarMock).getTransactionBufferProvider();
    doReturn(new TransactionPendingAckStoreProvider() {

        @Override
        public CompletableFuture<PendingAckStore> newPendingAckStore(PersistentSubscription subscription) {
            return CompletableFuture.completedFuture(new PendingAckStore() {

                @Override
                public void replayAsync(PendingAckHandleImpl pendingAckHandle, ScheduledExecutorService executorService) {
                    try {
                        Field field = PendingAckHandleState.class.getDeclaredField("state");
                        field.setAccessible(true);
                        field.set(pendingAckHandle, PendingAckHandleState.State.Ready);
                    } catch (NoSuchFieldException | IllegalAccessException e) {
                        fail();
                    }
                }

                @Override
                public CompletableFuture<Void> closeAsync() {
                    return CompletableFuture.completedFuture(null);
                }

                @Override
                public CompletableFuture<Void> appendIndividualAck(TxnID txnID, List<MutablePair<PositionImpl, Integer>> positions) {
                    return CompletableFuture.completedFuture(null);
                }

                @Override
                public CompletableFuture<Void> appendCumulativeAck(TxnID txnID, PositionImpl position) {
                    return CompletableFuture.completedFuture(null);
                }

                @Override
                public CompletableFuture<Void> appendCommitMark(TxnID txnID, AckType ackType) {
                    return CompletableFuture.completedFuture(null);
                }

                @Override
                public CompletableFuture<Void> appendAbortMark(TxnID txnID, AckType ackType) {
                    return CompletableFuture.completedFuture(null);
                }
            });
        }

        @Override
        public CompletableFuture<Boolean> checkInitializedBefore(PersistentSubscription subscription) {
            return CompletableFuture.completedFuture(true);
        }
    }).when(pulsarMock).getTransactionPendingAckStoreProvider();
    doReturn(svcConfig).when(pulsarMock).getConfiguration();
    doReturn(mock(Compactor.class)).when(pulsarMock).getCompactor();
    mlFactoryMock = mock(ManagedLedgerFactory.class);
    doReturn(mlFactoryMock).when(pulsarMock).getManagedLedgerFactory();
    ZooKeeper zkMock = createMockZooKeeper();
    doReturn(createMockBookKeeper(executor)).when(pulsarMock).getBookKeeperClient();
    store = new ZKMetadataStore(zkMock);
    doReturn(store).when(pulsarMock).getLocalMetadataStore();
    doReturn(store).when(pulsarMock).getConfigurationMetadataStore();
    brokerMock = spyWithClassAndConstructorArgs(BrokerService.class, pulsarMock, eventLoopGroup);
    doNothing().when(brokerMock).unloadNamespaceBundlesGracefully();
    doReturn(brokerMock).when(pulsarMock).getBrokerService();
    ledgerMock = mock(ManagedLedgerImpl.class);
    cursorMock = mock(ManagedCursorImpl.class);
    managedLedgerConfigMock = mock(ManagedLedgerConfig.class);
    doReturn(new ManagedCursorContainer()).when(ledgerMock).getCursors();
    doReturn("mockCursor").when(cursorMock).getName();
    doReturn(new PositionImpl(1, 50)).when(cursorMock).getMarkDeletedPosition();
    doReturn(ledgerMock).when(cursorMock).getManagedLedger();
    doReturn(managedLedgerConfigMock).when(ledgerMock).getConfig();
    doReturn(false).when(managedLedgerConfigMock).isAutoSkipNonRecoverableData();
    topic = new PersistentTopic(successTopicName, ledgerMock, brokerMock);
    consumerMock = mock(Consumer.class);
    persistentSubscription = new PersistentSubscription(topic, subName, cursorMock, false);
}
Also used : NamespaceResources(org.apache.pulsar.broker.resources.NamespaceResources) Policies(org.apache.pulsar.common.policies.data.Policies) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) Field(java.lang.reflect.Field) Compactor(org.apache.pulsar.compaction.Compactor) CompletableFuture(java.util.concurrent.CompletableFuture) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PendingAckStore(org.apache.pulsar.broker.transaction.pendingack.PendingAckStore) Consumer(org.apache.pulsar.broker.service.Consumer) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) List(java.util.List) ArrayList(java.util.ArrayList) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) PendingAckHandleImpl(org.apache.pulsar.broker.transaction.pendingack.impl.PendingAckHandleImpl) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) TxnID(org.apache.pulsar.client.api.transaction.TxnID) AckType(org.apache.pulsar.common.api.proto.CommandAck.AckType) ZooKeeper(org.apache.zookeeper.ZooKeeper) MockedPulsarServiceBaseTest.createMockZooKeeper(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper) ManagedCursorContainer(org.apache.bookkeeper.mledger.impl.ManagedCursorContainer) TransactionPendingAckStoreProvider(org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider) InMemTransactionBufferProvider(org.apache.pulsar.broker.transaction.buffer.impl.InMemTransactionBufferProvider) BrokerService(org.apache.pulsar.broker.service.BrokerService) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with TransactionPendingAckStoreProvider

use of org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider in project pulsar by yahoo.

the class PersistentSubscriptionTest method setup.

@BeforeMethod
public void setup() throws Exception {
    executor = OrderedExecutor.newBuilder().numThreads(1).name("persistent-subscription-test").build();
    eventLoopGroup = new NioEventLoopGroup();
    ServiceConfiguration svcConfig = spy(ServiceConfiguration.class);
    svcConfig.setBrokerShutdownTimeoutMs(0L);
    svcConfig.setLoadBalancerOverrideBrokerNicSpeedGbps(Optional.of(1.0d));
    svcConfig.setTransactionCoordinatorEnabled(true);
    svcConfig.setClusterName("pulsar-cluster");
    pulsarMock = spyWithClassAndConstructorArgs(PulsarService.class, svcConfig);
    PulsarResources pulsarResources = mock(PulsarResources.class);
    doReturn(pulsarResources).when(pulsarMock).getPulsarResources();
    NamespaceResources namespaceResources = mock(NamespaceResources.class);
    doReturn(namespaceResources).when(pulsarResources).getNamespaceResources();
    doReturn(Optional.of(new Policies())).when(namespaceResources).getPoliciesIfCached(any());
    doReturn(new InMemTransactionBufferProvider()).when(pulsarMock).getTransactionBufferProvider();
    doReturn(new TransactionPendingAckStoreProvider() {

        @Override
        public CompletableFuture<PendingAckStore> newPendingAckStore(PersistentSubscription subscription) {
            return CompletableFuture.completedFuture(new PendingAckStore() {

                @Override
                public void replayAsync(PendingAckHandleImpl pendingAckHandle, ScheduledExecutorService executorService) {
                    try {
                        Field field = PendingAckHandleState.class.getDeclaredField("state");
                        field.setAccessible(true);
                        field.set(pendingAckHandle, PendingAckHandleState.State.Ready);
                    } catch (NoSuchFieldException | IllegalAccessException e) {
                        fail();
                    }
                }

                @Override
                public CompletableFuture<Void> closeAsync() {
                    return CompletableFuture.completedFuture(null);
                }

                @Override
                public CompletableFuture<Void> appendIndividualAck(TxnID txnID, List<MutablePair<PositionImpl, Integer>> positions) {
                    return CompletableFuture.completedFuture(null);
                }

                @Override
                public CompletableFuture<Void> appendCumulativeAck(TxnID txnID, PositionImpl position) {
                    return CompletableFuture.completedFuture(null);
                }

                @Override
                public CompletableFuture<Void> appendCommitMark(TxnID txnID, AckType ackType) {
                    return CompletableFuture.completedFuture(null);
                }

                @Override
                public CompletableFuture<Void> appendAbortMark(TxnID txnID, AckType ackType) {
                    return CompletableFuture.completedFuture(null);
                }
            });
        }

        @Override
        public CompletableFuture<Boolean> checkInitializedBefore(PersistentSubscription subscription) {
            return CompletableFuture.completedFuture(true);
        }
    }).when(pulsarMock).getTransactionPendingAckStoreProvider();
    doReturn(svcConfig).when(pulsarMock).getConfiguration();
    doReturn(mock(Compactor.class)).when(pulsarMock).getCompactor();
    mlFactoryMock = mock(ManagedLedgerFactory.class);
    doReturn(mlFactoryMock).when(pulsarMock).getManagedLedgerFactory();
    ZooKeeper zkMock = createMockZooKeeper();
    doReturn(createMockBookKeeper(executor)).when(pulsarMock).getBookKeeperClient();
    store = new ZKMetadataStore(zkMock);
    doReturn(store).when(pulsarMock).getLocalMetadataStore();
    doReturn(store).when(pulsarMock).getConfigurationMetadataStore();
    brokerMock = spyWithClassAndConstructorArgs(BrokerService.class, pulsarMock, eventLoopGroup);
    doNothing().when(brokerMock).unloadNamespaceBundlesGracefully();
    doReturn(brokerMock).when(pulsarMock).getBrokerService();
    ledgerMock = mock(ManagedLedgerImpl.class);
    cursorMock = mock(ManagedCursorImpl.class);
    managedLedgerConfigMock = mock(ManagedLedgerConfig.class);
    doReturn(new ManagedCursorContainer()).when(ledgerMock).getCursors();
    doReturn("mockCursor").when(cursorMock).getName();
    doReturn(new PositionImpl(1, 50)).when(cursorMock).getMarkDeletedPosition();
    doReturn(ledgerMock).when(cursorMock).getManagedLedger();
    doReturn(managedLedgerConfigMock).when(ledgerMock).getConfig();
    doReturn(false).when(managedLedgerConfigMock).isAutoSkipNonRecoverableData();
    topic = new PersistentTopic(successTopicName, ledgerMock, brokerMock);
    consumerMock = mock(Consumer.class);
    persistentSubscription = new PersistentSubscription(topic, subName, cursorMock, false);
}
Also used : NamespaceResources(org.apache.pulsar.broker.resources.NamespaceResources) Policies(org.apache.pulsar.common.policies.data.Policies) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) Field(java.lang.reflect.Field) Compactor(org.apache.pulsar.compaction.Compactor) CompletableFuture(java.util.concurrent.CompletableFuture) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PendingAckStore(org.apache.pulsar.broker.transaction.pendingack.PendingAckStore) Consumer(org.apache.pulsar.broker.service.Consumer) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) List(java.util.List) ArrayList(java.util.ArrayList) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) PendingAckHandleImpl(org.apache.pulsar.broker.transaction.pendingack.impl.PendingAckHandleImpl) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) TxnID(org.apache.pulsar.client.api.transaction.TxnID) AckType(org.apache.pulsar.common.api.proto.CommandAck.AckType) ZooKeeper(org.apache.zookeeper.ZooKeeper) MockedPulsarServiceBaseTest.createMockZooKeeper(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper) ManagedCursorContainer(org.apache.bookkeeper.mledger.impl.ManagedCursorContainer) TransactionPendingAckStoreProvider(org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider) InMemTransactionBufferProvider(org.apache.pulsar.broker.transaction.buffer.impl.InMemTransactionBufferProvider) BrokerService(org.apache.pulsar.broker.service.BrokerService) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Field (java.lang.reflect.Field)6 ManagedCursorImpl (org.apache.bookkeeper.mledger.impl.ManagedCursorImpl)6 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)6 PulsarService (org.apache.pulsar.broker.PulsarService)6 TransactionPendingAckStoreProvider (org.apache.pulsar.broker.transaction.pendingack.TransactionPendingAckStoreProvider)6 PendingAckHandleImpl (org.apache.pulsar.broker.transaction.pendingack.impl.PendingAckHandleImpl)6 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 Cleanup (lombok.Cleanup)3 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)3 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)3 ManagedCursorContainer (org.apache.bookkeeper.mledger.impl.ManagedCursorContainer)3 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)3 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)3 MockedPulsarServiceBaseTest.createMockZooKeeper (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper)3