This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git
commit 3cc6b80b16efd85499503b91e1d933b115701ce5 Author: seanyinx <[email protected]> AuthorDate: Tue Jan 23 16:15:48 2018 +0800 SCB-237 added rudimentary steps definitions and test data Signed-off-by: seanyinx <[email protected]> --- acceptance-tests/acceptance-pack/pom.xml | 162 +++++++++++++++++++++ .../org/apache/servicecomb/saga/PackStepdefs.java | 35 +++-- .../{RunCucumberTest.java => RunCucumberIT.java} | 2 +- .../test/resources/log4j2-test.xml} | 25 ++-- .../test/resources/pack_success_scenario.feature | 24 ++- acceptance-tests/pom.xml | 20 +++ 6 files changed, 235 insertions(+), 33 deletions(-) diff --git a/acceptance-tests/acceptance-pack/pom.xml b/acceptance-tests/acceptance-pack/pom.xml index 5401ab5..67938f6 100644 --- a/acceptance-tests/acceptance-pack/pom.xml +++ b/acceptance-tests/acceptance-pack/pom.xml @@ -28,4 +28,166 @@ <artifactId>acceptance-pack</artifactId> + <profiles> + <profile> + <id>docker</id> + <build> + <plugins> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + <configuration> + <images> + <image> + <name>postgres</name> + <alias>postgres</alias> + <run> + <env> + <POSTGRES_DB>saga</POSTGRES_DB> + <POSTGRES_USER>saga</POSTGRES_USER> + <POSTGRES_PASSWORD>password</POSTGRES_PASSWORD> + </env> + <wait> + <log>database system is ready to accept connections</log> + <tcp> + <ports> + <port>5432</port> + </ports> + </tcp> + <time>60000</time> + </wait> + <ports> + <port>postgres.port:5432</port> + </ports> + </run> + </image> + <image> + <name>alpha-server:${project.version}</name> + <alias>alpha</alias> + <run> + <env> + <JAVA_OPTS> + -Dspring.profiles.active=prd + </JAVA_OPTS> + </env> + <links> + <link>postgres:postgresql.servicecomb.io</link> + </links> + <wait> + <log>Started [a-zA-Z]+ in [0-9.]+ seconds</log> + <tcp> + <ports> + <port>8080</port> + </ports> + </tcp> + <time>120000</time> + </wait> + <ports> + <port>alpha.port:8080</port> + </ports> + <dependsOn> + <dependsOn>postgres</dependsOn> + </dependsOn> + </run> + </image> + </images> + </configuration> + <executions> + <execution> + <id>start</id> + <phase>pre-integration-test</phase> + <goals> + <goal>start</goal> + </goals> + </execution> + <execution> + <id>stop</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.gmaven</groupId> + <artifactId>gmaven-plugin</artifactId> + <executions> + <execution> + <id>add-default-properties</id> + <phase>initialize</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <source> + project.properties.setProperty('docker.hostname', 'localhost') + log.info("Docker hostname is " + project.properties['docker.hostname']) + </source> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>${maven.failsafe.version}</version> + <configuration> + <systemPropertyVariables> + <alpha.cluster.address> + ${docker.hostname}:${alpha.port} + </alpha.cluster.address> + <spring.datasource.url> + jdbc:postgresql://${docker.hostname}:${postgres.port}/saga?useSSL=false + </spring.datasource.url> + </systemPropertyVariables> + <argLine>${jacoco.failsafe.argLine}</argLine> + </configuration> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>com.ethlo.persistence.tools</groupId> + <artifactId>eclipselink-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>docker-machine</id> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.gmaven</groupId> + <artifactId>gmaven-plugin</artifactId> + <executions> + <execution> + <id>add-dynamic-properties</id> + <phase>prepare-package</phase> + <goals> + <goal>execute</goal> + </goals> + <configuration> + <source> + def process = "docker-machine ip default".execute() + process.waitFor() + project.properties.setProperty('docker.hostname', process.in.text.trim()) + + log.info("Docker hostname is " + project.properties['docker.hostname']) + </source> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + </project> diff --git a/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/PackStepdefs.java b/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/PackStepdefs.java index fd98536..71c0887 100644 --- a/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/PackStepdefs.java +++ b/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/PackStepdefs.java @@ -17,29 +17,42 @@ package org.apache.servicecomb.saga; -import cucumber.api.PendingException; +import java.lang.invoke.MethodHandles; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import cucumber.api.DataTable; import cucumber.api.java8.En; public class PackStepdefs implements En { + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + public PackStepdefs() { Given("^Car Service is up and running$", () -> { - // Write code here that turns the phrase above into concrete actions - throw new PendingException(); }); And("^Hotel Service is up and running$", () -> { - // Write code here that turns the phrase above into concrete actions - throw new PendingException(); }); - When("^A booking transaction is received$", () -> { - // Write code here that turns the phrase above into concrete actions - throw new PendingException(); + When("^User ([A-Za-z]+) requests to book ([0-9]+) cars and ([0-9]+) rooms$", (username, cars, rooms) -> { + log.info("Received request from user {} to book {} cars and {} rooms", username, cars, rooms); }); - Then("^Alpha records the following events$", () -> { - // Write code here that turns the phrase above into concrete actions - throw new PendingException(); + Then("^Alpha records the following events$", (DataTable dataTable) -> { + List<Map<String, String>> maps = dataTable.asMaps(String.class, String.class); + log.info("events {}", maps); + }); + + And("^Car Service contains the following booking orders$", (DataTable dataTable) -> { + List<Map<String, String>> maps = dataTable.asMaps(String.class, String.class); + log.info("car orders {}", maps); + }); + And("^Hotel Service contains the following booking orders$", (DataTable dataTable) -> { + List<Map<String, String>> maps = dataTable.asMaps(String.class, String.class); + log.info("hotel orders {}", maps); }); } } diff --git a/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/RunCucumberTest.java b/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/RunCucumberIT.java similarity index 97% rename from acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/RunCucumberTest.java rename to acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/RunCucumberIT.java index d4e2b43..d4fc9ee 100644 --- a/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/RunCucumberTest.java +++ b/acceptance-tests/acceptance-pack/src/test/java/org/apache/servicecomb/saga/RunCucumberIT.java @@ -25,5 +25,5 @@ import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions(plugin = {"pretty", "html:target/cucumber"}, features = "src/test/resources") -public class RunCucumberTest { +public class RunCucumberIT { } diff --git a/acceptance-tests/acceptance-pack/pom.xml b/acceptance-tests/acceptance-pack/src/test/resources/log4j2-test.xml similarity index 65% copy from acceptance-tests/acceptance-pack/pom.xml copy to acceptance-tests/acceptance-pack/src/test/resources/log4j2-test.xml index 5401ab5..58924c6 100644 --- a/acceptance-tests/acceptance-pack/pom.xml +++ b/acceptance-tests/acceptance-pack/src/test/resources/log4j2-test.xml @@ -16,16 +16,15 @@ ~ limitations under the License. --> -<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"> - <parent> - <artifactId>acceptance-tests</artifactId> - <groupId>org.apache.servicecomb.saga</groupId> - <version>0.0.3-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>acceptance-pack</artifactId> - -</project> +<Configuration status="WARN"> + <Appenders> + <Console name="Console" target="SYSTEM_OUT"> + <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> + </Console> + </Appenders> + <Loggers> + <Root level="info"> + <AppenderRef ref="Console"/> + </Root> + </Loggers> +</Configuration> diff --git a/acceptance-tests/acceptance-pack/src/test/resources/pack_success_scenario.feature b/acceptance-tests/acceptance-pack/src/test/resources/pack_success_scenario.feature index 270e8ba..da233b0 100644 --- a/acceptance-tests/acceptance-pack/src/test/resources/pack_success_scenario.feature +++ b/acceptance-tests/acceptance-pack/src/test/resources/pack_success_scenario.feature @@ -4,13 +4,21 @@ Feature: Alpha records transaction events Given Car Service is up and running And Hotel Service is up and running - When A booking transaction is received + When User Sean requests to book 2 cars and 1 rooms Then Alpha records the following events - | event type | - | SagaStartedEvent | - | TxStartedEvent | - | TxEndedEvent | - | TxStartedEvent | - | TxEndedEvent | - | SagaEndedEvent | + | service name | event type | + | pack-booking | SagaStartedEvent | + | pack-car | TxStartedEvent | + | pack-car | TxEndedEvent | + | pack-hotel | TxStartedEvent | + | pack-hotel | TxEndedEvent | + | pack-booking | SagaEndedEvent | + + And Car Service contains the following booking orders + | user name | amount | confirmed | + | Sean | 2 | true | + + And Hotel Service contains the following booking orders + | user name | amount | confirmed | + | Sean | 1 | true | diff --git a/acceptance-tests/pom.xml b/acceptance-tests/pom.xml index 0c41f81..2a5f12b 100644 --- a/acceptance-tests/pom.xml +++ b/acceptance-tests/pom.xml @@ -53,6 +53,26 @@ <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> -- To stop receiving notification emails like this one, please contact [email protected].
