You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by aa...@apache.org on 2023/01/18 06:46:34 UTC
[rocketmq-e2e] branch master updated: Support authentication with rocketmq4.x and fix bugs (#6)
This is an automated email from the ASF dual-hosted git repository.
aaronai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-e2e.git
The following commit(s) were added to refs/heads/master by this push:
new 2ff234b Support authentication with rocketmq4.x and fix bugs (#6)
2ff234b is described below
commit 2ff234b1fa4dffa9aaf4e7943976321fd5234487
Author: yueya <10...@users.noreply.github.com>
AuthorDate: Wed Jan 18 14:46:29 2023 +0800
Support authentication with rocketmq4.x and fix bugs (#6)
* Modify the method of reading a local property file
(cherry picked from commit 66c85b5482124d6e6b446fa03996619a219eb57e)
* Modify README.md
(cherry picked from commit 0c77d6a9087381f068b3c49d9ec80da1d86a2347)
* remove some useless annotations
(cherry picked from commit ae501bb4432fe13bcb2755a4cb86d5dba6b08570)
* Modify the project directory structure, add php/c/c#/go/rust catalog
* Modify README.md
(cherry picked from commit 0c77d6a9087381f068b3c49d9ec80da1d86a2347)
* add e2e cases of rocketmq4.x with new module
* fix case's bug
* Modify README.md
(cherry picked from commit 0c77d6a9087381f068b3c49d9ec80da1d86a2347)
* add e2e cases of rocketmq4.x with new module
* fix case's bug
---
README.md | 9 +
README.md => golang/README.md | 0
golang/client_test.go | 22 ++
java/{e2e => e2e-v4}/pom.xml | 88 +----
.../java/org/apache/rocketmq/account/Account.java | 34 ++
.../rocketmq/client/callback/RMQSendCallBack.java | 92 +++++
.../org/apache/rocketmq/client/rmq/DelayConf.java | 23 ++
.../rocketmq/client/rmq/RMQNormalConsumer.java | 101 +++++
.../rocketmq/client/rmq/RMQNormalProducer.java | 428 ++++++++++++++++++++
.../client/rmq/RMQTransactionProducer.java | 76 ++++
.../apache/rocketmq/common/AbstractListener.java | 32 ++
.../apache/rocketmq/common/AbstractMQConsumer.java | 27 ++
.../apache/rocketmq/common/AbstractMQProducer.java | 34 ++
.../org/apache/rocketmq/common/MQCollector.java | 121 ++++++
.../org/apache/rocketmq/common/MQConsumer.java | 23 ++
.../org/apache/rocketmq/common/MQProducer.java | 24 ++
.../java/org/apache/rocketmq/enums/TESTSET.java | 53 +++
.../java/org/apache/rocketmq/enums/TransEnum.java | 57 +++
.../org/apache/rocketmq/factory/AclClient.java | 28 ++
.../apache/rocketmq/factory/ConsumerFactory.java | 48 +++
.../apache/rocketmq/factory/MessageFactory.java | 208 ++++++++++
.../apache/rocketmq/factory/ProducerFactory.java | 76 ++++
.../org/apache/rocketmq/frame/BaseOperate.java | 35 ++
.../org/apache/rocketmq/frame/ResourceInit.java | 190 +++++++++
.../apache/rocketmq/listener/AbstractListener.java | 31 ++
.../listener/rmq/concurrent/RMQNormalListener.java | 60 +++
.../listener/rmq/concurrent/RMQOrderListener.java | 60 +++
.../rmq/concurrent/TransactionListenerImpl.java | 99 +++++
.../listener/rmq/order/RMQOrderListener.java | 66 ++++
.../java/org/apache/rocketmq/utils/DateUtils.java | 115 ++++++
.../java/org/apache/rocketmq/utils/MQAdmin.java | 181 +++++++++
.../java/org/apache/rocketmq/utils/NameUtils.java | 64 +++
.../org/apache/rocketmq/utils/RandomUtils.java | 91 +++++
.../java/org/apache/rocketmq/utils/TestUtils.java | 138 +++++++
.../org/apache/rocketmq/utils/VerifyUtils.java | 435 +++++++++++++++++++++
.../rocketmq/utils/data/collect/DataCollector.java | 97 +++++
.../utils/data/collect/DataCollectorManager.java | 114 ++++++
.../data/collect/impl/ListDataCollectorImpl.java | 102 +++++
.../data/collect/impl/MapDataCollectorImpl.java | 118 ++++++
.../rocketmq/server/delay/DelayMessageTest.java | 91 +++++
.../rocketmq/server/normal/NormalMessageTest.java | 115 ++++++
.../rocketmq/server/order/OrderMessageTest.java | 92 +++++
.../server/transaction/TransactionMessageTest.java | 87 +++++
.../e2e-v4/src/test/resources/env/daily/daily.conf | 5 +
.../src/test/resources/junit-platform.properties | 18 +
java/e2e-v4/src/test/resources/log4j.properties | 25 ++
java/e2e-v4/src/test/resources/logback-test.xml | 35 ++
java/e2e/pom.xml | 62 +--
.../java/org/apache/rocketmq/util/VerifyUtils.java | 306 +++++++--------
.../rocketmq/broker/offset/ResetOffsetTest.java | 286 +++++++-------
.../rocketmq/broker/simple/SimpleAckTest.java | 11 +-
java/e2e/src/test/resources/env/daily/daily.conf | 4 +-
java/pom.xml | 48 +++
53 files changed, 4331 insertions(+), 454 deletions(-)
diff --git a/README.md b/README.md
index c9cc7e5..c1081e8 100644
--- a/README.md
+++ b/README.md
@@ -30,3 +30,12 @@ RocketMQ E2E Test
* Retry
* Normal message
* Order message
+
+#### How to start
+```angular2html
+mvn clean test -B -Dgroups=smoke -Dcluster=DefaultCluster
+```
+##### Options
+* `ALL_IP` : not required, default is null
+* `cluster`: not required, default `DefaultCluster`
+* `groups`: param of junit5, `src/main/java/org/apache/rocketmq/enums/TESTSET.java`
\ No newline at end of file
diff --git a/README.md b/golang/README.md
similarity index 100%
copy from README.md
copy to golang/README.md
diff --git a/golang/client_test.go b/golang/client_test.go
new file mode 100644
index 0000000..8edb68f
--- /dev/null
+++ b/golang/client_test.go
@@ -0,0 +1,22 @@
+package golang
+
+import "fmt"
+
+import "testing"
+
+func TestHello(t *testing.T) {
+ got := Hello()
+ want := "Hello, world"
+
+ if got != want {
+ t.Errorf("got %q want %q", got, want)
+ }
+}
+
+func Hello() string {
+ return "Hello, world"
+}
+
+func main() {
+ fmt.Println(Hello())
+}
diff --git a/java/e2e/pom.xml b/java/e2e-v4/pom.xml
similarity index 63%
copy from java/e2e/pom.xml
copy to java/e2e-v4/pom.xml
index 83d0640..5ae3c84 100644
--- a/java/e2e/pom.xml
+++ b/java/e2e-v4/pom.xml
@@ -3,110 +3,38 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
-
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-java-test</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
- <artifactId>rocketmq-java-e2e</artifactId>
+ <artifactId>rocketmq-java-e2e-v4</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
-
- <junit.jupiter.version>5.7.2</junit.jupiter.version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<rocketmq.client.version>4.9.3</rocketmq.client.version>
- <rocketmqV5.client.version>5.0.2</rocketmqV5.client.version>
</properties>
<dependencies>
- <!-- <dependency>-->
- <!-- <groupId>org.apache.rocketmq</groupId>-->
- <!-- <artifactId>rocketmq-client</artifactId>-->
- <!-- <version>${rocketmq.client.version}</version>-->
- <!-- </dependency>-->
<dependency>
<groupId>org.apache.rocketmq</groupId>
- <artifactId>rocketmq-client-java</artifactId>
- <version>${rocketmqV5.client.version}</version>
+ <artifactId>rocketmq-client</artifactId>
+ <version>${rocketmq.client.version}</version>
</dependency>
+
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-acl</artifactId>
- <version>5.0.0</version>
+ <version>${rocketmq.client.version}</version>
</dependency>
+
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-tools</artifactId>
- <version>5.0.0</version>
- </dependency>
- <!--junit5-->
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-launcher</artifactId>
- <version>1.7.2</version>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <version>${junit.jupiter.version}</version>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>${junit.jupiter.version}</version>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-params</artifactId>
- <version>${junit.jupiter.version}</version>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>1.18.8</version>
- </dependency>
- <!-- <dependency>-->
- <!-- <groupId>org.slf4j</groupId>-->
- <!-- <artifactId>slf4j-log4j12</artifactId>-->
- <!-- <version>1.7.7</version>-->
- <!-- </dependency>-->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>2.0.0-beta1</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>1.3.0-beta0</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <version>1.3.0-beta0</version>
- </dependency>
- <dependency>
- <groupId>com.aliyun</groupId>
- <artifactId>aliyun-java-sdk-core</artifactId>
- <version>3.5.0</version>
- </dependency>
- <dependency>
- <groupId>com.squareup.okhttp</groupId>
- <artifactId>okhttp</artifactId>
- <version>2.7.5</version>
- </dependency>
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>dns-cache-manipulator</artifactId>
- <version>1.5.1</version>
- </dependency>
- <dependency>
- <groupId>org.awaitility</groupId>
- <artifactId>awaitility</artifactId>
- <version>4.0.3</version>
+ <version>${rocketmq.client.version}</version>
</dependency>
</dependencies>
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/account/Account.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/account/Account.java
new file mode 100644
index 0000000..94a509f
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/account/Account.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.account;
+
+import lombok.Data;
+
+@Data
+public class Account {
+
+ public String accessKey;
+ public String secretKey;
+ public String userId;
+ private String namespaceId;
+
+ public Account(String accessKey, String secretKey) {
+ this.accessKey = accessKey;
+ this.secretKey = secretKey;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/client/callback/RMQSendCallBack.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/callback/RMQSendCallBack.java
new file mode 100644
index 0000000..310ea79
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/callback/RMQSendCallBack.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.client.callback;
+
+import org.apache.rocketmq.client.producer.SendCallback;
+import org.apache.rocketmq.client.producer.SendResult;
+import org.apache.rocketmq.utils.TestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RMQSendCallBack implements SendCallback {
+ private static Logger logger = LoggerFactory.getLogger(RMQSendCallBack.class);
+ private final static int WAIT_RESPONSE_MILLS = 15 * 1000;
+ private boolean isDebug = false;
+ private boolean bSuccessResponse = false;
+ private boolean bFailResponse = false;
+ private String messageId = null;
+
+ public RMQSendCallBack(boolean isDebug) {
+ this.isDebug = isDebug;
+ }
+
+ public RMQSendCallBack() {
+ }
+
+ @Override
+ public void onSuccess(SendResult sendResult) {
+ logger.info("{} callback msg success: {}", sendResult.getMessageQueue(), sendResult.getMsgId());
+ messageId = sendResult.getMsgId();
+ bSuccessResponse = true;
+ }
+
+ @Override
+ public void onException(Throwable e) {
+ //logger.warn("{} callback message failed: {} exception: {}", context.getTopic(), context.getMessageId(), context.getException());
+ bFailResponse = true;
+ }
+
+ public void waitResponse() {
+ long start = System.currentTimeMillis();
+ while (System.currentTimeMillis() - start < WAIT_RESPONSE_MILLS && (!bSuccessResponse && !bFailResponse)) {
+ TestUtils.waitForMoment(100);
+ }
+ }
+
+ public String getMessageId() {
+ return messageId;
+ }
+
+ public void setMessageId(String messageId) {
+ this.messageId = messageId;
+ }
+
+ public boolean isDebug() {
+ return isDebug;
+ }
+
+ public void setDebug(boolean debug) {
+ isDebug = debug;
+ }
+
+ public boolean isbSuccessResponse() {
+ return bSuccessResponse;
+ }
+
+ public void setbSuccessResponse(boolean bSuccessResponse) {
+ this.bSuccessResponse = bSuccessResponse;
+ }
+
+ public boolean isbFailResponse() {
+ return bFailResponse;
+ }
+
+ public void setbFailResponse(boolean bFailResponse) {
+ this.bFailResponse = bFailResponse;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/DelayConf.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/DelayConf.java
new file mode 100644
index 0000000..9a48d78
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/DelayConf.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.client.rmq;
+
+public class DelayConf {
+ public static final int[] DELAY_LEVEL = {1, 5, 10, 30, 1 * 60, 5 * 60, 10 * 60, 30 * 60, 1 * 3600, 2 * 3600, 6 * 3600, 12 * 3600, 1 * 24 * 3600};
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQNormalConsumer.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQNormalConsumer.java
new file mode 100644
index 0000000..4d464dd
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQNormalConsumer.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.client.rmq;
+
+import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
+import org.apache.rocketmq.client.consumer.MessageSelector;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.AbstractMQConsumer;
+import org.apache.rocketmq.listener.AbstractListener;
+import org.apache.rocketmq.listener.rmq.concurrent.RMQNormalListener;
+import org.apache.rocketmq.listener.rmq.concurrent.RMQOrderListener;
+import org.apache.rocketmq.utils.TestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RMQNormalConsumer extends AbstractMQConsumer {
+ private static Logger logger = LoggerFactory.getLogger(RMQNormalConsumer.class);
+
+ private DefaultMQPushConsumer consumer;
+ private AbstractListener listener = null;
+
+ public RMQNormalConsumer(DefaultMQPushConsumer consumer) {
+ this.consumer = consumer;
+ }
+
+ public void subscribeAndStart(String topic, String tag, RMQNormalListener listener) {
+ this.listener = listener;
+ try {
+ consumer.subscribe(topic, tag);
+ consumer.setMessageListener(listener);
+ consumer.start();
+ } catch (MQClientException e) {
+ logger.info("Start DefaultMQPushConsumer failed, {}", e.getMessage());
+ }
+ logger.info("DefaultMQPushConsumer started - topic: {}, tag: {}", topic, tag);
+ }
+
+ public void subscribeAndStart(String topic, String tag, RMQOrderListener listener) {
+ this.listener = listener;
+ try {
+ consumer.subscribe(topic, tag);
+ consumer.setMessageListener(listener);
+ consumer.start();
+ } catch (MQClientException e) {
+ logger.info("Start DefaultMQPushConsumer failed, {}", e.getMessage());
+ }
+ logger.info("DefaultMQPushConsumer started - topic: {}, tag: {}", topic, tag);
+ }
+
+ public void subscribeAndStart(String topic, MessageSelector messageSelector, RMQNormalListener listener) {
+ this.listener = listener;
+ try {
+ consumer.subscribe(topic, messageSelector);
+ consumer.setMessageListener(listener);
+ consumer.start();
+ } catch (MQClientException e) {
+ logger.info("Start DefaultMQPushConsumer failed, {}", e.getMessage());
+ }
+ logger.info("DefaultMQPushConsumer started - topic: {}, messageSelector: {}", topic, messageSelector.getExpression());
+ TestUtils.waitForSeconds(5);
+ }
+
+ @Override
+ public void shutdown() {
+ if (consumer != null) {
+ consumer.shutdown();
+ logger.info("DefaultMQPushConsumer shutdown !!!");
+ }
+ }
+
+ public DefaultMQPushConsumer getConsumer() {
+ return consumer;
+ }
+
+ public void setConsumer(DefaultMQPushConsumer consumer) {
+ this.consumer = consumer;
+ }
+
+ public AbstractListener getListener() {
+ return listener;
+ }
+
+ public void setListener(AbstractListener listener) {
+ this.listener = listener;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQNormalProducer.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQNormalProducer.java
new file mode 100644
index 0000000..60688d6
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQNormalProducer.java
@@ -0,0 +1,428 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.client.rmq;
+
+import org.apache.rocketmq.client.callback.RMQSendCallBack;
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.SendResult;
+import org.apache.rocketmq.common.AbstractMQProducer;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.factory.MessageFactory;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.utils.NameUtils;
+import org.junit.jupiter.api.Assertions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.UUID;
+
+public class RMQNormalProducer extends AbstractMQProducer {
+ private static Logger logger = LoggerFactory.getLogger(RMQNormalProducer.class);
+ private DefaultMQProducer producer;
+
+ public RMQNormalProducer(DefaultMQProducer producer) {
+ this.producer = producer;
+ }
+
+ public void send(String topic, int messageNum) {
+ logger.info("Producer start to send messages");
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessage(topic);
+ try {
+ SendResult sendResult = producer.send(message);
+ logger.info(sendResult.toString());
+
+ MessageExt messageExt = new MessageExt();
+ messageExt.setMsgId(sendResult.getMsgId());
+ logger.info("{}, index: {}", sendResult, i);
+ this.enqueueMessages.addData(messageExt);
+ } catch (Exception e) {
+ logger.error("DefaultMQProducer send message failed");
+ }
+ }
+ logger.info("Producer send messages finished");
+ }
+
+ public void send(String topic, String tag, int messageNum) {
+ logger.info("Producer start to send messages");
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessageWithTag(topic, tag);
+ try {
+ SendResult sendResult = producer.send(message);
+ MessageExt messageExt = new MessageExt();
+ messageExt.setMsgId(sendResult.getMsgId());
+ logger.info("{}, index: {}, tag: {}", sendResult, i, tag);
+ this.enqueueMessages.addData(messageExt);
+ } catch (Exception e) {
+ logger.error("DefaultMQProducer send message failed");
+ }
+ }
+ logger.info("Producer send messages finished");
+ }
+
+ /**
+ * 向哪些Queue发送顺序消息
+ *
+ * @param mqs Queue列表
+ * @param messageNum 每个Queue发送的消息数量
+ */
+ public void sendWithQueue(List<MessageQueue> mqs, int messageNum) {
+ String tag = NameUtils.getTagName();
+ logger.info("Producer start to send messages");
+ for (MessageQueue mq : mqs) {
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessageWithTagAndBody(mq.getTopic(), tag, String.valueOf(i));
+ try {
+ SendResult sendResult = producer.send(message, mq);
+ MessageExt messageExt = new MessageExt();
+ messageExt.setMsgId(sendResult.getMsgId());
+ messageExt.setBody(message.getBody());
+ logger.info("{}, index: {}, tag: {}", sendResult, i, tag);
+ this.enqueueMessages.addData(messageExt);
+ } catch (Exception e) {
+ logger.error("DefaultMQProducer send message failed");
+ }
+ }
+ }
+ logger.info("Producer send messages finished");
+ }
+
+ /**
+ * 发送指定正常的properties的普通消息l
+ *
+ * @param topic topic名称
+ * @param tag 标签
+ * @param messageBody 消息体
+ * @param messageNum 消息条数
+ */
+ public void sendWithTagAndBody(String topic, String tag, String messageBody, int messageNum) {
+ logger.info("Producer start to send messages");
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessageWithTagAndBody(topic, tag, messageBody);
+ SendResult sendResult = null;
+ try {
+ sendResult = producer.send(message);
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ } catch (MQBrokerException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ logger.info(sendResult.toString());
+ this.enqueueMessages.addData((MessageExt)message);
+ }
+ Assertions.assertEquals(messageNum, enqueueMessages.getAllData().size(), "消息没有全部发送成功!");
+ logger.info("Producer send messages finished");
+ }
+
+ public void sendAsync(String topic, RMQSendCallBack callBack, int messageNum) {
+ logger.info("Producer start to async send messages");
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessage(topic);
+ MessageExt messageExt = null;
+ try {
+ producer.send(message, callBack);
+ callBack.waitResponse();
+ if (callBack.isbSuccessResponse()) {
+ messageExt = new MessageExt();
+ messageExt.setMsgId(callBack.getMessageId());
+ this.enqueueMessages.addData(messageExt);
+ }
+ if (callBack.isbFailResponse()) {
+ this.enqueueFailedMessages.addData(messageExt);
+ }
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ logger.info("Producer async send messages finished");
+ if (enqueueFailedMessages.getAllData().size() > 0) {
+ logger.warn("send failed messages: {}", enqueueFailedMessages.getAllData());
+ }
+ }
+
+ //
+ //public void sendAsyncWithTagAndBody(String topic, String tag, String messageBody, OnsSendCallBack callBack, int messageNum) {
+ // logger.info("Producer start to async send messages");
+ // for (int i = 0; i < messageNum; i++) {
+ // Message message = MessageFactory.buildOneMessageWithTagAndBody(topic, tag, messageBody);
+ // producer.sendAsync(message, callBack);
+ // callBack.waitResponse();
+ // if (callBack.isBSuccessResponse()) {
+ // this.enqueueMessages.addData(message);
+ // }
+ // if (callBack.isBFailResponse()) {
+ // this.enqueueFailedMessages.addData(message);
+ // }
+ // }
+ // logger.info("Producer async send messages finished");
+ // if (enqueueFailedMessages.getAllData().size() > 0) {
+ // logger.warn("send failed messages: {}", enqueueFailedMessages.getAllData());
+ // }
+ //}
+ //
+ public void sendAsync(String topic, String tag, RMQSendCallBack callBack, int messageNum) {
+ logger.info("Producer start to async send messages");
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessageWithTag(topic, tag);
+ MessageExt messageExt = null;
+ try {
+ producer.send(message, callBack);
+ callBack.waitResponse();
+ if (callBack.isbSuccessResponse()) {
+ messageExt = new MessageExt();
+ messageExt.setMsgId(callBack.getMessageId());
+ this.enqueueMessages.addData(messageExt);
+ }
+ if (callBack.isbFailResponse()) {
+ this.enqueueFailedMessages.addData(messageExt);
+ }
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ logger.info("Producer async send messages finished");
+ if (enqueueFailedMessages.getAllData().size() > 0) {
+ logger.warn("send failed messages: {}", enqueueFailedMessages.getAllData());
+ }
+ }
+
+ public void sendOneWay(String topic, String tag, int messageNum) {
+ logger.info("Producer start to OneWay send message");
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessageWithTagAndBody(topic, tag, UUID.randomUUID().toString());
+ MessageExt messageExt = null;
+ try {
+ producer.sendOneway(message);
+ //this.enqueueMessages.addData(messageExt);
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ }
+ logger.info("Producer send messages finished");
+ }
+
+ public void sendOnewayWithTagAndBody(String topic, String tag, String messageBody, int messageNum) {
+ logger.info("Producer start to OneWay send message");
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessageWithTagAndBody(topic, tag, messageBody);
+ try {
+ producer.sendOneway(message);
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ //logger.info("topic: {}, msgId: {}, index: {}, tag: {}, body:{}", topic, message.getMsgID(), i, tag, messageBody);
+ this.enqueueMessages.addData((MessageExt)message);
+ }
+ logger.info("Producer send messages finished");
+ }
+
+ /**
+ * 发送延迟消息
+ *
+ * @param topic topic名称
+ * @param delayLevel 延迟时间,单位:秒
+ * @param messageNum 消息条数
+ */
+ public void sendDelay(String topic, int delayLevel, int messageNum) {
+ logger.info("Producer start to send delay messages");
+ for (int i = 0; i < messageNum; i++) {
+ Message message = MessageFactory.buildOneMessageWithDelayTimeLevel(topic, delayLevel);
+ SendResult sendResult = null;
+ MessageExt messageExt = null;
+ try {
+ sendResult = producer.send(message);
+ logger.info(sendResult.toString());
+
+ messageExt = new MessageExt();
+ messageExt.setMsgId(sendResult.getMsgId());
+ this.enqueueMessages.addData(messageExt);
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ } catch (MQBrokerException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ logger.info("Producer send delay messages finished");
+ }
+
+ ///**
+ // * 发送延迟消息
+ // *
+ // * @param topic topic名称
+ // * @param delaySecondTime 延迟时间,单位:秒
+ // * @param messageNum 消息条数
+ // */
+ //public void sendDelayWithTag(String topic, String tag, int delaySecondTime, int messageNum) {
+ // logger.info("Producer start to send delay messages");
+ // for (int i = 0; i < messageNum; i++) {
+ // Message message = MessageFactory.buildOneMessageWithTagAndStartDeliverTime(topic, tag,
+ // System.currentTimeMillis() + delaySecondTime * 1000L);
+ // SendResult sendResult = producer.send(message);
+ // logger.info(sendResult.toString());
+ // this.enqueueMessages.addData(message);
+ // }
+ // logger.info("Producer send delay messages finished");
+ //}
+ //
+ ///**
+ // * 发送定时消息
+ // *
+ // * @param topic topic名称
+ // * @param time 定时消息的时间戳
+ // * @param messageNum 消息条数
+ // */
+ //public void sendTimingWithTag(String topic, String tag, long time, int messageNum) {
+ // logger.info("Producer start to send delay messages");
+ // for (int i = 0; i < messageNum; i++) {
+ // String deliverTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis() + time * 1000L));
+ // Message message = MessageFactory.buildOneTimingMessageWithTag(topic, tag, UUID.randomUUID().toString(), deliverTime);
+ // SendResult sendResult = producer.send(message);
+ // logger.info(sendResult.toString());
+ // this.enqueueMessages.addData(message);
+ // }
+ // logger.info("Producer send delay messages finished");
+ //}
+ //
+ ///**
+ // * 发送定时消息
+ // *
+ // * @param topic topic名称
+ // * @param time 定时消息的时间戳
+ // * @param messageNum 消息条数
+ // */
+ //public void sendTimingWithTagAndBody(String topic, String tag, String body, long time, int messageNum) {
+ // logger.info("Producer start to send delay messages");
+ // for (int i = 0; i < messageNum; i++) {
+ // String deliverTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis() + time * 1000L));
+ // Message message = MessageFactory.buildOneTimingMessageWithTag(topic, tag, body, deliverTime);
+ // SendResult sendResult = producer.send(message);
+ // logger.info(sendResult.toString());
+ // this.enqueueMessages.addData(message);
+ // }
+ // logger.info("Producer send delay messages finished");
+ //}
+ //
+ ///**
+ // * @param topic 发送topic
+ // * @param tag 消息tag
+ // * @param messageNum 消息数量
+ // * @param userProps 消息属性
+ // */
+ //public void sendWithTagAndUserProps(String topic, String tag, int messageNum, HashMap<String, String> userProps) {
+ // logger.info("Producer start to send messages");
+ // for (int i = 0; i < messageNum; i++) {
+ // Message message = MessageFactory.buildOneMessageWithTagAndUserProps(topic, tag, UUID.randomUUID().toString(), userProps);
+ // SendResult sendResult = producer.send(message);
+ // logger.info(sendResult.toString());
+ // this.enqueueMessages.addData(message);
+ // }
+ // logger.info("Producer send messages finished");
+ //}
+ //
+ ///**
+ // * @param topic 发送topic
+ // * @param tag 消息tag
+ // * @param delaySeconds 消息延迟 单位:s
+ // * @param messageNum 消息数量
+ // * @param userProps 消息属性
+ // */
+ //public void sendDelayWithTagAndUserProps(String topic, String tag, int delaySeconds, int messageNum, HashMap<String, String> userProps) {
+ // logger.info("Producer start to send messages");
+ // for (int i = 0; i < messageNum; i++) {
+ // Message message = MessageFactory.buildOneDelayMessageWithTagAndUserProps(topic, tag, System.currentTimeMillis() + delaySeconds * 1000L,
+ // UUID.randomUUID().toString(), userProps);
+ // SendResult sendResult = producer.send(message);
+ // logger.info(sendResult.toString());
+ // this.enqueueMessages.addData(message);
+ // }
+ // logger.info("Producer send messages finished");
+ //}
+
+ public void send(Message message) {
+ SendResult sendResult = null;
+ try {
+ sendResult = producer.send(message);
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ } catch (MQBrokerException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ logger.info(sendResult.toString());
+ this.enqueueMessages.addData((MessageExt)message);
+ }
+
+ public List<MessageQueue> fetchPublishMessageQueues(String topic) {
+ List<MessageQueue> mqs = null;
+ try {
+ mqs = producer.fetchPublishMessageQueues(topic);
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ }
+ return mqs;
+ }
+
+ @Override
+ public void shutdown() {
+ if (producer != null) {
+ producer.shutdown();
+ logger.info("producer shutdown !!!");
+ }
+ }
+
+ public DefaultMQProducer getProducer() {
+ return producer;
+ }
+
+ public void setProducer(DefaultMQProducer producer) {
+ this.producer = producer;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQTransactionProducer.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQTransactionProducer.java
new file mode 100644
index 0000000..bf7ab03
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/client/rmq/RMQTransactionProducer.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.client.rmq;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.SendResult;
+import org.apache.rocketmq.client.producer.TransactionMQProducer;
+import org.apache.rocketmq.common.AbstractMQProducer;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.factory.MessageFactory;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RMQTransactionProducer extends AbstractMQProducer {
+ private static Logger logger = LoggerFactory.getLogger(RMQTransactionProducer.class);
+ private TransactionMQProducer producer = null;
+ private String nsAddr = null;
+
+ public RMQTransactionProducer(TransactionMQProducer producer) {
+ this.producer = producer;
+ }
+ //
+ //public RMQTransactionProducer(String nsAddr, String topic, TransactionListener transactionListener) {
+ // this(nsAddr, topic, false, transactionListener);
+ //}
+
+ @Override
+ public void shutdown() {
+ producer.shutdown();
+ }
+
+ public void send(String topic, String tag, int messageNum) {
+ logger.info("Producer start to send messages");
+ for (int i = 0; i < messageNum; i++) {
+ //Message message = MessageFactory.buildOneMessageWithTagAndBody(topic, tag, String.valueOf(i));
+ Message message = MessageFactory.buildOneMessageWithTag(topic, tag);
+ SendResult sendResult = null;
+ MessageExt messageExt = null;
+ try {
+ sendResult = producer.send(message);
+ messageExt = new MessageExt();
+ messageExt.setMsgId(sendResult.getMsgId());
+ logger.info("{}, index: {}, tag: {}", sendResult, i, tag);
+ this.enqueueMessages.addData(messageExt);
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ } catch (RemotingException e) {
+ e.printStackTrace();
+ } catch (MQBrokerException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ logger.info("Producer send messages finished");
+ }
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractListener.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractListener.java
new file mode 100644
index 0000000..be24833
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractListener.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.common;
+
+import lombok.Data;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Data
+public abstract class AbstractListener extends MQCollector {
+ private static Logger logger = LoggerFactory.getLogger(AbstractListener.class);
+
+ public AbstractListener() {
+ super();
+ }
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractMQConsumer.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractMQConsumer.java
new file mode 100644
index 0000000..0131be8
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractMQConsumer.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.common;
+
+import lombok.Data;
+
+@Data
+public abstract class AbstractMQConsumer implements MQConsumer {
+ public AbstractMQConsumer() {
+ }
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractMQProducer.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractMQProducer.java
new file mode 100644
index 0000000..e91cd46
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/AbstractMQProducer.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.common;
+
+import lombok.Data;
+
+@Data
+public abstract class AbstractMQProducer extends MQCollector implements MQProducer {
+
+ protected boolean startSuccess = false;
+ protected String producerGroupName = null;
+ protected String producerInstanceName = null;
+ protected boolean isDebug = false;
+
+ public AbstractMQProducer() {
+ super();
+ }
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQCollector.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQCollector.java
new file mode 100644
index 0000000..c794907
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQCollector.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.common;
+
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.utils.RandomUtils;
+import org.apache.rocketmq.utils.data.collect.DataCollector;
+import org.apache.rocketmq.utils.data.collect.DataCollectorManager;
+
+public abstract class MQCollector {
+ /**
+ * 成功入队的消息(发送成功)
+ */
+ protected DataCollector<MessageExt> enqueueMessages = null;
+ protected DataCollector<MessageExt> enqueueFailedMessages = null;
+ /**
+ * 成功出队的消息(消费返回成功)
+ */
+ protected DataCollector<MessageExt> dequeueMessages = null;
+ /**
+ * 全部出队的消息(包含重试消息)
+ */
+ protected DataCollector<MessageExt> dequeueAllMessages = null;
+ /**
+ * 全部出队的消息体(去重)
+ */
+ protected DataCollector<String> dequeueUndupMessageBody = null;
+ //消息发送响应时间收集器
+ protected DataCollector msgRTs = null;
+
+ public MQCollector() {
+ enqueueMessages = DataCollectorManager.getInstance().fetchListDataCollector(RandomUtils.getStringByUUID());
+ enqueueFailedMessages = DataCollectorManager.getInstance().fetchListDataCollector(RandomUtils.getStringByUUID());
+ dequeueMessages = DataCollectorManager.getInstance().fetchListDataCollector(RandomUtils.getStringByUUID());
+ dequeueAllMessages = DataCollectorManager.getInstance().fetchListDataCollector(RandomUtils.getStringByUUID());
+ dequeueUndupMessageBody = DataCollectorManager.getInstance().fetchListDataCollector(RandomUtils.getStringByUUID());
+
+ msgRTs = DataCollectorManager.getInstance().fetchListDataCollector(RandomUtils.getStringByUUID());
+ }
+
+ public void clearMsg() {
+ enqueueMessages.resetData();
+ enqueueFailedMessages.resetData();
+ dequeueMessages.resetData();
+ dequeueAllMessages.resetData();
+ dequeueUndupMessageBody.resetData();
+ msgRTs.resetData();
+ }
+
+ public void lockCollectors() {
+ enqueueMessages.lockIncrement();
+ enqueueFailedMessages.lockIncrement();
+ dequeueMessages.lockIncrement();
+ dequeueAllMessages.lockIncrement();
+ dequeueUndupMessageBody.lockIncrement();
+ msgRTs.lockIncrement();
+ }
+
+ public DataCollector<MessageExt> getEnqueueMessages() {
+ return enqueueMessages;
+ }
+
+ public void setEnqueueMessages(DataCollector<MessageExt> enqueueMessages) {
+ this.enqueueMessages = enqueueMessages;
+ }
+
+ public DataCollector<MessageExt> getEnqueueFailedMessages() {
+ return enqueueFailedMessages;
+ }
+
+ public void setEnqueueFailedMessages(DataCollector<MessageExt> enqueueFailedMessages) {
+ this.enqueueFailedMessages = enqueueFailedMessages;
+ }
+
+ public DataCollector<MessageExt> getDequeueMessages() {
+ return dequeueMessages;
+ }
+
+ public void setDequeueMessages(DataCollector<MessageExt> dequeueMessages) {
+ this.dequeueMessages = dequeueMessages;
+ }
+
+ public DataCollector<MessageExt> getDequeueAllMessages() {
+ return dequeueAllMessages;
+ }
+
+ public void setDequeueAllMessages(DataCollector<MessageExt> dequeueAllMessages) {
+ this.dequeueAllMessages = dequeueAllMessages;
+ }
+
+ public DataCollector<String> getDequeueUndupMessageBody() {
+ return dequeueUndupMessageBody;
+ }
+
+ public void setDequeueUndupMessageBody(DataCollector<String> dequeueUndupMessageBody) {
+ this.dequeueUndupMessageBody = dequeueUndupMessageBody;
+ }
+
+ public DataCollector getMsgRTs() {
+ return msgRTs;
+ }
+
+ public void setMsgRTs(DataCollector msgRTs) {
+ this.msgRTs = msgRTs;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQConsumer.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQConsumer.java
new file mode 100644
index 0000000..492100f
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQConsumer.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.common;
+
+public interface MQConsumer {
+
+ void shutdown();
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQProducer.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQProducer.java
new file mode 100644
index 0000000..1d93baf
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/common/MQProducer.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.common;
+
+
+public interface MQProducer {
+
+ void shutdown();
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/enums/TESTSET.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/enums/TESTSET.java
new file mode 100644
index 0000000..2e59e7c
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/enums/TESTSET.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.enums;
+
+public class TESTSET {
+ public static final String SMOKE = "smoke";
+
+ /**
+ * delay message
+ */
+ public static final String DELAY = "delay";
+ /**
+ * normal message
+ */
+ public static final String NORMAL = "normal";
+ /**
+ * order message
+ */
+ public static final String ORDER = "order";
+ /**
+ * transaction message
+ */
+ public static final String TRANSACTION = "transaction";
+
+ public static final String PULL = "pull";
+ public static final String BATCH_CONSUME = "batchConsume";
+ public static final String DEADLETTER = "deadletter";
+ public static final String REBALANCE = "rebalance";
+ public static final String CLIENT = "client";
+ public static final String RETRY = "retry";
+ public static final String ASNYC = "async";
+ public static final String TAG = "tag";
+ public static final String SQL = "sql";
+ public static final String CLUSTER = "cluster";
+ public static final String BROADCAST = "broadcast";
+ public static final String ACL = "acl";
+ public static final String SIMPLE = "Simple";
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/enums/TransEnum.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/enums/TransEnum.java
new file mode 100644
index 0000000..41b88b6
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/enums/TransEnum.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.enums;
+
+public enum TransEnum {
+ /**
+ *
+ */
+ COMMIT("COMMIT", "提交"),
+ /**
+ *
+ */
+ ROLLBACK("ROLLBACK", "回归"),
+ /**
+ *
+ */
+ UNKNOW("UNKNOW", "不操作");
+
+ private String value;
+ private String desc;
+
+ TransEnum(String value, String desc) {
+ this.value = value;
+ this.desc = desc;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/AclClient.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/AclClient.java
new file mode 100644
index 0000000..6d25f2d
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/AclClient.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.factory;
+
+import org.apache.rocketmq.acl.common.AclClientRPCHook;
+import org.apache.rocketmq.acl.common.SessionCredentials;
+import org.apache.rocketmq.remoting.RPCHook;
+
+public class AclClient {
+ public static RPCHook getAclRPCHook(String ak, String sk) {
+ return new AclClientRPCHook(new SessionCredentials(ak, sk));
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/ConsumerFactory.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/ConsumerFactory.java
new file mode 100644
index 0000000..0a37860
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/ConsumerFactory.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.factory;
+
+import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
+import org.apache.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely;
+import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.utils.RandomUtils;
+
+public class ConsumerFactory {
+
+ private static Boolean aclEnable = Boolean.parseBoolean(System.getProperty("aclEnable"));
+
+ public static RMQNormalConsumer getRMQNormalConsumer(String nsAddr, String consumerGroup) {
+ DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(consumerGroup);
+ consumer.setInstanceName(RandomUtils.getStringByUUID());
+ consumer.setNamesrvAddr(nsAddr);
+ return new RMQNormalConsumer(consumer);
+ }
+
+ public static RMQNormalConsumer getRMQNormalConsumer(String nsAddr, String consumerGroup, RPCHook rpcHook) {
+ DefaultMQPushConsumer consumer;
+ if (aclEnable) {
+ consumer = new DefaultMQPushConsumer(consumerGroup, rpcHook, new AllocateMessageQueueAveragely());
+ } else {
+ consumer = new DefaultMQPushConsumer(consumerGroup);
+ }
+ consumer.setInstanceName(RandomUtils.getStringByUUID());
+ consumer.setNamesrvAddr(nsAddr);
+ return new RMQNormalConsumer(consumer);
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/MessageFactory.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/MessageFactory.java
new file mode 100644
index 0000000..e1b32f3
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/MessageFactory.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.factory;
+
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.utils.RandomUtils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+
+public class MessageFactory {
+
+ public static Message getRandomMessage(String topic) {
+ return getStringMessage(topic, RandomUtils.getStringByUUID());
+ }
+
+ public static Message getStringMessage(String topic, String body) {
+ Message msg = new Message(topic, body.getBytes());
+ return msg;
+ }
+
+ public static Message getStringMessageByTag(String topic, String tags, String body) {
+ Message msg = new Message(topic, tags, body.getBytes());
+ return msg;
+ }
+
+ public static Message getRandomMessageByTag(String topic, String tags) {
+ return getStringMessageByTag(topic, tags, RandomUtils.getStringByUUID());
+ }
+
+ public static Collection<Message> getRandomMessageList(String topic, int size) {
+ List<Message> msgList = new ArrayList<Message>();
+ for (int i = 0; i < size; i++) {
+ msgList.add(getRandomMessage(topic));
+ }
+ return msgList;
+ }
+
+ public static Collection<Message> getRandomMessageListByTag(String topic, String tags, int size) {
+ List<Message> msgList = new ArrayList<Message>();
+ for (int i = 0; i < size; i++) {
+ msgList.add(getRandomMessageByTag(topic, tags));
+ }
+ return msgList;
+ }
+
+
+ /**
+ * 生成一条消息,tag不设置, body使用随机字符串
+ *
+ * @param topic topic
+ * @return message
+ */
+ public static Message buildOneMessage(String topic) {
+ return new Message(topic, "", RandomUtils.getStringByUUID().getBytes());
+ }
+
+ /**
+ * 根据tag生成一条消息, body使用随机字符串
+ *
+ * @param topic topic
+ * @param tag tag
+ * @return message
+ */
+ public static Message buildOneMessageWithTag(String topic, String tag) {
+ return new Message(topic, tag, RandomUtils.getStringByUUID().getBytes());
+ }
+
+ /**
+ * 根据消息体生成一条消息,tag不设置
+ *
+ * @param topic topic
+ * @param messageBody 消息体
+ * @return message
+ */
+ public static Message buildOneMessageWithBody(String topic, String messageBody) {
+ return new Message(topic, null, messageBody.getBytes());
+ }
+
+ /**
+ * 构建一条指定tag,消息body的message
+ *
+ * @param topic 发送topic
+ * @param tag 发送tag
+ * @param body 消息体
+ * @return Message
+ */
+ public static Message buildOneMessageWithTagAndBody(String topic, String tag, String body) {
+ return new Message(topic, tag, body.getBytes());
+ }
+
+ ///**
+ // * 构建指定一条指定properties,消息body的message
+ // *
+ // * @param topic 发送topic
+ // * @param properties 自定义属性
+ // * @return Message
+ // */
+ //public static Message buildMessageWithUserProperties(String topic, HashMap<String, String> properties) {
+ // Message msg = new Message(topic, null, RandomUtils.getStringByUUID().getBytes());
+ // for (Map.Entry<String, String> entry : properties.entrySet()) {
+ // msg.putUserProperties(entry.getKey(), entry.getValue());
+ // }
+ // return msg;
+ //}
+ //
+ /**
+ * 延时消息,单位毫秒(ms),在指定延迟时间(当前时间之后)进行投递,例如消息在3秒后投递
+ * 定时消息,单位毫秒(ms),在指定时间戳(当前时间之后)进行投递,例如2016-03-07 16:21:00投递。如果被设置成当前时间戳之前的某个时刻,消息将立即被投递给消费者。
+ *
+ * @param topic
+ * @param level
+ * @return
+ */
+ public static Message buildOneMessageWithDelayTimeLevel(String topic, int level) {
+ Message msg = new Message(topic, "TagA", RandomUtils.getStringByUUID().getBytes());
+ msg.setDelayTimeLevel(level);
+ return msg;
+ }
+ //
+ //public static Message buildOneMessageWithTagAndStartDeliverTime(String topic, String tag, long time) {
+ // Message msg = new Message(topic, tag, RandomUtils.getStringByUUID().getBytes());
+ // //发送时间
+ // msg.putUserProperties("sendTime", String.valueOf(System.currentTimeMillis()));
+ // //推送下发消息时间
+ // msg.putUserProperties("deliverTime", String.valueOf(time));
+ // msg.setStartDeliverTime(time);
+ // return msg;
+ //}
+ //
+ ///**
+ // * 定时消息,单位毫秒(ms),在指定时间戳(当前时间之后)进行投递,例如2016-03-07 16:21:00投递。如果被设置成当前时间戳之前的某个时刻,消息将立即被投递给消费者。
+ // *
+ // * @param topic
+ // * @param tag
+ // * @param msgBody
+ // * @param time
+ // * @return
+ // */
+ //public static Message buildOneTimingMessageWithTag(String topic, String tag, String msgBody, String time) {
+ // long timeStamp = 0;
+ // try {
+ // timeStamp = sdf.parse(time).getTime();
+ // } catch (ParseException e) {
+ // e.printStackTrace();
+ // }
+ // Message msg = new Message(topic, tag, msgBody.getBytes());
+ // msg.putUserProperties("sendTime", String.valueOf(System.currentTimeMillis()));
+ // msg.putUserProperties("deliverTime", String.valueOf(time));
+ // msg.setStartDeliverTime(timeStamp);
+ // return msg;
+ //}
+ //
+ ///**
+ // * @param topic
+ // * @param tag
+ // * @param messageBody
+ // * @param userProps
+ // * @return
+ // */
+ //public static Message buildOneMessageWithTagAndUserProps(String topic, String tag, String messageBody, HashMap<String, String> userProps) {
+ // Message msg = new Message(topic, tag, messageBody.getBytes());
+ // for (Map.Entry<String, String> entry : userProps.entrySet()) {
+ // msg.putUserProperties(entry.getKey(), entry.getValue());
+ // }
+ // return msg;
+ //}
+ //
+ ///**
+ // * @param topic
+ // * @param tag
+ // * @param delaySeconds
+ // * @param messageBody
+ // * @param userProps
+ // * @return
+ // */
+ //public static Message buildOneDelayMessageWithTagAndUserProps(String topic, String tag, long delaySeconds, String messageBody,
+ // HashMap<String, String> userProps) {
+ // Message msg = new Message(topic, tag, messageBody.getBytes());
+ // //发送时间
+ // msg.putUserProperties("sendTime", String.valueOf(System.currentTimeMillis()));
+ // //推送下发消息时间
+ // msg.putUserProperties("deliverTime", String.valueOf(delaySeconds));
+ // msg.setStartDeliverTime(delaySeconds);
+ // for (Map.Entry<String, String> entry : userProps.entrySet()) {
+ // msg.putUserProperties(entry.getKey(), entry.getValue());
+ // }
+ // return msg;
+ //}
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/ProducerFactory.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/ProducerFactory.java
new file mode 100644
index 0000000..cdf53f1
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/factory/ProducerFactory.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.factory;
+
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.TransactionListener;
+import org.apache.rocketmq.client.producer.TransactionMQProducer;
+import org.apache.rocketmq.client.rmq.RMQNormalProducer;
+import org.apache.rocketmq.client.rmq.RMQTransactionProducer;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.utils.RandomUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+
+public class ProducerFactory {
+ private static Logger logger = LoggerFactory.getLogger(ProducerFactory.class);
+ private static Boolean aclEnable = Boolean.parseBoolean(System.getProperty("aclEnable"));
+
+ public static RMQNormalProducer getRMQProducer(String ns, RPCHook rpcHook) {
+ DefaultMQProducer producer;
+ if (aclEnable) {
+ producer = new DefaultMQProducer(RandomUtils.getStringByUUID(), rpcHook);
+ } else {
+ producer = new DefaultMQProducer(RandomUtils.getStringByUUID());
+ }
+ producer.setInstanceName(UUID.randomUUID().toString());
+ producer.setNamesrvAddr(ns);
+ try {
+ producer.start();
+ } catch (MQClientException e) {
+ logger.info("Start DefaultMQProducer failed, {}", e.getMessage());
+ }
+ return new RMQNormalProducer(producer);
+ }
+
+ public static RMQTransactionProducer getTransProducer(String ns, ExecutorService executorService, TransactionListener transactionListener, RPCHook rpcHook) {
+ TransactionMQProducer producer;
+ if (aclEnable) {
+ producer = new TransactionMQProducer(RandomUtils.getStringByUUID(), rpcHook);
+ } else {
+ producer = new TransactionMQProducer(RandomUtils.getStringByUUID());
+ }
+ producer.setInstanceName(UUID.randomUUID().toString());
+ producer.setNamesrvAddr(ns);
+ try {
+ if (executorService != null) {
+ producer.setExecutorService(executorService);
+ }
+ producer.setTransactionListener(transactionListener);
+ producer.start();
+ } catch (MQClientException e) {
+ logger.info("Start TransactionMQProducer failed, {}", e.getMessage());
+ }
+ return new RMQTransactionProducer(producer);
+ }
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/frame/BaseOperate.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/frame/BaseOperate.java
new file mode 100644
index 0000000..d7e84f1
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/frame/BaseOperate.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.frame;
+
+import org.apache.rocketmq.utils.MQAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BaseOperate extends ResourceInit {
+ private static Logger logger = LoggerFactory.getLogger(BaseOperate.class);
+
+ static {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ MQAdmin.mqAdminExt.shutdown();
+ logger.info("Shutdown Hook is running !");
+ }
+ });
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/frame/ResourceInit.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/frame/ResourceInit.java
new file mode 100644
index 0000000..59e8c0d
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/frame/ResourceInit.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.frame;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.rocketmq.account.Account;
+import org.apache.rocketmq.factory.AclClient;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.utils.MQAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+public class ResourceInit {
+ private static final Logger log = LoggerFactory.getLogger(ResourceInit.class);
+
+ /**
+ * Read the configuration file to use
+ */
+ public static SystemConfigFileHelper configFileHelper = new SystemConfigFileHelper();
+ public static Account account = null;
+ /**
+ * Access point Information
+ */
+ protected static String namesrvAddr = null;
+ protected static Boolean aclEnable = null;
+ protected static String allIp;
+ protected static String cluster;
+ protected static List<String> nameserverIpList = new ArrayList<>();
+ protected static List<String> brokerIpList = new ArrayList<>();
+ protected static String nameserverPort = "9876";
+ private static Properties properties = null;
+ protected static RPCHook rpcHook;
+
+ static {
+ initResource();
+ MQAdmin.initMQAdminExtInstance(namesrvAddr);
+ log.info("Init process success");
+ }
+
+ private static void initResource() {
+ try {
+ String env = System.getProperty("env", "daily");
+ String region = System.getProperty("region", "daily");
+ InputStream inputStream = new FileInputStream(String.format("src/test/resources/env/%s/%s.conf", env, region));
+ log.info("INIT - use config env:{}, config:{}", env, region);
+ properties = configFileHelper.loadConfig(inputStream);
+ } catch (Exception e) {
+ log.error(ExceptionUtils.getStackTrace(e));
+ log.info("INIT - execute error,exit the process");
+ System.exit(0);
+ }
+ // init endpoint and nameserver
+ initConnectionInfo();
+ initAcl();
+
+ String namesrvAddrIp = namesrvAddr.substring(0, namesrvAddr.indexOf(":"));
+ String namesrvAddrPort = namesrvAddr.substring(namesrvAddr.lastIndexOf(":") + 1);
+ checkConnection(namesrvAddrIp, namesrvAddrPort);
+
+ }
+
+ private static void initAcl() {
+ aclEnable = Boolean.parseBoolean(System.getProperty("aclEnable", properties.getProperty("aclEnable", "false")));
+ if (aclEnable) {
+ String accessKey = System.getProperty("accessKey", properties.getProperty("accessKey"));
+ String secretKey = System.getProperty("secretKey", properties.getProperty("secretKey"));
+ account = new Account(accessKey, secretKey);
+ rpcHook = AclClient.getAclRPCHook(account.getAccessKey(), account.getSecretKey());
+ log.info("INIT - acl is enabled, [accessKey:{}, secretKey:{}]", accessKey, secretKey);
+ } else {
+ log.info("INIT - acl is disabled");
+ }
+ }
+
+ private static void initConnectionInfo() {
+ allIp = System.getProperty("ALL_IP", properties.getProperty("ALL_IP"));
+ if (allIp != null) {
+ String[] allPodInfos = allIp.split(",");
+ for (String podInfo : allPodInfos) {
+ if (podInfo.contains("nameserver")) {
+ nameserverIpList.add(podInfo.substring(podInfo.indexOf(":") + 1));
+ } else if (podInfo.contains("broker")) {
+ brokerIpList.add(podInfo.substring(podInfo.indexOf(":") + 1));
+ }
+ }
+ if (nameserverIpList.isEmpty()) {
+ log.warn("INIT- Get nameserver from external is empty");
+ namesrvAddr = System.getProperty("namesrvAddr", properties.getProperty("namesrvAddr"));
+ } else {
+ namesrvAddr = nameserverIpList.get(0) + ":" + nameserverPort;
+ }
+ } else {
+ log.info("INIT- Get ALL_IP is null, use local info");
+ namesrvAddr = System.getProperty("namesrvAddr", properties.getProperty("namesrvAddr"));
+ }
+ cluster = System.getProperty("cluster", properties.getProperty("cluster"));
+ if (cluster == null) {
+ log.error("INIT- cluster is null, system exit");
+ System.exit(-1);
+ }
+ log.info("INIT- namesrvAddr:{}, cluster:{}", namesrvAddr, cluster);
+ }
+
+ private static void checkConnection(String ip, String port) {
+ boolean isConnected = telnet(ip, Integer.parseInt(port), 5000);
+ if (!isConnected) {
+ log.error("INIT - check: telnet {} {} ==> timeout: {}, isConnected: false", ip, port, 5000);
+ log.error("INIT - Warning, exit!!!");
+ System.exit(0);
+ } else {
+ log.info("INIT - check: telnet {} {} ==> isConnected: true", ip, port);
+ }
+ }
+
+ public static class SystemConfigFileHelper {
+ private String file;
+
+ public SystemConfigFileHelper() {
+ }
+
+ public Properties loadConfig() throws Exception {
+ InputStream in = new BufferedInputStream(new FileInputStream(file));
+ Properties properties = new Properties();
+ properties.load(in);
+ in.close();
+ return properties;
+ }
+
+ public Properties loadConfig(InputStream inputStream) throws Exception {
+ InputStream in = new BufferedInputStream(inputStream);
+ Properties properties = new Properties();
+ properties.load(in);
+ in.close();
+ return properties;
+ }
+
+ public void update(Properties properties) throws Exception {
+ log.error("[SystemConfigFileHelper] update no thing.");
+ }
+
+ public void setFile(String file) {
+ this.file = file;
+ }
+
+ public String getFile() {
+ return file;
+ }
+ }
+
+ public static boolean telnet(String hostname, int port, int timeout) {
+ Socket socket = new Socket();
+ boolean isConnected = false;
+ try {
+ socket.connect(new InetSocketAddress(hostname, port), timeout);
+ isConnected = socket.isConnected();
+ } catch (IOException e) {
+ } finally {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ }
+ }
+ return isConnected;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/AbstractListener.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/AbstractListener.java
new file mode 100644
index 0000000..098e7fd
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/AbstractListener.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.listener;
+
+import org.apache.rocketmq.client.consumer.listener.MessageListener;
+import org.apache.rocketmq.common.MQCollector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AbstractListener extends MQCollector implements MessageListener {
+ private static Logger logger = LoggerFactory.getLogger(AbstractListener.class);
+
+ public AbstractListener() {
+ super();
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/RMQNormalListener.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/RMQNormalListener.java
new file mode 100644
index 0000000..91b703c
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/RMQNormalListener.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.listener.rmq.concurrent;
+
+import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
+import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
+import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.listener.AbstractListener;
+import org.apache.rocketmq.utils.RandomUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class RMQNormalListener extends AbstractListener implements MessageListenerConcurrently {
+ private static Logger logger = LoggerFactory.getLogger(RMQNormalListener.class);
+ private ConsumeConcurrentlyStatus consumeStatus = ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
+ private AtomicInteger msgIndex = new AtomicInteger(0);
+ private String listenerName;
+
+ public RMQNormalListener() {
+ this.listenerName = RandomUtils.getStringByUUID();
+ logger.info("启动监听:{}", listenerName);
+ }
+
+ public RMQNormalListener(ConsumeConcurrentlyStatus consumeStatus) {
+ this.consumeStatus = consumeStatus;
+ this.listenerName = RandomUtils.getStringByUUID();
+ logger.info("启动监听:{}", listenerName);
+ }
+
+ public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
+ for (MessageExt message : msgs) {
+ msgIndex.getAndIncrement();
+ message.putUserProperty("startDeliverTime", String.valueOf(System.currentTimeMillis()));
+ this.dequeueAllMessages.addData(message);
+ this.dequeueMessages.addData(message);
+ logger.info("{} - MessageId:{}, ReconsumeTimes:{}, Body:{}, tag:{}, recvIndex:{}, action:{}", listenerName, message.getMsgId(),
+ message.getReconsumeTimes(), new String(message.getBody()), message.getTags(), msgIndex.getAndIncrement() + 1, consumeStatus);
+ }
+ return consumeStatus;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/RMQOrderListener.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/RMQOrderListener.java
new file mode 100644
index 0000000..ead6bf8
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/RMQOrderListener.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.listener.rmq.concurrent;
+
+import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
+import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
+import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.listener.AbstractListener;
+import org.apache.rocketmq.utils.RandomUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class RMQOrderListener extends AbstractListener implements MessageListenerOrderly {
+ private static Logger logger = LoggerFactory.getLogger(RMQOrderListener.class);
+ private ConsumeOrderlyStatus consumeStatus = ConsumeOrderlyStatus.SUCCESS;
+ private AtomicInteger msgIndex = new AtomicInteger(0);
+ private String listenerName;
+
+ public RMQOrderListener() {
+ this.listenerName = RandomUtils.getStringByUUID();
+ logger.info("启动监听:{}", listenerName);
+ }
+
+ public RMQOrderListener(ConsumeOrderlyStatus consumeStatus) {
+ this.consumeStatus = consumeStatus;
+ this.listenerName = RandomUtils.getStringByUUID();
+ logger.info("启动监听:{}", listenerName);
+ }
+
+ @Override
+ public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
+ for (MessageExt message : msgs) {
+ msgIndex.getAndIncrement();
+ this.dequeueAllMessages.addData(message);
+ this.dequeueMessages.addData(message);
+ logger.info("{} - MessageId:{}, ReconsumeTimes:{}, Body:{}, tag:{}, recvIndex:{}, action:{}", listenerName, message.getMsgId(),
+ message.getReconsumeTimes(), new String(message.getBody()), message.getTags(), msgIndex.getAndIncrement() + 1, consumeStatus);
+ }
+ return consumeStatus;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/TransactionListenerImpl.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/TransactionListenerImpl.java
new file mode 100644
index 0000000..926f083
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/concurrent/TransactionListenerImpl.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.listener.rmq.concurrent;
+
+import org.apache.rocketmq.client.producer.LocalTransactionState;
+import org.apache.rocketmq.client.producer.TransactionListener;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.listener.AbstractListener;
+import org.apache.rocketmq.utils.RandomUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class TransactionListenerImpl extends AbstractListener implements TransactionListener {
+ private static Logger logger = LoggerFactory.getLogger(TransactionListenerImpl.class);
+ private LocalTransactionState checker = LocalTransactionState.COMMIT_MESSAGE;
+ private LocalTransactionState executor = LocalTransactionState.COMMIT_MESSAGE;
+ private int checkTimes = 1;
+ private int checkNum = 0;
+ private String checkerName;
+ private AtomicInteger transactionIndex = new AtomicInteger(0);
+
+ private ConcurrentHashMap<String, Integer> localTrans = new ConcurrentHashMap<>();
+
+
+
+ public TransactionListenerImpl() {
+ this.checkerName = RandomUtils.getStringByUUID();
+ logger.info("启动监听:{}", checkerName);
+ }
+
+ public TransactionListenerImpl(LocalTransactionState checker, LocalTransactionState executor) {
+ this.checkerName = RandomUtils.getStringByUUID();
+ this.checker = checker;
+ this.executor = executor;
+ logger.info("启动监听:{}", checkerName);
+ }
+
+ @Override
+ public LocalTransactionState executeLocalTransaction(Message message, Object arg) {
+ logger.warn("TransactionId:{}, transactionStatus:{}", message.getTransactionId(), executor.name());
+
+ //int value = transactionIndex.getAndIncrement();
+ //int status = value % 3;
+ //localTrans.put(message.getTransactionId(), status);
+ return executor;
+ }
+
+ @Override
+ public LocalTransactionState checkLocalTransaction(MessageExt message) {
+
+ //if (checkTimes == 1) {
+ // //消息 ID(有可能消息体一样,但消息 ID 不一样,当前消息属于半事务消息,所以消息 ID 在控制台无法查询)
+ // String msgId = message.getMsgId();
+ // logger.info("checker:{}, MessageId:{}, transactionStatus:{}", checkerName, msgId, checker.name());
+ // return checker;
+ //}
+ //if (new String(message.getBody()).equals(new String(sendMsg.getBody()))) {
+ // checkNum++;
+ // //check次数达到预期,则提交
+ // if (checkNum == checkTimes) {
+ // checker = LocalTransactionState.COMMIT_MESSAGE;
+ // }
+ // logger.info("checkerName:{}, MessageId:{}, status:{}, checkedTimes:{}, expectCheckNum:{}", checkerName, message.getMsgId(), checker, checkTimes,
+ // checkNum);
+ //}
+ //Integer status = localTrans.get(message.getTransactionId());
+ //if (null != status) {
+ // switch (status) {
+ // case 0:
+ // return LocalTransactionState.UNKNOW;
+ // case 1:
+ // return LocalTransactionState.COMMIT_MESSAGE;
+ // case 2:
+ // return LocalTransactionState.ROLLBACK_MESSAGE;
+ // }
+ //}
+ //本地事务已成功则提交消息
+ return checker;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/order/RMQOrderListener.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/order/RMQOrderListener.java
new file mode 100644
index 0000000..5667091
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/listener/rmq/order/RMQOrderListener.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.listener.rmq.order;
+
+import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
+import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
+import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.listener.AbstractListener;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class RMQOrderListener extends AbstractListener implements MessageListenerOrderly {
+ private Map<String/* brokerId_brokerIp */, Collection<Object>> msgs = new ConcurrentHashMap<String, Collection<Object>>();
+
+ public Collection<Collection<Object>> getMsgs() {
+ return msgs.values();
+ }
+
+ private void putMsg(MessageExt msg) {
+ Collection<Object> msgQueue = null;
+ String key = getKey(msg.getQueueId(), msg.getStoreHost().toString());
+ if (!msgs.containsKey(key)) {
+ msgQueue = new ArrayList<Object>();
+ } else {
+ msgQueue = msgs.get(key);
+ }
+
+ msgQueue.add(new String(msg.getBody()));
+ msgs.put(key, msgQueue);
+ }
+
+ private String getKey(int queueId, String brokerIp) {
+ return String.format("%s_%s", queueId, brokerIp);
+ }
+
+ @Override
+ public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs,
+ ConsumeOrderlyContext context) {
+ for (MessageExt msg : msgs) {
+
+ putMsg(msg);
+ }
+
+ return ConsumeOrderlyStatus.SUCCESS;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/DateUtils.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/DateUtils.java
new file mode 100644
index 0000000..0752557
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/DateUtils.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+public class DateUtils {
+ private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+
+ /**
+ * 获取当前时间的秒级偏移时间
+ * offset=10 10秒后 offset=-10 10秒前
+ * @param offset 偏移时间
+ * @return
+ */
+ public static long getCurrentTimeOffsetBySecond(int offset) {
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, offset);
+ Date beforeD = calendar.getTime();
+ long time = 0;
+ try {
+ time = SDF.parse(SDF.format(beforeD)).getTime();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return time;
+ }
+
+ /**
+ * 获取当前时间的分钟级偏移时间
+ *
+ * @param offset 偏移时间
+ * @return
+ */
+ public static long getCurrentTimeOffsetByMin(int offset) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.MINUTE, offset);
+ Date beforeD = calendar.getTime();
+ long time = 0;
+ try {
+ time = SDF.parse(SDF.format(beforeD)).getTime();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return time;
+ }
+
+ /**
+ * 获取当前时间的小时级偏移时间
+ *
+ * @param offset 偏移时间
+ * @return
+ */
+ public static long getCurrentTimeOffsetByHour(int offset) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.HOUR, offset);
+ Date beforeD = calendar.getTime();
+ long time = 0;
+ try {
+ time = SDF.parse(SDF.format(beforeD)).getTime();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return time;
+ }
+
+ /**
+ * 获取当前时间的天级偏移时间
+ *
+ * @param offset 偏移时间
+ * @return
+ */
+ public static long getCurrentTimeOffsetByDay(int offset) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DAY_OF_YEAR, offset);
+ Date beforeD = calendar.getTime();
+ long time = 0;
+ try {
+ time = SDF.parse(SDF.format(beforeD)).getTime();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return time;
+ }
+
+ /**
+ * 格式化时间戳
+ *
+ * @param time 偏移时间
+ * @return
+ */
+ public static String format(long time) {
+ return SDF.format(time);
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/MQAdmin.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/MQAdmin.java
new file mode 100644
index 0000000..1d62eb8
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/MQAdmin.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils;
+
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.common.protocol.body.ClusterInfo;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.subscription.SubscriptionGroupConfig;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.apache.rocketmq.tools.command.CommandUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.UUID;
+
+public class MQAdmin {
+ private static final Logger log = LoggerFactory.getLogger(MQAdmin.class);
+ public static DefaultMQAdminExt mqAdminExt;
+
+ public static DefaultMQAdminExt initMQAdminExtInstance(String namesrvAddr) {
+ mqAdminExt = new DefaultMQAdminExt();
+ mqAdminExt.setInstanceName(UUID.randomUUID().toString());
+ mqAdminExt.setNamesrvAddr(namesrvAddr);
+ try {
+ mqAdminExt.start();
+ } catch (MQClientException e) {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ return mqAdminExt;
+ }
+
+ public static boolean createTopic(String nameSrvAddr, String clusterName, String topic, int queueNum) {
+ int defaultWaitTime = 5;
+ return createTopic(nameSrvAddr, clusterName, topic, queueNum, defaultWaitTime);
+ }
+
+ public static boolean createTopic(String nameSrvAddr, String clusterName, String topic, int queueNum, int waitTimeSec) {
+ boolean createResult = false;
+ try {
+ mqAdminExt.createTopic(clusterName, topic, queueNum);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ long startTime = System.currentTimeMillis();
+ while (!createResult) {
+ createResult = checkTopicExist(mqAdminExt, topic);
+ if (System.currentTimeMillis() - startTime < waitTimeSec * 1000) {
+ TestUtils.waitForMoment(100);
+ } else {
+ log.error(String.format("timeout,but create topic[%s] failed!", topic));
+ break;
+ }
+ }
+ return createResult;
+ }
+
+ private static boolean checkTopicExist(DefaultMQAdminExt mqAdminExt, String topic) {
+ boolean createResult = false;
+ try {
+ TopicStatsTable topicInfo = mqAdminExt.examineTopicStats(topic);
+ createResult = !topicInfo.getOffsetTable().isEmpty();
+ } catch (Exception e) {
+ }
+
+ return createResult;
+ }
+
+ public static boolean createSub(String nameSrvAddr, String clusterName, String consumerId) {
+ boolean createResult = true;
+ SubscriptionGroupConfig config = new SubscriptionGroupConfig();
+ config.setGroupName(consumerId);
+ try {
+ Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(mqAdminExt, clusterName);
+ for (String addr : masterSet) {
+ try {
+ mqAdminExt.createAndUpdateSubscriptionGroupConfig(addr, config);
+ log.info(String.format("create subscription group %s to %s success.\n", consumerId, addr));
+ } catch (Exception e) {
+ e.printStackTrace();
+ Thread.sleep(1000 * 1);
+ }
+ }
+ } catch (Exception e) {
+ createResult = false;
+ e.printStackTrace();
+ }
+ return createResult;
+ }
+
+ public static ClusterInfo getCluster(String nameSrvAddr) {
+ ClusterInfo clusterInfo = null;
+ try {
+ clusterInfo = mqAdminExt.examineBrokerClusterInfo();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return clusterInfo;
+ }
+
+ public static boolean isBrokerExist(String ns, String ip) {
+ ClusterInfo clusterInfo = getCluster(ns);
+ if (clusterInfo == null) {
+ return false;
+ } else {
+ HashMap<String, BrokerData> brokers = clusterInfo.getBrokerAddrTable();
+ for (Entry<String, BrokerData> brokerEntry : brokers.entrySet()) {
+ HashMap<Long, String> brokerIps = brokerEntry.getValue().getBrokerAddrs();
+ for (Entry<Long, String> brokerIdEntry : brokerIps.entrySet()) {
+ if (brokerIdEntry.getValue().contains(ip)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public static void deleteTopic(String nameSrvAddr, String cluster, String topic) {
+ try {
+ Set<String> set = new HashSet<>();
+ set.add(nameSrvAddr);
+ mqAdminExt.deleteTopicInNameServer(set, topic);
+
+ boolean isTopicExist = checkTopicExist(mqAdminExt, topic);
+ long startTime = System.currentTimeMillis();
+ while (!isTopicExist) {
+ isTopicExist = checkTopicExist(mqAdminExt, topic);
+ if (System.currentTimeMillis() - startTime < 5 * 1000) {
+ TestUtils.waitForMoment(100);
+ } else {
+ log.error(String.format("timeout,but delete topic[%s] failed!", topic));
+ break;
+ }
+ }
+
+ } catch (Exception e) {
+ }
+ }
+
+ public void getSubConnection(String nameSrvAddr, String clusterName, String consumerId) {
+ SubscriptionGroupConfig config = new SubscriptionGroupConfig();
+ config.setGroupName(consumerId);
+ try {
+ Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(mqAdminExt, clusterName);
+ for (String addr : masterSet) {
+ try {
+
+ System.out.printf("create subscription group %s to %s success.\n", consumerId, addr);
+ } catch (Exception e) {
+ e.printStackTrace();
+ Thread.sleep(1000 * 1);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/NameUtils.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/NameUtils.java
new file mode 100644
index 0000000..45d3b7d
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/NameUtils.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils;
+
+import org.apache.commons.lang3.RandomStringUtils;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class NameUtils {
+ /**
+ * Make sure not used in other cases.
+ */
+ private static Map<String, String> alreadyUsed = new ConcurrentHashMap<>();
+
+ public synchronized static String getTopicName() {
+ while (true) {
+ String topic = "topic-server-" + RandomStringUtils.randomAlphanumeric(20);
+ String used = alreadyUsed.putIfAbsent(topic, topic);
+ if (used == null) {
+ return topic;
+ }
+ }
+
+ }
+
+ public synchronized static String getGroupName() {
+ while (true) {
+ String gid = "GID-server-" + RandomStringUtils.randomAlphanumeric(20);
+ String used = alreadyUsed.putIfAbsent(gid, gid);
+ if (used == null) {
+ return gid;
+ }
+ }
+
+ }
+
+ public synchronized static String getTagName() {
+ while (true) {
+ String tag = "tag-server-" + RandomStringUtils.randomAlphanumeric(20);
+ String used = alreadyUsed.putIfAbsent(tag, tag);
+ if (used == null) {
+ return tag;
+ }
+ }
+
+ }
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/RandomUtils.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/RandomUtils.java
new file mode 100644
index 0000000..246ad0e
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/RandomUtils.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils;
+
+import java.util.Random;
+import java.util.UUID;
+
+public class RandomUtils {
+ private static final int UNICODE_START = '\u4E00';
+ private static final int UNICODE_END = '\u9FA0';
+ private static Random rd = new Random();
+
+ private RandomUtils() {
+
+ }
+
+ public static String getStringByUUID() {
+ return UUID.randomUUID().toString();
+ }
+
+ public static String getCheseWord(int len) {
+ StringBuilder res = new StringBuilder();
+
+ for (int i = 0; i < len; ++i) {
+ char str = getCheseChar();
+ res.append(str);
+ }
+
+ return res.toString();
+ }
+
+ public static String getStringWithNumber(int n) {
+ int[] arg = new int[] {'0', '9' + 1};
+ return getString(n, arg);
+ }
+
+ public static String getStringWithCharacter(int n) {
+ int[] arg = new int[] {'a', 'z' + 1, 'A', 'Z' + 1};
+ return getString(n, arg);
+ }
+
+ private static String getString(int n, int[] arg) {
+ StringBuilder res = new StringBuilder();
+ for (int i = 0; i < n; i++) {
+ res.append(getChar(arg));
+ }
+ return res.toString();
+ }
+
+ private static char getChar(int[] arg) {
+ int size = arg.length;
+ int c = rd.nextInt(size / 2);
+ c = c * 2;
+ return (char) (getIntegerBetween(arg[c], arg[c + 1]));
+ }
+
+ public static int getIntegerBetween(int n, int m) {
+ if (m == n) {
+ return n;
+ }
+ int res = getIntegerMoreThanZero();
+ return n + res % (m - n);
+ }
+
+ public static int getIntegerMoreThanZero() {
+ int res = rd.nextInt();
+ while (res <= 0) {
+ res = rd.nextInt();
+ }
+ return res;
+ }
+
+ private static char getCheseChar() {
+ return (char) (UNICODE_START + rd.nextInt(UNICODE_END - UNICODE_START));
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/TestUtils.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/TestUtils.java
new file mode 100644
index 0000000..b28fcc1
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/TestUtils.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public class TestUtils {
+ private static Logger logger = LoggerFactory.getLogger(TestUtils.class);
+
+ private TestUtils() {
+ }
+
+ public static Long parseStringToLong(String s, Long defval) {
+ Long val;
+ try {
+ val = Long.parseLong(s);
+ } catch (NumberFormatException var4) {
+ val = defval;
+ }
+
+ return val;
+ }
+
+ public static Integer parseStringToInteger(String s, Integer defval) {
+ Integer val;
+ try {
+ val = Integer.parseInt(s);
+ } catch (NumberFormatException var4) {
+ val = defval;
+ }
+
+ return val;
+ }
+
+ public static String addQuoteToParamater(String param) {
+ StringBuilder sb = new StringBuilder("'");
+ sb.append(param).append("'");
+ return sb.toString();
+ }
+
+ public static void waitForMoment(long time) {
+ try {
+ Thread.sleep(time);
+ } catch (InterruptedException var3) {
+ var3.printStackTrace();
+ }
+
+ }
+
+ public static void waitForSeconds(long time) {
+ try {
+ logger.info("waiting {} seconds...", time);
+ TimeUnit.SECONDS.sleep(time);
+ } catch (InterruptedException var3) {
+ var3.printStackTrace();
+ }
+
+ }
+
+ public static void waitForMinutes(long time) {
+ try {
+ logger.info("waiting {} minutes...", time);
+ TimeUnit.MINUTES.sleep(time);
+ } catch (InterruptedException var3) {
+ var3.printStackTrace();
+ }
+
+ }
+
+ public static void waitForInputQuit() {
+ waitForInput("quit");
+ }
+
+ public static void waitForInput(String keyWord) {
+ waitForInput(keyWord, String.format("The thread will wait until you input stop command[%s]:", keyWord));
+ }
+
+ public static void waitForInput(String keyWord, String info) {
+ try {
+ byte[] b = new byte[1024];
+ int n = System.in.read(b);
+
+ for (String s = (new String(b, 0, n - 1)).replace("\r", "").replace("\n", ""); !s.equals(keyWord); s = new String(b, 0, n - 1)) {
+ n = System.in.read(b);
+ }
+
+ } catch (IOException var5) {
+ var5.printStackTrace();
+ }
+
+ }
+
+ public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
+ List<Map.Entry<K, V>> list = new LinkedList(map.entrySet());
+ Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
+ @Override
+ public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
+ return ((Comparable)o1.getValue()).compareTo(o2.getValue());
+ }
+ });
+ Map<K, V> result = new LinkedHashMap();
+ Iterator var3 = list.iterator();
+
+ while (var3.hasNext()) {
+ Map.Entry<K, V> entry = (Map.Entry)var3.next();
+ result.put(entry.getKey(), entry.getValue());
+ }
+
+ return result;
+ }
+
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/VerifyUtils.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/VerifyUtils.java
new file mode 100644
index 0000000..88e032f
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/VerifyUtils.java
@@ -0,0 +1,435 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils;
+
+import org.apache.rocketmq.client.rmq.DelayConf;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.utils.data.collect.DataCollector;
+import org.junit.jupiter.api.Assertions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class VerifyUtils {
+ private static Logger logger = LoggerFactory.getLogger(VerifyUtils.class);
+ private static final int TIMEOUT = 60;
+
+ /**
+ * 检验顺序消息
+ * 校验点:1. 每个shardingkey中的消息都是顺序的
+ *
+ * @param receivedMessage
+ * @return
+ */
+ public static boolean checkOrderMessage(ConcurrentHashMap<String, LinkedList<MessageExt>> receivedMessage) {
+ for (Map.Entry<String, LinkedList<MessageExt>> stringLinkedListEntry : receivedMessage.entrySet()) {
+ StringBuilder sb = new StringBuilder(String.format("shardingKey %s,message order: ", stringLinkedListEntry.getKey()));
+ int preNode = -1;
+ LinkedList<MessageExt> messages = stringLinkedListEntry.getValue();
+ String tag = messages.getFirst().getTags();
+ for (MessageExt message : messages) {
+ if (!message.getTags().equals(tag)) {
+ preNode = -1;
+ }
+ int curNode = Integer.parseInt(new String(message.getBody()));
+ sb.append(curNode).append(",");
+ if (preNode > curNode) {
+ logger.error(sb.toString());
+ return false;
+ }
+ preNode = curNode;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 普通消息检查器
+ *
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ */
+ public static void verifyNormalMessage(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages) {
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ }
+
+ /**
+ * 普通消息检查器
+ *
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ */
+ public static void verifyNormalMessage(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages, int timeout) {
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, timeout * 1000L, 1);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ }
+
+ /**
+ * 普通消息检查器,订阅消息是否与发送消息内容一致
+ *
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ * @param messageBody 消息体
+ */
+ public static void verifyNormalMessageWithBody(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages, String messageBody) {
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ Collection<MessageExt> receivedMessages = dequeueMessages.getAllData();
+ List<Message> messages = new ArrayList<>(receivedMessages);
+ for (Message message : messages) {
+ Assertions.assertEquals(messageBody, new String(message.getBody()), "订阅到的messageBody与期望不符");
+ }
+ }
+
+ /**
+ * 顺序消息检查器
+ *
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ */
+ public static void verifyOrderMessage(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages) {
+ //检查是否消费完成
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ //检查是否消费顺序性 logger.warn(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ Assertions.assertTrue(checkOrder(dequeueMessages), "消息非顺序");
+ }
+
+ /**
+ * 延迟、定时消息检查器
+ *
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ * @param delayLevel 预计需要的消费时间
+ */
+ public static void verifyDelayMessage(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages, int delayLevel) {
+ //检查是否消费完成
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, (TIMEOUT + DelayConf.DELAY_LEVEL[delayLevel - 1]) * 1000L, 1);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ //检查是否消费延迟性
+ HashMap<String, Long> delayUnExcept = checkDelay(dequeueMessages, 5);
+ StringBuilder sb = new StringBuilder();
+ sb.append("以下消息不符合延迟要求 \n");
+ for (String msg : delayUnExcept.keySet()) {
+ sb.append(msg).append(" , interval:").append(delayUnExcept.get(msg)).append("\n");
+ }
+ Assertions.assertEquals(0, delayUnExcept.size(), sb.toString());
+ }
+
+ /**
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ * @param delayTime 延迟时间
+ * @param count 不被消费的数量
+ */
+ public static void verifyDelayMessageWithUnConsumeCount(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages, int delayTime, int count) {
+ //检查是否消费完成
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, (TIMEOUT + delayTime) * 1000L, 1);
+ if (unConsumedMessages.size() > count) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ //检查是否消费延迟性
+ HashMap<String, Long> delayUnExcept = checkDelay(dequeueMessages, TIMEOUT + 5);
+ StringBuilder sb = new StringBuilder();
+ sb.append("以下消息不符合延迟要求 \n");
+ //时间戳格式化
+ SimpleDateFormat date = new SimpleDateFormat("ss");
+ for (String msg : delayUnExcept.keySet()) {
+ sb.append(msg).append(" , interval:").append("相差" + date.format(new Date(Long.parseLong(String.valueOf(delayUnExcept.get(msg))))) + "秒").append("\n");
+ }
+ Assertions.assertEquals(0, delayUnExcept.size(), sb.toString());
+ }
+
+ /**
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ * @param delayTime 延迟时间
+ * @param reconsumeTime 重试次数
+ */
+ public static void verifyDelayMessageWithReconsumeTimes(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages, int delayTime, int reconsumeTime) {
+ int flexibleTime = TIMEOUT;
+ if (reconsumeTime == 1) {
+ flexibleTime = flexibleTime + 10;
+ } else if (reconsumeTime == 2) {
+ flexibleTime = flexibleTime + 10 + 30;
+ } else if (reconsumeTime == 3) {
+ flexibleTime = flexibleTime + 10 + 30 + 60;
+ } else if (reconsumeTime == 4) {
+ flexibleTime = flexibleTime + 10 + 30 + 60 + 120;
+ }
+ //检查是否消费完成
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, (flexibleTime + delayTime) * 1000L, 1);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ //检查是否消费延迟性
+ HashMap<String, Long> delayUnExcept = checkDelay(dequeueMessages, 5 + flexibleTime - 30);
+ StringBuilder sb = new StringBuilder();
+ sb.append("以下消息不符合延迟要求 \n");
+ for (String msg : delayUnExcept.keySet()) {
+ sb.append(msg).append(" , interval:").append(delayUnExcept.get(msg)).append("\n");
+ }
+ Assertions.assertEquals(0, delayUnExcept.size(), sb.toString());
+ }
+
+ public static void verifyNormalMessageWithReconsumeTimes(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages, int reconsumeTime) {
+ int flexibleTime = TIMEOUT;
+ if (reconsumeTime == 1) {
+ flexibleTime = flexibleTime + 10;
+ } else if (reconsumeTime == 2) {
+ flexibleTime = flexibleTime + 10 + 30;
+ } else if (reconsumeTime == 3) {
+ flexibleTime = flexibleTime + 10 + 30 + 60;
+ } else if (reconsumeTime == 4) {
+ flexibleTime = flexibleTime + 10 + 30 + 60 + 120;
+ }
+ //检查是否消费完成
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, flexibleTime * 1000L, 1);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ }
+
+ /**
+ * 校验消息重试消费
+ *
+ * @param enqueueMessages 发送的消息列表
+ * @param dequeueAllMessages 消费的消息列表
+ * @param consumedTimes 重复消费的次数
+ */
+ public static void verifyRetryConsume(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueAllMessages, int consumedTimes) {
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueAllMessages, TIMEOUT * 1000L, consumedTimes);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ }
+
+ /**
+ * 事务消息检查器
+ *
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ */
+ public static void checkTransactionMessage(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages) {
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
+ if (unConsumedMessages.size() > 0) {
+ Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ }
+ }
+
+ public static void verifyConsumeFailed(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages, Integer reconsumeTimes) {
+ Collection<MessageExt> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, reconsumeTimes + 1);
+ if (unConsumedMessages.size() > 0) {
+ //Assertions.fail(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ logger.warn(String.format("以下%s条消息未被消费: %s", unConsumedMessages.size(), unConsumedMessages));
+ } else {
+ Assertions.fail("消息全部被消费");
+ }
+ }
+
+ /**
+ * @param everyConsumeResult
+ * @param batchConsumeSize
+ * @param lastConsumeSize
+ */
+ public static void verifyBatchSize(List<Integer> everyConsumeResult, int batchConsumeSize, int lastConsumeSize) {
+ boolean result = false;
+ if (lastConsumeSize == 0) {
+ long s = everyConsumeResult.stream().filter(a -> a == batchConsumeSize).count();
+ if (s == everyConsumeResult.size()) {
+ result = true;
+ }
+ } else {
+ if (lastConsumeSize == everyConsumeResult.get(everyConsumeResult.size() - 1)) {
+ everyConsumeResult.remove(everyConsumeResult.size() - 1);
+ long s = everyConsumeResult.stream().filter(a -> a == batchConsumeSize).count();
+ if (s == everyConsumeResult.size()) {
+ result = true;
+ }
+ }
+ }
+ Assertions.assertTrue(result, "批量消费校验失败");
+ }
+
+ /**
+ * 校验负载均衡
+ *
+ * @param msgSize 消费到的消息条数
+ * @param recvSize 每个客户端消费到的消息条数
+ */
+ public static void verifyBalance(int msgSize, long... recvSize) {
+ Assertions.assertTrue(verifyBalance(msgSize, 0.1f, recvSize), "客户端负载不均衡 " + Arrays.toString(recvSize));
+ //return verifyBalance(msgSize, 0.1f, recvSize);
+ }
+
+ private static boolean verifyBalance(int msgSize, float error, long... recvSize) {
+ boolean balance = true;
+ int evenSize = msgSize / recvSize.length; //平均值
+ for (long size : recvSize) {
+ //如果消费到的消息比平均值大于误差则不算均衡
+ if (Math.abs(size - evenSize) > error * evenSize) {
+ balance = false;
+ logger.error("msgSize:{}, recvSize:{}, not balance!", msgSize, recvSize);
+ break;
+ }
+ }
+ return balance;
+ }
+
+ private static HashMap<String, Long> checkDelay(DataCollector<MessageExt> dequeueMessages, int offset) {
+ HashMap<String, Long> map = new HashMap<>();
+ Collection<MessageExt> receivedMessages = dequeueMessages.getAllData();
+ for (MessageExt receivedMessage : receivedMessages) {
+ long startDeliverTime = Long.parseLong(receivedMessage.getUserProperty("startDeliverTime"));
+ //判断当前时间跟分发时间,如果相差在5s内,则满足要求
+ long bornTimestamp = receivedMessage.getBornTimestamp();
+ //if ()
+ if (Math.abs(startDeliverTime - bornTimestamp) / 1000 > DelayConf.DELAY_LEVEL[receivedMessage.getDelayTimeLevel() - 1] + offset) {
+ map.put(receivedMessage.getMsgId(), (startDeliverTime - bornTimestamp) / 1000);
+ }
+ }
+ return map;
+ }
+
+ /**
+ * 检查消息的顺序性
+ *
+ * @param dequeueMessages 收到的消息集合
+ * @return 是否分区顺序
+ */
+ private static boolean checkOrder(DataCollector<MessageExt> dequeueMessages) {
+ Collection<MessageExt> receivedMessages = dequeueMessages.getAllData();
+ ConcurrentHashMap<String, LinkedList<MessageExt>> map = new ConcurrentHashMap<>();
+ for (MessageExt receivedMessage : receivedMessages) {
+ String shardingKey = String.valueOf(receivedMessage.getQueueId());
+ LinkedList<MessageExt> messages;
+ if (map.containsKey(shardingKey)) {
+ messages = map.get(shardingKey);
+ messages.add(receivedMessage);
+ } else {
+ messages = new LinkedList<>();
+ messages.add(receivedMessage);
+ map.put(shardingKey, messages);
+ }
+ }
+ return checkOrderMessage(map);
+ }
+
+ /**
+ * 检查发送的消息是否都被消费
+ *
+ * @param enqueueMessages 发送入队消息集合
+ * @param dequeueMessages 消费出队消息集合
+ * @param timeoutMills 检查超时时间
+ * @param consumedTimes
+ * @return 未被消费的消息集合
+ */
+ private static Collection<MessageExt> waitForMessageConsume(DataCollector<MessageExt> enqueueMessages, DataCollector<MessageExt> dequeueMessages, Long timeoutMills, Integer consumedTimes) {
+ logger.info("Set timeout: {}ms", timeoutMills);
+ Collection<MessageExt> sendMessages = enqueueMessages.getAllData();
+
+ long currentTime = System.currentTimeMillis();
+
+ while (!sendMessages.isEmpty()) {
+ //logger.info("param1:{}, param2:{}", enqueueMessages.getDataSize(), dequeueMessages.getDataSize());
+ List<MessageExt> receivedMessagesCopy = new ArrayList<>(dequeueMessages.getAllData());
+ Iterator<MessageExt> iter = sendMessages.iterator();
+ while (iter.hasNext()) {
+ MessageExt message = iter.next();
+ long msgCount = receivedMessagesCopy
+ .stream()
+ .filter(msg -> {
+ if (msg.getUserProperty("UNIQ_KEY") != null && !msg.getUserProperty("UNIQ_KEY").equals(msg.getMsgId())) {
+ return msg.getUserProperty("UNIQ_KEY").equals(message.getMsgId()) || msg.getMsgId().equals(message.getMsgId());
+ }
+ return msg.getMsgId().equals(message.getMsgId());
+ })
+ .count();
+ if (msgCount > 0 && getRepeatedTimes(receivedMessagesCopy, message) == consumedTimes) {
+ iter.remove();
+ } else if (getRepeatedTimes(receivedMessagesCopy, message) > consumedTimes) {
+ Assertions.fail(String.format("消费到的重试消息多于预期(包含一条原始消息),Except:%s, Actual:%s, MsgId:%s", consumedTimes, getRepeatedTimes(receivedMessagesCopy, message), message.getMsgId()));
+ //logger.error("消费到的重试消息多于预期,Except:{}, Actual:{}", consumedTimes, getRepeatedTimes(receivedMessagesCopy, message));
+ }
+ }
+ if (sendMessages.isEmpty()) {
+ break;
+ }
+ if (System.currentTimeMillis() - currentTime >= timeoutMills) {
+ logger.error("Timeout but not received all send messages, not received msg: {}\n received msg:{}\n", sendMessages, receivedMessagesCopy);
+ break;
+ }
+ TestUtils.waitForMoment(500L);
+ }
+ return sendMessages;
+ }
+
+ private static synchronized int getRepeatedTimes(Collection<MessageExt> recvMsgs, MessageExt msg) {
+ int count = 0;
+ for (MessageExt recvMsg : recvMsgs) {
+ if (recvMsg.getUserProperty("UNIQ_KEY") != null && !recvMsg.getUserProperty("UNIQ_KEY").equals(recvMsg.getMsgId()) && !recvMsg.getMsgId().equals(msg.getMsgId())) {
+ if (recvMsg.getUserProperty("UNIQ_KEY").equals(msg.getMsgId())) {
+ count++;
+ }
+ } else if (recvMsg.getMsgId().equals(msg.getMsgId())) {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ /**
+ * 校验一段时间内没有消费
+ *
+ * @param receivedMessages
+ * @param timeout 时间
+ */
+ public static void waitForConsumeFailed(DataCollector<MessageExt> receivedMessages, int timeout) {
+ long currentTime = System.currentTimeMillis();
+ while (currentTime + timeout * 1000L > System.currentTimeMillis()) {
+ if (receivedMessages.getDataSize() > 0) {
+ Assertions.fail("消费到消息");
+ break;
+ }
+ TestUtils.waitForSeconds(5);
+ }
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/DataCollector.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/DataCollector.java
new file mode 100644
index 0000000..d991ad4
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/DataCollector.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils.data.collect;
+
+import java.util.Collection;
+public interface DataCollector<T> {
+ /**
+ * 计数归零
+ */
+ void resetData();
+
+ /**
+ * 取得所有的收集数据,包含重复的数据
+ *
+ * @return
+ */
+ Collection<T> getAllData();
+
+ /**
+ * 取得收集的非重复数据
+ *
+ * @return
+ */
+ Collection<T> getAllDataWithoutDuplicate();
+
+ /**
+ * 增加数据
+ */
+ void addData(T data);
+
+ /**
+ * 取得非重复数据的总个数
+ *
+ * @return
+ */
+ long getDataSizeWithoutDuplicate();
+
+ /**
+ * 取得所有数据的总个数,包括重复数据
+ *
+ * @return
+ */
+ long getDataSize();
+
+ /**
+ * 验证一条数据是否存在重复
+ *
+ * @return
+ */
+ boolean isRepeatedData(T data);
+
+ /**
+ * 取得一条数据重复出现的次数
+ *
+ * @return
+ */
+ int getRepeatedTimeForData(T data);
+
+ /**
+ * 移除一条数据
+ *
+ * @return
+ */
+ void removeData(T data);
+
+ /**
+ * 锁定计数器,使其不再增加,但是可以删除
+ *
+ * @return
+ */
+ void lockIncrement();
+
+ /**
+ * 接触计数器锁定,使其可以增加和删除
+ *
+ * @return
+ */
+ void unlockIncrement();
+
+
+ T getFirstElement();
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/DataCollectorManager.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/DataCollectorManager.java
new file mode 100644
index 0000000..818728d
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/DataCollectorManager.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils.data.collect;
+
+
+import org.apache.rocketmq.utils.data.collect.impl.ListDataCollectorImpl;
+import org.apache.rocketmq.utils.data.collect.impl.MapDataCollectorImpl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public final class DataCollectorManager {
+ private static DataCollectorManager instance = new DataCollectorManager();
+ private Map<String, DataCollector> collectMap = new HashMap<String, DataCollector>();
+ private Object lock = new Object();
+
+ private DataCollectorManager() {
+ }
+
+ public static DataCollectorManager getInstance() {
+ return instance;
+ }
+
+ public DataCollector fetchDataCollector(String key) {
+ String realKey = key;
+ if (!collectMap.containsKey(realKey)) {
+ synchronized (lock) {
+ if (!collectMap.containsKey(realKey)) {
+ DataCollector collect = (DataCollector) new MapDataCollectorImpl();
+ collectMap.put(realKey, collect);
+ }
+ }
+ }
+ return collectMap.get(realKey);
+ }
+
+ public DataCollector fetchMapDataCollector(String key) {
+ String realKey = key;
+ if (!collectMap.containsKey(realKey)
+ || collectMap.get(realKey) instanceof ListDataCollectorImpl) {
+ synchronized (lock) {
+ if (!collectMap.containsKey(realKey)
+ || collectMap.get(realKey) instanceof ListDataCollectorImpl) {
+ DataCollector collect = null;
+ if (collectMap.containsKey(realKey)) {
+ DataCollector src = collectMap.get(realKey);
+ collect = new MapDataCollectorImpl(src.getAllData());
+ } else {
+ collect = new MapDataCollectorImpl();
+ }
+ collectMap.put(realKey, collect);
+
+ }
+ }
+ }
+ return collectMap.get(realKey);
+ }
+
+ public DataCollector fetchListDataCollector(String key) {
+ String realKey = key;
+ if (!collectMap.containsKey(realKey)
+ || collectMap.get(realKey) instanceof MapDataCollectorImpl) {
+ synchronized (lock) {
+ if (!collectMap.containsKey(realKey)
+ || collectMap.get(realKey) instanceof MapDataCollectorImpl) {
+ DataCollector collect = null;
+ if (collectMap.containsKey(realKey)) {
+ DataCollector src = collectMap.get(realKey);
+ collect = new ListDataCollectorImpl(src.getAllData());
+ } else {
+ collect = new ListDataCollectorImpl();
+ }
+ collectMap.put(realKey, collect);
+ }
+ }
+ }
+ return collectMap.get(realKey);
+ }
+
+ public void resetDataCollect(String key) {
+ if (collectMap.containsKey(key)) {
+ collectMap.get(key).resetData();
+ }
+ }
+
+ public void resetAll() {
+ for (Map.Entry<String, DataCollector> entry : collectMap.entrySet()) {
+ entry.getValue().resetData();
+ }
+ }
+
+ public void removeDataCollect(String key) {
+ collectMap.remove(key);
+ }
+
+ public void removeAll() {
+ collectMap.clear();
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/impl/ListDataCollectorImpl.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/impl/ListDataCollectorImpl.java
new file mode 100644
index 0000000..f0d480d
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/impl/ListDataCollectorImpl.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils.data.collect.impl;
+
+import org.apache.rocketmq.utils.data.collect.DataCollector;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+
+
+public class ListDataCollectorImpl implements DataCollector {
+
+ private List<Object> datas = new ArrayList<Object>();
+ private boolean lock = false;
+
+ public ListDataCollectorImpl() {
+
+ }
+
+ public ListDataCollectorImpl(Collection<Object> datas) {
+ for (Object data : datas) {
+ addData(data);
+ }
+ }
+
+ public Collection<Object> getAllData() {
+ return datas;
+ }
+
+ public synchronized void resetData() {
+ datas.clear();
+ unlockIncrement();
+ }
+
+ public long getDataSizeWithoutDuplicate() {
+ return getAllDataWithoutDuplicate().size();
+ }
+
+ public synchronized void addData(Object data) {
+ if (lock) {
+ return;
+ }
+ datas.add(data);
+ }
+
+ public long getDataSize() {
+ return datas.size();
+ }
+
+ public boolean isRepeatedData(Object data) {
+ return Collections.frequency(datas, data) == 1;
+ }
+
+ public synchronized Collection<Object> getAllDataWithoutDuplicate() {
+ return new HashSet<Object>(datas);
+ }
+
+ public int getRepeatedTimeForData(Object data) {
+ int res = 0;
+ for (Object obj : datas) {
+ if (obj.equals(data)) {
+ res++;
+ }
+ }
+ return res;
+ }
+
+ public synchronized void removeData(Object data) {
+ datas.remove(data);
+ }
+
+ public void lockIncrement() {
+ lock = true;
+ }
+
+ public void unlockIncrement() {
+ lock = false;
+ }
+
+ @Override
+ public Object getFirstElement() {
+ return null;
+ }
+}
diff --git a/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/impl/MapDataCollectorImpl.java b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/impl/MapDataCollectorImpl.java
new file mode 100644
index 0000000..de037dd
--- /dev/null
+++ b/java/e2e-v4/src/main/java/org/apache/rocketmq/utils/data/collect/impl/MapDataCollectorImpl.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.utils.data.collect.impl;
+
+
+import org.apache.rocketmq.utils.data.collect.DataCollector;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class MapDataCollectorImpl implements DataCollector {
+
+ private Map<Object, AtomicInteger> datas = new ConcurrentHashMap<Object, AtomicInteger>();
+ private boolean lock = false;
+
+ public MapDataCollectorImpl() {
+
+ }
+
+ public MapDataCollectorImpl(Collection<Object> datas) {
+ for (Object data : datas) {
+ addData(data);
+ }
+ }
+
+ public synchronized void addData(Object data) {
+ if (lock) {
+ return;
+ }
+ if (datas.containsKey(data)) {
+ datas.get(data).addAndGet(1);
+ } else {
+ datas.put(data, new AtomicInteger(1));
+ }
+ }
+
+ public Collection<Object> getAllData() {
+ List<Object> lst = new ArrayList<Object>();
+ for (Entry<Object, AtomicInteger> entry : datas.entrySet()) {
+ for (int i = 0; i < entry.getValue().get(); i++) {
+ lst.add(entry.getKey());
+ }
+ }
+ return lst;
+ }
+
+ public long getDataSizeWithoutDuplicate() {
+ return datas.keySet().size();
+ }
+
+ public void resetData() {
+ datas.clear();
+ unlockIncrement();
+ }
+
+ public long getDataSize() {
+ long sum = 0;
+ for (AtomicInteger count : datas.values()) {
+ sum = sum + count.get();
+ }
+ return sum;
+ }
+
+ public boolean isRepeatedData(Object data) {
+ if (datas.containsKey(data)) {
+ return datas.get(data).get() == 1;
+ }
+ return false;
+ }
+
+ public Collection<Object> getAllDataWithoutDuplicate() {
+ return datas.keySet();
+ }
+
+ public int getRepeatedTimeForData(Object data) {
+ if (datas.containsKey(data)) {
+ return datas.get(data).intValue();
+ }
+ return 0;
+ }
+
+ public void removeData(Object data) {
+ datas.remove(data);
+ }
+
+ public void lockIncrement() {
+ lock = true;
+ }
+
+ public void unlockIncrement() {
+ lock = false;
+ }
+
+ @Override
+ public Object getFirstElement() {
+ return null;
+ }
+}
diff --git a/java/e2e-v4/src/test/java/com/apache/rocketmq/server/delay/DelayMessageTest.java b/java/e2e-v4/src/test/java/com/apache/rocketmq/server/delay/DelayMessageTest.java
new file mode 100644
index 0000000..7d8515c
--- /dev/null
+++ b/java/e2e-v4/src/test/java/com/apache/rocketmq/server/delay/DelayMessageTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.apache.rocketmq.server.delay;
+
+import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
+import org.apache.rocketmq.client.rmq.RMQNormalProducer;
+import org.apache.rocketmq.enums.TESTSET;
+import org.apache.rocketmq.factory.ConsumerFactory;
+import org.apache.rocketmq.factory.ProducerFactory;
+import org.apache.rocketmq.frame.BaseOperate;
+import org.apache.rocketmq.listener.rmq.concurrent.RMQNormalListener;
+import org.apache.rocketmq.utils.MQAdmin;
+import org.apache.rocketmq.utils.NameUtils;
+import org.apache.rocketmq.utils.VerifyUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Tag(TESTSET.SMOKE)
+@Tag(TESTSET.DELAY)
+public class DelayMessageTest extends BaseOperate {
+ private final Logger logger = LoggerFactory.getLogger(DelayMessageTest.class);
+ //private RMQOrderConsumer consumer;
+ private String tag;
+ private String topic;
+ private String groupId;
+ private final static int SEND_NUM = 100;
+
+ @BeforeEach
+ public void setUp() {
+ topic = NameUtils.getTopicName();
+ tag = NameUtils.getTagName();
+ groupId = NameUtils.getGroupName();
+ MQAdmin.createTopic(namesrvAddr, cluster, topic, 8);
+ logger.info("topic:{}, tag:{}, groupId:{}", topic, tag, groupId);
+ }
+
+ @AfterEach
+ public void tearDown() {
+
+ }
+
+ @Test
+ @DisplayName("测试延迟level=1")
+ public void testDelayLevel1() {
+ int delayLevel = 1;
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, "*", new RMQNormalListener());
+ RMQNormalProducer producer = ProducerFactory.getRMQProducer(namesrvAddr,rpcHook);
+
+ producer.sendDelay(topic, delayLevel, SEND_NUM);
+ VerifyUtils.verifyDelayMessage(producer.getEnqueueMessages(), consumer.getListener().getDequeueMessages(), delayLevel);
+
+ producer.shutdown();
+ consumer.shutdown();
+ }
+
+ @Test
+ @DisplayName("测试延迟level=4")
+ public void testDelayLevel4() {
+ int delayLevel = 4;
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, "*", new RMQNormalListener());
+ RMQNormalProducer producer = ProducerFactory.getRMQProducer(namesrvAddr,rpcHook);
+
+ producer.sendDelay(topic, delayLevel, SEND_NUM);
+ VerifyUtils.verifyDelayMessage(producer.getEnqueueMessages(), consumer.getListener().getDequeueMessages(), delayLevel);
+
+ producer.shutdown();
+ consumer.shutdown();
+ }
+}
diff --git a/java/e2e-v4/src/test/java/com/apache/rocketmq/server/normal/NormalMessageTest.java b/java/e2e-v4/src/test/java/com/apache/rocketmq/server/normal/NormalMessageTest.java
new file mode 100644
index 0000000..9393bde
--- /dev/null
+++ b/java/e2e-v4/src/test/java/com/apache/rocketmq/server/normal/NormalMessageTest.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.apache.rocketmq.server.normal;
+
+import org.apache.rocketmq.client.callback.RMQSendCallBack;
+import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
+import org.apache.rocketmq.client.rmq.RMQNormalProducer;
+import org.apache.rocketmq.enums.TESTSET;
+import org.apache.rocketmq.factory.ConsumerFactory;
+import org.apache.rocketmq.factory.ProducerFactory;
+import org.apache.rocketmq.frame.BaseOperate;
+import org.apache.rocketmq.listener.rmq.concurrent.RMQNormalListener;
+import org.apache.rocketmq.utils.MQAdmin;
+import org.apache.rocketmq.utils.NameUtils;
+import org.apache.rocketmq.utils.VerifyUtils;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Tag(TESTSET.NORMAL)
+@Tag(TESTSET.SMOKE)
+public class NormalMessageTest extends BaseOperate {
+ private final Logger logger = LoggerFactory.getLogger(NormalMessageTest.class);
+ private String tag;
+ private String topic;
+ private String groupId;
+ private final static int SEND_NUM = 10;
+
+ @BeforeEach
+ public void setUp() {
+ topic = NameUtils.getTopicName();
+ tag = NameUtils.getTagName();
+ groupId = NameUtils.getGroupName();
+ MQAdmin.createTopic(namesrvAddr, cluster, topic, 8);
+ logger.info("topic:{}, tag:{}, groupId:{}", topic, tag, groupId);
+ }
+
+ @Test
+ @DisplayName("同步发送10条普通消息,期望这10条消息被消费到")
+ public void testConsumeNormalMessage() {
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, tag, new RMQNormalListener());
+ RMQNormalProducer producer = ProducerFactory.getRMQProducer(namesrvAddr,rpcHook);
+ producer.send(topic, tag, SEND_NUM);
+
+ VerifyUtils.verifyNormalMessage(producer.getEnqueueMessages(), consumer.getListener().getDequeueMessages());
+ producer.shutdown();
+ consumer.shutdown();
+ }
+
+ @Test
+ @DisplayName("异步发送10条普通消息,期望这10条消息被消费到")
+ public void testConsumeNormalMessageAndSendWithAsync() {
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, tag, new RMQNormalListener());
+ RMQNormalProducer producer = ProducerFactory.getRMQProducer(namesrvAddr,rpcHook);
+ RMQSendCallBack callBack = new RMQSendCallBack();
+ producer.sendAsync(topic, tag, callBack, SEND_NUM);
+
+ Assertions.assertEquals(SEND_NUM, producer.getEnqueueMessages().getDataSize(), "消息发送失败");
+ VerifyUtils.verifyNormalMessage(producer.getEnqueueMessages(), consumer.getListener().getDequeueMessages());
+ }
+
+ @Test
+ @DisplayName("OneWay发送10条普通消息,期望这10条消息被消费到")
+ public void testConsumeNormalMessageAndSendWithOneWay() {
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, tag, new RMQNormalListener());
+ RMQNormalProducer producer = ProducerFactory.getRMQProducer(namesrvAddr,rpcHook);
+
+ producer.sendOneWay(topic, tag, SEND_NUM);
+
+ VerifyUtils.verifyNormalMessage(producer.getEnqueueMessages(), consumer.getListener().getDequeueMessages());
+ }
+
+ @Test
+ @DisplayName("topic创建,然后发送消息,不消费,删除该topic再次创建同名topic,启动消费,预期无法再次消费到")
+ public void testConsumeNormalMessageWithDeleteAndCreateTopicAgain() {
+
+ RMQNormalProducer producer = ProducerFactory.getRMQProducer(namesrvAddr,rpcHook);
+ producer.send(topic, tag, SEND_NUM);
+
+ MQAdmin.deleteTopic(namesrvAddr, cluster, topic);
+
+ MQAdmin.createTopic(namesrvAddr, cluster, topic, 8);
+
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, tag, new RMQNormalListener());
+ VerifyUtils.waitForConsumeFailed(consumer.getListener().getDequeueMessages(), 20);
+
+ producer.shutdown();
+ consumer.shutdown();
+ }
+
+}
+
diff --git a/java/e2e-v4/src/test/java/com/apache/rocketmq/server/order/OrderMessageTest.java b/java/e2e-v4/src/test/java/com/apache/rocketmq/server/order/OrderMessageTest.java
new file mode 100644
index 0000000..9e7bb1c
--- /dev/null
+++ b/java/e2e-v4/src/test/java/com/apache/rocketmq/server/order/OrderMessageTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.apache.rocketmq.server.order;
+
+import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
+import org.apache.rocketmq.client.rmq.RMQNormalProducer;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.enums.TESTSET;
+import org.apache.rocketmq.factory.ConsumerFactory;
+import org.apache.rocketmq.factory.ProducerFactory;
+import org.apache.rocketmq.frame.BaseOperate;
+import org.apache.rocketmq.listener.rmq.concurrent.RMQOrderListener;
+import org.apache.rocketmq.utils.MQAdmin;
+import org.apache.rocketmq.utils.NameUtils;
+import org.apache.rocketmq.utils.VerifyUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+@Tag(TESTSET.SMOKE)
+@Tag(TESTSET.ORDER)
+public class OrderMessageTest extends BaseOperate {
+ private final Logger logger = LoggerFactory.getLogger(OrderMessageTest.class);
+ private String tag;
+ private String topic;
+ private String groupId;
+ private final static int SEND_NUM = 100;
+
+ @BeforeEach
+ public void setUp() {
+ topic = NameUtils.getTopicName();
+ tag = NameUtils.getTagName();
+ groupId = NameUtils.getGroupName();
+ MQAdmin.createTopic(namesrvAddr, cluster, topic, 8);
+ logger.info("topic:{}, tag:{}, groupId:{}", topic, tag, groupId);
+ }
+
+ @AfterEach
+ public void tearDown() {
+
+ }
+
+ @Test
+ @DisplayName("使用分区顺序topic,设置8个shardingkey,发送100条分区顺序消息,期望能按顺序消费到全部消息")
+ public void testConsumePartitionOrderMessage() {
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, "*", new RMQOrderListener());
+ RMQNormalProducer producer = ProducerFactory.getRMQProducer(namesrvAddr, rpcHook);
+ List<MessageQueue> messageQueues = producer.fetchPublishMessageQueues(topic);
+ producer.sendWithQueue(messageQueues, 30);
+ VerifyUtils.verifyOrderMessage(producer.getEnqueueMessages(), consumer.getListener().getDequeueMessages());
+
+ producer.shutdown();
+ consumer.shutdown();
+ }
+
+ @Test
+ @DisplayName("使用全局顺序topic,发送100条全局顺序消息,期望能按顺序消费到全部消息")
+ public void testConsumeGlobalOrderMessage() {
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, "*", new RMQOrderListener());
+ RMQNormalProducer producer = ProducerFactory.getRMQProducer(namesrvAddr, rpcHook);
+ List<MessageQueue> messageQueues = producer.fetchPublishMessageQueues(topic);
+ messageQueues.removeIf(messageQueue -> messageQueue.getQueueId() != 0);
+ producer.sendWithQueue(messageQueues, SEND_NUM);
+ VerifyUtils.verifyOrderMessage(producer.getEnqueueMessages(), consumer.getListener().getDequeueMessages());
+
+ producer.shutdown();
+ consumer.shutdown();
+ }
+}
diff --git a/java/e2e-v4/src/test/java/com/apache/rocketmq/server/transaction/TransactionMessageTest.java b/java/e2e-v4/src/test/java/com/apache/rocketmq/server/transaction/TransactionMessageTest.java
new file mode 100644
index 0000000..5721154
--- /dev/null
+++ b/java/e2e-v4/src/test/java/com/apache/rocketmq/server/transaction/TransactionMessageTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.apache.rocketmq.server.transaction;
+
+import org.apache.rocketmq.client.producer.LocalTransactionState;
+import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
+import org.apache.rocketmq.client.rmq.RMQTransactionProducer;
+import org.apache.rocketmq.enums.TESTSET;
+import org.apache.rocketmq.factory.ConsumerFactory;
+import org.apache.rocketmq.factory.ProducerFactory;
+import org.apache.rocketmq.frame.BaseOperate;
+import org.apache.rocketmq.listener.rmq.concurrent.RMQNormalListener;
+import org.apache.rocketmq.listener.rmq.concurrent.TransactionListenerImpl;
+import org.apache.rocketmq.utils.MQAdmin;
+import org.apache.rocketmq.utils.NameUtils;
+import org.apache.rocketmq.utils.VerifyUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+
+@Tag(TESTSET.TRANSACTION)
+@Tag(TESTSET.SMOKE)
+public class TransactionMessageTest extends BaseOperate {
+ private final Logger logger = LoggerFactory.getLogger(TransactionMessageTest.class);
+ private String tag;
+ private String topic;
+ private String groupId;
+ private final static int SEND_NUM = 10;
+
+ @BeforeEach
+ public void setUp() {
+ topic = NameUtils.getTopicName();
+ tag = NameUtils.getTagName();
+ groupId = NameUtils.getGroupName();
+ MQAdmin.createTopic(namesrvAddr, cluster, topic, 8);
+ logger.info("topic:{}, tag:{}, groupId:{}", topic, tag, groupId);
+ }
+
+ @Test
+ @DisplayName("同步发送10条普通消息,期望这10条消息被消费到")
+ public void testConsumeNormalMessage() {
+ RMQNormalConsumer consumer = ConsumerFactory.getRMQNormalConsumer(namesrvAddr, groupId, rpcHook);
+ consumer.subscribeAndStart(topic, tag, new RMQNormalListener());
+
+ ExecutorService executorService = new ThreadPoolExecutor(2, 5, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(2000), new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread thread = new Thread(r);
+ thread.setName("client-transaction-msg-check-thread");
+ return thread;
+ }
+ });
+
+ RMQTransactionProducer producer = ProducerFactory.getTransProducer(namesrvAddr, executorService, new TransactionListenerImpl(LocalTransactionState.COMMIT_MESSAGE, LocalTransactionState.COMMIT_MESSAGE), rpcHook);
+ producer.send(topic, tag, SEND_NUM);
+
+ VerifyUtils.verifyNormalMessage(producer.getEnqueueMessages(), consumer.getListener().getDequeueMessages());
+ producer.shutdown();
+ consumer.shutdown();
+ }
+
+}
diff --git a/java/e2e-v4/src/test/resources/env/daily/daily.conf b/java/e2e-v4/src/test/resources/env/daily/daily.conf
new file mode 100644
index 0000000..8465f43
--- /dev/null
+++ b/java/e2e-v4/src/test/resources/env/daily/daily.conf
@@ -0,0 +1,5 @@
+aclEnable = false
+
+namesrvAddr = 127.0.0.1:9876
+# cluster
+cluster = DefaultCluster
\ No newline at end of file
diff --git a/java/e2e-v4/src/test/resources/junit-platform.properties b/java/e2e-v4/src/test/resources/junit-platform.properties
new file mode 100644
index 0000000..8ee793a
--- /dev/null
+++ b/java/e2e-v4/src/test/resources/junit-platform.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+junit.jupiter.execution.parallel.enabled=true
+junit.jupiter.execution.parallel.mode.default=concurrent
+junit.jupiter.execution.parallel.mode.classes.default=concurrent
\ No newline at end of file
diff --git a/java/e2e-v4/src/test/resources/log4j.properties b/java/e2e-v4/src/test/resources/log4j.properties
new file mode 100644
index 0000000..1398339
--- /dev/null
+++ b/java/e2e-v4/src/test/resources/log4j.properties
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+log4j.rootLogger=INFO, stdout
+#log4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppender
+#log4j.appender.ServerDailyRollingFile.DatePattern='.'yyyy-MM-dd
+##log4j.appender.ServerDailyRollingFile.File=${log.base}/logs/mq-server-test.log
+#log4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayout
+#log4j.appender.ServerDailyRollingFile.layout.ConversionPattern=%d - %m%n
+#log4j.appender.ServerDailyRollingFile.Append=true
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} %p [%c.%M:%L] %m%n
\ No newline at end of file
diff --git a/java/e2e-v4/src/test/resources/logback-test.xml b/java/e2e-v4/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..ce2a862
--- /dev/null
+++ b/java/e2e-v4/src/test/resources/logback-test.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<configuration debug="false" scan="true" scanPeriod="1 seconds">
+
+ <contextName>logback</contextName>
+ <!-- 输出到控制台 -->
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <!--<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level [%logger{12}#%M:%L] - %msg%n</pattern>-->
+ <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level [%-30.30logger{12}#%-20.20M:%4L] %msg%n</pattern>
+ <charset>UTF-8</charset>
+ </encoder>
+ </appender>
+
+ <root level="debug">
+ <appender-ref ref="CONSOLE" />
+ </root>
+
+</configuration>
\ No newline at end of file
diff --git a/java/e2e/pom.xml b/java/e2e/pom.xml
index 83d0640..f81ca84 100644
--- a/java/e2e/pom.xml
+++ b/java/e2e/pom.xml
@@ -15,18 +15,10 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
-
- <junit.jupiter.version>5.7.2</junit.jupiter.version>
- <rocketmq.client.version>4.9.3</rocketmq.client.version>
- <rocketmqV5.client.version>5.0.2</rocketmqV5.client.version>
+ <rocketmqV5.client.version>5.0.3</rocketmqV5.client.version>
</properties>
<dependencies>
- <!-- <dependency>-->
- <!-- <groupId>org.apache.rocketmq</groupId>-->
- <!-- <artifactId>rocketmq-client</artifactId>-->
- <!-- <version>${rocketmq.client.version}</version>-->
- <!-- </dependency>-->
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client-java</artifactId>
@@ -42,57 +34,7 @@
<artifactId>rocketmq-tools</artifactId>
<version>5.0.0</version>
</dependency>
- <!--junit5-->
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-launcher</artifactId>
- <version>1.7.2</version>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <version>${junit.jupiter.version}</version>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>${junit.jupiter.version}</version>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-params</artifactId>
- <version>${junit.jupiter.version}</version>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>1.18.8</version>
- </dependency>
- <!-- <dependency>-->
- <!-- <groupId>org.slf4j</groupId>-->
- <!-- <artifactId>slf4j-log4j12</artifactId>-->
- <!-- <version>1.7.7</version>-->
- <!-- </dependency>-->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>2.0.0-beta1</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>1.3.0-beta0</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <version>1.3.0-beta0</version>
- </dependency>
- <dependency>
- <groupId>com.aliyun</groupId>
- <artifactId>aliyun-java-sdk-core</artifactId>
- <version>3.5.0</version>
- </dependency>
+
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
diff --git a/java/e2e/src/main/java/org/apache/rocketmq/util/VerifyUtils.java b/java/e2e/src/main/java/org/apache/rocketmq/util/VerifyUtils.java
index 6c6eb7c..93d5b01 100644
--- a/java/e2e/src/main/java/org/apache/rocketmq/util/VerifyUtils.java
+++ b/java/e2e/src/main/java/org/apache/rocketmq/util/VerifyUtils.java
@@ -16,6 +16,16 @@
*/
package org.apache.rocketmq.util;
+import org.apache.rocketmq.client.apis.ClientException;
+import org.apache.rocketmq.client.apis.consumer.SimpleConsumer;
+import org.apache.rocketmq.client.apis.message.MessageView;
+import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
+import org.apache.rocketmq.client.rmq.RMQNormalProducer;
+import org.apache.rocketmq.util.data.collect.DataCollector;
+import org.junit.jupiter.api.Assertions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.Duration;
@@ -34,19 +44,12 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
-import org.apache.rocketmq.client.apis.ClientException;
-import org.apache.rocketmq.client.apis.consumer.SimpleConsumer;
-import org.apache.rocketmq.client.apis.message.MessageView;
-import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
-import org.apache.rocketmq.client.rmq.RMQNormalProducer;
-import org.apache.rocketmq.util.data.collect.DataCollector;
-import org.junit.jupiter.api.Assertions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class VerifyUtils {
private static final Logger log = LoggerFactory.getLogger(VerifyUtils.class);
@@ -92,7 +95,7 @@ public class VerifyUtils {
* @param dequeueMessages
*/
public static void verifyNormalMessage(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages) {
+ DataCollector<Object> dequeueMessages) {
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
if (unConsumedMessages.size() > 0) {
Assertions.fail(String.format("The following %s messages are not consumed: %s", unConsumedMessages.size(), unConsumedMessages));
@@ -100,7 +103,7 @@ public class VerifyUtils {
}
public static void verifyNormalMessage(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages, Set<String> unconsumedMsgIds, int timeout) {
+ DataCollector<Object> dequeueMessages, Set<String> unconsumedMsgIds, int timeout) {
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, timeout * 1000L, 1);
// if (unConsumedMessages.size() == 0) {
// Assertions.fail(String.format("Messages are all consumed"));
@@ -128,7 +131,7 @@ public class VerifyUtils {
}
public static void verifyNormalMessage(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages, int timeout) {
+ DataCollector<Object> dequeueMessages, int timeout) {
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, timeout * 1000L, 1);
if (unConsumedMessages.size() > 0) {
Assertions.fail(String.format("The following %s messages are not consumed: %s", unConsumedMessages.size(), unConsumedMessages));
@@ -143,7 +146,7 @@ public class VerifyUtils {
* @param messageBody Body of message
*/
public static void verifyNormalMessageWithBody(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages, String messageBody) {
+ DataCollector<Object> dequeueMessages, String messageBody) {
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
if (unConsumedMessages.size() > 0) {
Assertions.fail(String.format("The following %s messages are not consumed: %s", unConsumedMessages.size(), unConsumedMessages));
@@ -163,7 +166,7 @@ public class VerifyUtils {
* @param dequeueMessages Consume the outgoing message set
*/
public static void verifyOrderMessage(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages) {
+ DataCollector<Object> dequeueMessages) {
//Check whether the consumption is complete
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
if (unConsumedMessages.size() > 0) {
@@ -181,10 +184,10 @@ public class VerifyUtils {
* @param delayTime Estimated consumption time required
*/
public static void verifyDelayMessage(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages, int delayTime) {
+ DataCollector<Object> dequeueMessages, int delayTime) {
//Check whether the consumption is complete
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages,
- (TIMEOUT + delayTime) * 1000L, 1);
+ (TIMEOUT + delayTime) * 1000L, 1);
if (unConsumedMessages.size() > 0) {
Assertions.fail(String.format("The following %s messages are not consumed: %s", unConsumedMessages.size(), unConsumedMessages));
}
@@ -205,8 +208,8 @@ public class VerifyUtils {
* @param count The amount that is not consumed
*/
public static void verifyDelayMessageWithUnConsumeCount(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages, int delayTime,
- int count) {
+ DataCollector<Object> dequeueMessages, int delayTime,
+ int count) {
//Check whether the consumption is complete
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, (TIMEOUT + delayTime) * 1000L, 1);
if (unConsumedMessages.size() > count) {
@@ -220,7 +223,7 @@ public class VerifyUtils {
SimpleDateFormat date = new SimpleDateFormat("ss");
for (String msg : delayUnExcept.keySet()) {
sb.append(msg).append(" , interval:").append("Difference between" + date.format(new Date(Long.parseLong(String.valueOf(delayUnExcept.get(msg))))) + "s").append(
- "\n");
+ "\n");
}
Assertions.assertEquals(0, delayUnExcept.size(), sb.toString());
}
@@ -232,8 +235,8 @@ public class VerifyUtils {
* @param reconsumeTime Number of retries
*/
public static void verifyDelayMessageWithReconsumeTimes(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages, int delayTime,
- int reconsumeTime) {
+ DataCollector<Object> dequeueMessages, int delayTime,
+ int reconsumeTime) {
int flexibleTime = TIMEOUT;
if (reconsumeTime == 1) {
flexibleTime = flexibleTime + 10;
@@ -260,8 +263,8 @@ public class VerifyUtils {
}
public static void verifyNormalMessageWithReconsumeTimes(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages,
- int reconsumeTime) {
+ DataCollector<Object> dequeueMessages,
+ int reconsumeTime) {
int flexibleTime = TIMEOUT;
if (reconsumeTime == 1) {
flexibleTime = flexibleTime + 10;
@@ -287,7 +290,7 @@ public class VerifyUtils {
* @param consumedTimes The number of repeated purchases
*/
public static void verifyRetryConsume(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueAllMessages, int consumedTimes) {
+ DataCollector<Object> dequeueAllMessages, int consumedTimes) {
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueAllMessages, TIMEOUT * 1000L, consumedTimes);
if (unConsumedMessages.size() > 0) {
Assertions.fail(String.format("The following %s messages are not consumed: %s", unConsumedMessages.size(), unConsumedMessages));
@@ -301,7 +304,7 @@ public class VerifyUtils {
* @param dequeueMessages Consume the outgoing message set
*/
public static void checkTransactionMessage(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages) {
+ DataCollector<Object> dequeueMessages) {
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
if (unConsumedMessages.size() > 0) {
Assertions.fail(String.format("The following %s messages are not consumed: %s", unConsumedMessages.size(), unConsumedMessages));
@@ -359,8 +362,8 @@ public class VerifyUtils {
* @return A collection of messages that are not consumed
*/
private static Collection<Object> waitForMessageConsume(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages,
- Long timeoutMills, Integer consumedTimes) {
+ DataCollector<Object> dequeueMessages,
+ Long timeoutMills, Integer consumedTimes) {
log.info("Set timeout: {}ms", timeoutMills);
Collection<Object> sendMessages = new ArrayList<>(enqueueMessages.getAllData());
@@ -376,16 +379,16 @@ public class VerifyUtils {
// String messageId = (MessageView) message;
long msgCount = receivedMessagesCopy.stream().filter(
- msg -> {
- MessageView messageView = (MessageView) msg;
- return messageView.getMessageId().toString().equals(enqueueMessageId);
- }).count();
+ msg -> {
+ MessageView messageView = (MessageView) msg;
+ return messageView.getMessageId().toString().equals(enqueueMessageId);
+ }).count();
if (msgCount > 0 && getRepeatedTimes(receivedMessagesCopy, enqueueMessageId) == consumedTimes) {
iter.remove();
} else if (getRepeatedTimes(receivedMessagesCopy, enqueueMessageId) > consumedTimes) {
Assertions.fail(
- String.format("More retry messages were consumed than expected (including one original message) Except:%s, Actual:%s, MsgId:%s", consumedTimes, getRepeatedTimes(receivedMessagesCopy, enqueueMessageId),
- enqueueMessageId));
+ String.format("More retry messages were consumed than expected (including one original message) Except:%s, Actual:%s, MsgId:%s", consumedTimes, getRepeatedTimes(receivedMessagesCopy, enqueueMessageId),
+ enqueueMessageId));
//log.error("More retry messages were consumed than expected, Except:{}, Actual:{}", consumedTimes, getRepeatedTimes(receivedMessagesCopy, message));
}
}
@@ -395,7 +398,7 @@ public class VerifyUtils {
if (System.currentTimeMillis() - currentTime >= timeoutMills) {
log.error("Timeout but not received all send messages,topic:{}, send {} , recv {}, not received msg: {}\n received msg:{}\n",
- dequeueMessages.getDataSize() > 0 ? ((MessageView) dequeueMessages.getFirstElement()).getTopic() : null, enqueueMessages.getDataSize(), receivedMessagesCopy.size(), sendMessages, receivedMessagesCopy);
+ dequeueMessages.getDataSize() > 0 ? ((MessageView) dequeueMessages.getFirstElement()).getTopic() : null, enqueueMessages.getDataSize(), receivedMessagesCopy.size(), sendMessages, receivedMessagesCopy);
break;
}
TestUtils.waitForMoment(500L);
@@ -422,7 +425,7 @@ public class VerifyUtils {
* @param props The desired attribute condition is not met
*/
public static void verifyNormalMessageWithUserProperties(DataCollector<Object> enqueueMessages,
- DataCollector<Object> dequeueMessages, HashMap<String, String> props, int expectedUnrecvMsgNum) {
+ DataCollector<Object> dequeueMessages, HashMap<String, String> props, int expectedUnrecvMsgNum) {
Collection<Object> unConsumedMessages = waitForMessageConsume(enqueueMessages, dequeueMessages, TIMEOUT * 1000L, 1);
Collection<Object> recvMsgs = dequeueMessages.getAllData();
for (Object unConsumedMessage : recvMsgs) {
@@ -449,7 +452,7 @@ public class VerifyUtils {
*/
@SafeVarargs
public static void verifyClusterConsume(DataCollector<Object> enqueueMessages,
- DataCollector<Object>... dequeueAllMessages) {
+ DataCollector<Object>... dequeueAllMessages) {
long currentTime = System.currentTimeMillis();
List<Object> sendMessagesCopy = new ArrayList<>(enqueueMessages.getAllData());
@@ -526,7 +529,7 @@ public class VerifyUtils {
for (MessageView messageView : messageViews) {
receivedIndex.getAndIncrement();
log.info("MessageId:{}, Body:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
try {
consumer.ack(messageView);
} catch (ClientException e) {
@@ -547,7 +550,7 @@ public class VerifyUtils {
}
public static void waitReceiveThenAckAsync(RMQNormalProducer producer, SimpleConsumer consumer, int maxMessageNum,
- Duration invisibleDuration) {
+ Duration invisibleDuration) {
long endTime = System.currentTimeMillis() + TIMEOUT * 1000;
List<Runnable> runnables = new ArrayList<>();
Collection<Object> sendCollection = Collections.synchronizedCollection(producer.getEnqueueMessages().getAllData());
@@ -562,7 +565,7 @@ public class VerifyUtils {
for (MessageView messageView : messageViews) {
receivedIndex.getAndIncrement();
log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()).toString(), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ StandardCharsets.UTF_8.decode(messageView.getBody()).toString(), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
CompletableFuture<Void> future = consumer.ackAsync(messageView);
future.thenAccept(new Consumer<Void>() {
@Override
@@ -606,7 +609,7 @@ public class VerifyUtils {
}
public static void waitReceiveThenAck(RMQNormalProducer producer, SimpleConsumer consumer, int maxMessageNum,
- Duration invisibleDuration) {
+ Duration invisibleDuration) {
long endTime = System.currentTimeMillis() + TIMEOUT * 1000;
List<Runnable> runnables = new ArrayList<>(8);
@@ -622,7 +625,7 @@ public class VerifyUtils {
for (MessageView messageView : messageViews) {
receivedIndex.getAndIncrement();
log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
consumer.ack(messageView);
sendCollection.removeIf(sendMessageId -> sendMessageId.equals(messageView.getMessageId().toString()));
}
@@ -648,8 +651,8 @@ public class VerifyUtils {
}
public static void waitFIFOReceiveThenAck(RMQNormalProducer producer, SimpleConsumer consumer,
- int maxMessageNum,
- Duration invisibleDuration) {
+ int maxMessageNum,
+ Duration invisibleDuration) {
long endTime = System.currentTimeMillis() + TIMEOUT * 1000;
Collection<Object> sendCollection = producer.getEnqueueMessages().getAllData();
ConcurrentHashMap<String, LinkedList<Object>> map = new ConcurrentHashMap<>();
@@ -660,7 +663,7 @@ public class VerifyUtils {
for (MessageView messageView : messageViews) {
receivedIndex.getAndIncrement();
log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
consumer.ack(messageView);
sendCollection.removeIf(sendMessageId -> sendMessageId.equals(messageView.getMessageId().toString()));
String shardingKey = String.valueOf(messageView.getMessageGroup());
@@ -687,145 +690,120 @@ public class VerifyUtils {
}
public static void waitReceiveAsyncThenAck(RMQNormalProducer producer, SimpleConsumer consumer,
- int maxMessageNum,
- Duration invisibleDuration) {
+ int maxMessageNum,
+ Duration invisibleDuration) {
long endTime = System.currentTimeMillis() + TIMEOUT * 1000;
Collection<Object> sendCollection = Collections.synchronizedCollection(producer.getEnqueueMessages().getAllData());
-
- List<Runnable> runnables = new ArrayList<>();
- for (int i = 0; i < defaultSimpleThreadNums; i++) {
- runnables.add(new Runnable() {
+ ExecutorService executorService = Executors.newFixedThreadPool(4);
+ while (endTime > System.currentTimeMillis()) {
+ if (sendCollection.size() == 0) {
+ break;
+ }
+ final CompletableFuture<List<MessageView>> future = consumer.receiveAsync(maxMessageNum, invisibleDuration);
+ future.thenAcceptAsync(new Consumer<List<MessageView>>() {
@Override
- public void run() {
- while (endTime > System.currentTimeMillis()) {
- if (sendCollection.size() == 0) {
- break;
- }
- final CompletableFuture<List<MessageView>> future = consumer.receiveAsync(maxMessageNum, invisibleDuration);
- future.thenAccept(new Consumer<List<MessageView>>() {
- @Override
- public void accept(List<MessageView> messageViews) {
- log.info("Get {} message: {}", messageViews.size(), Arrays.toString(messageViews.toArray()));
- if (messageViews.size() > 0) {
- for (MessageView messageView : messageViews) {
- receivedIndex.getAndIncrement();
- log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
- try {
- consumer.ack(messageView);
- sendCollection.removeIf(sendMessageId -> sendMessageId.equals(messageView.getMessageId().toString()));
- } catch (ClientException e) {
- e.printStackTrace();
- }
- }
- log.info("Pull message: {} bar, remaining unconsumed message: {} bar", messageViews.size(), sendCollection.size());
- }
- }
- });
- future.exceptionally(new Function<Throwable, List<MessageView>>() {
- @Override
- public List<MessageView> apply(Throwable throwable) {
- throwable.printStackTrace();
-// log.info("received async failed:{}", throwable.getMessage());
- Assertions.fail(String.format("received async failed:%s", throwable.getMessage()));
- return null;
+ public void accept(List<MessageView> messageViews) {
+ log.info("Get {} message: {}", messageViews.size(), Arrays.toString(messageViews.toArray()));
+ if (messageViews.size() > 0) {
+ for (MessageView messageView : messageViews) {
+ receivedIndex.getAndIncrement();
+ log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
+ StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ try {
+ consumer.ack(messageView);
+ sendCollection.removeIf(sendMessageId -> sendMessageId.equals(messageView.getMessageId().toString()));
+ } catch (ClientException e) {
+ e.printStackTrace();
}
- });
- try {
- future.get();
- } catch (Exception e) {
- e.printStackTrace();
}
+ log.info("Pull message: {} bar, remaining unconsumed message: {} bar", messageViews.size(), sendCollection.size());
}
- Assertions.assertEquals(0, sendCollection.size(), String.format("Remaining [%s] unconsumed messages: %s", sendCollection.size(), Arrays.toString(sendCollection.toArray())));
+ }
+ }, executorService);
+ future.exceptionally(new Function<Throwable, List<MessageView>>() {
+ @Override
+ public List<MessageView> apply(Throwable throwable) {
+ throwable.printStackTrace();
+// log.info("received async failed:{}", throwable.getMessage());
+ Assertions.fail(String.format("received async failed:%s", throwable.getMessage()));
+ return null;
}
});
+ try {
+ future.get();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
-
- try {
- AssertUtils.assertConcurrent("Test Failed", runnables, TIMEOUT + 5);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ Assertions.assertEquals(0, sendCollection.size(), String.format("Remaining [%s] unconsumed messages: %s", sendCollection.size(), Arrays.toString(sendCollection.toArray())));
}
public static void waitReceiveAsyncThenAckAsync(RMQNormalProducer producer, SimpleConsumer consumer,
- int maxMessageNum, Duration invisibleDuration) {
+ int maxMessageNum, Duration invisibleDuration) {
long endTime = System.currentTimeMillis() + TIMEOUT * 1000;
Collection<Object> sendCollection = Collections.synchronizedCollection(producer.getEnqueueMessages().getAllData());
- List<Runnable> runnables = new ArrayList<>();
- for (int i = 0; i < defaultSimpleThreadNums; i++) {
- runnables.add(new Runnable() {
+ ExecutorService executorService = Executors.newFixedThreadPool(4);
+ while (endTime > System.currentTimeMillis()) {
+ if (sendCollection.size() == 0) {
+ break;
+ }
+ final CompletableFuture<List<MessageView>> future = consumer.receiveAsync(maxMessageNum, invisibleDuration);
+ future.thenAcceptAsync(new Consumer<List<MessageView>>() {
@Override
- public void run() {
- while (endTime > System.currentTimeMillis()) {
- if (sendCollection.size() == 0) {
- break;
- }
- final CompletableFuture<List<MessageView>> future = consumer.receiveAsync(maxMessageNum, invisibleDuration);
- future.thenAccept(new Consumer<List<MessageView>>() {
- @Override
- public void accept(List<MessageView> messageViews) {
- log.info("Get {} message: {}", messageViews.size(), Arrays.toString(messageViews.toArray()));
- if (messageViews.size() > 0) {
- for (MessageView messageView : messageViews) {
- receivedIndex.getAndIncrement();
- log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
- CompletableFuture<Void> ackFuture = consumer.ackAsync(messageView);
- ackFuture.thenAccept(new Consumer<Void>() {
- @Override
- public void accept(Void unused) {
- log.info("ack async success");
- sendCollection.removeIf(sendMessageId -> sendMessageId.equals(messageView.getMessageId().toString()));
- }
- });
- ackFuture.exceptionally(new Function<Throwable, Void>() {
- @Override
- public Void apply(Throwable throwable) {
- throwable.printStackTrace();
- Assertions.fail(String.format("ack async failed: %s", throwable.getMessage()));
- return null;
- }
- });
- try {
- ackFuture.get();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- log.info("Pull message: {} bar, remaining unconsumed message: {} bar", messageViews.size(), sendCollection.size());
+ public void accept(List<MessageView> messageViews) {
+ log.info("Get {} message: {}", messageViews.size(), Arrays.toString(messageViews.toArray()));
+ if (messageViews.size() > 0) {
+ for (MessageView messageView : messageViews) {
+ receivedIndex.getAndIncrement();
+ log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
+ StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ CompletableFuture<Void> ackFuture = consumer.ackAsync(messageView);
+ ackFuture.thenAccept(new Consumer<Void>() {
+ @Override
+ public void accept(Void unused) {
+ log.info("ack async success");
+ sendCollection.removeIf(sendMessageId -> sendMessageId.equals(messageView.getMessageId().toString()));
}
+ });
+ ackFuture.exceptionally(new Function<Throwable, Void>() {
+ @Override
+ public Void apply(Throwable throwable) {
+ throwable.printStackTrace();
+ Assertions.fail(String.format("ack async failed: %s", throwable.getMessage()));
+ return null;
+ }
+ });
+ try {
+ ackFuture.get();
+ } catch (Exception e) {
+ e.printStackTrace();
}
- });
- future.exceptionally(new Function<Throwable, List<MessageView>>() {
- @Override
- public List<MessageView> apply(Throwable throwable) {
- throwable.printStackTrace();
- Assertions.fail(String.format("received async failed:%s", throwable.getMessage()));
- return null;
- }
- });
- try {
- future.get();
- } catch (Exception e) {
- e.printStackTrace();
}
+ log.info("Pull message: {} bar, remaining unconsumed message: {} bar", messageViews.size(), sendCollection.size());
}
- Assertions.assertTrue(sendCollection.size() == 0, String.format("Remaining [%s] unconsumed messages: %s", sendCollection.size(), Arrays.toString(sendCollection.toArray())));
+ }
+ }, executorService);
+ future.exceptionally(new Function<Throwable, List<MessageView>>() {
+ @Override
+ public List<MessageView> apply(Throwable throwable) {
+ throwable.printStackTrace();
+ Assertions.fail(String.format("received async failed:%s", throwable.getMessage()));
+ return null;
}
});
+ try {
+ future.get();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- try {
- AssertUtils.assertConcurrent("Test Failed", runnables, TIMEOUT + 5);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ Assertions.assertTrue(sendCollection.size() == 0, String.format("Remaining [%s] unconsumed messages: %s", sendCollection.size(), Arrays.toString(sendCollection.toArray())));
+
}
public static void waitReceiveThenNack(RMQNormalProducer producer, SimpleConsumer consumer, int maxMessageNum,
- Duration receiveInvisibleDuration, Duration changeInvisibleDuration) {
+ Duration receiveInvisibleDuration, Duration changeInvisibleDuration) {
long endTime = System.currentTimeMillis() + TIMEOUT * 1000;
Collection<Object> sendCollection = producer.getEnqueueMessages().getAllData();
@@ -836,7 +814,7 @@ public class VerifyUtils {
for (MessageView messageView : messageViews) {
receivedIndex.getAndIncrement();
log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()).toString(), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ StandardCharsets.UTF_8.decode(messageView.getBody()).toString(), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
if (changeInvisibleDuration != null) {
consumer.changeInvisibleDuration(messageView, changeInvisibleDuration);
log.info("Change the invisibility duration of [{}] to (changeInvisibleDuration): {}", messageView.getMessageId().toString(), changeInvisibleDuration);
@@ -856,7 +834,7 @@ public class VerifyUtils {
}
public static void waitReceiveThenAck(RMQNormalProducer producer, SimpleConsumer consumer, int maxMessageNum,
- Duration invisibleDuration, int consumeTimes) {
+ Duration invisibleDuration, int consumeTimes) {
ConcurrentHashMap<String, Integer> msgMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Long> msgTimeMap = new ConcurrentHashMap<>();
List<Runnable> runnables = new ArrayList<>(4);
@@ -874,7 +852,7 @@ public class VerifyUtils {
for (MessageView messageView : messageViews) {
receivedIndex.getAndIncrement();
log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
String receivedMessageId = messageView.getMessageId().toString();
//Processing repeated consuming messages
@@ -926,7 +904,7 @@ public class VerifyUtils {
}
public static void waitReceiveThenAck(RMQNormalProducer producer, SimpleConsumer consumer, int maxMessageNum,
- Duration invisibleDuration, int consumeTimes, int waitTime, boolean needAck) {
+ Duration invisibleDuration, int consumeTimes, int waitTime, boolean needAck) {
ConcurrentHashMap<String, Integer> msgMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Long> msgTimeMap = new ConcurrentHashMap<>();
List<Runnable> runnables = new ArrayList<>(4);
@@ -944,7 +922,7 @@ public class VerifyUtils {
for (MessageView messageView : messageViews) {
receivedIndex.getAndIncrement();
log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
String receivedMessageId = messageView.getMessageId().toString();
//Processing repeated consuming messages
@@ -1012,7 +990,7 @@ public class VerifyUtils {
}
public static void waitDelayReceiveThenAck(RMQNormalProducer producer, SimpleConsumer consumer,
- int maxMessageNum, long delayTimeMillis) {
+ int maxMessageNum, long delayTimeMillis) {
long endTime = System.currentTimeMillis() + TIMEOUT * 1000;
Collection<Object> sendCollection = Collections.synchronizedCollection(producer.getEnqueueMessages().getAllData());
List<Runnable> runnables = new ArrayList<>();
@@ -1027,7 +1005,7 @@ public class VerifyUtils {
for (MessageView messageView : messageViews) {
receivedIndex.getAndIncrement();
log.info("MessageId:{}, Body:{}, tag:{}, Property:{}, Index:{}, Retry:{}", messageView.getMessageId(),
- StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
+ StandardCharsets.UTF_8.decode(messageView.getBody()), messageView.getTag().get(), messageView.getProperties(), receivedIndex.get(), messageView.getDeliveryAttempt());
consumer.ack(messageView);
long bornTimestamp = messageView.getBornTimestamp();
long startDeliverTime = messageView.getDeliveryTimestamp().get();
diff --git a/java/e2e/src/test/java/org/apache/rocketmq/broker/offset/ResetOffsetTest.java b/java/e2e/src/test/java/org/apache/rocketmq/broker/offset/ResetOffsetTest.java
index 0a1db0a..997f014 100644
--- a/java/e2e/src/test/java/org/apache/rocketmq/broker/offset/ResetOffsetTest.java
+++ b/java/e2e/src/test/java/org/apache/rocketmq/broker/offset/ResetOffsetTest.java
@@ -1,143 +1,143 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.rocketmq.broker.offset;
-
-import java.time.Duration;
-import java.util.Collection;
-import org.apache.rocketmq.client.apis.consumer.FilterExpression;
-import org.apache.rocketmq.client.apis.message.Message;
-import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
-import org.apache.rocketmq.client.rmq.RMQNormalProducer;
-import org.apache.rocketmq.common.attribute.TopicMessageType;
-import org.apache.rocketmq.enums.TESTSET;
-import org.apache.rocketmq.factory.ConsumerFactory;
-import org.apache.rocketmq.factory.MessageFactory;
-import org.apache.rocketmq.factory.ProducerFactory;
-import org.apache.rocketmq.frame.BaseOperate;
-import org.apache.rocketmq.listener.rmq.RMQNormalListener;
-import org.apache.rocketmq.util.NameUtils;
-import org.apache.rocketmq.util.RandomUtils;
-import org.apache.rocketmq.util.TestUtils;
-import org.apache.rocketmq.util.VerifyUtils;
-import org.apache.rocketmq.util.data.collect.DataCollector;
-import org.apache.rocketmq.util.data.collect.DataCollectorManager;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Tag(TESTSET.NORMAL)
-public class ResetOffsetTest extends BaseOperate {
- private final Logger log = LoggerFactory.getLogger(ResetOffsetTest.class);
- private String tag;
- private final static int SEND_NUM = 10;
- private RMQNormalProducer producer;
- private RMQNormalConsumer pushConsumer;
- private RMQNormalConsumer simpleConsumer;
-
- @BeforeEach
- public void setUp() {
- tag = NameUtils.getRandomTagName();
- }
-
- @AfterEach
- public void tearDown() {
- if (producer != null) {
- producer.close();
- }
- if (pushConsumer != null) {
- pushConsumer.close();
- }
- if (simpleConsumer != null) {
- simpleConsumer.close();
- }
- }
-
- @Test
- @DisplayName("Send 10 messages, reset the offset to the beginning after successful consumption, and expect to consume the 10 messages again")
- public void testResetOffsetFromBeginning() {
- String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
- String topic = getTopic(TopicMessageType.NORMAL.getValue(), methodName);
- String groupId = getGroupId(methodName);
- pushConsumer = ConsumerFactory.getRMQPushConsumer(account, topic, groupId, new FilterExpression(tag), new RMQNormalListener());
- simpleConsumer = ConsumerFactory.getRMQSimpleConsumer(account, topic, groupId, new FilterExpression(tag), Duration.ofSeconds(10));
- VerifyUtils.tryReceiveOnce(simpleConsumer.getSimpleConsumer());
-
- producer = ProducerFactory.getRMQProducer(account, topic);
- Assertions.assertNotNull(producer, "Get Producer failed");
-
- long timestamp = System.currentTimeMillis();
- TestUtils.waitForSeconds(1);
- for (int i = 0; i < SEND_NUM; i++) {
- Message message = MessageFactory.buildMessage(topic, tag, String.valueOf(i));
- producer.send(message);
- }
-
- Assertions.assertEquals(SEND_NUM, producer.getEnqueueMessages().getDataSize(), "send message failed");
-
- DataCollector enqueueMessages = DataCollectorManager.getInstance().fetchListDataCollector(RandomUtils.getStringByUUID());
- Collection<Object> collection = producer.getEnqueueMessages().getAllData();
- for (Object obj : collection) {
- enqueueMessages.addData(obj);
- }
-
- VerifyUtils.verifyNormalMessage(enqueueMessages, pushConsumer.getListener().getDequeueMessages());
- pushConsumer.getListener().getDequeueMessages().resetData();
-
- //reset offset from begin
- resetOffsetByTimestamp(groupId, topic, timestamp);
-
- VerifyUtils.verifyNormalMessage(producer.getEnqueueMessages(), pushConsumer.getListener().getDequeueMessages());
-
- pushConsumer.close();
- producer.close();
- }
-
- @Test
- @DisplayName("Send 10 messages, reset the offset to the latest after successful consumption, and expect to consume the 10 messages again")
- public void testResetOffsetFromLatest() {
- String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
- String topic = getTopic(TopicMessageType.NORMAL.getValue(), methodName);
- String groupId = getGroupId(methodName);
- simpleConsumer = ConsumerFactory.getRMQSimpleConsumer(account, topic, groupId, new FilterExpression(tag), Duration.ofSeconds(10));
- VerifyUtils.tryReceiveOnce(simpleConsumer.getSimpleConsumer());
-
- producer = ProducerFactory.getRMQProducer(account, topic);
- Assertions.assertNotNull(producer, "Get Producer failed");
-
- for (int i = 0; i < 30; i++) {
- Message message = MessageFactory.buildMessage(topic, tag, String.valueOf(i));
- producer.send(message);
- }
- Assertions.assertEquals(30, producer.getEnqueueMessages().getDataSize(), "send message failed");
-
- TestUtils.waitForSeconds(10);
- resetOffsetByTimestamp(groupId, topic, System.currentTimeMillis());
-
- pushConsumer = ConsumerFactory.getRMQPushConsumer(account, topic, groupId, new FilterExpression(tag), new RMQNormalListener());
- VerifyUtils.waitForConsumeFailed(pushConsumer.getListener().getDequeueMessages(), 30);
-
- pushConsumer.close();
- producer.close();
- }
-}
-
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one or more
+// * contributor license agreements. See the NOTICE file distributed with
+// * this work for additional information regarding copyright ownership.
+// * The ASF licenses this file to You under the Apache License, Version 2.0
+// * (the "License"); you may not use this file except in compliance with
+// * the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// */
+//
+//package org.apache.rocketmq.broker.offset;
+//
+//import java.time.Duration;
+//import java.util.Collection;
+//import org.apache.rocketmq.client.apis.consumer.FilterExpression;
+//import org.apache.rocketmq.client.apis.message.Message;
+//import org.apache.rocketmq.client.rmq.RMQNormalConsumer;
+//import org.apache.rocketmq.client.rmq.RMQNormalProducer;
+//import org.apache.rocketmq.common.attribute.TopicMessageType;
+//import org.apache.rocketmq.enums.TESTSET;
+//import org.apache.rocketmq.factory.ConsumerFactory;
+//import org.apache.rocketmq.factory.MessageFactory;
+//import org.apache.rocketmq.factory.ProducerFactory;
+//import org.apache.rocketmq.frame.BaseOperate;
+//import org.apache.rocketmq.listener.rmq.RMQNormalListener;
+//import org.apache.rocketmq.util.NameUtils;
+//import org.apache.rocketmq.util.RandomUtils;
+//import org.apache.rocketmq.util.TestUtils;
+//import org.apache.rocketmq.util.VerifyUtils;
+//import org.apache.rocketmq.util.data.collect.DataCollector;
+//import org.apache.rocketmq.util.data.collect.DataCollectorManager;
+//import org.junit.jupiter.api.AfterEach;
+//import org.junit.jupiter.api.Assertions;
+//import org.junit.jupiter.api.BeforeEach;
+//import org.junit.jupiter.api.DisplayName;
+//import org.junit.jupiter.api.Tag;
+//import org.junit.jupiter.api.Test;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//
+//@Tag(TESTSET.NORMAL)
+//public class ResetOffsetTest extends BaseOperate {
+// private final Logger log = LoggerFactory.getLogger(ResetOffsetTest.class);
+// private String tag;
+// private final static int SEND_NUM = 10;
+// private RMQNormalProducer producer;
+// private RMQNormalConsumer pushConsumer;
+// private RMQNormalConsumer simpleConsumer;
+//
+// @BeforeEach
+// public void setUp() {
+// tag = NameUtils.getRandomTagName();
+// }
+//
+// @AfterEach
+// public void tearDown() {
+// if (producer != null) {
+// producer.close();
+// }
+// if (pushConsumer != null) {
+// pushConsumer.close();
+// }
+// if (simpleConsumer != null) {
+// simpleConsumer.close();
+// }
+// }
+//
+// @Test
+// @DisplayName("Send 10 messages, reset the offset to the beginning after successful consumption, and expect to consume the 10 messages again")
+// public void testResetOffsetFromBeginning() {
+// String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
+// String topic = getTopic(TopicMessageType.NORMAL.getValue(), methodName);
+// String groupId = getGroupId(methodName);
+// pushConsumer = ConsumerFactory.getRMQPushConsumer(account, topic, groupId, new FilterExpression(tag), new RMQNormalListener());
+// simpleConsumer = ConsumerFactory.getRMQSimpleConsumer(account, topic, groupId, new FilterExpression(tag), Duration.ofSeconds(10));
+// VerifyUtils.tryReceiveOnce(simpleConsumer.getSimpleConsumer());
+//
+// producer = ProducerFactory.getRMQProducer(account, topic);
+// Assertions.assertNotNull(producer, "Get Producer failed");
+//
+// long timestamp = System.currentTimeMillis();
+// TestUtils.waitForSeconds(1);
+// for (int i = 0; i < SEND_NUM; i++) {
+// Message message = MessageFactory.buildMessage(topic, tag, String.valueOf(i));
+// producer.send(message);
+// }
+//
+// Assertions.assertEquals(SEND_NUM, producer.getEnqueueMessages().getDataSize(), "send message failed");
+//
+// DataCollector enqueueMessages = DataCollectorManager.getInstance().fetchListDataCollector(RandomUtils.getStringByUUID());
+// Collection<Object> collection = producer.getEnqueueMessages().getAllData();
+// for (Object obj : collection) {
+// enqueueMessages.addData(obj);
+// }
+//
+// VerifyUtils.verifyNormalMessage(enqueueMessages, pushConsumer.getListener().getDequeueMessages());
+// pushConsumer.getListener().getDequeueMessages().resetData();
+//
+// //reset offset from begin
+// resetOffsetByTimestamp(groupId, topic, timestamp);
+//
+// VerifyUtils.verifyNormalMessage(producer.getEnqueueMessages(), pushConsumer.getListener().getDequeueMessages());
+//
+// pushConsumer.close();
+// producer.close();
+// }
+//
+// @Test
+// @DisplayName("Send 10 messages, reset the offset to the latest after successful consumption, and expect to consume the 10 messages again")
+// public void testResetOffsetFromLatest() {
+// String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
+// String topic = getTopic(TopicMessageType.NORMAL.getValue(), methodName);
+// String groupId = getGroupId(methodName);
+// simpleConsumer = ConsumerFactory.getRMQSimpleConsumer(account, topic, groupId, new FilterExpression(tag), Duration.ofSeconds(10));
+// VerifyUtils.tryReceiveOnce(simpleConsumer.getSimpleConsumer());
+//
+// producer = ProducerFactory.getRMQProducer(account, topic);
+// Assertions.assertNotNull(producer, "Get Producer failed");
+//
+// for (int i = 0; i < 30; i++) {
+// Message message = MessageFactory.buildMessage(topic, tag, String.valueOf(i));
+// producer.send(message);
+// }
+// Assertions.assertEquals(30, producer.getEnqueueMessages().getDataSize(), "send message failed");
+//
+// TestUtils.waitForSeconds(10);
+// resetOffsetByTimestamp(groupId, topic, System.currentTimeMillis());
+//
+// pushConsumer = ConsumerFactory.getRMQPushConsumer(account, topic, groupId, new FilterExpression(tag), new RMQNormalListener());
+// VerifyUtils.waitForConsumeFailed(pushConsumer.getListener().getDequeueMessages(), 30);
+//
+// pushConsumer.close();
+// producer.close();
+// }
+//}
+//
diff --git a/java/e2e/src/test/java/org/apache/rocketmq/broker/simple/SimpleAckTest.java b/java/e2e/src/test/java/org/apache/rocketmq/broker/simple/SimpleAckTest.java
index 8bea2a5..bdc1105 100644
--- a/java/e2e/src/test/java/org/apache/rocketmq/broker/simple/SimpleAckTest.java
+++ b/java/e2e/src/test/java/org/apache/rocketmq/broker/simple/SimpleAckTest.java
@@ -17,7 +17,6 @@
package org.apache.rocketmq.broker.simple;
-import java.time.Duration;
import org.apache.rocketmq.client.apis.consumer.FilterExpression;
import org.apache.rocketmq.client.apis.consumer.SimpleConsumer;
import org.apache.rocketmq.client.apis.message.Message;
@@ -42,6 +41,8 @@ import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.time.Duration;
+
@Tag(TESTSET.NORMAL)
@Tag(TESTSET.SIMPLE)
public class SimpleAckTest extends BaseOperate {
@@ -69,7 +70,7 @@ public class SimpleAckTest extends BaseOperate {
@Test
@Timeout(180)
- @DisplayName("Send 20 normal messages synchronously and expect SimpleConsumer to receive() and ack() messages normally")
+ @DisplayName("Send 20 normal messages synchronously and expect consume with receive() and ack() messages successful")
public void testNormal_simple_receive_ack() {
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
@@ -90,7 +91,7 @@ public class SimpleAckTest extends BaseOperate {
}
@Test
- @DisplayName("Send 20 normal messages synchronously. Expect SimpleConsumer to receive normal receiveAsync() and ack() messages")
+ @DisplayName("Send 20 normal messages synchronously. Expect consume with receiveAsync() and ack() messages successful")
public void testNormal_simple_receiveAsync_ack() {
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
String topic = getTopic(TopicMessageType.NORMAL.getValue(), methodName);
@@ -112,7 +113,7 @@ public class SimpleAckTest extends BaseOperate {
@Test
@Timeout(180)
- @DisplayName("Send 20 normal messages synchronously and expect SimpleConsumer to receive() and ackAsync() messages normally")
+ @DisplayName("Send 20 normal messages synchronously and expect consume with receive() and ackAsync() messages successful")
public void testNormal_simple_receive_ackAsync() {
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
String topic = getTopic(TopicMessageType.NORMAL.getValue(), methodName);
@@ -134,7 +135,7 @@ public class SimpleAckTest extends BaseOperate {
@Test
@Timeout(180)
- @DisplayName("Send 20 normal messages synchronously. Expect SimpleConsumer to receive normal receiveAsync() and ackAsync() messages")
+ @DisplayName("Send 20 normal messages synchronously. Expect consume with receiveAsync() and ackAsync() messages successful")
public void testNormal_simple_receiveAsync_ackAsync() {
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
String topic = getTopic(TopicMessageType.NORMAL.getValue(), methodName);
diff --git a/java/e2e/src/test/resources/env/daily/daily.conf b/java/e2e/src/test/resources/env/daily/daily.conf
index 413c52e..3c2e30e 100644
--- a/java/e2e/src/test/resources/env/daily/daily.conf
+++ b/java/e2e/src/test/resources/env/daily/daily.conf
@@ -1,6 +1,6 @@
aclEnable = false
-namesrvAddr = 11.165.235.102:9876
-endPoint = 11.165.235.102:8081
+namesrvAddr = 127.0.0.1:9876
+endPoint = 127.0.0.1:8081
# cluster
cluster = DefaultCluster
\ No newline at end of file
diff --git a/java/pom.xml b/java/pom.xml
index 9f48a5c..444f170 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -10,12 +10,60 @@
<version>1.0-SNAPSHOT</version>
<modules>
<module>e2e</module>
+ <module>e2e-v4</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <junit.jupiter.version>5.7.2</junit.jupiter.version>
</properties>
+
+ <dependencies>
+ <!--junit5-->
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-launcher</artifactId>
+ <version>1.7.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>${junit.jupiter.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit.jupiter.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <version>${junit.jupiter.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>2.0.0-beta1</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.3.0-beta0</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>1.3.0-beta0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.8</version>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file