From d7fcde47541bf7983811435a20490bd05dad926d Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Wed, 6 Jun 2018 11:28:48 -0400 Subject: [PATCH] CF Acceptance tests: ticktock --- .../manifests/log-sink-manifest.yml | 20 ++++++ .../manifests/time-source-manifest.yml | 18 +++++ cf-acceptance-tests/runAcceptanceTests.sh | 72 +++++++++++++++++-- .../acceptance/tests/AbstractSampleTests.java | 48 ++++--------- .../tests/PartitionAcceptanceTests.java | 2 +- .../tests/TickTockAcceptanceTests.java | 50 +++++++++++++ 6 files changed, 168 insertions(+), 42 deletions(-) create mode 100644 cf-acceptance-tests/manifests/log-sink-manifest.yml create mode 100644 cf-acceptance-tests/manifests/time-source-manifest.yml create mode 100644 cf-acceptance-tests/src/test/java/sample/acceptance/tests/TickTockAcceptanceTests.java diff --git a/cf-acceptance-tests/manifests/log-sink-manifest.yml b/cf-acceptance-tests/manifests/log-sink-manifest.yml new file mode 100644 index 0000000..416c166 --- /dev/null +++ b/cf-acceptance-tests/manifests/log-sink-manifest.yml @@ -0,0 +1,20 @@ +--- +applications: +- name: ticktock-log-sink + host: ticktock-log-sink + memory: 2G + disk_quota: 2G + instances: 1 + path: /tmp/ticktock-log-sink.jar + env: +# LOGGING_FILE: ticktocklog.log +# MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE: logfile +# ENDPOINTS_LOGFILE_SENSITIVE: false +# SPRING_CLOUD_STREAM_BINDINGS_INPUT_DESTINATION: ticktock + logging.file: ticktocklog.log + endpoints.logfile.sensitive: false + spring.cloud.stream.bindings.input.destination: ticktock + #LOG_EXPRESSION: "'TICKTOCK - TIMESTAMP: '.concat(payload)" + log.expression: "'TICKTOCK - TIMESTAMP: '.concat(payload)" +services: +- scst-rabbit \ No newline at end of file diff --git a/cf-acceptance-tests/manifests/time-source-manifest.yml b/cf-acceptance-tests/manifests/time-source-manifest.yml new file mode 100644 index 0000000..c15cc4a --- /dev/null +++ b/cf-acceptance-tests/manifests/time-source-manifest.yml @@ -0,0 +1,18 @@ +--- +applications: +- name: ticktock-time-source + host: ticktock-time-source + memory: 2G + disk_quota: 2G + instances: 1 + path: /tmp/ticktock-time-source.jar + env: +# LOGGING_FILE: ticktocktime.log +# MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE: logfile +# ENDPOINTS_LOGFILE_SENSITIVE: false + logging.file: ticktocklog.log + endpoints.logfile.sensitive: false + #SPRING_CLOUD_STREAM_BINDINGS_OUTPUT_DESTINATION: ticktock + spring.cloud.stream.bindings.output.destination: ticktock +services: +- scst-rabbit \ No newline at end of file diff --git a/cf-acceptance-tests/runAcceptanceTests.sh b/cf-acceptance-tests/runAcceptanceTests.sh index 1dc983f..9542c9d 100755 --- a/cf-acceptance-tests/runAcceptanceTests.sh +++ b/cf-acceptance-tests/runAcceptanceTests.sh @@ -16,6 +16,36 @@ popd () { command popd "$@" > /dev/null } +function prepare_ticktock_with_rabbit_binder() { + + wget -O /tmp/ticktock-time-source.jar http://repo.spring.io/release/org/springframework/cloud/stream/app/time-source-rabbit/1.3.1.RELEASE/time-source-rabbit-1.3.1.RELEASE.jar + + wget -O /tmp/ticktock-log-sink.jar http://repo.spring.io/release/org/springframework/cloud/stream/app/log-sink-rabbit/1.3.1.RELEASE/log-sink-rabbit-1.3.1.RELEASE.jar + + if [ $6 == "skip-ssl-validation" ] + then + cf login -a $1 --skip-ssl-validation -u $2 -p $3 -o $4 -s $5 + else + cf login -a $1 -u $2 -p $3 -o $4 -s $5 + fi + + cf push -f ./manifests/time-source-manifest.yml + + cf app ticktock-time-source > /tmp/ticktock-time-source-route.txt + + TICKTOCK_TIME_SOURCE_ROUTE=`grep routes /tmp/ticktock-time-source-route.txt | awk '{ print $2 }'` + + FULL_TICKTOCK_TIME_SOURCE_ROUTE=http://$TICKTOCK_TIME_SOURCE_ROUTE + + cf push -f ./manifests/log-sink-manifest.yml + + cf app ticktock-log-sink > /tmp/ticktock-log-sink-route.txt + + TICKTOCK_LOG_SINK_ROUTE=`grep routes /tmp/ticktock-log-sink-route.txt | awk '{ print $2 }'` + + FULL_TICKTOCK_LOG_SINK_ROUTE=http://$TICKTOCK_LOG_SINK_ROUTE +} + function prepare_uppercase_transformer_with_rabbit_binder() { pushd ../processor-samples/uppercase-transformer @@ -38,7 +68,6 @@ function prepare_uppercase_transformer_with_rabbit_binder() { UPPERCASE_PROCESSOR_ROUTE=`grep routes /tmp/uppercase-route.txt | awk '{ print $2 }'` FULL_UPPERCASE_ROUTE=http://$UPPERCASE_PROCESSOR_ROUTE - } function prepare_partitioning_test_with_rabbit_binder() { @@ -103,15 +132,41 @@ function prepare_partitioning_test_with_rabbit_binder() { PARTITIONING_CONSUMER4_ROUTE=`grep routes /tmp/part-consumer4-route.txt | awk '{ print $2 }'` FULL_PARTITIONING_CONSUMER4_ROUTE=http://$PARTITIONING_CONSUMER4_ROUTE - } - #Main script starting SECONDS=0 -echo "Prepare artifacts for testing" +echo "Prepare artifacts for ticktock testing" + +prepare_ticktock_with_rabbit_binder $1 $2 $3 $4 $5 $6 + +./mvnw clean package -Dtest=TickTockAcceptanceTests -Dmaven.test.skip=false -Dtime.source.route=$FULL_TICKTOCK_TIME_SOURCE_ROUTE -Dlog.sink.route=$FULL_TICKTOCK_LOG_SINK_ROUTE +BUILD_RETURN_VALUE=$? + +cf stop ticktock-time-source +cf stop ticktock-log-sink + +cf delete ticktock-time-source -f +cf delete ticktock-log-sink -f + +cf logout + +rm /tmp/ticktock-time-source-route.txt +rm /tmp/ticktock-log-sink-route.txt + +if [ "$BUILD_RETURN_VALUE" != 0 ] +then + echo "Early exit due to test failure in ticktock tests" + duration=$SECONDS + + echo "Total time: Build took $(($duration / 60)) minutes and $(($duration % 60)) seconds to complete." + + exit $BUILD_RETURN_VALUE +fi + +echo "Prepare artifacts for uppercase transformer testing" prepare_uppercase_transformer_with_rabbit_binder $1 $2 $3 $4 $5 $6 @@ -128,15 +183,20 @@ rm /tmp/uppercase-route.txt if [ "$BUILD_RETURN_VALUE" != 0 ] then - echo "Early exit due to test failure" + echo "Early exit due to test failure in uppercase transformer" + duration=$SECONDS + + echo "Total time: Build took $(($duration / 60)) minutes and $(($duration % 60)) seconds to complete." + exit $BUILD_RETURN_VALUE fi -echo "Prepare artifacts for testing" +echo "Prepare artifacts for partitions testing" prepare_partitioning_test_with_rabbit_binder $1 $2 $3 $4 $5 $6 ./mvnw clean package -Dtest=PartitionAcceptanceTests -Dmaven.test.skip=false -Duppercase.processor.route=$FULL_UPPERCASE_ROUTE -Dpartitioning.producer.route=$FULL_PARTITIONING_PRODUCER_ROUTE -Dpartitioning.consumer1.route=$FULL_PARTITIONING_CONSUMER1_ROUTE -Dpartitioning.consumer2.route=$FULL_PARTITIONING_CONSUMER2_ROUTE -Dpartitioning.consumer3.route=$FULL_PARTITIONING_CONSUMER3_ROUTE -Dpartitioning.consumer4.route=$FULL_PARTITIONING_CONSUMER4_ROUTE +BUILD_RETURN_VALUE=$? cf stop partitioning-producer cf stop partitioning-consumer1 diff --git a/cf-acceptance-tests/src/test/java/sample/acceptance/tests/AbstractSampleTests.java b/cf-acceptance-tests/src/test/java/sample/acceptance/tests/AbstractSampleTests.java index 86c6b1a..068978e 100644 --- a/cf-acceptance-tests/src/test/java/sample/acceptance/tests/AbstractSampleTests.java +++ b/cf-acceptance-tests/src/test/java/sample/acceptance/tests/AbstractSampleTests.java @@ -32,34 +32,12 @@ abstract class AbstractSampleTests { private static final Logger logger = LoggerFactory.getLogger(AbstractSampleTests.class); + boolean waitForLogEntry(boolean noBoot2, String app, String route, String... entries) { + return waitForLogEntryInResource(noBoot2, app, route, entries); + } + boolean waitForLogEntry(String app, String route, String... entries) { - logger.info("Looking for '" + StringUtils.arrayToCommaDelimitedString(entries) + "' in logfile for " + app + " - " + route); - long timeout = System.currentTimeMillis() + (30 * 1000); - boolean exists = false; - while (!exists && System.currentTimeMillis() < timeout) { - try { - Thread.sleep(7 * 1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new IllegalStateException(e.getMessage(), e); - } - if (!exists) { - logger.info("Polling to get log file. Remaining poll time = " - + (timeout - System.currentTimeMillis() + " ms.")); - String log = getLog(route + "/actuator"); - if (log != null) { - if (Stream.of(entries).allMatch(s -> log.contains(s))) { - exists = true; - } - } - } - } - if (exists) { - logger.info("Matched all '" + StringUtils.arrayToCommaDelimitedString(entries) + "' in logfile for app " + app); - } else { - logger.error("ERROR: Couldn't find all '" + StringUtils.arrayToCommaDelimitedString(entries) + "' in logfile for " + app); - } - return exists; + return waitForLogEntryInResource(false, app, route, entries); } private String getLog(String url) { @@ -81,30 +59,30 @@ abstract class AbstractSampleTests { return log; } - - protected boolean waitForLogEntryInFileWithoutFailing(String app, String route, String... entries) { - logger.info("Looking for '" + StringUtils.arrayToCommaDelimitedString(entries) + "' in logfile for " + app); - long timeout = System.currentTimeMillis() + (60 * 1000); + private boolean waitForLogEntryInResource(boolean noBoot2, String app, String route, String... entries) { + logger.info("Looking for '" + StringUtils.arrayToCommaDelimitedString(entries) + "' in logfile for " + app + " - " + route); + long timeout = System.currentTimeMillis() + (30 * 1000); boolean exists = false; while (!exists && System.currentTimeMillis() < timeout) { try { - Thread.sleep(2 * 1000); + Thread.sleep(7 * 1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException(e.getMessage(), e); } logger.info("Polling to get log file. Remaining poll time = " + (timeout - System.currentTimeMillis() + " ms.")); - String log = getLog(route + "/actuator"); - + String log = noBoot2 ? getLog(route) : getLog(route + "/actuator"); if (log != null) { - if (Stream.of(entries).allMatch(log::contains)) { + if (Stream.of(entries).allMatch(s -> log.contains(s))) { exists = true; } } } if (exists) { logger.info("Matched all '" + StringUtils.arrayToCommaDelimitedString(entries) + "' in logfile for app " + app); + } else { + logger.error("ERROR: Couldn't find all '" + StringUtils.arrayToCommaDelimitedString(entries) + "' in logfile for " + app); } return exists; } diff --git a/cf-acceptance-tests/src/test/java/sample/acceptance/tests/PartitionAcceptanceTests.java b/cf-acceptance-tests/src/test/java/sample/acceptance/tests/PartitionAcceptanceTests.java index 3b7e5f5..f65b498 100644 --- a/cf-acceptance-tests/src/test/java/sample/acceptance/tests/PartitionAcceptanceTests.java +++ b/cf-acceptance-tests/src/test/java/sample/acceptance/tests/PartitionAcceptanceTests.java @@ -81,7 +81,7 @@ public class PartitionAcceptanceTests extends AbstractSampleTests { ExecutorService executorService = Executors.newSingleThreadExecutor(); Future submit = executorService.submit(() -> { - boolean found = waitForLogEntryInFileWithoutFailing(consumer1Msg, consumerRoute, entries); + boolean found = waitForLogEntry(consumer1Msg, consumerRoute, entries); if (!found) { fail("Could not find the test data in the logs"); } diff --git a/cf-acceptance-tests/src/test/java/sample/acceptance/tests/TickTockAcceptanceTests.java b/cf-acceptance-tests/src/test/java/sample/acceptance/tests/TickTockAcceptanceTests.java new file mode 100644 index 0000000..2452ecf --- /dev/null +++ b/cf-acceptance-tests/src/test/java/sample/acceptance/tests/TickTockAcceptanceTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed 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 sample.acceptance.tests; + +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * @author Soby Chacko + */ +public class TickTockAcceptanceTests extends AbstractSampleTests { + + @Test + public void testTickTockRabbit() { + + String timeSourceUrl = System.getProperty("time.source.route"); + String logSinkUrl = System.getProperty("log.sink.route"); + + boolean foundLogs = waitForLogEntry(true, "Time Source", timeSourceUrl, "Started TimeSource"); + if(!foundLogs) { + fail("Did not find the time source started logging message."); + } + + foundLogs = waitForLogEntry(true,"Log Sink", logSinkUrl, "Started LogSink"); + if(!foundLogs) { + fail("Did not find the log sink started logging message."); + } + + foundLogs = waitForLogEntry(true,"Log Sink", logSinkUrl, "TICKTOCK - TIMESTAMP:"); + if(!foundLogs) { + fail("Did not find the ticktock messages in log sink"); + } + } + +}