Search in sources :

Example 1 with AckType

use of org.apache.pulsar.common.api.proto.CommandAck.AckType in project pulsar by apache.

the class MLPendingAckReplyCallBack method handleMetadataEntry.

@Override
public void handleMetadataEntry(PendingAckMetadataEntry pendingAckMetadataEntry) {
    TxnID txnID = new TxnID(pendingAckMetadataEntry.getTxnidMostBits(), pendingAckMetadataEntry.getTxnidLeastBits());
    AckType ackType = pendingAckMetadataEntry.getAckType();
    switch(pendingAckMetadataEntry.getPendingAckOp()) {
        case ABORT:
            pendingAckHandle.handleAbort(txnID, ackType);
            break;
        case COMMIT:
            pendingAckHandle.handleCommit(txnID, ackType, Collections.emptyMap());
            break;
        case ACK:
            if (ackType == AckType.Cumulative) {
                PendingAckMetadata pendingAckMetadata = pendingAckMetadataEntry.getPendingAckMetadatasList().get(0);
                pendingAckHandle.handleCumulativeAckRecover(txnID, PositionImpl.get(pendingAckMetadata.getLedgerId(), pendingAckMetadata.getEntryId()));
            } else {
                List<MutablePair<PositionImpl, Integer>> positions = new ArrayList<>();
                pendingAckMetadataEntry.getPendingAckMetadatasList().forEach(pendingAckMetadata -> {
                    if (pendingAckMetadata.getAckSetsCount() == 0) {
                        positions.add(new MutablePair<>(PositionImpl.get(pendingAckMetadata.getLedgerId(), pendingAckMetadata.getEntryId()), pendingAckMetadata.getBatchSize()));
                    } else {
                        PositionImpl position = PositionImpl.get(pendingAckMetadata.getLedgerId(), pendingAckMetadata.getEntryId());
                        if (pendingAckMetadata.getAckSetsCount() > 0) {
                            long[] ackSets = new long[pendingAckMetadata.getAckSetsCount()];
                            for (int i = 0; i < pendingAckMetadata.getAckSetsCount(); i++) {
                                ackSets[i] = pendingAckMetadata.getAckSetAt(i);
                            }
                            position.setAckSet(ackSets);
                        }
                        positions.add(new MutablePair<>(position, pendingAckMetadata.getBatchSize()));
                    }
                });
                pendingAckHandle.handleIndividualAckRecover(txnID, positions);
            }
            break;
        default:
            throw new IllegalStateException("Transaction pending ack replay " + "error with illegal state : " + pendingAckMetadataEntry.getPendingAckOp());
    }
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) TxnID(org.apache.pulsar.client.api.transaction.TxnID) AckType(org.apache.pulsar.common.api.proto.CommandAck.AckType) PendingAckMetadata(org.apache.pulsar.broker.transaction.pendingack.proto.PendingAckMetadata) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) ArrayList(java.util.ArrayList)

Example 2 with AckType

use of org.apache.pulsar.common.api.proto.CommandAck.AckType in project pulsar by apache.

the class ConsumerImpl method doReconsumeLater.

