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