use of org.apache.pulsar.broker.transaction.buffer.TransactionBuffer in project pulsar by apache.
the class TransactionTest method testNotChangeMaxReadPositionAndAddAbortTimesWhenCheckIfNoSnapshot.
@Test
public void testNotChangeMaxReadPositionAndAddAbortTimesWhenCheckIfNoSnapshot() throws Exception {
PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic(NAMESPACE1 + "/test", true).get().get();
TransactionBuffer buffer = persistentTopic.getTransactionBuffer();
Field field = TopicTransactionBuffer.class.getDeclaredField("changeMaxReadPositionAndAddAbortTimes");
field.setAccessible(true);
AtomicLong changeMaxReadPositionAndAddAbortTimes = (AtomicLong) field.get(buffer);
Field field1 = TopicTransactionBufferState.class.getDeclaredField("state");
field1.setAccessible(true);
Awaitility.await().untilAsserted(() -> {
TopicTransactionBufferState.State state = (TopicTransactionBufferState.State) field1.get(buffer);
Assert.assertEquals(state, TopicTransactionBufferState.State.NoSnapshot);
});
Assert.assertEquals(changeMaxReadPositionAndAddAbortTimes.get(), 0L);
buffer.syncMaxReadPositionForNormalPublish(new PositionImpl(1, 1));
Assert.assertEquals(changeMaxReadPositionAndAddAbortTimes.get(), 0L);
}
use of org.apache.pulsar.broker.transaction.buffer.TransactionBuffer in project pulsar by yahoo.
the class TransactionTest method testNotChangeMaxReadPositionAndAddAbortTimesWhenCheckIfNoSnapshot.
@Test
public void testNotChangeMaxReadPositionAndAddAbortTimesWhenCheckIfNoSnapshot() throws Exception {
PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic(NAMESPACE1 + "/changeMaxReadPositionAndAddAbortTimes" + UUID.randomUUID(), true).get().get();
TransactionBuffer buffer = persistentTopic.getTransactionBuffer();
Field field = TopicTransactionBuffer.class.getDeclaredField("changeMaxReadPositionAndAddAbortTimes");
field.setAccessible(true);
AtomicLong changeMaxReadPositionAndAddAbortTimes = (AtomicLong) field.get(buffer);
Field field1 = TopicTransactionBufferState.class.getDeclaredField("state");
field1.setAccessible(true);
Awaitility.await().untilAsserted(() -> {
TopicTransactionBufferState.State state = (TopicTransactionBufferState.State) field1.get(buffer);
Assert.assertEquals(state, TopicTransactionBufferState.State.NoSnapshot);
});
Assert.assertEquals(changeMaxReadPositionAndAddAbortTimes.get(), 0L);
buffer.syncMaxReadPositionForNormalPublish(new PositionImpl(1, 1));
Assert.assertEquals(changeMaxReadPositionAndAddAbortTimes.get(), 0L);
}
use of org.apache.pulsar.broker.transaction.buffer.TransactionBuffer in project pulsar by yahoo.
the class TransactionTest method testEndTBRecoveringWhenManagerLedgerDisReadable.
@Test
public void testEndTBRecoveringWhenManagerLedgerDisReadable() throws Exception {
String topic = NAMESPACE1 + "/testEndTBRecoveringWhenManagerLedgerDisReadable";
admin.topics().createNonPartitionedTopic(topic);
@Cleanup Producer<String> producer = pulsarClient.newProducer(Schema.STRING).producerName("test").enableBatching(false).sendTimeout(0, TimeUnit.SECONDS).topic(topic).create();
Transaction txn = pulsarClient.newTransaction().withTransactionTimeout(10, TimeUnit.SECONDS).build().get();
producer.newMessage(txn).value("test").send();
PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic("persistent://" + topic, false).get().get();
persistentTopic.getManagedLedger().getConfig().setAutoSkipNonRecoverableData(true);
ManagedCursorImpl managedCursor = mock(ManagedCursorImpl.class);
doReturn("transaction-buffer-sub").when(managedCursor).getName();
doReturn(true).when(managedCursor).hasMoreEntries();
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());
Class<ManagedLedgerImpl> managedLedgerClass = ManagedLedgerImpl.class;
Field field = managedLedgerClass.getDeclaredField("cursors");
field.setAccessible(true);
ManagedCursorContainer managedCursors = (ManagedCursorContainer) field.get(persistentTopic.getManagedLedger());
managedCursors.removeCursor("transaction-buffer-sub");
managedCursors.add(managedCursor);
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.ManagedLedgerFencedException(), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
TransactionBuffer buffer2 = new TopicTransactionBuffer(persistentTopic);
Awaitility.await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(buffer2.getStats().state, "Ready"));
managedCursors.removeCursor("transaction-buffer-sub");
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.CursorAlreadyClosedException("test"), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
managedCursors.add(managedCursor);
TransactionBuffer buffer3 = new TopicTransactionBuffer(persistentTopic);
Awaitility.await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(buffer3.getStats().state, "Ready"));
persistentTopic.getInternalStats(false).thenAccept(internalStats -> {
assertTrue(internalStats.cursors.isEmpty());
});
managedCursors.removeCursor("transaction-buffer-sub");
}
use of org.apache.pulsar.broker.transaction.buffer.TransactionBuffer in project incubator-pulsar by apache.
the class TransactionTest method testEndTBRecoveringWhenManagerLedgerDisReadable.
@Test
public void testEndTBRecoveringWhenManagerLedgerDisReadable() throws Exception {
String topic = NAMESPACE1 + "/testEndTBRecoveringWhenManagerLedgerDisReadable";
admin.topics().createNonPartitionedTopic(topic);
@Cleanup Producer<String> producer = pulsarClient.newProducer(Schema.STRING).producerName("test").enableBatching(false).sendTimeout(0, TimeUnit.SECONDS).topic(topic).create();
Transaction txn = pulsarClient.newTransaction().withTransactionTimeout(10, TimeUnit.SECONDS).build().get();
producer.newMessage(txn).value("test").send();
PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic("persistent://" + topic, false).get().get();
persistentTopic.getManagedLedger().getConfig().setAutoSkipNonRecoverableData(true);
ManagedCursorImpl managedCursor = mock(ManagedCursorImpl.class);
doReturn("transaction-buffer-sub").when(managedCursor).getName();
doReturn(true).when(managedCursor).hasMoreEntries();
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());
Class<ManagedLedgerImpl> managedLedgerClass = ManagedLedgerImpl.class;
Field field = managedLedgerClass.getDeclaredField("cursors");
field.setAccessible(true);
ManagedCursorContainer managedCursors = (ManagedCursorContainer) field.get(persistentTopic.getManagedLedger());
managedCursors.removeCursor("transaction-buffer-sub");
managedCursors.add(managedCursor);
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.ManagedLedgerFencedException(), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
TransactionBuffer buffer2 = new TopicTransactionBuffer(persistentTopic);
Awaitility.await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(buffer2.getStats().state, "Ready"));
managedCursors.removeCursor("transaction-buffer-sub");
doAnswer(invocation -> {
AsyncCallbacks.ReadEntriesCallback callback = invocation.getArgument(1);
callback.readEntriesFailed(new ManagedLedgerException.CursorAlreadyClosedException("test"), null);
return null;
}).when(managedCursor).asyncReadEntries(anyInt(), any(), any(), any());
managedCursors.add(managedCursor);
TransactionBuffer buffer3 = new TopicTransactionBuffer(persistentTopic);
Awaitility.await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(buffer3.getStats().state, "Ready"));
persistentTopic.getInternalStats(false).thenAccept(internalStats -> {
assertTrue(internalStats.cursors.isEmpty());
});
managedCursors.removeCursor("transaction-buffer-sub");
}
use of org.apache.pulsar.broker.transaction.buffer.TransactionBuffer in project incubator-pulsar by apache.
the class TransactionTest method testNotChangeMaxReadPositionAndAddAbortTimesWhenCheckIfNoSnapshot.
@Test
public void testNotChangeMaxReadPositionAndAddAbortTimesWhenCheckIfNoSnapshot() throws Exception {
PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService().getTopic(NAMESPACE1 + "/changeMaxReadPositionAndAddAbortTimes" + UUID.randomUUID(), true).get().get();
TransactionBuffer buffer = persistentTopic.getTransactionBuffer();
Field field = TopicTransactionBuffer.class.getDeclaredField("changeMaxReadPositionAndAddAbortTimes");
field.setAccessible(true);
AtomicLong changeMaxReadPositionAndAddAbortTimes = (AtomicLong) field.get(buffer);
Field field1 = TopicTransactionBufferState.class.getDeclaredField("state");
field1.setAccessible(true);
Awaitility.await().untilAsserted(() -> {
TopicTransactionBufferState.State state = (TopicTransactionBufferState.State) field1.get(buffer);
Assert.assertEquals(state, TopicTransactionBufferState.State.NoSnapshot);
});
Assert.assertEquals(changeMaxReadPositionAndAddAbortTimes.get(), 0L);
buffer.syncMaxReadPositionForNormalPublish(new PositionImpl(1, 1));
Assert.assertEquals(changeMaxReadPositionAndAddAbortTimes.get(), 0L);
}
Aggregations