Search in sources :

Example 1 with InMemTransactionBufferProvider

use of org.apache.pulsar.broker.transaction.buffer.impl.InMemTransactionBufferProvider 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 2 with InMemTransactionBufferProvider

use of org.apache.pulsar.broker.transaction.buffer.impl.InMemTransactionBufferProvider 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)

Example 3 with InMemTransactionBufferProvider

use of org.apache.pulsar.broker.transaction.buffer.impl.InMemTransactionBufferProvider in project 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.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

NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 Field (java.lang.reflect.Field)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)3 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)3 ManagedCursorContainer (org.apache.bookkeeper.mledger.impl.ManagedCursorContainer)3 ManagedCursorImpl (org.apache.bookkeeper.mledger.impl.ManagedCursorImpl)3 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)3 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)3 PulsarService (org.apache.pulsar.broker.PulsarService)3 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)3 MockedPulsarServiceBaseTest.createMockZooKeeper (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper)3 NamespaceResources (org.apache.pulsar.broker.resources.NamespaceResources)3 PulsarResources (org.apache.pulsar.broker.resources.PulsarResources)3 BrokerService (org.apache.pulsar.broker.service.BrokerService)3 Consumer (org.apache.pulsar.broker.service.Consumer)3 InMemTransactionBufferProvider (org.apache.pulsar.broker.transaction.buffer.impl.InMemTransactionBufferProvider)3