You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2022/07/14 02:59:15 UTC
[pulsar] branch master updated: [improve][test] Improve the TransactionTest to reduce the execution time (#16580)
This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 596fc3cd6b0 [improve][test] Improve the TransactionTest to reduce the execution time (#16580)
596fc3cd6b0 is described below
commit 596fc3cd6b080bd4b0ddf9202aceab6dccc1a1fd
Author: lipenghui <pe...@apache.org>
AuthorDate: Thu Jul 14 10:59:08 2022 +0800
[improve][test] Improve the TransactionTest to reduce the execution time (#16580)
### Motivation
The TransactionTest run over 3 minutes. To avoid start a pulsar cluster for each test method.
```
[INFO] Tests run: 24, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 186.322 s - in org.apache.pulsar.broker.transaction.TransactionTest
```
After this change, the execution time reduce to under 1 minute on my laptop
---
.../broker/intercept/CounterBrokerInterceptor.java | 15 ++++++++++++
.../pulsar/broker/transaction/TransactionTest.java | 27 +++++++++++-----------
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/CounterBrokerInterceptor.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/CounterBrokerInterceptor.java
index 4ae4cf00acb..c56d1682c5b 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/CounterBrokerInterceptor.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/CounterBrokerInterceptor.java
@@ -61,6 +61,21 @@ public class CounterBrokerInterceptor implements BrokerInterceptor {
int committedTxnCount = 0;
int abortedTxnCount = 0;
+ public void reset() {
+ beforeSendCount = 0;
+ count = 0;
+ connectionCreationCount = 0;
+ producerCount = 0;
+ consumerCount = 0;
+ messageCount = 0;
+ messageDispatchCount = 0;
+ messageAckCount = 0;
+ handleAckCount = 0;
+ txnCount = 0;
+ committedTxnCount = 0;
+ abortedTxnCount = 0;
+ }
+
private List<ResponseEvent> responseList = new ArrayList<>();
@Data
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTest.java
index 78d499cbb62..30eded8eb25 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/transaction/TransactionTest.java
@@ -70,7 +70,6 @@ import org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl;
import org.apache.bookkeeper.mledger.impl.PositionImpl;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.ServiceConfiguration;
-import org.apache.pulsar.broker.intercept.BrokerInterceptor;
import org.apache.pulsar.broker.intercept.CounterBrokerInterceptor;
import org.apache.pulsar.broker.service.BacklogQuotaManager;
import org.apache.pulsar.broker.service.BrokerService;
@@ -136,8 +135,8 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.reflect.Whitebox;
import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
@@ -150,11 +149,16 @@ public class TransactionTest extends TransactionTestBase {
private static final int NUM_BROKERS = 1;
private static final int NUM_PARTITIONS = 1;
- @BeforeMethod
+ @BeforeClass
protected void setup() throws Exception {
setUpBase(NUM_BROKERS, NUM_PARTITIONS, NAMESPACE1 + "/test", 0);
}
+ @AfterClass(alwaysRun = true)
+ protected void cleanup() throws Exception {
+ super.internalCleanup();
+ }
+
@Test
public void testCreateTransactionSystemTopic() throws Exception {
String subName = "test";
@@ -259,12 +263,6 @@ public class TransactionTest extends TransactionTestBase {
Assert.assertNull(topics.get(MLPendingAckStore.getTransactionPendingAckStoreSuffix(topicName, subName)));
}
-
- @AfterMethod(alwaysRun = true)
- protected void cleanup() throws Exception {
- super.internalCleanup();
- }
-
public Consumer<byte[]> getConsumer(String topicName, String subName) throws PulsarClientException {
return pulsarClient.newConsumer()
.topic(topicName)
@@ -371,7 +369,7 @@ public class TransactionTest extends TransactionTestBase {
ReaderBuilder<TransactionBufferSnapshot> readerBuilder = pulsarClient
.newReader(Schema.AVRO(TransactionBufferSnapshot.class))
- .startMessageId(MessageId.earliest)
+ .startMessageId(MessageId.latest)
.topic(NAMESPACE1 + "/" + SystemTopicNames.TRANSACTION_BUFFER_SNAPSHOT);
Reader<TransactionBufferSnapshot> reader = readerBuilder.create();
@@ -679,7 +677,7 @@ public class TransactionTest extends TransactionTestBase {
@Test
public void testEndTCRecoveringWhenManagerLedgerDisReadable() throws Exception{
- String topic = NAMESPACE1 + "/testEndTBRecoveringWhenManagerLedgerDisReadable";
+ String topic = NAMESPACE1 + "/testEndTCRecoveringWhenManagerLedgerDisReadable";
admin.topics().createNonPartitionedTopic(topic);
PersistentTopic persistentTopic = (PersistentTopic) getPulsarServiceList().get(0).getBrokerService()
@@ -752,6 +750,9 @@ public class TransactionTest extends TransactionTestBase {
@Test
public void testEndTxnWhenCommittingOrAborting() throws Exception {
+ CounterBrokerInterceptor listener = (CounterBrokerInterceptor) getPulsarServiceList().get(0)
+ .getBrokerInterceptor();
+ listener.reset();
Transaction commitTxn = pulsarClient
.newTransaction()
.withTransactionTimeout(5, TimeUnit.SECONDS)
@@ -770,7 +771,7 @@ public class TransactionTest extends TransactionTestBase {
field.set(commitTxn, TransactionImpl.State.COMMITTING);
field.set(abortTxn, TransactionImpl.State.ABORTING);
- BrokerInterceptor listener = getPulsarServiceList().get(0).getBrokerInterceptor();
+
assertEquals(((CounterBrokerInterceptor)listener).getTxnCount(),2);
abortTxn.abort().get();
assertEquals(((CounterBrokerInterceptor)listener).getAbortedTxnCount(),1);