|
38 | 38 | import lombok.Cleanup; |
39 | 39 | import org.apache.bookkeeper.mledger.ManagedLedger; |
40 | 40 | import org.apache.bookkeeper.mledger.ManagedLedgerException; |
| 41 | +import org.apache.bookkeeper.mledger.Position; |
41 | 42 | import org.apache.bookkeeper.mledger.PositionFactory; |
42 | 43 | import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl; |
43 | 44 | import org.apache.commons.lang3.RandomUtils; |
|
50 | 51 | import org.apache.pulsar.broker.service.persistent.PersistentTopic; |
51 | 52 | import org.apache.pulsar.broker.stats.OpenTelemetryTopicStats; |
52 | 53 | import org.apache.pulsar.broker.transaction.TransactionTestBase; |
| 54 | +import org.apache.pulsar.broker.transaction.buffer.impl.InMemTransactionBuffer; |
| 55 | +import org.apache.pulsar.broker.transaction.buffer.impl.InMemTransactionBufferProvider; |
53 | 56 | import org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBuffer; |
54 | 57 | import org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState; |
55 | 58 | import org.apache.pulsar.broker.transaction.buffer.utils.TransactionBufferTestImpl; |
@@ -574,4 +577,27 @@ public void testRefCountWhenAppendBufferToTxn() throws Exception { |
574 | 577 | byteBuf2.release(); |
575 | 578 | byteBuf3.release(); |
576 | 579 | } |
| 580 | + |
| 581 | + @Test(timeOut = 10000) |
| 582 | + public void testAppendBufferToTxnWithInMemTransactionBuffer() throws Exception { |
| 583 | + // 1. Prepare test resource |
| 584 | + this.pulsarServiceList.forEach(pulsarService -> { |
| 585 | + pulsarService.setTransactionBufferProvider(new InMemTransactionBufferProvider()); |
| 586 | + }); |
| 587 | + String topic = "persistent://" + NAMESPACE1 + "/testAppendBufferToTxnWithInMemTransactionBuffer"; |
| 588 | + admin.topics().createNonPartitionedTopic(topic); |
| 589 | + PersistentTopic persistentTopic = (PersistentTopic) pulsarServiceList.get(0).getBrokerService() |
| 590 | + .getTopic(topic, false) |
| 591 | + .get() |
| 592 | + .get(); |
| 593 | + InMemTransactionBuffer topicTransactionBuffer = (InMemTransactionBuffer) persistentTopic |
| 594 | + .getTransactionBuffer(); |
| 595 | + ByteBuf byteBuf = Unpooled.buffer(); |
| 596 | + Position position = topicTransactionBuffer.appendBufferToTxn(new TxnID(1, 1), 1L, byteBuf) |
| 597 | + .get(5, TimeUnit.SECONDS); |
| 598 | + // 2.position should be PositionFactory.EARLIEST with InMemTransactionBuffer |
| 599 | + assertEquals(PositionFactory.EARLIEST, position); |
| 600 | + // 3. release resource |
| 601 | + byteBuf.release(); |
| 602 | + } |
577 | 603 | } |
0 commit comments