Search in sources :

Example 1 with TransactionBuffer

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);
}
Also used : Field(java.lang.reflect.Field) AtomicLong(java.util.concurrent.atomic.AtomicLong) TopicTransactionBufferState(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState) TransactionMetadataStoreState(org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) TopicTransactionBuffer(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer) TransactionBuffer(org.apache.pulsar.broker.transaction.buffer.TransactionBuffer) TopicTransactionBufferState(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState) Test(org.testng.annotations.Test)

Example 2 with TransactionBuffer

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);
}
Also used : Field(java.lang.reflect.Field) AtomicLong(java.util.concurrent.atomic.AtomicLong) TopicTransactionBufferState(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState) TransactionMetadataStoreState(org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) TopicTransactionBuffer(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer) TransactionBuffer(org.apache.pulsar.broker.transaction.buffer.TransactionBuffer) TopicTransactionBufferState(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState) Test(org.testng.annotations.Test)

Example 3 with TransactionBuffer

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");
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) Cleanup(lombok.Cleanup) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) Field(java.lang.reflect.Field) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) Transaction(org.apache.pulsar.client.api.transaction.Transaction) ManagedCursorContainer(org.apache.bookkeeper.mledger.impl.ManagedCursorContainer) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) TopicTransactionBuffer(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer) TransactionBuffer(org.apache.pulsar.broker.transaction.buffer.TransactionBuffer) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) TopicTransactionBuffer(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer) Test(org.testng.annotations.Test)

Example 4 with TransactionBuffer

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");
}
Also used : ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) Cleanup(lombok.Cleanup) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) Field(java.lang.reflect.Field) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) Transaction(org.apache.pulsar.client.api.transaction.Transaction) ManagedCursorContainer(org.apache.bookkeeper.mledger.impl.ManagedCursorContainer) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) TopicTransactionBuffer(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer) TransactionBuffer(org.apache.pulsar.broker.transaction.buffer.TransactionBuffer) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) TopicTransactionBuffer(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer) Test(org.testng.annotations.Test)

Example 5 with TransactionBuffer

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);
}
Also used : Field(java.lang.reflect.Field) AtomicLong(java.util.concurrent.atomic.AtomicLong) TopicTransactionBufferState(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState) TransactionMetadataStoreState(org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) TopicTransactionBuffer(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer) TransactionBuffer(org.apache.pulsar.broker.transaction.buffer.TransactionBuffer) TopicTransactionBufferState(org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState) Test(org.testng.annotations.Test)

Aggregations

Field (java.lang.reflect.Field)6 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)6 TransactionBuffer (org.apache.pulsar.broker.transaction.buffer.TransactionBuffer)6 TopicTransactionBuffer (org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer)6 Test (org.testng.annotations.Test)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Cleanup (lombok.Cleanup)3 AsyncCallbacks (org.apache.bookkeeper.mledger.AsyncCallbacks)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3 ManagedCursorContainer (org.apache.bookkeeper.mledger.impl.ManagedCursorContainer)3 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)3 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)3 TopicTransactionBufferState (org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState)3 Transaction (org.apache.pulsar.client.api.transaction.Transaction)3 TransactionMetadataStoreState (org.apache.pulsar.transaction.coordinator.TransactionMetadataStoreState)3 ManagedCursorImpl (org.apache.bookkeeper.mledger.impl.ManagedCursorImpl)2 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)1