This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch SCB-1597 in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git
commit 6ae83b96e3ed4a34fd181c5a1447c5f3cbb22bd2 Author: Willem Jiang <[email protected]> AuthorDate: Sun Nov 17 20:06:51 2019 +0800 SCB-1597 Clean up the code of acceptance-tests --- .../acceptance-pack-akka-spring-demo/pom.xml | 49 +------ .../org/apache/servicecomb/pack/PackStepdefs.java | 77 +---------- .../acceptance-pack-cluster-spring-demo/pom.xml | 48 +------ .../org/apache/servicecomb/pack/PackStepdefs.java | 133 +----------------- .../acceptance-pack-dubbo-demo/pom.xml | 11 +- .../acceptance/dubbodemo/DubboDemoStepdefs.java | 69 +--------- .../pom.xml | 48 +------ .../org/apache/servicecomb/pack/PackStepdefs.java | 82 +---------- .../acceptance-pack-spring-demo-with-nacos/pom.xml | 48 +------ .../org/apache/servicecomb/pack/PackStepdefs.java | 76 +--------- .../pom.xml | 48 +------ .../org/apache/servicecomb/pack/PackStepdefs.java | 82 +---------- .../acceptance-pack-spring-demo/pom.xml | 48 +------ .../acceptance-pack-tcc-spring-demo/pom.xml | 43 +----- .../org/apache/servicecomb/pack/PackStepdefs.java | 72 +--------- acceptance-tests/acceptance-test-common/pom.xml | 31 +++++ .../apache/servicecomb/pack/StepDefSupport.java} | 153 ++++----------------- acceptance-tests/pom.xml | 126 +++++++++++++++-- 18 files changed, 207 insertions(+), 1037 deletions(-) diff --git a/acceptance-tests/acceptance-pack-akka-spring-demo/pom.xml b/acceptance-tests/acceptance-pack-akka-spring-demo/pom.xml index dde0a3b..b8aadd0 100644 --- a/acceptance-tests/acceptance-pack-akka-spring-demo/pom.xml +++ b/acceptance-tests/acceptance-pack-akka-spring-demo/pom.xml @@ -31,56 +31,13 @@ <dependencies> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.byteman</groupId> - <artifactId>byteman-submit</artifactId> - <version>${byteman.version}</version> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <type>test-jar</type> </dependency> </dependencies> - <profiles> <profile> - <id>jdk9</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <!-- TODO using jdk argLine to get rid of the jaxb dependencies --> - <properties> - <jdk.argLine>--add-modules java.xml.bind</jdk.argLine> - </properties> - <dependencies> - <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>javax.activation</groupId> - <artifactId>activation</artifactId> - <version>${javax.activation.version}</version> - </dependency> - </dependencies> - </profile> - <profile> <id>docker</id> <activation> <file> diff --git a/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java b/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java index 19c1487..533cdad 100644 --- a/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java +++ b/acceptance-tests/acceptance-pack-akka-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java @@ -40,21 +40,15 @@ import cucumber.api.DataTable; import cucumber.api.java.After; import cucumber.api.java8.En; -public class PackStepdefs implements En { +public class PackStepdefs extends StepDefSupport { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String ALPHA_REST_ADDRESS = "alpha.rest.address"; private static final String CAR_SERVICE_ADDRESS = "car.service.address"; private static final String HOTEL_SERVICE_ADDRESS = "hotel.service.address"; private static final String BOOKING_SERVICE_ADDRESS = "booking.service.address"; - private static final String INFO_SERVICE_URI = "info.service.uri"; private static final String[] addresses = {CAR_SERVICE_ADDRESS, HOTEL_SERVICE_ADDRESS}; - private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { - }; - - private static final Map<String, Submit> submits = new HashMap<>(); - public PackStepdefs() { String[] globalTxId = new String[1]; @@ -141,73 +135,4 @@ public class PackStepdefs implements En { } } } - - @SuppressWarnings("unchecked") - private void dataMatches(String address, DataTable dataTable, Consumer<Map<String, String>[]> dataProcessor) { - List<Map<String, String>> expectedMaps = dataTable.asMaps(String.class, String.class); - List<Map<String, String>> actualMaps = new ArrayList<>(); - - await().atMost(10, SECONDS).until(() -> { - actualMaps.clear(); - Collections.addAll(actualMaps, retrieveDataMaps(address, dataProcessor)); - // write the log if the Map size is not same - boolean result = expectedMaps.size() == actualMaps.size(); - if (!result) { - LOG.warn("The response message size is not we expected. ExpectedMap size is {}, ActualMap size is {}", expectedMaps.size(), actualMaps.size()); - } - return expectedMaps.size() == actualMaps.size(); - }); - - if (expectedMaps.isEmpty() && actualMaps.isEmpty()) { - return; - } - - LOG.info("Retrieved data {} from service", actualMaps); - dataTable.diff(DataTable.create(actualMaps)); - } - - @SuppressWarnings("unchecked") - private Map<String, String>[] retrieveDataMaps(String address, Consumer<Map<String, String>[]> dataProcessor) { - Map<String, String>[] dataMap = given() - .when() - .get(address) - .then() - .statusCode(is(200)) - .extract() - .body() - .as(Map[].class); - - dataProcessor.accept(dataMap); - return dataMap; - } - - private void probe(String address) { - String infoURI = System.getProperty(INFO_SERVICE_URI); - if (isEmpty(infoURI)) { - infoURI = "/info"; - } - LOG.info("The info service uri is " + infoURI); - probe(address, infoURI); - } - - private void probe(String address, String infoURI) { - LOG.info("Connecting to service address {}", address); - given() - .when() - .get(address + infoURI) - .then() - .statusCode(is(200)); - } - - private Submit getBytemanSubmit(String service) { - if (submits.containsKey(service)) { - return submits.get(service); - } else { - String address = System.getProperty("byteman.address"); - String port = System.getProperty(service.toLowerCase() + ".byteman.port"); - Submit bm = new Submit(address, Integer.parseInt(port)); - submits.put(service, bm); - return bm; - } - } } diff --git a/acceptance-tests/acceptance-pack-cluster-spring-demo/pom.xml b/acceptance-tests/acceptance-pack-cluster-spring-demo/pom.xml index 60fb6fe..c62299c 100644 --- a/acceptance-tests/acceptance-pack-cluster-spring-demo/pom.xml +++ b/acceptance-tests/acceptance-pack-cluster-spring-demo/pom.xml @@ -31,56 +31,14 @@ <dependencies> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.byteman</groupId> - <artifactId>byteman-submit</artifactId> - <version>${byteman.version}</version> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <type>test-jar</type> </dependency> </dependencies> <profiles> <profile> - <id>jdk9</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <!-- TODO using jdk argLine to get rid of the jaxb dependencies --> - <properties> - <jdk.argLine>--add-modules java.xml.bind</jdk.argLine> - </properties> - <dependencies> - <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>javax.activation</groupId> - <artifactId>activation</artifactId> - <version>${javax.activation.version}</version> - </dependency> - </dependencies> - </profile> - <profile> <id>docker</id> <activation> <file> diff --git a/acceptance-tests/acceptance-pack-cluster-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java b/acceptance-tests/acceptance-pack-cluster-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java index 33c77cd..3bcf8ee 100644 --- a/acceptance-tests/acceptance-pack-cluster-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java +++ b/acceptance-tests/acceptance-pack-cluster-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java @@ -41,21 +41,16 @@ import cucumber.api.DataTable; import cucumber.api.java.After; import cucumber.api.java8.En; -public class PackStepdefs implements En { +public class PackStepdefs extends StepDefSupport { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String ALPHA_REST_ADDRESS = "alpha.rest.address"; private static final String CAR_SERVICE_ADDRESS = "car.service.address"; private static final String HOTEL_SERVICE_ADDRESS = "hotel.service.address"; private static final String BOOKING_SERVICE_ADDRESS = "booking.service.address"; - private static final String INFO_SERVICE_URI = "info.service.uri"; private static final String[] addresses = {CAR_SERVICE_ADDRESS, HOTEL_SERVICE_ADDRESS}; - private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { - }; - private static AlpahClusterAddress alphaClusterAddress; - private static final Map<String, Submit> submits = new HashMap<>(); @Before public void before() { @@ -154,130 +149,4 @@ public class PackStepdefs implements En { } } } - - @SuppressWarnings("unchecked") - private void dataMatches(String address, DataTable dataTable, Consumer<Map<String, String>[]> dataProcessor) { - List<Map<String, String>> expectedMaps = dataTable.asMaps(String.class, String.class); - List<Map<String, String>> actualMaps = new ArrayList<>(); - - await().atMost(5, SECONDS).until(() -> { - actualMaps.clear(); - Collections.addAll(actualMaps, retrieveDataMaps(address, dataProcessor)); - // write the log if the Map size is not same - boolean result = expectedMaps.size() == actualMaps.size(); - if (!result) { - LOG.warn("The response message size is not we expected. ExpectedMap size is {}, ActualMap size is {}", expectedMaps.size(), actualMaps.size()); - } - return expectedMaps.size() == actualMaps.size(); - }); - - if (expectedMaps.isEmpty() && actualMaps.isEmpty()) { - return; - } - - LOG.info("Retrieved data {} from service", actualMaps); - dataTable.diff(DataTable.create(actualMaps)); - } - - @SuppressWarnings("unchecked") - private Map<String, String>[] retrieveDataMaps(String address, Consumer<Map<String, String>[]> dataProcessor) { - Map<String, String>[] dataMap = given() - .when() - .get(address) - .then() - .statusCode(is(200)) - .extract() - .body() - .as(Map[].class); - - dataProcessor.accept(dataMap); - return dataMap; - } - - private void probe(String address) { - String infoURI = System.getProperty(INFO_SERVICE_URI); - if (isEmpty(infoURI)) { - infoURI = "/info"; - } - LOG.info("The info service uri is " + infoURI); - probe(address, infoURI); - } - - private void probe(String address, String infoURI) { - LOG.info("Connecting to service address {}", address); - given() - .when() - .get(address + infoURI) - .then() - .statusCode(is(200)); - } - - private void probeAlphaMaster(AlpahClusterAddress alphaClusterAddress) { - LOG.info("Check to Alpah Master server"); - assertNotNull(alphaClusterAddress.getMasterAddress()); - } - - private Submit getBytemanSubmit(String service) { - if (submits.containsKey(service)) { - return submits.get(service); - } else { - String address = System.getProperty("byteman.address"); - String port = System.getProperty(service.toLowerCase() + ".byteman.port"); - Submit bm = new Submit(address, Integer.parseInt(port)); - submits.put(service, bm); - return bm; - } - } - - class AlpahClusterAddress { - - private List<String> addresss; - - private int maxRetry=6; - - AlpahClusterAddress(String address) { - this.addresss = Arrays.asList(address.split(",")); - } - - public List<String> getAddresss() { - return addresss; - } - - // get the master node in the alpha server cluster - public String getMasterAddress() { - Predicate<String> matchMasterNode = - endpoint -> matches(endpoint::toString, ofNullable("MASTER")); - Optional<String> masterAddress = Optional.empty(); - int retryCounter = 0; - while(!masterAddress.isPresent() && retryCounter<maxRetry){ - masterAddress = addresss.stream().filter(matchMasterNode).findAny(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - retryCounter++; - } - if(masterAddress.isPresent()){ - return masterAddress.get(); - }else{ - throw new RuntimeException("Max retries exception!"); - } - } - - private <T> boolean matches(Supplier<T> supplier, Optional<String> value) { - try{ - String nodeType = given().get(supplier.get() + "/alpha/api/v1/metrics").jsonPath().getString("nodeType"); - LOG.info("Check alpha server {} nodeType is {}",supplier.get(),nodeType); - if (value.get().equalsIgnoreCase(nodeType)) { - return true; - } else { - return false; - } - }catch (Exception ex){ - LOG.info("Check alpha server {} nodeType fail, {}",supplier.get(),ex.getMessage()); - return false; - } - } - } } diff --git a/acceptance-tests/acceptance-pack-dubbo-demo/pom.xml b/acceptance-tests/acceptance-pack-dubbo-demo/pom.xml index 580b362..cd0cf68 100644 --- a/acceptance-tests/acceptance-pack-dubbo-demo/pom.xml +++ b/acceptance-tests/acceptance-pack-dubbo-demo/pom.xml @@ -30,14 +30,9 @@ <dependencies> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <type>test-jar</type> </dependency> </dependencies> diff --git a/acceptance-tests/acceptance-pack-dubbo-demo/src/test/java/org/apache/servicecomb/pack/acceptance/dubbodemo/DubboDemoStepdefs.java b/acceptance-tests/acceptance-pack-dubbo-demo/src/test/java/org/apache/servicecomb/pack/acceptance/dubbodemo/DubboDemoStepdefs.java index 810073f..690f706 100644 --- a/acceptance-tests/acceptance-pack-dubbo-demo/src/test/java/org/apache/servicecomb/pack/acceptance/dubbodemo/DubboDemoStepdefs.java +++ b/acceptance-tests/acceptance-pack-dubbo-demo/src/test/java/org/apache/servicecomb/pack/acceptance/dubbodemo/DubboDemoStepdefs.java @@ -19,7 +19,6 @@ package org.apache.servicecomb.pack.acceptance.dubbodemo; import static io.restassured.RestAssured.given; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.awaitility.Awaitility.await; import static org.hamcrest.core.Is.is; @@ -30,6 +29,7 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; +import org.apache.servicecomb.pack.StepDefSupport; import org.hamcrest.core.StringContains; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +39,7 @@ import cucumber.api.DataTable; import cucumber.api.java.Before; import cucumber.api.java8.En; -public class DubboDemoStepdefs implements En { +public class DubboDemoStepdefs extends StepDefSupport { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String ALPHA_REST_ADDRESS = "alpha.rest.address"; @@ -50,10 +50,6 @@ public class DubboDemoStepdefs implements En { private static final String SERVICEC_ADDRESS = "servicec.address"; - private static final String INFO_SERVICE_URI = "info.service.uri"; - - private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { - }; public DubboDemoStepdefs() { Given("^ServiceA is up and running$", () -> probe(System.getProperty(SERVICEA_ADDRESS))); @@ -76,9 +72,9 @@ public class DubboDemoStepdefs implements En { }); Then("^Alpha records the following events$", (DataTable dataTable) -> { - Consumer<Map<String, Object>[]> sortAndColumnStrippingConsumer = dataMaps -> { + Consumer<Map<String, String>[]> sortAndColumnStrippingConsumer = dataMaps -> { //blur match: service for sagaEndedEvent may be unable to que - for (Map<String, Object> dataMap : dataMaps) { + for (Map<String, String> dataMap : dataMaps) { if (dataMap.values().contains("SagaEndedEvent")) { for (String key : dataMap.keySet()) { if ("SagaEndedEvent".equals(dataMap.get(key))) { @@ -89,7 +85,7 @@ public class DubboDemoStepdefs implements En { } } //strip columns - for (Map<String, Object> map : dataMaps) { + for (Map<String, String> map : dataMaps) { map.keySet().retainAll(dataTable.topCells()); } }; @@ -98,8 +94,8 @@ public class DubboDemoStepdefs implements En { }); And("^(service[a-c]+) success update status$", (String serviceName, DataTable dataTable) -> { - Consumer<Map<String, Object>[]> columnStrippingConsumer = dataMap -> { - for (Map<String, Object> map : dataMap) { + Consumer<Map<String, String>[]> columnStrippingConsumer = dataMap -> { + for (Map<String, String> map : dataMap) { map.keySet().retainAll(dataTable.topCells()); } }; @@ -120,56 +116,5 @@ public class DubboDemoStepdefs implements En { .statusCode(is(200)); } - @SuppressWarnings("unchecked") - private void dataMatches(String address, DataTable dataTable, Consumer<Map<String, Object>[]> dataProcessor) { - List<Map<String, Object>> expectedMaps = dataTable.asMaps(String.class, Object.class); - List<Map<String, Object>> actualMaps = new ArrayList<>(); - - await().atMost(8, SECONDS).until(() -> { - actualMaps.clear(); - Collections.addAll(actualMaps, retrieveDataMaps(address, dataProcessor)); - - return expectedMaps.size() == actualMaps.size(); - }); - - if (expectedMaps.isEmpty() && actualMaps.isEmpty()) { - return; - } - - LOG.info("Retrieved data {} from service", actualMaps); - dataTable.unorderedDiff(DataTable.create(actualMaps)); - } - - @SuppressWarnings("unchecked") - private Map<String, Object>[] retrieveDataMaps(String address, Consumer<Map<String, Object>[]> dataProcessor) { - Map<String, Object>[] dataMap = given() - .when() - .get(address) - .then() - .statusCode(is(200)) - .extract() - .body() - .as(Map[].class); - dataProcessor.accept(dataMap); - return dataMap; - } - - private void probe(String address) { - String infoURI = System.getProperty(INFO_SERVICE_URI); - if (isEmpty(infoURI)) { - infoURI = "/info"; - } - LOG.info("The info service uri is " + infoURI); - probe(address, infoURI); - } - - private void probe(String address, String infoURI) { - LOG.info("Connecting to service address {}", address); - given() - .when() - .get(address + infoURI) - .then() - .statusCode(is(200)); - } } diff --git a/acceptance-tests/acceptance-pack-spring-demo-with-consul/pom.xml b/acceptance-tests/acceptance-pack-spring-demo-with-consul/pom.xml index 83908ac..5a7bbe7 100644 --- a/acceptance-tests/acceptance-pack-spring-demo-with-consul/pom.xml +++ b/acceptance-tests/acceptance-pack-spring-demo-with-consul/pom.xml @@ -31,56 +31,14 @@ <dependencies> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.byteman</groupId> - <artifactId>byteman-submit</artifactId> - <version>${byteman.version}</version> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <type>test-jar</type> </dependency> </dependencies> <profiles> <profile> - <id>jdk9</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <!-- TODO using jdk argLine to get rid of the jaxb dependencies --> - <properties> - <jdk.argLine>--add-modules java.xml.bind</jdk.argLine> - </properties> - <dependencies> - <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>javax.activation</groupId> - <artifactId>activation</artifactId> - <version>${javax.activation.version}</version> - </dependency> - </dependencies> - </profile> - <profile> <id>docker</id> <activation> <file> diff --git a/acceptance-tests/acceptance-pack-spring-demo-with-consul/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java b/acceptance-tests/acceptance-pack-spring-demo-with-consul/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java index 711edd2..795c6c5 100644 --- a/acceptance-tests/acceptance-pack-spring-demo-with-consul/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java +++ b/acceptance-tests/acceptance-pack-spring-demo-with-consul/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java @@ -18,15 +18,10 @@ package org.apache.servicecomb.pack; import static io.restassured.RestAssured.given; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.commons.lang3.StringUtils.isEmpty; -import static org.awaitility.Awaitility.await; import static org.hamcrest.core.Is.is; import java.lang.invoke.MethodHandles; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -38,23 +33,16 @@ import org.slf4j.LoggerFactory; import io.restassured.response.Response; import cucumber.api.DataTable; import cucumber.api.java.After; -import cucumber.api.java8.En; -public class PackStepdefs implements En { +public class PackStepdefs extends StepDefSupport { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String ALPHA_REST_ADDRESS = "alpha.rest.address"; private static final String CAR_SERVICE_ADDRESS = "car.service.address"; private static final String HOTEL_SERVICE_ADDRESS = "hotel.service.address"; private static final String BOOKING_SERVICE_ADDRESS = "booking.service.address"; - private static final String INFO_SERVICE_URI = "info.service.uri"; private static final String[] addresses = {CAR_SERVICE_ADDRESS, HOTEL_SERVICE_ADDRESS}; - private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { - }; - - private static final Map<String, Submit> submits = new HashMap<>(); - public PackStepdefs() { Given("^Car Service is up and running$", () -> { probe(System.getProperty(CAR_SERVICE_ADDRESS)); @@ -140,72 +128,4 @@ public class PackStepdefs implements En { } } - @SuppressWarnings("unchecked") - private void dataMatches(String address, DataTable dataTable, Consumer<Map<String, String>[]> dataProcessor) { - List<Map<String, String>> expectedMaps = dataTable.asMaps(String.class, String.class); - List<Map<String, String>> actualMaps = new ArrayList<>(); - - await().atMost(5, SECONDS).until(() -> { - actualMaps.clear(); - Collections.addAll(actualMaps, retrieveDataMaps(address, dataProcessor)); - // write the log if the Map size is not same - boolean result = expectedMaps.size() == actualMaps.size(); - if (!result) { - LOG.warn("The response message size is not we expected. ExpectedMap size is {}, ActualMap size is {}", expectedMaps.size(), actualMaps.size()); - } - return expectedMaps.size() == actualMaps.size(); - }); - - if (expectedMaps.isEmpty() && actualMaps.isEmpty()) { - return; - } - - LOG.info("Retrieved data {} from service", actualMaps); - dataTable.diff(DataTable.create(actualMaps)); - } - - @SuppressWarnings("unchecked") - private Map<String, String>[] retrieveDataMaps(String address, Consumer<Map<String, String>[]> dataProcessor) { - Map<String, String>[] dataMap = given() - .when() - .get(address) - .then() - .statusCode(is(200)) - .extract() - .body() - .as(Map[].class); - - dataProcessor.accept(dataMap); - return dataMap; - } - - private void probe(String address) { - String infoURI = System.getProperty(INFO_SERVICE_URI); - if (isEmpty(infoURI)) { - infoURI = "/info"; - } - LOG.info("The info service uri is " + infoURI); - probe(address, infoURI); - } - - private void probe(String address, String infoURI) { - LOG.info("Connecting to service address {}", address); - given() - .when() - .get(address + infoURI) - .then() - .statusCode(is(200)); - } - - private Submit getBytemanSubmit(String service) { - if (submits.containsKey(service)) { - return submits.get(service); - } else { - String address = System.getProperty("byteman.address"); - String port = System.getProperty(service.toLowerCase() + ".byteman.port"); - Submit bm = new Submit(address, Integer.parseInt(port)); - submits.put(service, bm); - return bm; - } - } } diff --git a/acceptance-tests/acceptance-pack-spring-demo-with-nacos/pom.xml b/acceptance-tests/acceptance-pack-spring-demo-with-nacos/pom.xml index 7ec46ba..47a5832 100644 --- a/acceptance-tests/acceptance-pack-spring-demo-with-nacos/pom.xml +++ b/acceptance-tests/acceptance-pack-spring-demo-with-nacos/pom.xml @@ -31,56 +31,14 @@ <dependencies> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.byteman</groupId> - <artifactId>byteman-submit</artifactId> - <version>${byteman.version}</version> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <type>test-jar</type> </dependency> </dependencies> <profiles> <profile> - <id>jdk9</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <!-- TODO using jdk argLine to get rid of the jaxb dependencies --> - <properties> - <jdk.argLine>--add-modules java.xml.bind</jdk.argLine> - </properties> - <dependencies> - <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>javax.activation</groupId> - <artifactId>activation</artifactId> - <version>${javax.activation.version}</version> - </dependency> - </dependencies> - </profile> - <profile> <id>docker</id> <activation> <file> diff --git a/acceptance-tests/acceptance-pack-spring-demo-with-nacos/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java b/acceptance-tests/acceptance-pack-spring-demo-with-nacos/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java index 711edd2..8ff4165 100644 --- a/acceptance-tests/acceptance-pack-spring-demo-with-nacos/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java +++ b/acceptance-tests/acceptance-pack-spring-demo-with-nacos/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java @@ -40,21 +40,15 @@ import cucumber.api.DataTable; import cucumber.api.java.After; import cucumber.api.java8.En; -public class PackStepdefs implements En { +public class PackStepdefs extends StepDefSupport { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String ALPHA_REST_ADDRESS = "alpha.rest.address"; private static final String CAR_SERVICE_ADDRESS = "car.service.address"; private static final String HOTEL_SERVICE_ADDRESS = "hotel.service.address"; private static final String BOOKING_SERVICE_ADDRESS = "booking.service.address"; - private static final String INFO_SERVICE_URI = "info.service.uri"; private static final String[] addresses = {CAR_SERVICE_ADDRESS, HOTEL_SERVICE_ADDRESS}; - private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { - }; - - private static final Map<String, Submit> submits = new HashMap<>(); - public PackStepdefs() { Given("^Car Service is up and running$", () -> { probe(System.getProperty(CAR_SERVICE_ADDRESS)); @@ -140,72 +134,4 @@ public class PackStepdefs implements En { } } - @SuppressWarnings("unchecked") - private void dataMatches(String address, DataTable dataTable, Consumer<Map<String, String>[]> dataProcessor) { - List<Map<String, String>> expectedMaps = dataTable.asMaps(String.class, String.class); - List<Map<String, String>> actualMaps = new ArrayList<>(); - - await().atMost(5, SECONDS).until(() -> { - actualMaps.clear(); - Collections.addAll(actualMaps, retrieveDataMaps(address, dataProcessor)); - // write the log if the Map size is not same - boolean result = expectedMaps.size() == actualMaps.size(); - if (!result) { - LOG.warn("The response message size is not we expected. ExpectedMap size is {}, ActualMap size is {}", expectedMaps.size(), actualMaps.size()); - } - return expectedMaps.size() == actualMaps.size(); - }); - - if (expectedMaps.isEmpty() && actualMaps.isEmpty()) { - return; - } - - LOG.info("Retrieved data {} from service", actualMaps); - dataTable.diff(DataTable.create(actualMaps)); - } - - @SuppressWarnings("unchecked") - private Map<String, String>[] retrieveDataMaps(String address, Consumer<Map<String, String>[]> dataProcessor) { - Map<String, String>[] dataMap = given() - .when() - .get(address) - .then() - .statusCode(is(200)) - .extract() - .body() - .as(Map[].class); - - dataProcessor.accept(dataMap); - return dataMap; - } - - private void probe(String address) { - String infoURI = System.getProperty(INFO_SERVICE_URI); - if (isEmpty(infoURI)) { - infoURI = "/info"; - } - LOG.info("The info service uri is " + infoURI); - probe(address, infoURI); - } - - private void probe(String address, String infoURI) { - LOG.info("Connecting to service address {}", address); - given() - .when() - .get(address + infoURI) - .then() - .statusCode(is(200)); - } - - private Submit getBytemanSubmit(String service) { - if (submits.containsKey(service)) { - return submits.get(service); - } else { - String address = System.getProperty("byteman.address"); - String port = System.getProperty(service.toLowerCase() + ".byteman.port"); - Submit bm = new Submit(address, Integer.parseInt(port)); - submits.put(service, bm); - return bm; - } - } } diff --git a/acceptance-tests/acceptance-pack-spring-demo-with-zookeeper/pom.xml b/acceptance-tests/acceptance-pack-spring-demo-with-zookeeper/pom.xml index 9a132da..8a8b306 100644 --- a/acceptance-tests/acceptance-pack-spring-demo-with-zookeeper/pom.xml +++ b/acceptance-tests/acceptance-pack-spring-demo-with-zookeeper/pom.xml @@ -31,56 +31,14 @@ <dependencies> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.byteman</groupId> - <artifactId>byteman-submit</artifactId> - <version>${byteman.version}</version> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <type>test-jar</type> </dependency> </dependencies> <profiles> <profile> - <id>jdk9</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <!-- TODO using jdk argLine to get rid of the jaxb dependencies --> - <properties> - <jdk.argLine>--add-modules java.xml.bind</jdk.argLine> - </properties> - <dependencies> - <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>javax.activation</groupId> - <artifactId>activation</artifactId> - <version>${javax.activation.version}</version> - </dependency> - </dependencies> - </profile> - <profile> <id>docker</id> <activation> <file> diff --git a/acceptance-tests/acceptance-pack-spring-demo-with-zookeeper/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java b/acceptance-tests/acceptance-pack-spring-demo-with-zookeeper/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java index 711edd2..795c6c5 100644 --- a/acceptance-tests/acceptance-pack-spring-demo-with-zookeeper/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java +++ b/acceptance-tests/acceptance-pack-spring-demo-with-zookeeper/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java @@ -18,15 +18,10 @@ package org.apache.servicecomb.pack; import static io.restassured.RestAssured.given; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.commons.lang3.StringUtils.isEmpty; -import static org.awaitility.Awaitility.await; import static org.hamcrest.core.Is.is; import java.lang.invoke.MethodHandles; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -38,23 +33,16 @@ import org.slf4j.LoggerFactory; import io.restassured.response.Response; import cucumber.api.DataTable; import cucumber.api.java.After; -import cucumber.api.java8.En; -public class PackStepdefs implements En { +public class PackStepdefs extends StepDefSupport { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String ALPHA_REST_ADDRESS = "alpha.rest.address"; private static final String CAR_SERVICE_ADDRESS = "car.service.address"; private static final String HOTEL_SERVICE_ADDRESS = "hotel.service.address"; private static final String BOOKING_SERVICE_ADDRESS = "booking.service.address"; - private static final String INFO_SERVICE_URI = "info.service.uri"; private static final String[] addresses = {CAR_SERVICE_ADDRESS, HOTEL_SERVICE_ADDRESS}; - private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { - }; - - private static final Map<String, Submit> submits = new HashMap<>(); - public PackStepdefs() { Given("^Car Service is up and running$", () -> { probe(System.getProperty(CAR_SERVICE_ADDRESS)); @@ -140,72 +128,4 @@ public class PackStepdefs implements En { } } - @SuppressWarnings("unchecked") - private void dataMatches(String address, DataTable dataTable, Consumer<Map<String, String>[]> dataProcessor) { - List<Map<String, String>> expectedMaps = dataTable.asMaps(String.class, String.class); - List<Map<String, String>> actualMaps = new ArrayList<>(); - - await().atMost(5, SECONDS).until(() -> { - actualMaps.clear(); - Collections.addAll(actualMaps, retrieveDataMaps(address, dataProcessor)); - // write the log if the Map size is not same - boolean result = expectedMaps.size() == actualMaps.size(); - if (!result) { - LOG.warn("The response message size is not we expected. ExpectedMap size is {}, ActualMap size is {}", expectedMaps.size(), actualMaps.size()); - } - return expectedMaps.size() == actualMaps.size(); - }); - - if (expectedMaps.isEmpty() && actualMaps.isEmpty()) { - return; - } - - LOG.info("Retrieved data {} from service", actualMaps); - dataTable.diff(DataTable.create(actualMaps)); - } - - @SuppressWarnings("unchecked") - private Map<String, String>[] retrieveDataMaps(String address, Consumer<Map<String, String>[]> dataProcessor) { - Map<String, String>[] dataMap = given() - .when() - .get(address) - .then() - .statusCode(is(200)) - .extract() - .body() - .as(Map[].class); - - dataProcessor.accept(dataMap); - return dataMap; - } - - private void probe(String address) { - String infoURI = System.getProperty(INFO_SERVICE_URI); - if (isEmpty(infoURI)) { - infoURI = "/info"; - } - LOG.info("The info service uri is " + infoURI); - probe(address, infoURI); - } - - private void probe(String address, String infoURI) { - LOG.info("Connecting to service address {}", address); - given() - .when() - .get(address + infoURI) - .then() - .statusCode(is(200)); - } - - private Submit getBytemanSubmit(String service) { - if (submits.containsKey(service)) { - return submits.get(service); - } else { - String address = System.getProperty("byteman.address"); - String port = System.getProperty(service.toLowerCase() + ".byteman.port"); - Submit bm = new Submit(address, Integer.parseInt(port)); - submits.put(service, bm); - return bm; - } - } } diff --git a/acceptance-tests/acceptance-pack-spring-demo/pom.xml b/acceptance-tests/acceptance-pack-spring-demo/pom.xml index ca944d5..9ab873e 100644 --- a/acceptance-tests/acceptance-pack-spring-demo/pom.xml +++ b/acceptance-tests/acceptance-pack-spring-demo/pom.xml @@ -31,56 +31,14 @@ <dependencies> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.byteman</groupId> - <artifactId>byteman-submit</artifactId> - <version>${byteman.version}</version> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <type>test-jar</type> </dependency> </dependencies> <profiles> <profile> - <id>jdk9</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <!-- TODO using jdk argLine to get rid of the jaxb dependencies --> - <properties> - <jdk.argLine>--add-modules java.xml.bind</jdk.argLine> - </properties> - <dependencies> - <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>javax.activation</groupId> - <artifactId>activation</artifactId> - <version>${javax.activation.version}</version> - </dependency> - </dependencies> - </profile> - <profile> <id>docker</id> <activation> <file> diff --git a/acceptance-tests/acceptance-pack-tcc-spring-demo/pom.xml b/acceptance-tests/acceptance-pack-tcc-spring-demo/pom.xml index c54afa0..6f3fbaa 100644 --- a/acceptance-tests/acceptance-pack-tcc-spring-demo/pom.xml +++ b/acceptance-tests/acceptance-pack-tcc-spring-demo/pom.xml @@ -31,51 +31,14 @@ <dependencies> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <type>test-jar</type> </dependency> </dependencies> <profiles> <profile> - <id>jdk9</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <!-- TODO using jdk argLine to get rid of the jaxb dependencies --> - <properties> - <jdk.argLine>--add-modules java.xml.bind</jdk.argLine> - </properties> - <dependencies> - <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>com.sun.xml.bind</groupId> - <artifactId>jaxb-impl</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${jaxb.version}</version> - </dependency> - <dependency> - <groupId>javax.activation</groupId> - <artifactId>activation</artifactId> - <version>${javax.activation.version}</version> - </dependency> - </dependencies> - </profile> - <profile> <id>docker</id> <activation> <file> diff --git a/acceptance-tests/acceptance-pack-tcc-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java b/acceptance-tests/acceptance-pack-tcc-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java index f5bae62..35ae648 100644 --- a/acceptance-tests/acceptance-pack-tcc-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java +++ b/acceptance-tests/acceptance-pack-tcc-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java @@ -18,15 +18,9 @@ package org.apache.servicecomb.pack; import static io.restassured.RestAssured.given; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.commons.lang3.StringUtils.isEmpty; -import static org.awaitility.Awaitility.await; import static org.hamcrest.core.Is.is; import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -36,9 +30,9 @@ import org.slf4j.LoggerFactory; import io.restassured.response.Response; import cucumber.api.DataTable; import cucumber.api.java.After; -import cucumber.api.java8.En; -public class PackStepdefs implements En { + +public class PackStepdefs extends StepDefSupport { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final String ALPHA_REST_ADDRESS = "alpha.rest.address"; @@ -47,13 +41,9 @@ public class PackStepdefs implements En { private static final String ORDERING_SERVICE_ADDRESS = "ordering.service.address"; private static final String INVENTORY_ORDERS_URI = "/orderings"; private static final String PAYMENT_ORDERS_URI = "/transactions"; - private static final String INFO_SERVICE_URI = "info.service.uri"; private static final String[] addresses = {INVENTORY_SERVICE_ADDRESS, PAYMENT_SERVICE_ADDRESS}; private static final String[] uris = {INVENTORY_ORDERS_URI, PAYMENT_ORDERS_URI}; - private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { - }; - public PackStepdefs() { Given("^Inventory Service is up and running$", () -> { probe(System.getProperty(INVENTORY_SERVICE_ADDRESS)); @@ -128,62 +118,4 @@ public class PackStepdefs implements En { .statusCode(is(200)); } - - @SuppressWarnings("unchecked") - private void dataMatches(String address, DataTable dataTable, Consumer<Map<String, String>[]> dataProcessor) { - List<Map<String, String>> expectedMaps = dataTable.asMaps(String.class, String.class); - List<Map<String, String>> actualMaps = new ArrayList<>(); - - await().atMost(5, SECONDS).until(() -> { - actualMaps.clear(); - Collections.addAll(actualMaps, retrieveDataMaps(address, dataProcessor)); - // write the log if the Map size is not same - boolean result = expectedMaps.size() == actualMaps.size(); - if (!result) { - LOG.warn("The response message size is not we expected. ExpectedMap size is {}, ActualMap size is {}", expectedMaps.size(), actualMaps.size()); - } - return expectedMaps.size() == actualMaps.size(); - }); - - if (expectedMaps.isEmpty() && actualMaps.isEmpty()) { - return; - } - - LOG.info("Retrieved data {} from service", actualMaps); - dataTable.diff(DataTable.create(actualMaps)); - } - - @SuppressWarnings("unchecked") - private Map<String, String>[] retrieveDataMaps(String address, Consumer<Map<String, String>[]> dataProcessor) { - Map<String, String>[] dataMap = given() - .when() - .get(address) - .then() - .statusCode(is(200)) - .extract() - .body() - .as(Map[].class); - - dataProcessor.accept(dataMap); - return dataMap; - } - - private void probe(String address) { - String infoURI = System.getProperty(INFO_SERVICE_URI); - if (isEmpty(infoURI)) { - infoURI = "/info"; - } - LOG.info("The info service uri is " + infoURI); - probe(address, infoURI); - } - - private void probe(String address, String infoURI) { - LOG.info("Connecting to service address {}", address); - given() - .when() - .get(address + infoURI) - .then() - .statusCode(is(200)); - } - } diff --git a/acceptance-tests/acceptance-test-common/pom.xml b/acceptance-tests/acceptance-test-common/pom.xml new file mode 100644 index 0000000..f831b80 --- /dev/null +++ b/acceptance-tests/acceptance-test-common/pom.xml @@ -0,0 +1,31 @@ +<?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. + --> +<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.pack</groupId> + <version>0.6.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>acceptance-test-common</artifactId> + <name>Pack:Acceptance Tests:Common</name> + +</project> diff --git a/acceptance-tests/acceptance-pack-cluster-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java b/acceptance-tests/acceptance-test-common/src/test/java/org/apache/servicecomb/pack/StepDefSupport.java similarity index 52% copy from acceptance-tests/acceptance-pack-cluster-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java copy to acceptance-tests/acceptance-test-common/src/test/java/org/apache/servicecomb/pack/StepDefSupport.java index 33c77cd..a424dc4 100644 --- a/acceptance-tests/acceptance-pack-cluster-spring-demo/src/test/java/org/apache/servicecomb/pack/PackStepdefs.java +++ b/acceptance-tests/acceptance-test-common/src/test/java/org/apache/servicecomb/pack/StepDefSupport.java @@ -1,4 +1,4 @@ -/* +package org.apache.servicecomb.pack;/* * 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. @@ -15,148 +15,41 @@ * limitations under the License. */ -package org.apache.servicecomb.pack; - -import static io.restassured.RestAssured.given; import static java.util.Optional.ofNullable; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.commons.lang3.StringUtils.isEmpty; +import static io.restassured.RestAssured.given; import static org.awaitility.Awaitility.await; +import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import java.lang.invoke.MethodHandles; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; -import cucumber.api.java.Before; import org.jboss.byteman.agent.submit.Submit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.restassured.response.Response; import cucumber.api.DataTable; -import cucumber.api.java.After; import cucumber.api.java8.En; -public class PackStepdefs implements En { +public class StepDefSupport implements En { private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - private static final String ALPHA_REST_ADDRESS = "alpha.rest.address"; - private static final String CAR_SERVICE_ADDRESS = "car.service.address"; - private static final String HOTEL_SERVICE_ADDRESS = "hotel.service.address"; - private static final String BOOKING_SERVICE_ADDRESS = "booking.service.address"; private static final String INFO_SERVICE_URI = "info.service.uri"; - private static final String[] addresses = {CAR_SERVICE_ADDRESS, HOTEL_SERVICE_ADDRESS}; - - private static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { + protected static final Map<String, Submit> submits = new HashMap<>(); + protected static final Consumer<Map<String, String>[]> NO_OP_CONSUMER = (dataMap) -> { }; - private static AlpahClusterAddress alphaClusterAddress; - private static final Map<String, Submit> submits = new HashMap<>(); - - @Before - public void before() { - alphaClusterAddress = new AlpahClusterAddress(System.getProperty(ALPHA_REST_ADDRESS)); - } - - public PackStepdefs() { - Given("^Car Service is up and running$", () -> { - probe(System.getProperty(CAR_SERVICE_ADDRESS)); - }); - - And("^Hotel Service is up and running$", () -> { - probe(System.getProperty(HOTEL_SERVICE_ADDRESS)); - }); - - And("^Booking Service is up and running$", () -> { - probe(System.getProperty(BOOKING_SERVICE_ADDRESS)); - }); - - And("^Alpha is up and running$", () -> { - probeAlphaMaster(alphaClusterAddress); - }); - - And("^Alpha cluster is up and running$", () -> { - alphaClusterAddress.getAddresss().stream().forEach(address -> { - LOG.info("Alpha address {}", address); - probe(address); - }); - LOG.info("Alpah master address {}", alphaClusterAddress.getMasterAddress()); - }); - - Given("^Install the byteman script ([A-Za-z0-9_\\.]+) to ([A-Za-z]+) Service$", (String script, String service) -> { - LOG.info("Install the byteman script {} to {} service", script, service); - List<String> rules = new ArrayList<>(); - rules.add("target/test-classes/" + script); - Submit bm = getBytemanSubmit(service); - bm.addRulesFromFiles(rules); - }); - - When("^User ([A-Za-z]+) requests to book ([0-9]+) cars and ([0-9]+) rooms (success|fail)$", (username, cars, rooms, result) -> { - LOG.info("Received request from user {} to book {} cars and {} rooms", username, cars, rooms); - - Response resp = given() - .pathParam("name", username) - .pathParam("rooms", rooms) - .pathParam("cars", cars) - .when() - .post(System.getProperty("booking.service.address") + "/booking/{name}/{rooms}/{cars}"); - if (result.equals("success")) { - resp.then().statusCode(is(200)); - } else if (result.equals("fail")) { - resp.then().statusCode(is(500)); - } - }); - - Then("^Alpha records the following events$", (DataTable dataTable) -> { - Consumer<Map<String, String>[]> columnStrippingConsumer = dataMap -> { - for (Map<String, String> map : dataMap) - map.keySet().retainAll(dataTable.topCells()); - }; - dataMatches(alphaClusterAddress.getMasterAddress() + "/saga/events", dataTable, columnStrippingConsumer); - }); - - - And("^Car Service contains the following booking orders$", (DataTable dataTable) -> { - dataMatches(System.getProperty(CAR_SERVICE_ADDRESS) + "/bookings", dataTable, NO_OP_CONSUMER); - }); - - And("^Hotel Service contains the following booking orders$", (DataTable dataTable) -> { - dataMatches(System.getProperty(HOTEL_SERVICE_ADDRESS) + "/bookings", dataTable, NO_OP_CONSUMER); - }); - } - - @After - public void cleanUp() { - LOG.info("Cleaning up services"); - for (String address : addresses) { - given() - .when() - .delete(System.getProperty(address) + "/bookings") - .then() - .statusCode(is(200)); - } - - given() - .when() - .delete(alphaClusterAddress.getMasterAddress() + "/saga/events") - .then() - .statusCode(is(200)); - - for (Submit bm : submits.values()) { - try { - bm.deleteAllRules(); - } catch (Exception e) { - LOG.warn("Fail to delete the byteman rules " + e); - } - } - } - - @SuppressWarnings("unchecked") - private void dataMatches(String address, DataTable dataTable, Consumer<Map<String, String>[]> dataProcessor) { + protected void dataMatches(String address, DataTable dataTable, Consumer<Map<String, String>[]> dataProcessor) { List<Map<String, String>> expectedMaps = dataTable.asMaps(String.class, String.class); List<Map<String, String>> actualMaps = new ArrayList<>(); @@ -180,7 +73,7 @@ public class PackStepdefs implements En { } @SuppressWarnings("unchecked") - private Map<String, String>[] retrieveDataMaps(String address, Consumer<Map<String, String>[]> dataProcessor) { + protected Map<String, String>[] retrieveDataMaps(String address, Consumer<Map<String, String>[]> dataProcessor) { Map<String, String>[] dataMap = given() .when() .get(address) @@ -194,7 +87,7 @@ public class PackStepdefs implements En { return dataMap; } - private void probe(String address) { + protected void probe(String address) { String infoURI = System.getProperty(INFO_SERVICE_URI); if (isEmpty(infoURI)) { infoURI = "/info"; @@ -212,12 +105,7 @@ public class PackStepdefs implements En { .statusCode(is(200)); } - private void probeAlphaMaster(AlpahClusterAddress alphaClusterAddress) { - LOG.info("Check to Alpah Master server"); - assertNotNull(alphaClusterAddress.getMasterAddress()); - } - - private Submit getBytemanSubmit(String service) { + protected Submit getBytemanSubmit(String service) { if (submits.containsKey(service)) { return submits.get(service); } else { @@ -229,6 +117,11 @@ public class PackStepdefs implements En { } } + protected void probeAlphaMaster(AlpahClusterAddress alphaClusterAddress) { + LOG.info("Check to Alpha Master server"); + assertNotNull(alphaClusterAddress.getMasterAddress()); + } + class AlpahClusterAddress { private List<String> addresss; @@ -246,7 +139,7 @@ public class PackStepdefs implements En { // get the master node in the alpha server cluster public String getMasterAddress() { Predicate<String> matchMasterNode = - endpoint -> matches(endpoint::toString, ofNullable("MASTER")); + endpoint -> matches(endpoint::toString, ofNullable("MASTER")); Optional<String> masterAddress = Optional.empty(); int retryCounter = 0; while(!masterAddress.isPresent() && retryCounter<maxRetry){ diff --git a/acceptance-tests/pom.xml b/acceptance-tests/pom.xml index e91e82f..0f8f3a6 100644 --- a/acceptance-tests/pom.xml +++ b/acceptance-tests/pom.xml @@ -30,6 +30,7 @@ <name>Pack:Acceptance Tests</name> <packaging>pom</packaging> <modules> + <module>acceptance-test-common</module> <module>acceptance-pack-dubbo-demo</module> <module>acceptance-pack-spring-demo</module> <module>acceptance-pack-tcc-spring-demo</module> @@ -42,21 +43,79 @@ <properties> <cucumber.version>2.3.1</cucumber.version> + <groovy.version>2.4.15</groovy.version> <info.service.uri>/actuator/info</info.service.uri> </properties> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>io.cucumber</groupId> + <artifactId>cucumber-java8</artifactId> + <version>${cucumber.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.cucumber</groupId> + <artifactId>cucumber-junit</artifactId> + <version>${cucumber.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.byteman</groupId> + <artifactId>byteman-submit</artifactId> + <version>${byteman.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + <version>${jackson.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>${jackson.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy</artifactId> + <version>${groovy.version}</version> + <scope>test</scope> + </dependency> + <!-- Added the dependency version of acceptance-test-common --> + <dependency> + <groupId>org.apache.servicecomb.pack</groupId> + <artifactId>acceptance-test-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + </dependency> + <dependency> + <groupId>org.jboss.byteman</groupId> + <artifactId>byteman-submit</artifactId> + </dependency> + <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java8</artifactId> - <version>${cucumber.version}</version> - <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> - <version>${cucumber.version}</version> - <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> @@ -65,27 +124,22 @@ <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> - <scope>test</scope> </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> <dependency> <groupId>org.awaitility</groupId> @@ -95,8 +149,58 @@ <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy</artifactId> - <version>2.4.15</version> - <scope>test</scope> </dependency> </dependencies> + + <profiles> + <profile> + <id>jdk9</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <!-- TODO using jdk argLine to get rid of the jaxb dependencies --> + <properties> + <jdk.argLine>--add-modules java.xml.bind</jdk.argLine> + </properties> + <dependencies> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>${jaxb.version}</version> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>${jaxb.version}</version> + </dependency> + <dependency> + <groupId>org.glassfish.jaxb</groupId> + <artifactId>jaxb-runtime</artifactId> + <version>${jaxb.version}</version> + </dependency> + <dependency> + <groupId>javax.activation</groupId> + <artifactId>activation</artifactId> + <version>${javax.activation.version}</version> + </dependency> + </dependencies> + </profile> + </profiles> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.2.0</version> + <executions> + <execution> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project>