@SuppressWarnings("unchecked")
@Override
protected CompletableFuture<Void> doReconsumeLater(Message<?> message, AckType ackType, Map<String, String> customProperties, long delayTime, TimeUnit unit) {
    MessageId messageId = message.getMessageId();
    if (messageId == null) {
        return FutureUtil.failedFuture(new PulsarClientException.InvalidMessageException("Cannot handle message with null messageId"));
    }
    if (messageId instanceof TopicMessageIdImpl) {
        messageId = ((TopicMessageIdImpl) messageId).getInnerMessageId();
    }
    checkArgument(messageId instanceof MessageIdImpl);
    if (getState() != State.Ready && getState() != State.Connecting) {
        stats.incrementNumAcksFailed();
        PulsarClientException exception = new PulsarClientException("Consumer not ready. State: " + getState());
        if (AckType.Individual.equals(ackType)) {
            onAcknowledge(messageId, exception);
        } else if (AckType.Cumulative.equals(ackType)) {
            onAcknowledgeCumulative(messageId, exception);
        }
        return FutureUtil.failedFuture(exception);
    }
    if (delayTime < 0) {
        delayTime = 0;
    }
    if (retryLetterProducer == null) {
        createProducerLock.writeLock().lock();
        try {
            if (retryLetterProducer == null) {
                retryLetterProducer = client.newProducer(schema).topic(this.deadLetterPolicy.getRetryLetterTopic()).enableBatching(false).blockIfQueueFull(false).create();
            }
        } catch (Exception e) {
            log.error("Create retry letter producer exception with topic: {}", deadLetterPolicy.getRetryLetterTopic(), e);
        } finally {
            createProducerLock.writeLock().unlock();
        }
    }
    CompletableFuture<Void> result = new CompletableFuture<>();
    if (retryLetterProducer != null) {
        try {
            MessageImpl<T> retryMessage = (MessageImpl<T>) getMessageImpl(message);
            String originMessageIdStr = getOriginMessageIdStr(message);
            String originTopicNameStr = getOriginTopicNameStr(message);
            SortedMap<String, String> propertiesMap = getPropertiesMap(message, originMessageIdStr, originTopicNameStr);
            if (customProperties != null) {
                propertiesMap.putAll(customProperties);
            }
            int reconsumetimes = 1;
            if (propertiesMap.containsKey(RetryMessageUtil.SYSTEM_PROPERTY_RECONSUMETIMES)) {
                reconsumetimes = Integer.parseInt(propertiesMap.get(RetryMessageUtil.SYSTEM_PROPERTY_RECONSUMETIMES));
                reconsumetimes = reconsumetimes + 1;
            }
            propertiesMap.put(RetryMessageUtil.SYSTEM_PROPERTY_RECONSUMETIMES, String.valueOf(reconsumetimes));
            propertiesMap.put(RetryMessageUtil.SYSTEM_PROPERTY_DELAY_TIME, String.valueOf(unit.toMillis(delayTime)));
            MessageId finalMessageId = messageId;
            if (reconsumetimes > this.deadLetterPolicy.getMaxRedeliverCount() && StringUtils.isNotBlank(deadLetterPolicy.getDeadLetterTopic())) {
                initDeadLetterProducerIfNeeded();
                deadLetterProducer.thenAccept(dlqProducer -> {
                    TypedMessageBuilder<byte[]> typedMessageBuilderNew = dlqProducer.newMessage(Schema.AUTO_PRODUCE_BYTES(retryMessage.getReaderSchema().get())).value(retryMessage.getData()).properties(propertiesMap);
                    typedMessageBuilderNew.sendAsync().thenAccept(msgId -> {
                        doAcknowledge(finalMessageId, ackType, Collections.emptyMap(), null).thenAccept(v -> {
                            result.complete(null);
                        }).exceptionally(ex -> {
                            result.completeExceptionally(ex);
                            return null;
                        });
                    }).exceptionally(ex -> {
                        result.completeExceptionally(ex);
                        return null;
                    });
                }).exceptionally(ex -> {
                    result.completeExceptionally(ex);
                    deadLetterProducer = null;
                    return null;
                });
            } else {
                TypedMessageBuilder<T> typedMessageBuilderNew = retryLetterProducer.newMessage().value(retryMessage.getValue()).properties(propertiesMap);
                if (delayTime > 0) {
                    typedMessageBuilderNew.deliverAfter(delayTime, unit);
                }
                if (message.hasKey()) {
                    typedMessageBuilderNew.key(message.getKey());
                }
                typedMessageBuilderNew.sendAsync().thenAccept(__ -> doAcknowledge(finalMessageId, ackType, Collections.emptyMap(), null).thenAccept(v -> result.complete(null))).exceptionally(ex -> {
                    result.completeExceptionally(ex);
                    return null;
                });
            }
        } catch (Exception e) {
            log.error("Send to retry letter topic exception with topic: {}, messageId: {}", retryLetterProducer.getTopic(), messageId, e);
            Set<MessageId> messageIds = Collections.singleton(messageId);
            unAckedMessageTracker.remove(messageId);
            redeliverUnacknowledgedMessages(messageIds);
        }
    }
    MessageId finalMessageId = messageId;
    result.exceptionally(ex -> {
        Set<MessageId> messageIds = Collections.singleton(finalMessageId);
        unAckedMessageTracker.remove(finalMessageId);
        redeliverUnacknowledgedMessages(messageIds);
        return null;
    });
    return result;
}
Also used : EncryptionKey(org.apache.pulsar.common.api.EncryptionContext.EncryptionKey) SubscriptionMode(org.apache.pulsar.client.api.SubscriptionMode) MessageIdData(org.apache.pulsar.common.api.proto.MessageIdData) Producer(org.apache.pulsar.client.api.Producer) LoggerFactory(org.slf4j.LoggerFactory) MessageCryptoBc(org.apache.pulsar.client.impl.crypto.MessageCryptoBc) MessageCrypto(org.apache.pulsar.client.api.MessageCrypto) StringUtils(org.apache.commons.lang3.StringUtils) KeyValue(org.apache.pulsar.common.api.proto.KeyValue) ByteBuffer(java.nio.ByteBuffer) GrowableArrayBlockingQueue(org.apache.pulsar.common.util.collections.GrowableArrayBlockingQueue) ProtocolVersion(org.apache.pulsar.common.api.proto.ProtocolVersion) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TxnID(org.apache.pulsar.client.api.transaction.TxnID) Handle(io.netty.util.Recycler.Handle) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorProvider(org.apache.pulsar.client.util.ExecutorProvider) Runnables.catchingAndLoggingThrowables(org.apache.pulsar.common.util.Runnables.catchingAndLoggingThrowables) Map(java.util.Map) Messages(org.apache.pulsar.client.api.Messages) RetryMessageUtil(org.apache.pulsar.client.util.RetryMessageUtil) CompletableFutureCancellationHandler(org.apache.pulsar.common.util.CompletableFutureCancellationHandler) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) BrokerEntryMetadata(org.apache.pulsar.common.api.proto.BrokerEntryMetadata) Crc32cIntChecksum(com.scurrilous.circe.checksum.Crc32cIntChecksum) ValidationError(org.apache.pulsar.common.api.proto.CommandAck.ValidationError) BitSetRecyclable(org.apache.pulsar.common.util.collections.BitSetRecyclable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) EncryptionContext(org.apache.pulsar.common.api.EncryptionContext) ComparisonChain(com.google.common.collect.ComparisonChain) Collectors(java.util.stream.Collectors) PulsarByteBufAllocator(org.apache.pulsar.common.allocator.PulsarByteBufAllocator) Recycler(io.netty.util.Recycler) Objects(java.util.Objects) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) MessageMetadata(org.apache.pulsar.common.api.proto.MessageMetadata) ConcurrentOpenHashMap(org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap) EncryptionKeys(org.apache.pulsar.common.api.proto.EncryptionKeys) CommandMessage(org.apache.pulsar.common.api.proto.CommandMessage) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) Optional(java.util.Optional) SchemaInfo(org.apache.pulsar.common.schema.SchemaInfo) SortedMap(java.util.SortedMap) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CompressionCodec(org.apache.pulsar.common.compression.CompressionCodec) Iterables(com.google.common.collect.Iterables) AtomicIntegerFieldUpdater(java.util.concurrent.atomic.AtomicIntegerFieldUpdater) ConsumerCryptoFailureAction(org.apache.pulsar.client.api.ConsumerCryptoFailureAction) TopicName(org.apache.pulsar.common.naming.TopicName) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) AckType(org.apache.pulsar.common.api.proto.CommandAck.AckType) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Message(org.apache.pulsar.client.api.Message) SubscriptionInitialPosition(org.apache.pulsar.client.api.SubscriptionInitialPosition) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) SchemaType(org.apache.pulsar.common.schema.SchemaType) ArrayList(java.util.ArrayList) Commands(org.apache.pulsar.common.protocol.Commands) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Commands.hasChecksum(org.apache.pulsar.common.protocol.Commands.hasChecksum) TopicDoesNotExistException(org.apache.pulsar.client.api.PulsarClientException.TopicDoesNotExistException) CompressionCodecProvider(org.apache.pulsar.common.compression.CompressionCodecProvider) CompressionType(org.apache.pulsar.common.api.proto.CompressionType) TypedMessageBuilder(org.apache.pulsar.client.api.TypedMessageBuilder) SafeCollectionUtils(org.apache.pulsar.common.util.SafeCollectionUtils) DEFAULT_CONSUMER_EPOCH(org.apache.pulsar.common.protocol.Commands.DEFAULT_CONSUMER_EPOCH) Timeout(io.netty.util.Timeout) Logger(org.slf4j.Logger) TransactionImpl(org.apache.pulsar.client.impl.transaction.TransactionImpl) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) DeadLetterPolicy(org.apache.pulsar.client.api.DeadLetterPolicy) IOException(java.io.IOException) AtomicLongFieldUpdater(java.util.concurrent.atomic.AtomicLongFieldUpdater) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) Schema(org.apache.pulsar.client.api.Schema) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) MessageId(org.apache.pulsar.client.api.MessageId) TreeMap(java.util.TreeMap) SingleMessageMetadata(org.apache.pulsar.common.api.proto.SingleMessageMetadata) Collections(java.util.Collections) Set(java.util.Set) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) TopicDoesNotExistException(org.apache.pulsar.client.api.PulsarClientException.TopicDoesNotExistException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TypedMessageBuilder(org.apache.pulsar.client.api.TypedMessageBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) MessageId(org.apache.pulsar.client.api.MessageId)

Example 3 with AckType

use of org.apache.pulsar.common.api.proto.CommandAck.AckType in project pulsar by apache.

the class MultiTopicsConsumerImpl method doAcknowledge.

@Override
protected CompletableFuture<Void> doAcknowledge(List<MessageId> messageIdList, AckType ackType, Map<String, Long> properties, TransactionImpl txn) {
    List<CompletableFuture<Void>> resultFutures = new ArrayList<>();
    if (ackType == AckType.Cumulative) {
        messageIdList.forEach(messageId -> resultFutures.add(doAcknowledge(messageId, ackType, properties, txn)));
        return CompletableFuture.allOf(resultFutures.toArray(new CompletableFuture[0]));
    } else {
        if (getState() != State.Ready) {
            return FutureUtil.failedFuture(new PulsarClientException("Consumer already closed"));
        }
        Map<String, List<MessageId>> topicToMessageIdMap = new HashMap<>();
        for (MessageId messageId : messageIdList) {
            if (!(messageId instanceof TopicMessageIdImpl)) {
                return FutureUtil.failedFuture(new IllegalArgumentException("messageId is not instance of TopicMessageIdImpl"));
            }
            TopicMessageIdImpl topicMessageId = (TopicMessageIdImpl) messageId;
            topicToMessageIdMap.putIfAbsent(topicMessageId.getTopicPartitionName(), new ArrayList<>());
            topicToMessageIdMap.get(topicMessageId.getTopicPartitionName()).add(topicMessageId.getInnerMessageId());
        }
        topicToMessageIdMap.forEach((topicPartitionName, messageIds) -> {
            ConsumerImpl<T> consumer = consumers.get(topicPartitionName);
            resultFutures.add(consumer.doAcknowledgeWithTxn(messageIds, ackType, properties, txn).thenAccept((res) -> messageIdList.forEach(unAckedMessageTracker::remove)));
        });
        return CompletableFuture.allOf(resultFutures.toArray(new CompletableFuture[0]));
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ConsumerName(org.apache.pulsar.client.util.ConsumerName) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Pair(org.apache.commons.lang3.tuple.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorProvider(org.apache.pulsar.client.util.ExecutorProvider) Map(java.util.Map) Messages(org.apache.pulsar.client.api.Messages) CompletableFutureCancellationHandler(org.apache.pulsar.common.util.CompletableFutureCancellationHandler) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Optional(java.util.Optional) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IntStream(java.util.stream.IntStream) TopicName(org.apache.pulsar.common.naming.TopicName) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) AckType(org.apache.pulsar.common.api.proto.CommandAck.AckType) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Message(org.apache.pulsar.client.api.Message) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) Function(java.util.function.Function) Builder(com.google.common.collect.ImmutableMap.Builder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ConsumerStats(org.apache.pulsar.client.api.ConsumerStats) Lists(com.google.common.collect.Lists) TimerTask(io.netty.util.TimerTask) Timeout(io.netty.util.Timeout) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) TransactionImpl(org.apache.pulsar.client.impl.transaction.TransactionImpl) NotSupportedException(org.apache.pulsar.client.api.PulsarClientException.NotSupportedException) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) Schema(org.apache.pulsar.client.api.Schema) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MessageId(org.apache.pulsar.client.api.MessageId) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) List(java.util.List) ArrayList(java.util.ArrayList) MessageId(org.apache.pulsar.client.api.MessageId)

Example 4 with AckType

use of org.apache.pulsar.common.api.proto.CommandAck.AckType 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

ArrayList (java.util.ArrayList)4 AckType (org.apache.pulsar.common.api.proto.CommandAck.AckType)4 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 TxnID (org.apache.pulsar.client.api.transaction.TxnID)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Timeout (io.netty.util.Timeout)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 Function (java.util.function.Function)2