Skip to content

Commit

Permalink
[ISSUE #23]Add the design of the test case specification (#22)
Browse files Browse the repository at this point in the history
* add bdd cases demo

* Add check for delay message
  • Loading branch information
cryptoya authored Apr 21, 2023
1 parent 8e96fac commit 3ca14a6
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 18 deletions.
18 changes: 0 additions & 18 deletions bdd/normal.feature

This file was deleted.

145 changes: 145 additions & 0 deletions bdd/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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>

<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-bdd</artifactId>
<version>1.0-SNAPSHOT</version>

<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>
<cucumber.version>7.11.1</cucumber.version>
</properties>

<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.cucumber</groupId>-->
<!-- <artifactId>cucumber-junit</artifactId>-->
<!-- <version>${cucumber.version}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>verify</id>
<phase>verify</phase>
<configuration>
<configLocation>style/rmq_checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>false</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<version>0.12</version>
<configuration>
<excludes>
<exclude>.gitignore</exclude>
<exclude>.travis.yml</exclude>
<exclude>CONTRIBUTING.md</exclude>
<exclude>bin/README.md</exclude>
<exclude>.github/**</exclude>
<exclude>src/test/resources/certs/*</exclude>
<exclude>src/test/**/*.log</exclude>
<exclude>src/test/resources/META-INF/service/*</exclude>
<exclude>src/main/resources/META-INF/service/*</exclude>
<exclude>*/target/**</exclude>
<exclude>*/*.iml</exclude>
<exclude>docs/**</exclude>
<exclude>localbin/**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<rerunFailingTestsCount>1</rerunFailingTestsCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.conf</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
</project>
100 changes: 100 additions & 0 deletions bdd/src/main/java/org/apache/rocketmq/ClientInitStepdefs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package org.apache.rocketmq;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class ClientInitStepdefs {
@And("Shutdown the producer and consumer")
public void shutdownTheProducerAndConsumer() {
}

@And("Create a Producer, set the <NameServer>, <RequestTimeout>")
public void createAProducerSetTheNameServerRequestTimeout() {
}

@And("Create a Producer, set the {string}, {string}")
public void createAProducerSetThe(String nameserver, String requestTimeout) {
}

@Then("Create a message, including the {string}, {string}, {string}, and {string}")
public void createAMessageIncludingTheAnd(String arg0, String arg1, String arg2, String arg3) {
}

@When("Create a PushConsumer, set the {string}, {string}, {string}:{string}, {string}")
public void createAPushConsumerSetThe(String arg0, String arg1, String arg2, String arg3, String arg4) {

}

@And("Send {string} messages {string}")
public void sendMessages(String arg0, String arg1) {

}

@And("Shutdown the producer")
public void shutdownTheProducer() {

}

@Then("Check all messages that can be consumed within {int}s")
public void checkAllMessagesThatCanBeConsumedWithinS(int arg0) {

}

@And("A total of {int} messages are sent {string} to the {int} MessageGroups in turn")
public void aTotalOfMessagesAreSentToTheMessageGroupsInTurn(int arg0, String arg1, int arg2) {

}

@Given("Create a {string} topic:{string} if not exist, a {string} group:{string}")
public void createATopicIfNotExistAGroup(String arg0, String arg1, String arg2, String arg3) {

}

@And("Create a Producer, set the {string}, {string}, {string}")
public void createAProducerSetThe(String arg0, String arg1, String arg2) {

}

@And("Create a Producer, set the {string}, {string}, {string}, {string}")
public void createAProducerSetThe(String arg0, String arg1, String arg2, String arg3) {


}

@And("Execute transaction:{string}")
public void executeTransaction(String arg0) {

}

@Then("Check all messages send {string}")
public void checkAllMessagesSend(String arg0) {

}

@When("Create a PushConsumer, set the Endpoint\\({string}), ConsumerGroup\\({string}), SubscriptionExpression\\({string}), Topic\\({string}), MessageListener\\({string})")
public void createAPushConsumerSetTheEndpointConsumerGroupSubscriptionExpressionTopicMessageListener(String arg0, String arg1, String arg2, String arg3, String arg4) {

}

@And("Create a Producer, set the Endpoint\\({string}), RequestTimeout:\\({string}), Topic\\({string}), TransactionChecker:\\({string})")
public void createAProducerSetTheEndpointRequestTimeoutTopicTransactionChecker(String arg0, String arg1, String arg2, String arg3) {

}

@Then("Create a message, including the Topic\\({string}), SubscriptionExpression\\({string}), Key\\({string}), and Body\\({string})")
public void createAMessageIncludingTheTopicSubscriptionExpressionKeyAndBody(String arg0, String arg1, String arg2, String arg3) {

}

@And("Create a Producer, set the Endpoint\\({string}), RequestTimeout:\\({string}), Topic\\({string})")
public void createAProducerSetTheEndpointRequestTimeoutTopic(String arg0, String arg1, String arg2) {

}

@Then("Check send message failed")
public void checkSendMessageFailed() {

}
}
31 changes: 31 additions & 0 deletions bdd/src/main/java/org/apache/rocketmq/DelayStepdefs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.apache.rocketmq;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;

public class DelayStepdefs {
@And("Check consume all messages immediately")
public void checkConsumeAllMessagesImmediately() {

}

@Then("Check consume all {int} messages after {int}s\\(±{int}s)")
public void checkConsumeAllMessagesAfterSS(int arg0, int arg1, int arg2) {

}

@And("Set message {string} to {int} seconds before the current system time")
public void setMessageToSecondsBeforeTheCurrentSystemTime(String arg0, int arg1) {

}

@And("Set message {string} to {int} seconds after the current system time")
public void setMessageToSecondsAfterTheCurrentSystemTime(String arg0, int arg1) {

}

@And("Check the received message's {string} property {string} and value is expected")
public void checkTheReceivedMessageSPropertyAndValueIsExpected(String arg0, String arg1) {

}
}
33 changes: 33 additions & 0 deletions bdd/src/main/resources/delay.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Feature: Test the message transfer mode and topic type

Scenario: Send 10 messages set delivery timestamp after 30s after the current system time. Expect to consume all 10 messages after 30s
Given Create a "DELAY" topic:"random-topic" if not exist, a "Concurrently" group:"random-group"
When Create a PushConsumer, set the Endpoint("127.0.0.1:9876"), ConsumerGroup("random-group"), SubscriptionExpression("TagA"), Topic("random-topic"), MessageListener("default")
And Create a Producer, set the Endpoint("127.0.0.1:9876"), RequestTimeout:("10s"), Topic("random-topic")
Then Create a message, including the Topic("random-topic"), SubscriptionExpression("TagA"), Key("Key"), and Body("Body")
And Set message "DeliveryTimestamp" to 20 seconds before the current system time
And Send "10" messages "synchronous"
Then Check all messages that can be consumed within 60s
And Check the received message's "DeliveryTimestamp" property "isNotNull" and value is expected
And Check consume all messages immediately
And Shutdown the producer and consumer

Scenario: Send 10 messages set delivery timestamp 10s before the current system time. Expect timing does not take effect, all 10 messages can be consumed immediately
Given Create a "DELAY" topic:"random-topic" if not exist, a "Concurrently" group:"random-group"
When Create a PushConsumer, set the Endpoint("127.0.0.1:9876"), ConsumerGroup("random-group"), SubscriptionExpression("TagA"), Topic("random-topic"), MessageListener("default")
And Create a Producer, set the Endpoint("127.0.0.1:9876"), RequestTimeout:("10s"), Topic("random-topic")
Then Create a message, including the Topic("random-topic"), SubscriptionExpression("TagA"), Key("Key"), and Body("Body")
And Set message "DeliveryTimestamp" to 30 seconds after the current system time
And Send "10" messages "synchronous"
Then Check consume all 10 messages after 30s(±5s)
And Check the received message's "DeliveryTimestamp" property "isNotNull" and value is expected
And Shutdown the producer and consumer

Scenario: Send a message set delivery timestamp 24h+5s after the current system time. Expect send message failed
Given Create a "DELAY" topic:"random-topic" if not exist, a "Concurrently" group:"random-group"
And Create a Producer, set the Endpoint("127.0.0.1:9876"), RequestTimeout:("10s"), Topic("random-topic")
Then Create a message, including the Topic("random-topic"), SubscriptionExpression("TagA"), Key("Key"), and Body("Body")
And Set message "DeliveryTimestamp" to 86405 seconds after the current system time
And Send "1" messages "synchronous"
Then Check send message failed
And Shutdown the producer
15 changes: 15 additions & 0 deletions bdd/src/main/resources/normal.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Test the message transfer mode

Scenario Outline: 10 normal messages are sent synchronously and are expected to be received
Given Create a "Normal" topic:"random-topic" if not exist, a "Concurrently" group:"random-group"
When Create a PushConsumer, set the Endpoint("127.0.0.1:9876"), ConsumerGroup("random-group"), SubscriptionExpression("TagA"), Topic("random-topic"), MessageListener("default")
And Create a Producer, set the Endpoint("127.0.0.1:9876"), RequestTimeout:("10s"), Topic("random-topic")
Then Create a message, including the Topic("random-topic"), SubscriptionExpression("TagA"), Key("Key"), and Body("Body")
And Send "10" messages "<TransmissionMode>"
Then Check all messages that can be consumed within 60s
And Shutdown the producer and consumer

Examples:
| TransmissionMode |
| synchronous |
| asynchronous |
11 changes: 11 additions & 0 deletions bdd/src/main/resources/order.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Test the message transfer mode and topic type

Scenario: Send 100 messages with in 2 MessageGroup, expect consumed all messages orderly
Given Create a "FIFO" topic:"random-topic" if not exist, a "Orderly" group:"random-group"
When Create a PushConsumer, set the Endpoint("127.0.0.1:9876"), ConsumerGroup("random-group"), SubscriptionExpression("TagA"), Topic("random-topic"), MessageListener("default")
And Create a Producer, set the Endpoint("127.0.0.1:9876"), RequestTimeout:("10s"), Topic("random-topic")
Then Create a message, including the Topic("random-topic"), SubscriptionExpression("TagA"), Key("Key"), and Body("Body")
And A total of 100 messages are sent "<TransmissionMode>" to the 2 MessageGroups in turn
Then Check all messages that can be consumed within 60s
And Check each MessageGroup consumes up to 50 messages separately and is consumed orderly
And Shutdown the producer and consumer
20 changes: 20 additions & 0 deletions bdd/src/main/resources/transaction.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Test the message transfer mode

Scenario Outline: 10 transaction messages are sent synchronously and are expected to be received
Given Create a "Normal" topic:"random-topic" if not exist, a "Concurrently" group:"random-group"
When Create a PushConsumer, set the Endpoint("127.0.0.1:9876"), ConsumerGroup("random-group"), SubscriptionExpression("TagA"), Topic("random-topic"), MessageListener("default")
And Create a Producer, set the Endpoint("127.0.0.1:9876"), RequestTimeout:("10s"), Topic("random-topic"), TransactionChecker:("<TransactionChecker>")
And Create a transaction branch
Then Create a message, including the Topic("random-topic"), SubscriptionExpression("TagA"), Key("Key"), and Body("Body")
And Send a half message
And Execute transaction:"<TransactionExecutor>"
Then Check all messages send "success"
And Check all messages that can be consumed within 60s
And Shutdown the producer and consumer

Examples:
| TransactionChecker | TransactionExecutor |
| COMMIT | COMMIT |
| ROLLBACK | COMMIT |
| UNKNOWN | COMMIT |

0 comments on commit 3ca14a6

Please sign in to comment.