diff --git a/Jenkinsfile-Agent-Test b/Jenkinsfile-Agent-Test new file mode 100755 index 0000000000000000000000000000000000000000..341575cce7c129907416ad7c7097b8e54d3f1342 --- /dev/null +++ b/Jenkinsfile-Agent-Test @@ -0,0 +1,70 @@ +/* + * 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. + * + */ + +pipeline { + agent { + label 'skywalking' + } + + options { + timestamps() + timeout(time: 5, unit: 'HOURS') + } + + tools { + jdk 'JDK 1.8 (latest)' + } + + environment { + MAVEN_OPTS = '-Dmaven.repo.local=.m2/repository -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:-UseGCOverheadLimit -Xmx3g' + } + + stages { + stage('Checkout Source Code') { + steps { + deleteDir() + checkout scm + sh 'git submodule update --init' + } + } + + stage('Compile agent Codes') { + steps { + sh './mvnw -Pagent clean package -DskipTests' + } + } + + stage('Compile plugin-test tools Codes') { + steps { + sh './mvnw -f test/plugin/pom.xml -Pagent clean package -DskipTests -Dbuild_id=${BUILD_ID} docker:build' + } + } + + stage('httpclient 4.3.x-4.5.x') { + steps { + sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} httpclient-4.3.x-scenario' + } + } + } + + post { + always { + deleteDir() + } + } +} diff --git a/test/plugin/containers/jvm-container/docker/Dockerfile b/test/plugin/containers/jvm-container/docker/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..60131b57616cfbeb401375759d252e1e3488b4e9 --- /dev/null +++ b/test/plugin/containers/jvm-container/docker/Dockerfile @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM openjdk:7 +MAINTAINER zhangxin@apache.org + +ADD docker-entrypoint.sh / +RUN chmod +x /docker-entrypoint.sh + +ENTRYPOINT ["/docker-entrypoint.sh"] +RUN ["/bin/bash"] diff --git a/test/plugin/containers/jvm-container/docker/docker-entrypoint.sh b/test/plugin/containers/jvm-container/docker/docker-entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..9446ea6b1fb511fa29d043931585426503d3c088 --- /dev/null +++ b/test/plugin/containers/jvm-container/docker/docker-entrypoint.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +# 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. + +/usr/local/skywalking-agent-scenario/skywalking-mock-collector/collector-startup.sh & +sleep 30 +# start applications +exec "$@" & +sleep 60 +curl ${SCENARIO_ENTRY_SERVICE} +sleep 40 +curl http://localhost:12800/receiveData > ${SCENARIO_DATA}/${SCENARIO_NAME}_${SCENARIO_VERSION}/actualData.yaml +# +echo "Scenario[${SCENARIO_NAME}, ${SCENARIO_VERSION}] build successfully!" diff --git a/test/plugin/containers/jvm-container/pom.xml b/test/plugin/containers/jvm-container/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..5111955857449901a825ec83071f0aed2908b96e --- /dev/null +++ b/test/plugin/containers/jvm-container/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + jar + + + org.apache.skywalking.plugin + containers + 1.0.0 + + + jvm-container + agent-test-jvm + + + false + + diff --git a/test/plugin/containers/pom.xml b/test/plugin/containers/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..de3a598ee0b9b38be0cc137e63d7401d08c3b6da --- /dev/null +++ b/test/plugin/containers/pom.xml @@ -0,0 +1,65 @@ + + + + + 4.0.0 + pom + + + org.apache.skywalking.plugin + apache-skywalking-test-plugin + 1.0.0 + + + containers + + tomcat-container + jvm-container + + + + true + + + + + + com.spotify + docker-maven-plugin + ${docker-maven-plugin.version} + + ${build_id} + skywalking/${project.name} + ${project.basedir}/docker + ${skip.docker} + + + / + ${project.basedir}/../../dist + skywalking-mock-collector.tar.gz + skywalking-validator-tools.jar + + + + + + + diff --git a/test/plugin/containers/tomcat-container/docker/Dockerfile b/test/plugin/containers/tomcat-container/docker/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..3c70887079924147770d189a10372b994a44aadf --- /dev/null +++ b/test/plugin/containers/tomcat-container/docker/Dockerfile @@ -0,0 +1,31 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM tomcat:8.5.42-jdk8-openjdk +MAINTAINER zhangxin@apache.org +WORKDIR /usr/local/skywalking/tools + +COPY run.sh / +COPY catalina.sh /usr/local/tomcat/bin/ + +COPY skywalking-validator-tools.jar /usr/local/skywalking/tools +COPY skywalking-mock-collector.tar.gz /usr/local/skywalking/tools +RUN tar -xvf skywalking-mock-collector.tar.gz -C /usr/local/skywalking/tools + +RUN chmod +x /usr/local/tomcat/bin/catalina.sh && chmod +x /run.sh + +WORKDIR /usr/local/skywalking/scenario +CMD ["/run.sh"] diff --git a/test/plugin/containers/tomcat-container/docker/catalina.sh b/test/plugin/containers/tomcat-container/docker/catalina.sh new file mode 100644 index 0000000000000000000000000000000000000000..22ca290a141cc6a1814824fa761585147832d6c5 --- /dev/null +++ b/test/plugin/containers/tomcat-container/docker/catalina.sh @@ -0,0 +1,627 @@ +#!/bin/sh + +# 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. + +# ----------------------------------------------------------------------------- +# Control Script for the CATALINA Server +# +# Environment Variable Prerequisites +# +# Do not set the variables in this script. Instead put them into a script +# setenv.sh in CATALINA_BASE/bin to keep your customizations separate. +# +# CATALINA_HOME May point at your Catalina "build" directory. +# +# CATALINA_BASE (Optional) Base directory for resolving dynamic portions +# of a Catalina installation. If not present, resolves to +# the same directory that CATALINA_HOME points to. +# +# CATALINA_OUT (Optional) Full path to a file where stdout and stderr +# will be redirected. +# Default is $CATALINA_BASE/logs/catalina.out +# +# CATALINA_OPTS (Optional) Java runtime options used when the "start", +# "run" or "debug" command is executed. +# Include here and not in JAVA_OPTS all options, that should +# only be used by Tomcat itself, not by the stop process, +# the version command etc. +# Examples are heap size, GC logging, JMX ports etc. +# +# CATALINA_TMPDIR (Optional) Directory path location of temporary directory +# the JVM should use (java.io.tmpdir). Defaults to +# $CATALINA_BASE/temp. +# +# JAVA_HOME Must point at your Java Development Kit installation. +# Required to run the with the "debug" argument. +# +# JRE_HOME Must point at your Java Runtime installation. +# Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME +# are both set, JRE_HOME is used. +# +# JAVA_OPTS (Optional) Java runtime options used when any command +# is executed. +# Include here and not in CATALINA_OPTS all options, that +# should be used by Tomcat and also by the stop process, +# the version command etc. +# Most options should go into CATALINA_OPTS. +# +# JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories +# containing some jars in order to allow replacement of APIs +# created outside of the JCP (i.e. DOM and SAX from W3C). +# It can also be used to update the XML parser implementation. +# Defaults to $CATALINA_HOME/endorsed. +# +# JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start" +# command is executed. The default is "dt_socket". +# +# JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start" +# command is executed. The default is localhost:8000. +# +# JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start" +# command is executed. Specifies whether JVM should suspend +# execution immediately after startup. Default is "n". +# +# JPDA_OPTS (Optional) Java runtime options used when the "jpda start" +# command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS, +# and JPDA_SUSPEND are ignored. Thus, all required jpda +# options MUST be specified. The default is: +# +# -agentlib:jdwp=transport=$JPDA_TRANSPORT, +# address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND +# +# JSSE_OPTS (Optional) Java runtime options used to control the TLS +# implementation when JSSE is used. Default is: +# "-Djdk.tls.ephemeralDHKeySize=2048" +# +# CATALINA_PID (Optional) Path of the file which should contains the pid +# of the catalina startup java process, when start (fork) is +# used +# +# LOGGING_CONFIG (Optional) Override Tomcat's logging config file +# Example (all one line) +# LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties" +# +# LOGGING_MANAGER (Optional) Override Tomcat's logging manager +# Example (all one line) +# LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" +# +# USE_NOHUP (Optional) If set to the string true the start command will +# use nohup so that the Tomcat process will ignore any hangup +# signals. Default is "false" unless running on HP-UX in which +# case the default is "true" +# ----------------------------------------------------------------------------- + +export AGENT_FILE_PATH=/usr/local/skywalking/scenario/agent +echo "${AGENT_FILE_PATH}/skywalking-agent.jar" +if [ -f "${AGENT_FILE_PATH}/skywalking-agent.jar" ]; then + CATALINA_OPTS="$CATALINA_OPTS -javaagent:${AGENT_FILE_PATH}/skywalking-agent.jar + -Dskywalking.collector.grpc_channel_check_interval=2 + -Dskywalking.collector.app_and_service_register_check_interval=2 + -Dskywalking.collector.discovery_check_interval=2 + -Dskywalking.collector.backend_service=localhost:19876 + -Dskywalking.agent.service_name=${SCENARIO_NAME} + -Dskywalking.logging.dir=/usr/local/skywalking/scenario/logs + -Xms256m -Xmx256m -XX:PermSize=64M -XX:MaxPermSize=64" +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false +darwin=false +os400=false +hpux=false +case "`uname`" in +CYGWIN*) cygwin=true;; +Darwin*) darwin=true;; +OS400*) os400=true;; +HP-UX*) hpux=true;; +esac + +# resolve links - $0 may be a softlink +PRG="$0" + +while [ -h "$PRG" ]; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done + +# Get standard environment variables +PRGDIR=`dirname "$PRG"` + +# Only set CATALINA_HOME if not already set +[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." >/dev/null; pwd` + +# Copy CATALINA_BASE from CATALINA_HOME if not already set +[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME" + +# Ensure that any user defined CLASSPATH variables are not used on startup, +# but allow them to be specified in setenv.sh, in rare case when it is needed. +CLASSPATH= + +if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then + . "$CATALINA_BASE/bin/setenv.sh" +elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then + . "$CATALINA_HOME/bin/setenv.sh" +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$JRE_HOME" ] && JRE_HOME=`cygpath --unix "$JRE_HOME"` + [ -n "$CATALINA_HOME" ] && CATALINA_HOME=`cygpath --unix "$CATALINA_HOME"` + [ -n "$CATALINA_BASE" ] && CATALINA_BASE=`cygpath --unix "$CATALINA_BASE"` + [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# Ensure that neither CATALINA_HOME nor CATALINA_BASE contains a colon +# as this is used as the separator in the classpath and Java provides no +# mechanism for escaping if the same character appears in the path. +case $CATALINA_HOME in + *:*) echo "Using CATALINA_HOME: $CATALINA_HOME"; + echo "Unable to start as CATALINA_HOME contains a colon (:) character"; + exit 1; +esac +case $CATALINA_BASE in + *:*) echo "Using CATALINA_BASE: $CATALINA_BASE"; + echo "Unable to start as CATALINA_BASE contains a colon (:) character"; + exit 1; +esac + +# For OS400 +if $os400; then + # Set job priority to standard for interactive (interactive - 6) by using + # the interactive priority - 6, the helper threads that respond to requests + # will be running at the same priority as interactive jobs. + COMMAND='chgjob job('$JOBNAME') runpty(6)' + system $COMMAND + + # Enable multi threading + export QIBM_MULTI_THREADED=Y +fi + +# Get standard Java environment variables +if $os400; then + # -r will Only work on the os400 if the files are: + # 1. owned by the user + # 2. owned by the PRIMARY group of the user + # this will not work if the user belongs in secondary groups + . "$CATALINA_HOME"/bin/setclasspath.sh +else + if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then + . "$CATALINA_HOME"/bin/setclasspath.sh + else + echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh" + echo "This file is needed to run this program" + exit 1 + fi +fi + +# Add on extra jar files to CLASSPATH +if [ ! -z "$CLASSPATH" ] ; then + CLASSPATH="$CLASSPATH": +fi +CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar + +if [ -z "$CATALINA_OUT" ] ; then + CATALINA_OUT=/usr/local/skywalking/scenario/logs/catalina.out +fi + +if [ -z "$CATALINA_TMPDIR" ] ; then + # Define the java.io.tmpdir to use for Catalina + CATALINA_TMPDIR="$CATALINA_BASE"/temp +fi + +# Add tomcat-juli.jar to classpath +# tomcat-juli.jar can be over-ridden per instance +if [ -r "$CATALINA_BASE/bin/tomcat-juli.jar" ] ; then + CLASSPATH=$CLASSPATH:$CATALINA_BASE/bin/tomcat-juli.jar +else + CLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar +fi + +# Bugzilla 37848: When no TTY is available, don't output to console +have_tty=0 +if [ "`tty`" != "not a tty" ]; then + have_tty=1 +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"` + JRE_HOME=`cygpath --absolute --windows "$JRE_HOME"` + CATALINA_HOME=`cygpath --absolute --windows "$CATALINA_HOME"` + CATALINA_BASE=`cygpath --absolute --windows "$CATALINA_BASE"` + CATALINA_TMPDIR=`cygpath --absolute --windows "$CATALINA_TMPDIR"` + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"` +fi + +if [ -z "$JSSE_OPTS" ] ; then + JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048" +fi +JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS" + +# Register custom URL handlers +# Do this here so custom URL handles (specifically 'war:...') can be used in the security policy +JAVA_OPTS="$JAVA_OPTS -Djava.protocol.handler.pkgs=org.apache.catalina.webresources" + +# Set juli LogManager config file if it is present and an override has not been issued +if [ -z "$LOGGING_CONFIG" ]; then + if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then + LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties" + else + # Bugzilla 45585 + LOGGING_CONFIG="-Dnop" + fi +fi + +if [ -z "$LOGGING_MANAGER" ]; then + LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" +fi + +# Uncomment the following line to make the umask available when using the +# org.apache.catalina.security.SecurityListener +#JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`" + +if [ -z "$USE_NOHUP" ]; then + if $hpux; then + USE_NOHUP="true" + else + USE_NOHUP="false" + fi +fi +unset _NOHUP +if [ "$USE_NOHUP" = "true" ]; then + _NOHUP=nohup +fi + +# ----- Execute The Requested Command ----------------------------------------- + +# Bugzilla 37848: only output this if we have a TTY +if [ $have_tty -eq 1 ]; then + echo "Using CATALINA_BASE: $CATALINA_BASE" + echo "Using CATALINA_HOME: $CATALINA_HOME" + echo "Using CATALINA_TMPDIR: $CATALINA_TMPDIR" + if [ "$1" = "debug" ] ; then + echo "Using JAVA_HOME: $JAVA_HOME" + else + echo "Using JRE_HOME: $JRE_HOME" + fi + echo "Using CLASSPATH: $CLASSPATH" + if [ ! -z "$CATALINA_PID" ]; then + echo "Using CATALINA_PID: $CATALINA_PID" + fi +fi + +if [ "$1" = "jpda" ] ; then + if [ -z "$JPDA_TRANSPORT" ]; then + JPDA_TRANSPORT="dt_socket" + fi + if [ -z "$JPDA_ADDRESS" ]; then + JPDA_ADDRESS="localhost:8000" + fi + if [ -z "$JPDA_SUSPEND" ]; then + JPDA_SUSPEND="n" + fi + if [ -z "$JPDA_OPTS" ]; then + JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND" + fi + CATALINA_OPTS="$JPDA_OPTS $CATALINA_OPTS" + shift +fi + +if [ "$1" = "debug" ] ; then + if $os400; then + echo "Debug command not available on OS400" + exit 1 + else + shift + if [ "$1" = "-security" ] ; then + if [ $have_tty -eq 1 ]; then + echo "Using Security Manager" + fi + shift + exec "$_RUNJDB" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ + -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ + -sourcepath "$CATALINA_HOME"/../../java \ + -Djava.security.manager \ + -Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \ + -Dcatalina.base="$CATALINA_BASE" \ + -Dcatalina.home="$CATALINA_HOME" \ + -Djava.io.tmpdir="$CATALINA_TMPDIR" \ + org.apache.catalina.startup.Bootstrap "$@" start + else + exec "$_RUNJDB" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ + -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ + -sourcepath "$CATALINA_HOME"/../../java \ + -Dcatalina.base="$CATALINA_BASE" \ + -Dcatalina.home="$CATALINA_HOME" \ + -Djava.io.tmpdir="$CATALINA_TMPDIR" \ + org.apache.catalina.startup.Bootstrap "$@" start + fi + fi + +elif [ "$1" = "run" ]; then + + shift + if [ "$1" = "-security" ] ; then + if [ $have_tty -eq 1 ]; then + echo "Using Security Manager" + fi + shift + eval exec "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ + -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \ + -Djava.security.manager \ + -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \ + -Dcatalina.base="\"$CATALINA_BASE\"" \ + -Dcatalina.home="\"$CATALINA_HOME\"" \ + -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ + org.apache.catalina.startup.Bootstrap "$@" start + else + eval exec "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ + -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \ + -Dcatalina.base="\"$CATALINA_BASE\"" \ + -Dcatalina.home="\"$CATALINA_HOME\"" \ + -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ + org.apache.catalina.startup.Bootstrap "$@" start + fi + +elif [ "$1" = "start" ] ; then + + if [ ! -z "$CATALINA_PID" ]; then + if [ -f "$CATALINA_PID" ]; then + if [ -s "$CATALINA_PID" ]; then + echo "Existing PID file found during start." + if [ -r "$CATALINA_PID" ]; then + PID=`cat "$CATALINA_PID"` + ps -p $PID >/dev/null 2>&1 + if [ $? -eq 0 ] ; then + echo "Tomcat appears to still be running with PID $PID. Start aborted." + echo "If the following process is not a Tomcat process, remove the PID file and try again:" + ps -f -p $PID + exit 1 + else + echo "Removing/clearing stale PID file." + rm -f "$CATALINA_PID" >/dev/null 2>&1 + if [ $? != 0 ]; then + if [ -w "$CATALINA_PID" ]; then + cat /dev/null > "$CATALINA_PID" + else + echo "Unable to remove or clear stale PID file. Start aborted." + exit 1 + fi + fi + fi + else + echo "Unable to read PID file. Start aborted." + exit 1 + fi + else + rm -f "$CATALINA_PID" >/dev/null 2>&1 + if [ $? != 0 ]; then + if [ ! -w "$CATALINA_PID" ]; then + echo "Unable to remove or write to empty PID file. Start aborted." + exit 1 + fi + fi + fi + fi + fi + + shift + touch "$CATALINA_OUT" + if [ "$1" = "-security" ] ; then + if [ $have_tty -eq 1 ]; then + echo "Using Security Manager" + fi + shift + eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ + -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \ + -Djava.security.manager \ + -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \ + -Dcatalina.base="\"$CATALINA_BASE\"" \ + -Dcatalina.home="\"$CATALINA_HOME\"" \ + -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ + org.apache.catalina.startup.Bootstrap "$@" start \ + >> "$CATALINA_OUT" 2>&1 "&" + + else + eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ + -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \ + -Dcatalina.base="\"$CATALINA_BASE\"" \ + -Dcatalina.home="\"$CATALINA_HOME\"" \ + -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ + org.apache.catalina.startup.Bootstrap "$@" start \ + >> "$CATALINA_OUT" 2>&1 "&" + + fi + + if [ ! -z "$CATALINA_PID" ]; then + echo $! > "$CATALINA_PID" + fi + + echo "Tomcat started." + +elif [ "$1" = "stop" ] ; then + + shift + + SLEEP=5 + if [ ! -z "$1" ]; then + echo $1 | grep "[^0-9]" >/dev/null 2>&1 + if [ $? -gt 0 ]; then + SLEEP=$1 + shift + fi + fi + + FORCE=0 + if [ "$1" = "-force" ]; then + shift + FORCE=1 + fi + + if [ ! -z "$CATALINA_PID" ]; then + if [ -f "$CATALINA_PID" ]; then + if [ -s "$CATALINA_PID" ]; then + kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1 + if [ $? -gt 0 ]; then + echo "PID file found but no matching process was found. Stop aborted." + exit 1 + fi + else + echo "PID file is empty and has been ignored." + fi + else + echo "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted." + exit 1 + fi + fi + + eval "\"$_RUNJAVA\"" $LOGGING_MANAGER $JAVA_OPTS \ + -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \ + -Dcatalina.base="\"$CATALINA_BASE\"" \ + -Dcatalina.home="\"$CATALINA_HOME\"" \ + -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ + org.apache.catalina.startup.Bootstrap "$@" stop + + # stop failed. Shutdown port disabled? Try a normal kill. + if [ $? != 0 ]; then + if [ ! -z "$CATALINA_PID" ]; then + echo "The stop command failed. Attempting to signal the process to stop through OS signal." + kill -15 `cat "$CATALINA_PID"` >/dev/null 2>&1 + fi + fi + + if [ ! -z "$CATALINA_PID" ]; then + if [ -f "$CATALINA_PID" ]; then + while [ $SLEEP -ge 0 ]; do + kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1 + if [ $? -gt 0 ]; then + rm -f "$CATALINA_PID" >/dev/null 2>&1 + if [ $? != 0 ]; then + if [ -w "$CATALINA_PID" ]; then + cat /dev/null > "$CATALINA_PID" + # If Tomcat has stopped don't try and force a stop with an empty PID file + FORCE=0 + else + echo "The PID file could not be removed or cleared." + fi + fi + echo "Tomcat stopped." + break + fi + if [ $SLEEP -gt 0 ]; then + sleep 1 + fi + if [ $SLEEP -eq 0 ]; then + echo "Tomcat did not stop in time." + if [ $FORCE -eq 0 ]; then + echo "PID file was not removed." + fi + echo "To aid diagnostics a thread dump has been written to standard out." + kill -3 `cat "$CATALINA_PID"` + fi + SLEEP=`expr $SLEEP - 1 ` + done + fi + fi + + KILL_SLEEP_INTERVAL=5 + if [ $FORCE -eq 1 ]; then + if [ -z "$CATALINA_PID" ]; then + echo "Kill failed: \$CATALINA_PID not set" + else + if [ -f "$CATALINA_PID" ]; then + PID=`cat "$CATALINA_PID"` + echo "Killing Tomcat with the PID: $PID" + kill -9 $PID + while [ $KILL_SLEEP_INTERVAL -ge 0 ]; do + kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1 + if [ $? -gt 0 ]; then + rm -f "$CATALINA_PID" >/dev/null 2>&1 + if [ $? != 0 ]; then + if [ -w "$CATALINA_PID" ]; then + cat /dev/null > "$CATALINA_PID" + else + echo "The PID file could not be removed." + fi + fi + echo "The Tomcat process has been killed." + break + fi + if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then + sleep 1 + fi + KILL_SLEEP_INTERVAL=`expr $KILL_SLEEP_INTERVAL - 1 ` + done + if [ $KILL_SLEEP_INTERVAL -lt 0 ]; then + echo "Tomcat has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE." + fi + fi + fi + fi + +elif [ "$1" = "configtest" ] ; then + + eval "\"$_RUNJAVA\"" $LOGGING_MANAGER $JAVA_OPTS \ + -Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \ + -Dcatalina.base="\"$CATALINA_BASE\"" \ + -Dcatalina.home="\"$CATALINA_HOME\"" \ + -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ + org.apache.catalina.startup.Bootstrap configtest + result=$? + if [ $result -ne 0 ]; then + echo "Configuration error detected!" + fi + exit $result + +elif [ "$1" = "version" ] ; then + + "$_RUNJAVA" \ + -classpath "$CATALINA_HOME/lib/catalina.jar" \ + org.apache.catalina.util.ServerInfo + +else + + echo "Usage: catalina.sh ( commands ... )" + echo "commands:" + if $os400; then + echo " debug Start Catalina in a debugger (not available on OS400)" + echo " debug -security Debug Catalina with a security manager (not available on OS400)" + else + echo " debug Start Catalina in a debugger" + echo " debug -security Debug Catalina with a security manager" + fi + echo " jpda start Start Catalina under JPDA debugger" + echo " run Start Catalina in the current window" + echo " run -security Start in the current window with security manager" + echo " start Start Catalina in a separate window" + echo " start -security Start in a separate window with security manager" + echo " stop Stop Catalina, waiting up to 5 seconds for the process to end" + echo " stop n Stop Catalina, waiting up to n seconds for the process to end" + echo " stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running" + echo " stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running" + echo " configtest Run a basic syntax check on server.xml - check exit code for result" + echo " version What version of tomcat are you running?" + echo "Note: Waiting for the process to end and use of the -force option require that \$CATALINA_PID is defined" + exit 1 + +fi diff --git a/test/plugin/containers/tomcat-container/docker/run.sh b/test/plugin/containers/tomcat-container/docker/run.sh new file mode 100644 index 0000000000000000000000000000000000000000..dc27bb6dd979773e07e93e0a182f035e48f0f306 --- /dev/null +++ b/test/plugin/containers/tomcat-container/docker/run.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# 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. + +function exitOnError() { + echo -e "\033[31m[ERROR] $1\033[0m">&2 + exitAndClean 1 +} + +function exitAndClean() { + [[ -f ${SCENARIO_HOME}/data/actualData.yaml ]] && rm -rf ${SCENARIO_HOME}/data/actualData.yaml + [[ -d ${SCENARIO_HOME}/logs ]] && rm -rf ${SCENARIO_HOME}/logs + exit $1 +} + +function healthCheck() { + HEALTH_CHECK_URL=$1 + + for ((i=1; i<=10; i++)); + do + STATUS_CODE="$(curl -Is ${HEALTH_CHECK_URL} | head -n 1)" + if [[ $STATUS_CODE == *"200"* ]]; then + echo "${HEALTH_CHECK_URL}: ${STATUS_CODE}" + return 0 + fi + sleep 2 + done + + exitOnError "${SCENARIO_NAME}-${SCENARIO_VERSION} health check failed!" +} + +TOOLS_HOME=/usr/local/skywalking/tools +SCENARIO_HOME=/usr/local/skywalking/scenario + +# Speed up launch tomcat +rm /usr/local/tomcat/webapps/* -rf # remove needn't app +sed -i "s%securerandom.source=file:/dev/random%securerandom.source=file:/dev/urandom%g" $JAVA_HOME/jre/lib/security/java.security + +# To deploy testcase +cp ${SCENARIO_HOME}/*.war /usr/local/tomcat/webapps/ + +# start mock collector +echo "To start mock collector" +${TOOLS_HOME}/skywalking-mock-collector/bin/collector-startup.sh 1>/dev/null & +healthCheck http://localhost:12800/receiveData + +echo "To start tomcat" +/usr/local/tomcat/bin/catalina.sh start 1>/dev/null & +healthCheck ${SCENARIO_HEALTH_CHECK_URL} + +echo "To visit entry service" +curl -s ${SCENARIO_ENTRY_SERVICE} +sleep 5 + +echo "To receive actual data" +curl -s http://localhost:12800/receiveData > ${SCENARIO_HOME}/data/actualData.yaml +[[ ! -f ${SCENARIO_HOME}/data/actualData.yaml ]] && exitOnError "${SCENARIO_NAME}-${SCENARIO_VERSION}, 'actualData.yaml' Not Found!" + +echo "To validate" +java -jar \ + -Dv2=true \ + -Xmx256m -Xms256m \ + -DtestDate="`date +%Y-%m-%d-%H-%M`" \ + -DtestCasePath=${SCENARIO_HOME}/data/ \ + ${TOOLS_HOME}/skywalking-validator-tools.jar 1>/dev/null +status=$? + +if [[ $status -eq 0 ]]; then + echo "Scenario[${SCENARIO_NAME}-${SCENARIO_VERSION}] passed!" >&2 +else + cat ${SCENARIO_HOME}/data/actualData.yaml >&2 + exitOnError "Scenario[${SCENARIO_NAME}-${SCENARIO_VERSION}] failed!" +fi +exitAndClean $status diff --git a/test/plugin/containers/tomcat-container/pom.xml b/test/plugin/containers/tomcat-container/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..d150cb989fdc48b5699a80d0e9f339c8b387f72a --- /dev/null +++ b/test/plugin/containers/tomcat-container/pom.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + jar + + + org.apache.skywalking.plugin + containers + 1.0.0 + + + tomcat-container + agent-test-tomcat + + + false + + + + diff --git a/test/plugin/mock-collector/bin/collector-startup.sh b/test/plugin/mock-collector/bin/collector-startup.sh new file mode 100644 index 0000000000000000000000000000000000000000..419e345975a17b46b4b5eea712c1fd544d02b3b1 --- /dev/null +++ b/test/plugin/mock-collector/bin/collector-startup.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# 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. + +PRG="$0" +PRGDIR=`dirname "$PRG"` +[ -z "$COLLECTOR_HOME" ] && COLLECTOR_HOME=`cd "$PRGDIR/.." >/dev/null; pwd` + +_RUNJAVA=${JAVA_HOME}/bin/java +[ -z "$JAVA_HOME" ] && _RUNJAVA=`java` + +CLASSPATH="$COLLECTOR_HOME/config:$CLASSPATH" +for i in "$COLLECTOR_HOME"/libs/*.jar +do + CLASSPATH="$i:$CLASSPATH" +done + +JAVA_OPTS="${JAVA_OPTS} -Xmx256m -Xms256m" +JAVA_OPTS="${JAVA_OPTS} -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 " + +$_RUNJAVA ${JAVA_OPTS} -classpath $CLASSPATH org.apache.skywalking.plugin.test.mockcollector.Main diff --git a/test/plugin/mock-collector/docker/Dockerfile b/test/plugin/mock-collector/docker/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..27952b968b8875deccecf3de6c7b192c0d66bbc8 --- /dev/null +++ b/test/plugin/mock-collector/docker/Dockerfile @@ -0,0 +1,30 @@ +# 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. + +FROM openjdk:8-jdk + +ENV GRPC_BIND_HOST=127.0.0.1 \ + GRPC_BIND_PORT=19876 + +ADD skywalking-mock-collector.tar.gz /usr/local +ADD config.properties /usr/local/skywalking-mock-collector/config/config.properties +EXPOSE 12800 +EXPOSE 5005 + +ADD docker-entrypoint.sh / +RUN chmod +x /docker-entrypoint.sh +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["/usr/local/skywalking-mock-collector/bin/collector-startup.sh"] diff --git a/test/plugin/mock-collector/docker/config.properties b/test/plugin/mock-collector/docker/config.properties new file mode 100644 index 0000000000000000000000000000000000000000..360086e0747d12cddc22863b87b3d9f418c09788 --- /dev/null +++ b/test/plugin/mock-collector/docker/config.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +grpc_bind_host={GRPC_BIND_HOST} +grpc_bind_port={GRPC_BIND_PORT} diff --git a/test/plugin/mock-collector/docker/docker-entrypoint.sh b/test/plugin/mock-collector/docker/docker-entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..f5d390abcd29ae7e5574f40cd2d56b56ac23adc2 --- /dev/null +++ b/test/plugin/mock-collector/docker/docker-entrypoint.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# 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. + +echo "replace GRPC_BIND_HOST with $GRPC_BIND_HOST" +eval sed -i -e 's/\{GRPC_BIND_HOST\}/$GRPC_BIND_HOST/' /usr/local/skywalking-mock-collector/config/config.properties + +echo "replace GRPC_BIND_PORT with $GRPC_BIND_PORT" +eval sed -i -e 's/\{GRPC_BIND_PORT\}/$GRPC_BIND_PORT/' /usr/local/skywalking-mock-collector/config/config.properties + +exec "$@" diff --git a/test/plugin/mock-collector/pom.xml b/test/plugin/mock-collector/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..baf712a7d656ad453691080e1a8f7a52fd4aa0d9 --- /dev/null +++ b/test/plugin/mock-collector/pom.xml @@ -0,0 +1,202 @@ + + + + + 4.0.0 + + + org.apache.skywalking.plugin + apache-skywalking-test-plugin + 1.0.0 + + + skywalking-mock-collector + 6.0.0-2018 + jar + + skywalking-mock-collector + http://maven.apache.org + + + UTF-8 + 1.4.0 + 4.1.12.Final + 9.4.2.v20170220 + 2.8.0 + 1.18 + skywalking/mock-collector + ${project.version} + + + + + io.grpc + grpc-netty + ${grpc.version} + + + io.netty + netty-codec-http2 + + + io.netty + netty-handler-proxy + + + + + io.grpc + grpc-protobuf + ${grpc.version} + + + io.grpc + grpc-stub + ${grpc.version} + + + io.netty + netty-codec-http2 + ${netty.version} + + + org.eclipse.jetty + jetty-server + ${jetty.version} + + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + + + com.google.code.gson + gson + ${gson.version} + + + + org.projectlombok + lombok + 1.16.18 + + + + + skywalking-mock-collector + + + kr.motd.maven + os-maven-plugin + 1.4.1.Final + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.4.3 + + ${project.build.sourceEncoding} + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.5.0 + + com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier} + + grpc-java + io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier} + + + + + + compile + compile-custom + + + + + + org.codehaus.mojo + versions-maven-plugin + 2.7 + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-assembly-plugin + + + assembly + package + + single + + + + src/main/assembly/assembly.xml + + ${project.basedir}/../dist + + + + + + com.spotify + docker-maven-plugin + 0.4.13 + + true + ${docker.image.name} + + ${docker.image.version} + + ${project.basedir}/docker + + + / + ${project.basedir}/../dist + ${build.finalName}.tar.gz + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.2 + + + *.properties + *.yaml + *.xml + + + + + + diff --git a/test/plugin/mock-collector/src/main/assembly/assembly.xml b/test/plugin/mock-collector/src/main/assembly/assembly.xml new file mode 100644 index 0000000000000000000000000000000000000000..2ba07c126254bcad66d66069543c64a5e6c84e0e --- /dev/null +++ b/test/plugin/mock-collector/src/main/assembly/assembly.xml @@ -0,0 +1,57 @@ + + + + + tar.gz + + + + /libs + runtime + + + + + ${project.basedir}/bin + /bin + + *.sh + + 0755 + + + src/main/resources + + collector.properties + log4j2.xml + + /config + + + ${project.build.directory} + /libs + + ${build.finalName}.jar + + + + diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/Main.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..4193484434a2f6fd58575843f99ff6470bde9675 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/Main.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector; + +import io.grpc.netty.NettyServerBuilder; +import io.netty.channel.local.LocalAddress; + +import java.net.InetSocketAddress; + +import org.apache.skywalking.plugin.test.mockcollector.service.*; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; + +public class Main { + public static void main(String[] args) throws Exception { + NettyServerBuilder.forAddress(LocalAddress.ANY).forPort(19876) + .maxConcurrentCallsPerConnection(12).maxMessageSize(16777216) + .addService(new MockRegisterService()) + .addService(new MockInstancePingService()) + .addService(new MockJVMMetricsService()) + .addService(new MockTraceSegmentV1Service()) + .addService(new MockApplicationRegisterService()) + .addService(new MockInstanceDiscoveryService()) + .addService(new MockJVMMetricsV1Service()) + .addService(new MockNetworkAddressRegisterService()) + .addService(new MockServiceNameDiscoveryService()) + .addService(new MockTraceSegmentService()) + .addService(new MockJVMMetricReportService()) + .build().start(); + + Server jettyServer = new Server(new InetSocketAddress("0.0.0.0", + Integer.valueOf(12800))); + String contextPath = "/"; + ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); + servletContextHandler.setContextPath(contextPath); + servletContextHandler.addServlet(GrpcAddressHttpService.class, GrpcAddressHttpService.SERVLET_PATH); + servletContextHandler.addServlet(ReceiveDataService.class, ReceiveDataService.SERVLET_PATH); + servletContextHandler.addServlet(ClearReceiveDataService.class, ClearReceiveDataService.SERVLET_PATH); + jettyServer.setHandler(servletContextHandler); + jettyServer.start(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/RegistryItem.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/RegistryItem.java new file mode 100644 index 0000000000000000000000000000000000000000..5dec61819f0b27abd63816bb16c58ba18d70aa21 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/RegistryItem.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.entity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.skywalking.apm.network.language.agent.SpanType; + +public class RegistryItem { + /** + * applicationCode, applicationId + */ + private final Map applications; + /** + * applicationCode, operationName + */ + private final Map> operationNames; + /** + * applicationCode, instanceId + */ + private final Map> instanceMapping; + /** + * applicationCode, count + */ + private final Map heartBeats; + + public RegistryItem() { + applications = new HashMap<>(); + operationNames = new HashMap<>(); + instanceMapping = new HashMap<>(); + heartBeats = new HashMap<>(); + } + + public void registryApplication(Application application) { + applications.putIfAbsent(application.applicationCode, application.applicationId); + } + + public void registryOperationName(OperationName operationName) { + String applicationCode = findApplicationCode(operationName.applicationId); + Set operationNameList = operationNames.get(applicationCode); + if (operationNameList == null) { + operationNameList = new HashSet<>(); + operationNames.put(applicationCode, operationNameList); + } + operationNameList.add(operationName.operationName); + } + + public void registryInstance(Instance instance) { + String applicationCode = findApplicationCode(instance.applicationId); + List instances = instanceMapping.get(applicationCode); + if (instances == null) { + instances = new ArrayList<>(); + instanceMapping.put(applicationCode, instances); + } + + if (!instances.contains(instance)) { + instances.add(instance.instanceId); + } + } + + public String findApplicationCode(int id) { + for (Map.Entry entry : applications.entrySet()) { + if (entry.getValue() == id) { + return entry.getKey(); + } + } + throw new RuntimeException("Cannot found the code of applicationID[" + id + "]."); + } + + public void registryHeartBeat(HeartBeat heartBeat) { + for (Map.Entry> entry : instanceMapping.entrySet()) { + if (entry.getValue().contains(heartBeat.instanceID)) { + Integer count = heartBeats.get(entry.getKey()); + if (count != null) { + heartBeats.put(entry.getKey(), 0); + heartBeats.put(entry.getKey(), count++); + } + } + } + } + + public static class OperationName { + int applicationId; + String operationName; + + public OperationName(int applicationId, String operationName) { + this.applicationId = applicationId; + this.operationName = operationName; + } + } + + public static class Application { + String applicationCode; + int applicationId; + + public Application(String applicationCode, int applicationId) { + this.applicationCode = applicationCode; + this.applicationId = applicationId; + } + } + + public static class Instance { + int applicationId; + int instanceId; + + public Instance(int applicationId, int instanceId) { + this.applicationId = applicationId; + this.instanceId = instanceId; + } + } + + public static class HeartBeat { + private int instanceID; + + public HeartBeat(int instanceID) { + this.instanceID = instanceID; + } + } + + public Map getApplications() { + return applications; + } + + public Map> getOperationNames() { + return operationNames; + } + + public Map> getInstanceMapping() { + return instanceMapping; + } + + public Map getHeartBeats() { + return heartBeats; + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/RegistryItemSerializer.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/RegistryItemSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..37fc0e86d9af4090552001dd9c360f6e13d27e5d --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/RegistryItemSerializer.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.entity; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; + +public class RegistryItemSerializer implements JsonSerializer { + @Override + public JsonElement serialize(RegistryItem src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject jsonObject = new JsonObject(); + JsonArray applicationArrays = new JsonArray(); + src.getApplications().forEach((applicationCode, applicationId) -> { + JsonObject applicationJson = new JsonObject(); + applicationJson.addProperty(applicationCode, applicationId); + applicationArrays.add(applicationJson); + }); + jsonObject.add("applications", applicationArrays); + + JsonArray instanceArrays = new JsonArray(); + src.getInstanceMapping().forEach((applicationCode, instanceIds) -> { + JsonObject instanceJson = new JsonObject(); + instanceJson.addProperty(applicationCode, instanceIds.size()); + instanceArrays.add(instanceJson); + }); + jsonObject.add("instances", instanceArrays); + + JsonArray operationNameArrays = new JsonArray(); + src.getOperationNames().forEach((applicationCode, operationNames) -> { + JsonObject instanceJson = new JsonObject(); + instanceJson.add(applicationCode, new Gson().toJsonTree(operationNames)); + operationNameArrays.add(instanceJson); + }); + jsonObject.add("operationNames", operationNameArrays); + + JsonArray heartBeatArrays = new JsonArray(); + src.getHeartBeats().forEach((applicationCode, count) -> { + JsonObject instanceJson = new JsonObject(); + instanceJson.addProperty(applicationCode, count); + heartBeatArrays.add(instanceJson); + }); + jsonObject.add("heartbeat", heartBeatArrays); + return jsonObject; + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Segment.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Segment.java new file mode 100644 index 0000000000000000000000000000000000000000..1a723e34d1025ccddfa7116b777328d14445dd94 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Segment.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.entity; + +import java.util.ArrayList; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.ToString; +import org.apache.skywalking.apm.network.language.agent.UniqueId; + +@ToString +@Builder +@AllArgsConstructor +public class Segment { + private String segmentId; + private List spans; + + public static class SegmentBuilder { + + public SegmentBuilder addSpan(Span.SpanBuilder spanBuilder) { + if (spans == null) { + this.spans = new ArrayList<>(); + } + + spans.add(spanBuilder.build()); + return this; + } + + public SegmentBuilder segmentId(UniqueId segmentUniqueId) { + segmentId = String.join(".", Long.toString(segmentUniqueId.getIdParts(0)), Long.toString(segmentUniqueId.getIdParts(1)), Long.toString(segmentUniqueId.getIdParts(2))); + return this; + } + } + +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItem.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItem.java new file mode 100644 index 0000000000000000000000000000000000000000..06d79e99fca3da43f890034af49c37076b8e29a0 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItem.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.entity; + +import java.util.ArrayList; +import java.util.List; + +public class SegmentItem { + private String applicationCode; + private List segments; + + public SegmentItem(String applicationCode) { + this.applicationCode = applicationCode; + segments = new ArrayList<>(); + } + + public void addSegments(Segment item) { + segments.add(item); + } + + public String getApplicationCode() { + return applicationCode; + } + + public List getSegments() { + return segments; + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItems.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItems.java new file mode 100644 index 0000000000000000000000000000000000000000..020a4ce8569128090cc28d161376315053a867c7 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItems.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.entity; + +import java.util.HashMap; +import java.util.Map; + +public class SegmentItems { + private Map segmentItems; + + public SegmentItems() { + this.segmentItems = new HashMap<>(); + } + + public SegmentItems addSegmentItem(int applicationId, Segment segment) { + String applicationCode = ValidateData.INSTANCE.getRegistryItem().findApplicationCode(applicationId); + SegmentItem segmentItem = segmentItems.get(applicationCode); + if (segmentItem == null) { + segmentItem = new SegmentItem(applicationCode); + segmentItems.put(applicationCode, segmentItem); + } + segmentItem.addSegments(segment); + return this; + } + + public Map getSegmentItems() { + return segmentItems; + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItemsSerializer.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItemsSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..0d786663ee0a94f877bae6c5bc4c5374d486d4d9 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/SegmentItemsSerializer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.entity; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; + +public class SegmentItemsSerializer implements JsonSerializer { + + @Override + public JsonElement serialize(SegmentItems src, Type typeOfSrc, JsonSerializationContext context) { + JsonArray applicationSegmentItems = new JsonArray(); + src.getSegmentItems().forEach((applicationCode, segmentItem) -> { + JsonObject segmentJson = new JsonObject(); + segmentJson.addProperty("applicationCode", applicationCode); + segmentJson.addProperty("segmentSize", segmentItem.getSegments().size()); + JsonArray segments = new JsonArray(); + segmentItem.getSegments().forEach(segment -> { + segments.add(new Gson().toJsonTree(segment)); + }); + segmentJson.add("segments", segments); + applicationSegmentItems.add(segmentJson); + }); + + return applicationSegmentItems; + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Span.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Span.java new file mode 100644 index 0000000000000000000000000000000000000000..ae51fdcf2b2c7862fce2e03df87ba4272f41b1cf --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Span.java @@ -0,0 +1,192 @@ +/* + * 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. + */ +/* + * Copyright 2017, OpenSkywalking Organization All rights reserved. + * + * 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. + * + * Project repository: https://github.com/OpenSkywalking/skywalking + */ + +package org.apache.skywalking.plugin.test.mockcollector.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; +import org.apache.skywalking.apm.network.common.KeyStringValuePair; +import org.apache.skywalking.apm.network.language.agent.KeyWithStringValue; +import org.apache.skywalking.apm.network.language.agent.TraceSegmentReference; +import org.apache.skywalking.apm.network.language.agent.UniqueId; +import org.apache.skywalking.apm.network.language.agent.v2.SegmentReference; + +import java.util.ArrayList; +import java.util.List; + +@Builder +@ToString +@AllArgsConstructor +public class Span { + private String operationName; + private int operationId; + private int parentSpanId; + private int spanId; + private String spanLayer; + private long startTime; + private long endTime; + private int componentId; + private String componentName; + private boolean isError; + private String spanType; + private String peer; + private int peerId; + private List tags = new ArrayList<>(); + private List logs = new ArrayList<>(); + private List refs = new ArrayList<>(); + + public static class LogEvent { + private List logEvent; + + public LogEvent() { + this.logEvent = new ArrayList<>(); + } + } + + public static class SpanBuilder { + public SpanBuilder logEvent(List eventMessage) { + if (logs == null) { + logs = new ArrayList<>(); + } + + LogEvent event = new LogEvent(); + for (KeyStringValuePair value : eventMessage) { + event.logEvent.add(new KeyValuePair(value.getKey(), value.getValue())); + } + logs.add(event); + return this; + } + + public SpanBuilder tags(String key, String value) { + if (tags == null) { + tags = new ArrayList<>(); + } + + tags.add(new KeyValuePair(key, value)); + return this; + } + + public SpanBuilder ref(SegmentRef segmentRefBuilder) { + if (refs == null) { + refs = new ArrayList<>(); + } + + refs.add(segmentRefBuilder); + return this; + } + + public SpanBuilder logEventV1(List dataList) { + if (logs == null) { + logs = new ArrayList<>(); + } + + LogEvent event = new LogEvent(); + for (KeyWithStringValue value : dataList) { + event.logEvent.add(new KeyValuePair(value.getKey(), value.getValue())); + } + logs.add(event); + return this; + } + } + + public static class KeyValuePair { + @Getter + private String key; + @Getter + private String value; + + public KeyValuePair(String key, String value) { + this.key = key; + this.value = value; + } + } + + @ToString + public static class SegmentRef { + @Getter + private int parentEndpointId; + @Getter + private String parentEndpoint; + @Getter + private int networkAddressId; + @Getter + private int entryEndpointId; + @Getter + private String refType; + @Getter + private int parentSpanId; + @Getter + private String parentTraceSegmentId; + @Getter + private int parentServiceInstanceId; + @Getter + private String networkAddress; + @Getter + private String entryEndpoint; + @Getter + private int entryServiceInstanceId; + + public SegmentRef(SegmentReference ref) { + UniqueId segmentUniqueId = ref.getParentTraceSegmentId(); + this.parentTraceSegmentId = String.join(".", Long.toString(segmentUniqueId.getIdParts(0)), Long.toString(segmentUniqueId.getIdParts(1)), Long.toString(segmentUniqueId.getIdParts(2))); + this.refType = ref.getRefType().toString(); + this.parentSpanId = ref.getParentSpanId(); + this.entryEndpointId = ref.getEntryEndpointId(); + this.networkAddressId = ref.getNetworkAddressId(); + this.parentServiceInstanceId = ref.getParentServiceInstanceId(); + this.parentEndpointId = ref.getParentEndpointId(); + this.parentEndpoint = ref.getParentEndpoint(); + this.networkAddress = ref.getNetworkAddress(); + this.entryEndpoint = ref.getEntryEndpoint(); + this.entryServiceInstanceId = ref.getEntryServiceInstanceId(); + } + + public SegmentRef(TraceSegmentReference ref) { + UniqueId segmentUniqueId = ref.getParentTraceSegmentId(); + this.parentTraceSegmentId = String.join(".", Long.toString(segmentUniqueId.getIdParts(0)), Long.toString(segmentUniqueId.getIdParts(1)), Long.toString(segmentUniqueId.getIdParts(2))); + this.refType = ref.getRefType().toString(); + this.parentSpanId = ref.getParentSpanId(); + this.entryEndpointId = ref.getEntryServiceId(); + this.networkAddressId = ref.getNetworkAddressId(); + this.parentServiceInstanceId = ref.getParentApplicationInstanceId(); + this.parentEndpointId = ref.getParentServiceId(); + this.parentEndpoint = ref.getParentServiceName(); + this.networkAddress = ref.getNetworkAddress(); + this.entryEndpoint = ref.getEntryServiceName(); + this.entryServiceInstanceId = ref.getEntryApplicationInstanceId(); + } + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/ValidateData.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/ValidateData.java new file mode 100644 index 0000000000000000000000000000000000000000..7c7ea1ad309b45a719f6f16c82c4b93a43433cb7 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/ValidateData.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.entity; + +public class ValidateData { + public static ValidateData INSTANCE = new ValidateData(); + private RegistryItem registryItem; + private SegmentItems segmentItem; + + public ValidateData() { + registryItem = new RegistryItem(); + segmentItem = new SegmentItems(); + } + + public RegistryItem getRegistryItem() { + return registryItem; + } + + public SegmentItems getSegmentItem() { + return segmentItem; + } + + public static void clearData(){ + System.out.println("Clear Data"); + INSTANCE.segmentItem = new SegmentItems(); + INSTANCE.registryItem.getOperationNames().clear(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/ValidateDataSerializer.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/ValidateDataSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..117563c2cad951e3e613a2293340b08260d75423 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/ValidateDataSerializer.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.entity; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; + +/** + * Created by xin on 2017/7/14. + */ +public class ValidateDataSerializer implements JsonSerializer { + @Override + public JsonElement serialize(ValidateData src, Type typeOfSrc, JsonSerializationContext context) { + Gson gson = new GsonBuilder().registerTypeAdapter(RegistryItem.class, new RegistryItemSerializer()) + .registerTypeAdapter(SegmentItems.class, new SegmentItemsSerializer()).create(); + + JsonObject jsonObject = new JsonObject(); + jsonObject.add("registryItems", gson.toJsonTree(src.getRegistryItem())); + jsonObject.add("segmentItems", gson.toJsonTree(src.getSegmentItem())); + return jsonObject; + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/ClearReceiveDataService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/ClearReceiveDataService.java new file mode 100644 index 0000000000000000000000000000000000000000..a90fc2b2648718063de5419fd98191d9178f3b34 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/ClearReceiveDataService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import java.io.IOException; +import java.io.Writer; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; + +public class ClearReceiveDataService extends HttpServlet { + + public static final String SERVLET_PATH = "/receiveData/clear"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/json"); + resp.setCharacterEncoding("utf-8"); + resp.setStatus(200); + ValidateData.clearData(); + Writer out = resp.getWriter(); + out.flush(); + out.close(); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doGet(req, resp); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/GrpcAddressHttpService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/GrpcAddressHttpService.java new file mode 100644 index 0000000000000000000000000000000000000000..85374db77e2237e51c55324b34f5592328247611 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/GrpcAddressHttpService.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import com.google.gson.JsonArray; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.plugin.test.mockcollector.util.ConfigReader; + +public class GrpcAddressHttpService extends HttpServlet { + + public static String SERVLET_PATH = "/agent/gRPC"; + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + JsonArray jsonArray = new JsonArray(); + jsonArray.add(ConfigReader.getGrpcBindHost() + ":" + ConfigReader.getGrpcBindPort()); + resp.setContentType("text/json"); + resp.setCharacterEncoding("utf-8"); + resp.setStatus(200); + + PrintWriter out = resp.getWriter(); + out.print(jsonArray.toString()); + out.flush(); + out.close(); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doPost(req, resp); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockApplicationRegisterService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockApplicationRegisterService.java new file mode 100644 index 0000000000000000000000000000000000000000..0c381179435951508c0bb6a19712f564613425ae --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockApplicationRegisterService.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import io.grpc.stub.StreamObserver; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.apm.network.language.agent.Application; +import org.apache.skywalking.apm.network.language.agent.ApplicationMapping; +import org.apache.skywalking.apm.network.language.agent.ApplicationRegisterServiceGrpc; +import org.apache.skywalking.apm.network.language.agent.KeyWithIntegerValue; +import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; + +/** + * Created by xin on 2017/7/11. + */ +public class MockApplicationRegisterService extends ApplicationRegisterServiceGrpc.ApplicationRegisterServiceImplBase { + private Logger logger = LogManager.getLogger(MockTraceSegmentService.class); + + @Override + public void applicationCodeRegister(Application request, StreamObserver responseObserver) { + logger.debug("receive application register."); + String applicationCode = request.getApplicationCode(); + ApplicationMapping.Builder builder = ApplicationMapping.newBuilder(); + + if (applicationCode.startsWith("localhost") || applicationCode.startsWith("127.0.0.1") || applicationCode.contains(":") || applicationCode.contains("/")) { + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + return; + } + + Integer applicationId = Sequences.SERVICE_MAPPING.get(applicationCode); + if (applicationId == null) { + applicationId = Sequences.ENDPOINT_SEQUENCE.incrementAndGet(); + Sequences.SERVICE_MAPPING.put(applicationCode, applicationId); + ValidateData.INSTANCE.getRegistryItem().registryApplication(new RegistryItem.Application(applicationCode, + applicationId)); + } + + builder.setApplication(KeyWithIntegerValue.newBuilder().setKey(applicationCode).setValue(applicationId)); + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockCLRMetricReportService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockCLRMetricReportService.java new file mode 100644 index 0000000000000000000000000000000000000000..95b57c34f81a9cdbf058cf7065efa47d7caed611 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockCLRMetricReportService.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import org.apache.skywalking.apm.network.language.agent.v2.CLRMetricReportServiceGrpc; + +/** + * Author Daming + * Email zteny@foxmail.com + **/ +public class MockCLRMetricReportService extends CLRMetricReportServiceGrpc.CLRMetricReportServiceImplBase { + +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockInstanceDiscoveryService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockInstanceDiscoveryService.java new file mode 100644 index 0000000000000000000000000000000000000000..510698968bab030bfb3dd6256cdeb3bc9f29b57a --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockInstanceDiscoveryService.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import io.grpc.stub.StreamObserver; + +import org.apache.skywalking.apm.network.language.agent.*; +import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; + +public class MockInstanceDiscoveryService extends InstanceDiscoveryServiceGrpc.InstanceDiscoveryServiceImplBase { + + + @Override + public void heartbeat(ApplicationInstanceHeartbeat request, StreamObserver responseObserver) { + ValidateData.INSTANCE.getRegistryItem().registryHeartBeat(new RegistryItem.HeartBeat(request.getApplicationInstanceId())); + responseObserver.onNext(Downstream.getDefaultInstance()); + responseObserver.onCompleted(); + } + + @Override + public void registerInstance(ApplicationInstance request, + StreamObserver responseObserver) { + int instanceId = Sequences.INSTANCE_SEQUENCE.incrementAndGet(); + ValidateData.INSTANCE.getRegistryItem().registryInstance(new RegistryItem.Instance(request.getApplicationId(), instanceId)); + + responseObserver.onNext(ApplicationInstanceMapping.newBuilder().setApplicationId(request.getApplicationId()) + .setApplicationInstanceId(instanceId).build()); + responseObserver.onCompleted(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockInstancePingService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockInstancePingService.java new file mode 100644 index 0000000000000000000000000000000000000000..6b2f24ac514bf8f55e009fe7d8dc52f6a06e3fa5 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockInstancePingService.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.network.common.Commands; +import org.apache.skywalking.apm.network.register.v2.ServiceInstancePingGrpc; +import org.apache.skywalking.apm.network.register.v2.ServiceInstancePingPkg; +import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; + +public class MockInstancePingService extends ServiceInstancePingGrpc.ServiceInstancePingImplBase { + + @Override + public void doPing(ServiceInstancePingPkg request, StreamObserver responseObserver) { + ValidateData.INSTANCE.getRegistryItem().registryHeartBeat(new RegistryItem.HeartBeat(request.getServiceInstanceId())); + responseObserver.onNext(Commands.getDefaultInstance()); + responseObserver.onCompleted(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricReportService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricReportService.java new file mode 100644 index 0000000000000000000000000000000000000000..dbc8826cb7041fe59281511d640ac29da95dd997 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricReportService.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import org.apache.skywalking.apm.network.language.agent.v2.JVMMetricReportServiceGrpc; + +/** + * Author Daming + * Email zteny@foxmail.com + **/ +public class MockJVMMetricReportService extends JVMMetricReportServiceGrpc.JVMMetricReportServiceImplBase { + +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricsService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricsService.java new file mode 100644 index 0000000000000000000000000000000000000000..7f46678756930f503f29b0ff74cd63fc610cccc6 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricsService.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.network.language.agent.Downstream; +import org.apache.skywalking.apm.network.language.agent.JVMMetrics; +import org.apache.skywalking.apm.network.language.agent.JVMMetricsServiceGrpc; + +/** + * Created by xin on 2017/7/11. + */ +public class MockJVMMetricsService extends JVMMetricsServiceGrpc.JVMMetricsServiceImplBase { + @Override + public void collect(JVMMetrics request, StreamObserver responseObserver) { + responseObserver.onNext(Downstream.getDefaultInstance()); + responseObserver.onCompleted(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricsV1Service.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricsV1Service.java new file mode 100644 index 0000000000000000000000000000000000000000..a45345e3576aac63c3edbeff0c4f7dbfee688233 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockJVMMetricsV1Service.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.network.language.agent.Downstream; +import org.apache.skywalking.apm.network.language.agent.JVMMetrics; +import org.apache.skywalking.apm.network.language.agent.JVMMetricsServiceGrpc; + +/** + * Created by xin on 2017/7/11. + */ +public class MockJVMMetricsV1Service extends JVMMetricsServiceGrpc.JVMMetricsServiceImplBase { + + @Override + public void collect(JVMMetrics request, StreamObserver responseObserver) { + responseObserver.onNext(Downstream.getDefaultInstance()); + responseObserver.onCompleted(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockNetworkAddressRegisterService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockNetworkAddressRegisterService.java new file mode 100644 index 0000000000000000000000000000000000000000..7e620d453f8d338172f9692f9bb6fcb09f7be7ba --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockNetworkAddressRegisterService.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.plugin.test.mockcollector.service; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.network.language.agent.NetworkAddressMappings; +import org.apache.skywalking.apm.network.language.agent.NetworkAddressRegisterServiceGrpc; +import org.apache.skywalking.apm.network.language.agent.NetworkAddresses; + +public class MockNetworkAddressRegisterService extends NetworkAddressRegisterServiceGrpc.NetworkAddressRegisterServiceImplBase { + + @Override + public void batchRegister(NetworkAddresses request, StreamObserver responseObserver) { + responseObserver.onNext(NetworkAddressMappings.getDefaultInstance()); + responseObserver.onCompleted(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockRegisterService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockRegisterService.java new file mode 100644 index 0000000000000000000000000000000000000000..43fbd440c68affc65d7263867effc9d1173b7352 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockRegisterService.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import io.grpc.stub.StreamObserver; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.apm.network.common.KeyIntValuePair; +import org.apache.skywalking.apm.network.register.v2.*; +import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; + +public class MockRegisterService extends RegisterGrpc.RegisterImplBase { + + private Logger logger = LogManager.getLogger(MockTraceSegmentService.class); + + + @Override + public void doEndpointRegister(Enpoints request, StreamObserver responseObserver) { + for (Endpoint endpoint : request.getEndpointsList()) { + ValidateData.INSTANCE.getRegistryItem().registryOperationName(new RegistryItem.OperationName(endpoint.getServiceId(), + endpoint.getEndpointName())); + } + responseObserver.onNext(EndpointMapping.getDefaultInstance()); + responseObserver.onCompleted(); + } + + @Override + public void doNetworkAddressRegister(NetAddresses request, StreamObserver responseObserver) { + responseObserver.onNext(NetAddressMapping.getDefaultInstance()); + responseObserver.onCompleted(); + } + + @Override + public void doServiceInstanceRegister(ServiceInstances request, StreamObserver responseObserver) { + if (request.getInstancesCount() <= 0) { + responseObserver.onNext(ServiceInstanceRegisterMapping.getDefaultInstance()); + responseObserver.onCompleted(); + return; + } + + for (ServiceInstance serviceInstance : request.getInstancesList()) { + int instanceId = Sequences.INSTANCE_SEQUENCE.incrementAndGet(); + ValidateData.INSTANCE.getRegistryItem().registryInstance(new RegistryItem.Instance(serviceInstance.getServiceId(), instanceId)); + + responseObserver.onNext(ServiceInstanceRegisterMapping.newBuilder().addServiceInstances(KeyIntValuePair.newBuilder() + .setKey(serviceInstance.getInstanceUUID()).setValue(instanceId).build()).build()); + responseObserver.onCompleted(); + } + } + + @Override + public void doServiceRegister(Services request, StreamObserver responseObserver) { + logger.debug("receive application register."); + if (request.getServicesCount() <= 0) { + logger.warn("The service count is empty. return the default service register mapping"); + responseObserver.onNext(ServiceRegisterMapping.getDefaultInstance()); + responseObserver.onCompleted(); + return; + } + + for (Service service : request.getServicesList()) { + String applicationCode = service.getServiceName(); + ServiceRegisterMapping.Builder builder = ServiceRegisterMapping.newBuilder(); + + if (applicationCode.startsWith("localhost") || applicationCode.startsWith("127.0.0.1") || applicationCode.contains(":") || applicationCode.contains("/")) { + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + return; + } + + Integer applicationId = Sequences.SERVICE_MAPPING.get(applicationCode); + if (applicationId == null) { + applicationId = Sequences.ENDPOINT_SEQUENCE.incrementAndGet(); + Sequences.SERVICE_MAPPING.put(applicationCode, applicationId); + ValidateData.INSTANCE.getRegistryItem().registryApplication(new RegistryItem.Application(applicationCode, + applicationId)); + } + + builder.addServices(KeyIntValuePair.newBuilder().setKey(applicationCode).setValue(applicationId).build()); + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + } + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockServiceNameDiscoveryService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockServiceNameDiscoveryService.java new file mode 100644 index 0000000000000000000000000000000000000000..52dce63bea331be2899057eea4e749d9e8bba39e --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockServiceNameDiscoveryService.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import io.grpc.stub.StreamObserver; +import org.apache.skywalking.apm.network.language.agent.ServiceNameCollection; +import org.apache.skywalking.apm.network.language.agent.ServiceNameDiscoveryServiceGrpc; +import org.apache.skywalking.apm.network.language.agent.ServiceNameElement; +import org.apache.skywalking.apm.network.language.agent.ServiceNameMappingCollection; +import org.apache.skywalking.plugin.test.mockcollector.entity.RegistryItem; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; + +public class MockServiceNameDiscoveryService extends ServiceNameDiscoveryServiceGrpc.ServiceNameDiscoveryServiceImplBase { + + @Override + public void discovery(ServiceNameCollection request, + StreamObserver responseObserver) { + for (ServiceNameElement element : request.getElementsList()) { + ValidateData.INSTANCE.getRegistryItem().registryOperationName(new RegistryItem.OperationName(element.getApplicationId(), + element.getServiceName())); + } + responseObserver.onNext(ServiceNameMappingCollection.getDefaultInstance()); + responseObserver.onCompleted(); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockTraceSegmentService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockTraceSegmentService.java new file mode 100644 index 0000000000000000000000000000000000000000..095f372f816814c0c768367800451e98ba91626c --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockTraceSegmentService.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import com.google.protobuf.InvalidProtocolBufferException; +import io.grpc.stub.StreamObserver; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.apm.network.common.Commands; +import org.apache.skywalking.apm.network.common.KeyStringValuePair; +import org.apache.skywalking.apm.network.language.agent.*; +import org.apache.skywalking.apm.network.language.agent.v2.*; +import org.apache.skywalking.plugin.test.mockcollector.entity.Segment; +import org.apache.skywalking.plugin.test.mockcollector.entity.Span; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; + +public class MockTraceSegmentService extends TraceSegmentReportServiceGrpc.TraceSegmentReportServiceImplBase { + + private Logger logger = LogManager.getLogger(MockTraceSegmentService.class); + + @Override + public StreamObserver collect(StreamObserver responseObserver) { + return new StreamObserver() { + @Override public void onNext(UpstreamSegment value) { + try { + SegmentObject traceSegmentObject = SegmentObject.parseFrom(value.getSegment()); + Segment.SegmentBuilder segmentBuilder = Segment.builder().segmentId(traceSegmentObject.getTraceSegmentId()); + logger.debug("Receive segment: ServiceID[{}], TraceSegmentId[{}]", + traceSegmentObject.getServiceId(), + traceSegmentObject.getTraceSegmentId()); + + for (SpanObjectV2 spanObject : traceSegmentObject.getSpansList()) { + Span.SpanBuilder spanBuilder = Span.builder().operationName(spanObject.getOperationName()).parentSpanId(spanObject.getParentSpanId()) + .spanId(spanObject.getSpanId()).componentId(spanObject.getComponentId()).componentName(spanObject.getComponent()) + .spanLayer(spanObject.getSpanLayer().toString()).endTime(spanObject.getEndTime()) + .startTime(spanObject.getStartTime()).spanType(spanObject.getSpanType().toString()) + .peer(spanObject.getPeer()).peerId(spanObject.getPeerId()).operationId(spanObject.getOperationNameId()); + + for (Log logMessage : spanObject.getLogsList()) { + spanBuilder.logEvent(logMessage.getDataList()); + } + + for (KeyStringValuePair tags : spanObject.getTagsList()) { + spanBuilder.tags(tags.getKey(), tags.getValue()); + } + + for (SegmentReference ref : spanObject.getRefsList()) { + spanBuilder.ref(new Span.SegmentRef(ref)); + } + + segmentBuilder.addSpan(spanBuilder); + } + + ValidateData.INSTANCE.getSegmentItem().addSegmentItem(traceSegmentObject.getServiceId(), segmentBuilder.build()); + } catch (InvalidProtocolBufferException e) { + e.printStackTrace(); + } + } + + @Override public void onError(Throwable t) { + + } + + @Override public void onCompleted() { + responseObserver.onNext(Commands.newBuilder().build()); + responseObserver.onCompleted(); + } + }; + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockTraceSegmentV1Service.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockTraceSegmentV1Service.java new file mode 100644 index 0000000000000000000000000000000000000000..659c3b7265cf14d5203b508080a036ac1ad6e6d6 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/MockTraceSegmentV1Service.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import com.google.protobuf.InvalidProtocolBufferException; +import io.grpc.stub.StreamObserver; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.apm.network.language.agent.*; +import org.apache.skywalking.plugin.test.mockcollector.entity.Segment; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; +import org.apache.skywalking.plugin.test.mockcollector.entity.Span; + +public class MockTraceSegmentV1Service extends TraceSegmentServiceGrpc.TraceSegmentServiceImplBase { + + private Logger logger = LogManager.getLogger(MockTraceSegmentService.class); + + @Override + public StreamObserver collect(final StreamObserver responseObserver) { + return new StreamObserver() { + @Override public void onNext(UpstreamSegment value) { + try { + TraceSegmentObject traceSegmentObject = TraceSegmentObject.parseFrom(value.getSegment()); + Segment.SegmentBuilder segmentBuilder = Segment.builder().segmentId(traceSegmentObject.getTraceSegmentId()); + logger.debug("Receive segment: Application[{}], TraceSegmentId[{}]", + traceSegmentObject.getApplicationId(), + traceSegmentObject.getTraceSegmentId()); + + for (SpanObject spanObject : traceSegmentObject.getSpansList()) { + Span.SpanBuilder spanBuilder = Span.builder().operationName(spanObject.getOperationName()).parentSpanId(spanObject.getParentSpanId()) + .spanId(spanObject.getSpanId()).componentId(spanObject.getComponentId()).componentName(spanObject.getComponent()) + .spanLayer(spanObject.getSpanLayer().toString()).endTime(spanObject.getEndTime()) + .startTime(spanObject.getStartTime()).spanType(spanObject.getSpanType().toString()) + .peer(spanObject.getPeer()).peerId(spanObject.getPeerId()).operationId(spanObject.getOperationNameId()); + + for (LogMessage logMessage : spanObject.getLogsList()) { + spanBuilder.logEventV1(logMessage.getDataList()); + } + + for (KeyWithStringValue tags : spanObject.getTagsList()) { + spanBuilder.tags(tags.getKey(), tags.getValue()); + } + + for (TraceSegmentReference ref : spanObject.getRefsList()) { + spanBuilder.ref(new Span.SegmentRef(ref)); + } + + segmentBuilder.addSpan(spanBuilder); + } + + ValidateData.INSTANCE.getSegmentItem().addSegmentItem(traceSegmentObject.getApplicationId(), segmentBuilder.build()); + } catch (InvalidProtocolBufferException e) { + e.printStackTrace(); + } + } + + @Override public void onError(Throwable t) { + + } + + @Override public void onCompleted() { + responseObserver.onNext(Downstream.getDefaultInstance()); + responseObserver.onCompleted(); + } + }; + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/ReceiveDataService.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/ReceiveDataService.java new file mode 100644 index 0000000000000000000000000000000000000000..368e27c73fea42f5b292f903a7701b5408f05bc4 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/ReceiveDataService.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.io.IOException; +import java.io.Writer; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateData; +import org.apache.skywalking.plugin.test.mockcollector.entity.ValidateDataSerializer; +import org.yaml.snakeyaml.Yaml; + +public class ReceiveDataService extends HttpServlet { + public static final String SERVLET_PATH = "/receiveData"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/json"); + resp.setCharacterEncoding("utf-8"); + resp.setStatus(200); + Gson gson = new GsonBuilder().registerTypeAdapter(ValidateData.class, new ValidateDataSerializer()).create(); + System.out.println(); + Yaml yaml = new Yaml(); + Writer out = resp.getWriter(); + out.write(yaml.dump(yaml.load(gson.toJson(ValidateData.INSTANCE)))); + out.flush(); + out.close(); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doGet(req, resp); + } +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/Sequences.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/Sequences.java new file mode 100644 index 0000000000000000000000000000000000000000..dbcca97ed873750d9749d006b5e06080d8e9215d --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/service/Sequences.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.service; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +public class Sequences { + + public static final AtomicInteger INSTANCE_SEQUENCE = new AtomicInteger(); + + public static final AtomicInteger ENDPOINT_SEQUENCE = new AtomicInteger(1); + + public static final ConcurrentHashMap SERVICE_MAPPING = new ConcurrentHashMap(); +} diff --git a/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/util/ConfigReader.java b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/util/ConfigReader.java new file mode 100644 index 0000000000000000000000000000000000000000..4704e5e9b11bdb0e57ccc984f8dc8a3130eaa4e1 --- /dev/null +++ b/test/plugin/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/util/ConfigReader.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.mockcollector.util; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class ConfigReader { + private static Properties config = new Properties(); + + static { + InputStream inputStream = ConfigReader.class.getClassLoader().getResourceAsStream("config.properties"); + try { + config.load(inputStream); + } catch (IOException e) { + System.err.println("Failed to load config."); + System.exit(-1); + } + } + + public static String getGrpcBindHost() { + return config.getProperty("grpc_bind_host","127.0.0.1"); + } + + public static int getGrpcBindPort() { + return Integer.parseInt(config.getProperty("grpc_bind_port","19876")); + } +} diff --git a/test/plugin/mock-collector/src/main/proto/README.md b/test/plugin/mock-collector/src/main/proto/README.md new file mode 100644 index 0000000000000000000000000000000000000000..536bc1f2e6f3a1b048505fb3d9e44ee320600165 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/README.md @@ -0,0 +1,5 @@ +# Apache SkyWalking data collect protocol +Apache SkyWalking can collect data from different sources. Each kind of source should follow the protocols in this repo. + +## License +Apache 2.0 diff --git a/test/plugin/mock-collector/src/main/proto/common/CLR.proto b/test/plugin/mock-collector/src/main/proto/common/CLR.proto new file mode 100644 index 0000000000000000000000000000000000000000..57bc8600fd8e5e5a2317027d7078f998e9bb2bf3 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/common/CLR.proto @@ -0,0 +1,46 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "common/common.proto"; + +message CLRMetric { + int64 time = 1; + CPU cpu = 2; + ClrGC gc = 3; + ClrThread thread = 4; +} + +message ClrGC { + int64 Gen0CollectCount = 1; + int64 Gen1CollectCount = 2; + int64 Gen2CollectCount = 3; + int64 HeapMemory = 4; +} + +message ClrThread { + int32 AvailableCompletionPortThreads = 1; + int32 AvailableWorkerThreads = 2; + int32 MaxCompletionPortThreads = 3; + int32 MaxWorkerThreads = 4; +} \ No newline at end of file diff --git a/test/plugin/mock-collector/src/main/proto/common/JVM.proto b/test/plugin/mock-collector/src/main/proto/common/JVM.proto new file mode 100644 index 0000000000000000000000000000000000000000..543c640dc636e3867485c2b0db3bdd5e21f597e4 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/common/JVM.proto @@ -0,0 +1,69 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "common/common.proto"; + +message JVMMetric { + int64 time = 1; + CPU cpu = 2; + repeated Memory memory = 3; + repeated MemoryPool memoryPool = 4; + repeated GC gc = 5; +} + +message Memory { + bool isHeap = 1; + int64 init = 2; + int64 max = 3; + int64 used = 4; + int64 committed = 5; +} + +message MemoryPool { + PoolType type = 1; + int64 init = 2; + int64 max = 3; + int64 used = 4; + int64 commited = 5; +} + +enum PoolType { + CODE_CACHE_USAGE = 0; + NEWGEN_USAGE = 1; + OLDGEN_USAGE = 2; + SURVIVOR_USAGE = 3; + PERMGEN_USAGE = 4; + METASPACE_USAGE = 5; +} + +message GC { + GCPhrase phrase = 1; + int64 count = 2; + int64 time = 3; +} + +enum GCPhrase { + NEW = 0; + OLD = 1; +} diff --git a/test/plugin/mock-collector/src/main/proto/common/common.proto b/test/plugin/mock-collector/src/main/proto/common/common.proto new file mode 100644 index 0000000000000000000000000000000000000000..ce50c7662c744a933717c04f1e2776d79cf25f9c --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/common/common.proto @@ -0,0 +1,55 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.common"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +message KeyStringValuePair { + string key = 1; + string value = 2; +} + +message KeyIntValuePair { + string key = 1; + int32 value = 2; +} + +message CPU { + double usagePercent = 2; +} + +// In most cases, detect point should be `server` or `client`. +// Even in service mesh, this means `server`/`client` side sidecar +// `proxy` is reserved only. +enum DetectPoint { + client = 0; + server = 1; + proxy = 2; +} + +message Commands { + repeated Command commands = 1; +} + +message Command { + string command = 1; + repeated KeyStringValuePair args = 2; +} diff --git a/test/plugin/mock-collector/src/main/proto/common/trace-common.proto b/test/plugin/mock-collector/src/main/proto/common/trace-common.proto new file mode 100644 index 0000000000000000000000000000000000000000..dcbe03d166170f7920804d757a97f2becb0535e3 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/common/trace-common.proto @@ -0,0 +1,52 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +message UpstreamSegment { + repeated UniqueId globalTraceIds = 1; + bytes segment = 2; // the byte array of TraceSegmentObject +} + +enum SpanType { + Entry = 0; + Exit = 1; + Local = 2; +} + +message UniqueId { + repeated int64 idParts = 1; +} + +enum RefType { + CrossProcess = 0; + CrossThread = 1; +} + +enum SpanLayer { + Unknown = 0; + Database = 1; + RPCFramework = 2; + Http = 3; + MQ = 4; + Cache = 5; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent-v2/CLRMetric.proto b/test/plugin/mock-collector/src/main/proto/language-agent-v2/CLRMetric.proto new file mode 100644 index 0000000000000000000000000000000000000000..da023b6a2cb2e7dad34cd62e1b8e43dabd598939 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent-v2/CLRMetric.proto @@ -0,0 +1,36 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent.v2"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "common/common.proto"; +import "common/CLR.proto"; + +service CLRMetricReportService { + rpc collect (CLRMetricCollection) returns (Commands) { + } +} + +message CLRMetricCollection { + repeated CLRMetric metrics = 1; + int32 serviceInstanceId = 2; +} \ No newline at end of file diff --git a/test/plugin/mock-collector/src/main/proto/language-agent-v2/JVMMetric.proto b/test/plugin/mock-collector/src/main/proto/language-agent-v2/JVMMetric.proto new file mode 100644 index 0000000000000000000000000000000000000000..845624cdf247275ced94aaacfd3b5d6302c246aa --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent-v2/JVMMetric.proto @@ -0,0 +1,36 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent.v2"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "common/common.proto"; +import "common/JVM.proto"; + +service JVMMetricReportService { + rpc collect (JVMMetricCollection) returns (Commands) { + } +} + +message JVMMetricCollection { + repeated JVMMetric metrics = 1; + int32 serviceInstanceId = 2; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent-v2/trace.proto b/test/plugin/mock-collector/src/main/proto/language-agent-v2/trace.proto new file mode 100644 index 0000000000000000000000000000000000000000..c6120c58561c771d54f68a99867b61d58b414bbf --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent-v2/trace.proto @@ -0,0 +1,77 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent.v2"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "common/common.proto"; +import "common/trace-common.proto"; + +service TraceSegmentReportService { + rpc collect (stream UpstreamSegment) returns (Commands) { + } +} + +message SegmentObject { + UniqueId traceSegmentId = 1; + repeated SpanObjectV2 spans = 2; + int32 serviceId = 3; + int32 serviceInstanceId = 4; + bool isSizeLimited = 5; +} + +message SegmentReference { + RefType refType = 1; + UniqueId parentTraceSegmentId = 2; + int32 parentSpanId = 3; + int32 parentServiceInstanceId = 4; + string networkAddress = 5; + int32 networkAddressId = 6; + int32 entryServiceInstanceId = 7; + string entryEndpoint = 8; + int32 entryEndpointId = 9; + string parentEndpoint = 10; + int32 parentEndpointId = 11; +} + +message SpanObjectV2 { + int32 spanId = 1; + int32 parentSpanId = 2; + int64 startTime = 3; + int64 endTime = 4; + repeated SegmentReference refs = 5; + int32 operationNameId = 6; + string operationName = 7; + int32 peerId = 8; + string peer = 9; + SpanType spanType = 10; + SpanLayer spanLayer = 11; + int32 componentId = 12; + string component = 13; + bool isError = 14; + repeated KeyStringValuePair tags = 15; + repeated Log logs = 16; +} + +message Log { + int64 time = 1; + repeated KeyStringValuePair data = 2; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent/ApplicationRegisterService.proto b/test/plugin/mock-collector/src/main/proto/language-agent/ApplicationRegisterService.proto new file mode 100644 index 0000000000000000000000000000000000000000..fd8ee0d4d02b371d279464e509b535f53f9b1bdb --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent/ApplicationRegisterService.proto @@ -0,0 +1,39 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "language-agent/KeyWithIntegerValue.proto"; + +//register service for ApplicationCode, this service is called when service starts. +service ApplicationRegisterService { + rpc applicationCodeRegister (Application) returns (ApplicationMapping) { + } +} + +message Application { + string applicationCode = 1; +} + +message ApplicationMapping { + KeyWithIntegerValue application = 1; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent/DiscoveryService.proto b/test/plugin/mock-collector/src/main/proto/language-agent/DiscoveryService.proto new file mode 100644 index 0000000000000000000000000000000000000000..bc392a72c8ba7e2677423086f5c9fdde714ad316 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent/DiscoveryService.proto @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "language-agent/Downstream.proto"; +import "common/trace-common.proto"; + +service InstanceDiscoveryService { + rpc registerInstance (ApplicationInstance) returns (ApplicationInstanceMapping) { + } + + rpc heartbeat (ApplicationInstanceHeartbeat) returns (Downstream) { + } + +} + +message ApplicationInstance { + int32 applicationId = 1; + string agentUUID = 2; + int64 registerTime = 3; + OSInfo osinfo = 4; +} + +message ApplicationInstanceMapping { + int32 applicationId = 1; + int32 applicationInstanceId = 2; +} + +message ApplicationInstanceRecover { + int32 applicationId = 1; + int32 applicationInstanceId = 2; + int64 registerTime = 3; + OSInfo osinfo = 4; +} + +message ApplicationInstanceHeartbeat { + int32 applicationInstanceId = 1; + int64 heartbeatTime = 2; +} + +message OSInfo { + string osName = 1; + string hostname = 2; + int32 processNo = 3; + repeated string ipv4s = 4; +} + +//discovery service for ServiceName by Network address or application code +service ServiceNameDiscoveryService { + rpc discovery (ServiceNameCollection) returns (ServiceNameMappingCollection) { + } +} + +message ServiceNameCollection { + repeated ServiceNameElement elements = 1; +} + +message ServiceNameMappingCollection { + repeated ServiceNameMappingElement elements = 1; +} + +message ServiceNameMappingElement { + int32 serviceId = 1; + ServiceNameElement element = 2; +} + +message ServiceNameElement { + string serviceName = 1; + int32 applicationId = 2; + SpanType srcSpanType = 3; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent/Downstream.proto b/test/plugin/mock-collector/src/main/proto/language-agent/Downstream.proto new file mode 100644 index 0000000000000000000000000000000000000000..e7bbb39a238c2560a97e90ac7f9c1d403f26e441 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent/Downstream.proto @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +// nothing down stream from collector yet. +message Downstream { +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent/JVMMetricsService.proto b/test/plugin/mock-collector/src/main/proto/language-agent/JVMMetricsService.proto new file mode 100644 index 0000000000000000000000000000000000000000..229f41a965d8858955a943b7b90a0b2e7bfa43d2 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent/JVMMetricsService.proto @@ -0,0 +1,36 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "language-agent/Downstream.proto"; +import "common/JVM.proto"; + +service JVMMetricsService { + rpc collect (JVMMetrics) returns (Downstream) { + } +} + +message JVMMetrics { + repeated JVMMetric metrics = 1; + int32 applicationInstanceId = 2; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent/KeyWithIntegerValue.proto b/test/plugin/mock-collector/src/main/proto/language-agent/KeyWithIntegerValue.proto new file mode 100644 index 0000000000000000000000000000000000000000..ed48a5485b7702e99f0b142d22d5892774537e8c --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent/KeyWithIntegerValue.proto @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +message KeyWithIntegerValue { + string key = 1; + int32 value = 2; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent/KeyWithStringValue.proto b/test/plugin/mock-collector/src/main/proto/language-agent/KeyWithStringValue.proto new file mode 100644 index 0000000000000000000000000000000000000000..111426775e04157cd07499b7749cde9e1968ec68 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent/KeyWithStringValue.proto @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +message KeyWithStringValue { + string key = 1; + string value = 2; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent/NetworkAddressRegisterService.proto b/test/plugin/mock-collector/src/main/proto/language-agent/NetworkAddressRegisterService.proto new file mode 100644 index 0000000000000000000000000000000000000000..a299edcf631f11bde18472208372e9b5b72bc52e --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent/NetworkAddressRegisterService.proto @@ -0,0 +1,38 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "language-agent/KeyWithIntegerValue.proto"; + +service NetworkAddressRegisterService { + rpc batchRegister (NetworkAddresses) returns (NetworkAddressMappings) { + } +} + +message NetworkAddresses { + repeated string addresses = 1; +} + +message NetworkAddressMappings { + repeated KeyWithIntegerValue addressIds = 1; +} diff --git a/test/plugin/mock-collector/src/main/proto/language-agent/TraceSegmentService.proto b/test/plugin/mock-collector/src/main/proto/language-agent/TraceSegmentService.proto new file mode 100644 index 0000000000000000000000000000000000000000..f8566b2da45dfa35da8ff38a7ff0961ba4d39768 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/language-agent/TraceSegmentService.proto @@ -0,0 +1,78 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.language.agent"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "language-agent/Downstream.proto"; +import "language-agent/KeyWithStringValue.proto"; +import "common/trace-common.proto"; + +service TraceSegmentService { + rpc collect (stream UpstreamSegment) returns (Downstream) { + } +} + +message TraceSegmentObject { + UniqueId traceSegmentId = 1; + repeated SpanObject spans = 2; + int32 applicationId = 3; + int32 applicationInstanceId = 4; + bool isSizeLimited = 5; +} + +message TraceSegmentReference { + RefType refType = 1; + UniqueId parentTraceSegmentId = 2; + int32 parentSpanId = 3; + int32 parentApplicationInstanceId = 4; + string networkAddress = 5; + int32 networkAddressId = 6; + int32 entryApplicationInstanceId = 7; + string entryServiceName = 8; + int32 entryServiceId = 9; + string parentServiceName = 10; + int32 parentServiceId = 11; +} + +message SpanObject { + int32 spanId = 1; + int32 parentSpanId = 2; + int64 startTime = 3; + int64 endTime = 4; + repeated TraceSegmentReference refs = 5; + int32 operationNameId = 6; + string operationName = 7; + int32 peerId = 8; + string peer = 9; + SpanType spanType = 10; + SpanLayer spanLayer = 11; + int32 componentId = 12; + string component = 13; + bool isError = 14; + repeated KeyWithStringValue tags = 15; + repeated LogMessage logs = 16; +} + +message LogMessage { + int64 time = 1; + repeated KeyWithStringValue data = 2; +} diff --git a/test/plugin/mock-collector/src/main/proto/register/InstancePing.proto b/test/plugin/mock-collector/src/main/proto/register/InstancePing.proto new file mode 100644 index 0000000000000000000000000000000000000000..3a8ffe16c6a3dc11dc561978dd4971293aae6ce3 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/register/InstancePing.proto @@ -0,0 +1,36 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.register.v2"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "common/common.proto"; + +service ServiceInstancePing { + rpc doPing (ServiceInstancePingPkg) returns (Commands) { + } +} + +message ServiceInstancePingPkg { + int32 serviceInstanceId = 1; + int64 time = 2; + string serviceInstanceUUID = 3; +} diff --git a/test/plugin/mock-collector/src/main/proto/register/Register.proto b/test/plugin/mock-collector/src/main/proto/register/Register.proto new file mode 100644 index 0000000000000000000000000000000000000000..aff9ea5be530a950626ace6d1827f19348e3421f --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/register/Register.proto @@ -0,0 +1,124 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.register.v2"; +option csharp_namespace = "SkyWalking.NetworkProtocol"; + +import "common/common.proto"; + +//register service for ApplicationCode, this service is called when service starts. +service Register { + rpc doServiceRegister (Services) returns (ServiceRegisterMapping) { + } + + rpc doServiceInstanceRegister (ServiceInstances) returns (ServiceInstanceRegisterMapping) { + } + + rpc doEndpointRegister (Enpoints) returns (EndpointMapping) { + } + + rpc doNetworkAddressRegister (NetAddresses) returns (NetAddressMapping) { + } + + rpc doServiceAndNetworkAddressMappingRegister (ServiceAndNetworkAddressMappings) returns(Commands) { + } +} + +// Service register +message Services { + repeated Service services = 1; +} + +message Service { + string serviceName = 1; + repeated KeyStringValuePair tags = 3; + repeated KeyStringValuePair properties = 4; +} + +message ServiceRegisterMapping { + repeated KeyIntValuePair services = 1; +} + +// Service Instance register +message ServiceInstances { + repeated ServiceInstance instances = 1; +} + +message ServiceInstance { + int32 serviceId = 1; + string instanceUUID = 2; + int64 time = 3; + repeated KeyStringValuePair tags = 4; + repeated KeyStringValuePair properties = 5; +} + +message ServiceInstanceRegisterMapping { + repeated KeyIntValuePair serviceInstances = 1; +} + +// Network address register + +// Only known use case is the language agent. +// Network address represents the ip/hostname:port, which is usually used at client side of RPC. +message NetAddresses { + repeated string addresses = 1; +} + +message NetAddressMapping { + repeated KeyIntValuePair addressIds = 1; +} + +// Endpint register +message Enpoints { + repeated Endpoint endpoints = 1; +} + +message Endpoint { + int32 serviceId = 1; + string endpointName = 2; + repeated KeyStringValuePair tags = 3; + repeated KeyStringValuePair properties = 4; + // For endpoint + // from DetectPoint is either `client` or `server`. No chance to be `proxy`. + DetectPoint from = 5; +} + +message EndpointMapping { + repeated EndpointMappingElement elements = 1; +} + +message EndpointMappingElement { + int32 serviceId = 1; + string endpointName = 2; + int32 endpointId = 3; + DetectPoint from = 4; +} + +message ServiceAndNetworkAddressMappings { + repeated ServiceAndNetworkAddressMapping mappings = 1; +} + +message ServiceAndNetworkAddressMapping { + int32 serviceId = 1; + int32 serviceInstanceId = 2; + string networkAddress = 3; + int32 networkAddressId = 4; +} diff --git a/test/plugin/mock-collector/src/main/proto/service-mesh-probe/istio/skywalking.config.pb.html b/test/plugin/mock-collector/src/main/proto/service-mesh-probe/istio/skywalking.config.pb.html new file mode 100644 index 0000000000000000000000000000000000000000..a92c8040766d7e116bcc2c68207b8d765ee1e8c1 --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/service-mesh-probe/istio/skywalking.config.pb.html @@ -0,0 +1,39 @@ +--- +title: Apache SkyWalking +description: Adapter to deliver metrics to Apache SkyWalking. +location: https://istio.io/docs/reference/config/policy-and-telemetry/adapters/apache-skywalking.html +layout: protoc-gen-docs +generator: protoc-gen-docs +provider: Apache SkyWalking +contact_email: dev@skywalking.apache.org +support_link: +source_link: https://github.com/apache/skywalking +latest_release_link: https://skywalking.apache.org/downloads/ +helm_chart_link: +istio_versions: "1.0.3, 1.0.4, 1.1.0, 1.1.1" +supported_templates: metric +logo_link: https://github.com/apache/skywalking-website/raw/master/docs/.vuepress/public/assets/logo.svg +number_of_entries: 1 +--- + + + +

The SkyWalking adapter uses the Istio bypass adapter to collect metrics and make them available to +Apache SkyWalking. SkyWalking provides a topology map and metrics graph +to visualize the whole mesh.

+ +

This adapter supports the metric template.

+ +

Follow the official Apache SkyWalking documentation +and SkyWalking k8s documentation for details on configuring SkyWalking and the Istio bypass adapter.

diff --git a/test/plugin/mock-collector/src/main/proto/service-mesh-probe/service-mesh.proto b/test/plugin/mock-collector/src/main/proto/service-mesh-probe/service-mesh.proto new file mode 100644 index 0000000000000000000000000000000000000000..87e0b70d425f2c95186ec988a85de13c9d5a69ef --- /dev/null +++ b/test/plugin/mock-collector/src/main/proto/service-mesh-probe/service-mesh.proto @@ -0,0 +1,56 @@ +/* + * 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. + * + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.skywalking.apm.network.servicemesh"; + +import "common/common.proto"; + +service ServiceMeshMetricService { + rpc collect(stream ServiceMeshMetric) returns (MeshProbeDownstream) { + } +} + +message ServiceMeshMetric { + int64 startTime = 1; + int64 endTime = 2; + string sourceServiceName = 3; + int32 sourceServiceId = 4; + string sourceServiceInstance = 5; + int32 sourceServiceInstanceId = 6; + string destServiceName = 7; + int32 destServiceId = 8; + string destServiceInstance = 9; + int32 destServiceInstanceId = 10; + string endpoint = 11; + int32 latency = 12; + int32 responseCode = 13; + bool status = 14; + Protocol protocol = 15; + DetectPoint detectPoint = 16; +} + +enum Protocol { + HTTP = 0; + gRPC = 1; +} + +message MeshProbeDownstream { +} diff --git a/test/plugin/mock-collector/src/main/resources/config.properties b/test/plugin/mock-collector/src/main/resources/config.properties new file mode 100644 index 0000000000000000000000000000000000000000..88fd1c8bf0ab8491a1384937a1bbc09e0f6adc21 --- /dev/null +++ b/test/plugin/mock-collector/src/main/resources/config.properties @@ -0,0 +1,17 @@ +# 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. + +grpc_bind_host=127.0.0.1 +grpc_bind_port=19876 diff --git a/test/plugin/mock-collector/src/main/resources/expect-data.yaml b/test/plugin/mock-collector/src/main/resources/expect-data.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ed70818f50be8ae5ec97eb9b18802d470829abae --- /dev/null +++ b/test/plugin/mock-collector/src/main/resources/expect-data.yaml @@ -0,0 +1,78 @@ +# 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. +expectData: + - registryItem: + - applications: + - test-applicationCode1: nq 0 // the application id of test-applicationCode is 3 + - test-applicationCode2: nq 0 + - operationNames: + - test-applicationCode1: {testOperationName, testOperationName1} // there are three operation names in test-applicationCode1 has been registery + - instances: + - test-applicationCode1: eq 3 // test-applicationCode1 has 3 instances + - test-applicationCode2: 1 // test-applicationCode2 has 1 instance + - heartbeat: + - test-applicationCode1: gt 2 // there are 3 instance of test-applicationCode has been send heartbeat + + - segmentsItems: + - + test-applicationCode: 1 // test-applicationCode has seend 1 segment. + segments: + - + segmentId: not null + refs: + - parentSpanId: 1 + - parentTraceSegmentId: ${test-applicationCode2[0]} + - networkAddress: xxx + - parentServiceId: 1 + - parentServiceName: not null + - networkAddressId: 1 + - entryServiceId: 1 + - refType: xx + - parentApplicationInstanceId: 1 + - entryServiceName: xx + spans: + - + operationName: testOperationName + parentSpanId: 0 + spanId: 1 + spanLayer: HTTP + logs: + - xx: xx + - bb: bb + tags: + - xx: xx + - aa: aa + stattime: not empty + endtime: not empty + componentId: 1 + componentName: + spanType: Entry + isError: false + - + test-applicationCode2: 2 + segments: + - + segmentId: not null + spans: + - + operationName: testOperationName + parentSpanId: 0 + spanId: 1 + spanLayer: HTTP + logs: + - xx: xx + - bb: bb + globalSegmentId: diff --git a/test/plugin/mock-collector/src/main/resources/log4j2.xml b/test/plugin/mock-collector/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..f8cf727437f7937db95d8139feffb8af3605052b --- /dev/null +++ b/test/plugin/mock-collector/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + diff --git a/test/plugin/mock-collector/src/main/resources/sample-data.yaml b/test/plugin/mock-collector/src/main/resources/sample-data.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a648290d3e26debdddfd2cc4ce8b38ea37eeb6a1 --- /dev/null +++ b/test/plugin/mock-collector/src/main/resources/sample-data.yaml @@ -0,0 +1,68 @@ +# 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. +# +validateData: + - registryItem: + - applications: + - test-applicationCode1: 3 // the application id of test-applicationCode is 3 + - test-applicationCode2: 1 + - operationNames: + - test-applicationCode1: {testOperationName, testOperationName1} // there are three operation names in test-applicationCode1 has been registery + - instances: + - test-applicationCode1: 3 // test-applicationCode1 has 3 instances + - test-applicationCode2: 1 // test-applicationCode2 has 1 instance + - heartbeat: + - test-applicationCode1: 3 // there are 3 instance of test-applicationCode has been send heartbeat + + - segmentsItems: + - + test-applicationCode: 1 // test-applicationCode has seend 1 segment. + segments: + - + segmentId: xxxx + refs: + - parentSpanId: 1 + - parentTraceSegmentId: ${test-applicationCode2[0]} + - networkAddress: xxx + - parentServiceId: 1 + - parentServiceName: not null + - networkAddressId: 1 + - entryServiceId: 1 + - refType: xx + - parentApplicationInstanceId: 1 + - entryServiceName: xx + spans: + - + operationName: testOperationName + parentSpanId: 0 + spanId: 1 + spanLayer: HTTP + logs: + - xx: xx + - bb: bb + tags: + - xx: xx + - aa: aa + stattime: 141 + endtime: 141 + componentId: 1 + componentName: + spanType: Entry + isError: false + - + test-applicationCode2: 2 + segments: + //..... diff --git a/test/plugin/pom.xml b/test/plugin/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..655d9e7ab9f1c824457644fffbd4f6cb706b0012 --- /dev/null +++ b/test/plugin/pom.xml @@ -0,0 +1,117 @@ + + + + + + 4.0.0 + + org.apache.skywalking.plugin + apache-skywalking-test-plugin + 1.0.0 + + SkyWalking Plugins Tests + pom + + + runner + validator + mock-collector + containers + + + + 1.8 + ${java.version} + ${java.version} + + UTF-8 + + 4.11 + 20.0 + 2.8.5 + 1.18.4 + 1.24 + + 3.8.0 + 0.4.13 + + 1.0.0 + true + + + + + junit + junit + ${junit.version} + + + + com.google.guava + guava + ${guava.version} + + + + org.yaml + snakeyaml + ${snakeyaml.version} + + + + org.apache.logging.log4j + log4j-core + 2.8.1 + + + + org.apache.logging.log4j + log4j-api + 2.8.1 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.source} + ${project.build.sourceEncoding} + + + + com.spotify + docker-maven-plugin + ${docker-maven-plugin.version} + + skywalking/${project.name} + ${project.basedir}/docker + ${skip.docker} + + + + + + diff --git a/test/plugin/run.sh b/test/plugin/run.sh new file mode 100644 index 0000000000000000000000000000000000000000..46f3f3d0b8eb1a051f2a26033b963a249fdc17de --- /dev/null +++ b/test/plugin/run.sh @@ -0,0 +1,167 @@ +#!/bin/bash +# +# 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. + +home="$(cd "$(dirname $0)"; pwd)" +scenario_name="empty" +parallel_run_size=1 +build_id="latest" + + +mvnw=${home}/../../mvnw +agent_home=${home}"/../../skywalking-agent" +scenarios_home="${home}/scenarios" + +_positionals=() +parse_commandline() { + _positionals_count=0 + while test $# -gt 0 + do + _key="$1" + case "$_key" in + --build_id) + test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 + build_id="$2" + shift + ;; + --build_id=*) + build_id="${_key##--build_id=}" + ;; + --parallel_run_size) + test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1 + parallel_run_size="$2" + shift + ;; + --parallel_run_size=*) + parallel_run_size="${_key##--parallel_run_size=}" + ;; + -h|--help) + print_help + exit 0 + ;; + -h*) + print_help + exit 0 + ;; + *) + scenario_name=$1 + ;; + esac + shift + done +} + +exitWithMessage() { + echo -e "\033[31m[ERROR] $1\033[0m">&2 + exitAndClean 1 +} + +exitAndClean() { + if [[ "${build_id}" =~ "latest" ]]; then + docker images -q "skywalking/agent-test-*:${build_id}" | xargs -r docker rmi -f + fi + + elapsed=$(( `date +%s` - $start_stamp )) + num_of_testcases="`ls -l ${task_state_house} |grep -c FINISH`" + printf "Scenarios: %s, Testcases: %d, parallel_run_size: %d, Elapsed: %02d:%02d:%02d \n" \ + ${scenario_name} "${num_of_testcases}" "${parallel_run_size}" \ + $(( ${elapsed}/3600 )) $(( ${elapsed}%3600/60 )) $(( ${elapsed}%60 )) + exit $1 +} + +waitForAvailable() { + while [[ `ls -l ${task_state_house} |grep -c RUNNING` -ge ${parallel_run_size} ]] + do + sleep 2 + done + + if [[ `ls -l ${task_state_house} |grep -c FAILURE` -gt 0 ]]; then + exitAndClean 1 + fi +} +parse_commandline "$@" + +start_stamp=`date +%s` ### start + +workspace="${home}/workspace/${scenario_name}" +task_state_house="${workspace}/.states" +[[ -d ${workspace} ]] && rm -rf $workspace +mkdir -p ${task_state_house} + +plugin_autotest_helper="${home}/dist/plugin-autotest-helper.jar" +if [[ ! -f ${plugin_autotest_helper} ]]; then + exitWithMessage "plugin autotest helper not exist!" +fi + +echo "start submit job" +scenario_home=${scenarios_home}/${scenario_name} && cd ${scenario_home} + +supported_version_file=${scenario_home}/support-version.list +if [[ ! -f $supported_version_file ]]; then + exitWithMessage "cannot found 'support-version.list' in directory ${scenario_name}" +fi + +supported_versions=`grep -v -E "^$|^#" ${supported_version_file}` +for version in ${supported_versions} +do + waitForAvailable + testcase_name="${scenario_name}-${version}" + + # testcase working directory, there are logs, data and packages. + case_work_base=${workspace}/${version} + mkdir -p ${case_work_base}/{data,logs} + + case_work_logs_dir=${case_work_base}/logs + + # copy expectedData.yml + cp ./config/expectedData.yaml ${case_work_base}/data + + # echo "build ${testcase_name}" + ${mvnw} clean package -P${testcase_name} + + mv ./target/${scenario_name}.war ${case_work_base} + + java -jar \ + -Xmx256m -Xms256m \ + -Dconfigure.file=${scenario_home}/configuration.yml \ + -Dscenario.home=${case_work_base} \ + -Dscenario.name=${scenario_name} \ + -Dscenario.version=${version} \ + -Doutput.dir=${case_work_base} \ + -Dagent.dir=${agent_home} \ + -Ddocker.image.version=${build_id} \ + ${plugin_autotest_helper} 1>${case_work_logs_dir}/helper.log + + [[ $? -ne 0 ]] && exitWithMessage "${testcase_name}, generate script failure!" + + echo "start container of testcase.name=${testcase_name}" + bash ${case_work_base}/scenario.sh ${task_state_house} 1>${case_work_logs_dir}/${testcase_name}.log & + sleep 3 +done + +echo -e "\033[33m${scenario_name} has already sumbitted\033[0m" + +# wait to finish +while [[ `ls -l ${task_state_house} |grep -c RUNNING` -gt 0 ]]; do + sleep 1 +done + +if [[ `ls -l ${task_state_house} |grep -c FAILURE` -gt 0 ]]; then + exitAndClean 1 +fi + +exitAndClean 0 diff --git a/test/plugin/runner/pom.xml b/test/plugin/runner/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..3781b0a63c65574b3565f9d5a8abdb316f424f00 --- /dev/null +++ b/test/plugin/runner/pom.xml @@ -0,0 +1,89 @@ + + + + + + org.apache.skywalking.plugin + apache-skywalking-test-plugin + 1.0.0 + + + 4.0.0 + runner + plugin-autotest-helper + + + + junit + junit + 4.12 + test + + + + org.mockito + mockito-core + 3.0.0 + test + + + + com.google.guava + guava + ${guava.version} + + + + org.freemarker + freemarker + 2.3.28 + + + + + plugin-autotest-helper + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + + org.apache.skywalking.plugin.test.helper.Main + + + + ../dist/${project.build.finalName}.jar + + + + + + + diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/AbstractRunningGenerator.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/AbstractRunningGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..d17cc7468dfb79b7dcaf32e4afe7f36fe44cf60f --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/AbstractRunningGenerator.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import freemarker.template.Configuration; +import freemarker.template.TemplateExceptionHandler; +import java.io.File; +import java.io.FileWriter; +import java.lang.invoke.MethodHandles; +import java.util.HashMap; +import java.util.Map; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException; + +public abstract class AbstractRunningGenerator implements ScenarioRunningScriptGenerator { + private Logger logger = LogManager.getLogger(MethodHandles.lookup().lookupClass()); + protected final Configuration cfg; + + protected AbstractRunningGenerator() { + cfg = new Configuration(Configuration.VERSION_2_3_28); + try { + cfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), "/"); + cfg.setDefaultEncoding("UTF-8"); + cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + cfg.setLogTemplateExceptions(false); + cfg.setWrapUncheckedExceptions(true); + } catch (Exception e) { + // never to do this + } + } + + @Override + public final void generate(IConfiguration configuration) throws GenerateFailedException { + generateAdditionFiles(configuration); + + Map root = new HashMap<>(); + root.put("running_script", runningScript(configuration)); + root.put("scenario_name", configuration.scenarioName()); + root.put("scenario_version", configuration.scenarioVersion()); + + try { + cfg.getTemplate("scenario.sh").process(root, + new FileWriter(new File(configuration.outputDir() + File.separator + "scenario.sh"))); + } catch (Exception e) { + logger.error("Failed to write scenario.sh", e); + } + } + + public abstract void generateAdditionFiles(IConfiguration configuration) throws GenerateFailedException; + + public abstract String runningScript(IConfiguration configuration); +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/ConfigurationImpl.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/ConfigurationImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..c83e054018a5d54abd66eba380f4ac7ab691fab6 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/ConfigurationImpl.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.UUID; + +import org.apache.skywalking.plugin.test.helper.exception.ConfigureFileNotFoundException; +import org.apache.skywalking.plugin.test.helper.util.StringUtils; +import org.apache.skywalking.plugin.test.helper.vo.CaseConfiguration; +import org.yaml.snakeyaml.Yaml; + +public class ConfigurationImpl implements IConfiguration { + + private CaseConfiguration configuration; + private final String scenarioHome; + + public ConfigurationImpl() throws FileNotFoundException, ConfigureFileNotFoundException { + String configureFile = System.getProperty("configure.file"); + if (StringUtils.isBlank(configureFile)) { + throw new ConfigureFileNotFoundException(); + } + + this.configuration = new Yaml().loadAs(new FileReader(new File(configureFile)), CaseConfiguration.class); + this.scenarioHome = System.getProperty("scenario.home"); + } + + @Override + public String agentHome() { + return System.getProperty("agent.dir"); + } + + @Override public RunningType runningType() { + return (configuration.getDependencies() != null && configuration.getDependencies().size() > 0) ? + RunningType.DockerCompose : + RunningType.Container; + } + + @Override public ScenarioRunningScriptGenerator scenarioGenerator() { + switch (runningType()) { + case DockerCompose: + return new DockerComposeV2RunningGenerator(); + case Container: + return new DockerContainerRunningGenerator(); + default: + throw new RuntimeException(); + } + } + + @Override public CaseConfiguration caseConfiguration() { + return this.configuration; + } + + @Override public String scenarioName() { + return System.getProperty("scenario.name"); + } + + @Override public String scenarioVersion() { + return System.getProperty("scenario.version"); + } + + @Override public String testFramework() { + return this.configuration.getFramework(); + } + + @Override public String entryService() { + return this.configuration.getEntryService(); + } + + @Override public String healthCheck() { + return this.configuration.getHealthCheck(); + } + + @Override public String dockerImageName() { + switch (this.configuration.getType().toLowerCase()) { + case "tomcat" : + return "skywalking/agent-test-tomcat"; + case "jvm" : + return "skywalking/agent-test-jvm"; + } + + throw new RuntimeException("Illegal type!"); + } + + @Override + public String dockerImageVersion() { + return System.getProperty("docker.image.version", "latest"); + } + + @Override + public String dockerContainerName() { + return scenarioName() + "-" + scenarioVersion() + "-" + Long.toHexString(System.nanoTime()); + } + + @Override public String scenarioHome() { + return this.scenarioHome; + } + + @Override public String outputDir(){ + return System.getProperty("output.dir"); + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerComposeRunningGenerator.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerComposeRunningGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..a09899f807c40fe9b862eb9c43ebd0edbe7ee898 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerComposeRunningGenerator.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException; +import org.apache.skywalking.plugin.test.helper.vo.DockerCompose; +import org.apache.skywalking.plugin.test.helper.vo.DockerService; +import org.apache.skywalking.plugin.test.helper.vo.DockerServiceReader; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.introspector.Property; +import org.yaml.snakeyaml.nodes.NodeTuple; +import org.yaml.snakeyaml.nodes.Tag; +import org.yaml.snakeyaml.representer.Representer; + +public class DockerComposeRunningGenerator extends AbstractRunningGenerator { + + @Override + public void generateAdditionFiles(IConfiguration configuration) throws GenerateFailedException { + DockerCompose dockerCompose = convertDockerCompose(configuration); + + try { + getFileWriter().dump(dockerCompose, new FileWriter(new File(configuration.outputDir(), "docker-compose" + + ".yml"))); + } catch (IOException e) { + throw new GenerateFailedException(); + } + } + + private DockerCompose convertDockerCompose(IConfiguration configuration) { + DockerCompose dockerCompose = new DockerCompose(); + dockerCompose.setVersion("2.1"); + + HashMap dockerServices = new HashMap<>(); + DockerService container = new DockerService(); + container.setImage(String.format("%s:latest", configuration.dockerImageName())); + + configuration.caseConfiguration().getDependencies().forEach((name, dependencyComponent) -> { + DockerService dockerService = new DockerService(); + DockerServiceReader serviceReader = dependencyComponent; + dockerService.setEnvironments(serviceReader.environment()); + dockerService.setImage(serviceReader.image()); + dockerServices.put(name, dockerService); + }); + + container.setLinks(new ArrayList<>(configuration.caseConfiguration().getDependencies().keySet())); + + List environment = new ArrayList(); + environment.add(String.format("SCENARIO_VERSION=%s", configuration.scenarioVersion())); + environment.add(String.format("SCENARIO_SUPPORT_FRAMEWORK=%s", configuration.testFramework())); + environment.add(String.format("SCENARIO_ENTRY_SERVICE=%s", configuration.entryService())); + environment.add(String.format("SCENARIO_HEALTH_CHECK_URL=%s", configuration.healthCheck())); + + List volumes = new ArrayList<>(); + volumes.add(String.format("%s:/usr/local/skywalking-agent-scenario/agent", configuration.agentHome())); + + container.setVolumes(volumes); + container.setEnvironments(environment); + + dockerServices.put(String.format("skywalking-agent-test-%s-%s", configuration.testFramework(), + configuration.scenarioVersion()) + , container); + dockerCompose.setServices(dockerServices); + + return dockerCompose; + } + + private Yaml getFileWriter() { + DumperOptions dumperOptions = new DumperOptions(); + dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + Representer representer = new Representer() { + @Override + protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, + Tag customTag) { + if (propertyValue == null) { + return null; + } else { + return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); + } + } + }; + + representer.addClassTag(DockerCompose.class, Tag.MAP); + return new Yaml(representer, dumperOptions); + } + + @Override + public String runningScript(IConfiguration configuration) { + return String.format("docker-compose -f %s up", configuration.outputDir() + File.separator + "docker-compose" + + ".yml"); + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerComposeV2RunningGenerator.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerComposeV2RunningGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..a03eb03f240d43d44af3fdbe6f4de1a709f94acb --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerComposeV2RunningGenerator.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import com.google.common.collect.Lists; +import freemarker.template.Configuration; +import freemarker.template.TemplateException; +import freemarker.template.TemplateExceptionHandler; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.plugin.test.helper.vo.DependencyComponent; +import org.apache.skywalking.plugin.test.helper.vo.DockerService; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class DockerComposeV2RunningGenerator extends AbstractRunningGenerator { + private static Logger logger = LogManager.getLogger(MethodHandles.lookup().lookupClass()); + + protected DockerComposeV2RunningGenerator() { + } + + @Override + public void generateAdditionFiles(IConfiguration configuration) { + Map root = new HashMap<>(); + root.put("agent_home", configuration.agentHome()); + root.put("scenario_home", configuration.scenarioHome()); + + root.put("scenario_name", configuration.scenarioName()); + root.put("scenario_version", configuration.scenarioVersion()); + root.put("entry_service", configuration.entryService()); + root.put("health_check", configuration.healthCheck()); + root.put("test_framework", configuration.testFramework()); + root.put("docker_image_name", configuration.dockerImageName()); + root.put("docker_image_version", configuration.dockerImageVersion()); + root.put("docker_container_name", configuration.dockerContainerName()); + + ArrayList links = Lists.newArrayList(); + configuration.caseConfiguration().getDependencies().forEach((k, service) -> { + links.add(service.getHost()); + }); + + root.put("links", links); + root.put("services", convertDockerServices(configuration.caseConfiguration().getDependencies())); + + Configuration cfg = new Configuration(Configuration.VERSION_2_3_28); + try { + cfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), "/"); + cfg.setDefaultEncoding("UTF-8"); + cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + cfg.setLogTemplateExceptions(false); + cfg.setWrapUncheckedExceptions(true); + } catch (Exception e) { + // never to do this + } + try { + cfg.getTemplate("docker-compose.template").process(root, new FileWriter(new File(configuration.outputDir(), + "docker-compose.yml"))); + } catch (TemplateException | IOException e) { + logger.error(e); + } + } + + protected List convertDockerServices(Map componentMap) { + ArrayList services = Lists.newArrayList(); + componentMap.forEach((name, dependency) -> { + DockerService service = new DockerService(); + service.setName(name); + service.setVersion(dependency.getVersion()); + service.setImage(dependency.getImage()); + service.setHost(dependency.getHost()); + service.setExpose(nullToEmpty(dependency.getExpose())); + service.setVolumes(nullToEmpty(dependency.getVolumes())); + service.setEnvironments(nullToEmpty(dependency.getEnvironment())); + services.add(service); + }); + return services; + } + private static final List nullToEmpty(List list) { + return list == null ? Lists.newArrayList() : list; + } + + @Override + public String runningScript(IConfiguration configuration) { + return String.format("docker-compose -f %s up", configuration.outputDir() + File.separator + + "docker-compose.yml"); + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerContainerRunningGenerator.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerContainerRunningGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..57158ad63f9ac656f1f9f3bc16007c111df11d6b --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/DockerContainerRunningGenerator.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.StringWriter; +import java.lang.invoke.MethodHandles; +import java.util.HashMap; +import java.util.Map; + +public class DockerContainerRunningGenerator extends AbstractRunningGenerator { + private static Logger logger = LogManager.getLogger(MethodHandles.lookup().lookupClass()); + + protected DockerContainerRunningGenerator() { + } + + @Override + public void generateAdditionFiles(IConfiguration configuration) { + // DO Nothing + } + + @Override + public String runningScript(IConfiguration configuration) { + Map root = new HashMap<>(); + root.put("agent_home", configuration.agentHome()); + root.put("scenario_home", configuration.scenarioHome()); + + root.put("scenario_name", configuration.scenarioName()); + root.put("scenario_version", configuration.scenarioVersion()); + root.put("entry_service", configuration.entryService()); + root.put("health_check", configuration.healthCheck()); + root.put("test_framework", configuration.testFramework()); + root.put("docker_image_name", configuration.dockerImageName()); + root.put("docker_image_version", configuration.dockerImageVersion()); + root.put("docker_container_name", configuration.dockerContainerName()); + StringWriter out = null; + + try { + out = new StringWriter(); + cfg.getTemplate("container-start-script.template").process(root, out); + } catch (Exception e) { + logger.error("Failed to generate running script.", e); + } + return out.toString(); + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/IConfiguration.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/IConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..416ea8578bbd8d2dab0ce14f01de6b3c7e220faa --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/IConfiguration.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import org.apache.skywalking.plugin.test.helper.vo.CaseConfiguration; + +public interface IConfiguration { + String agentHome(); + + RunningType runningType(); + + ScenarioRunningScriptGenerator scenarioGenerator(); + + CaseConfiguration caseConfiguration(); + + String scenarioName(); + + String scenarioVersion(); + + @Deprecated + String testFramework(); + + String entryService(); + + String healthCheck(); + + String dockerImageName(); + + String dockerContainerName(); + + String dockerImageVersion(); + + String scenarioHome(); + + String outputDir(); +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/Main.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..657086407e026a58e039ee89e6d0da0185300a17 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/Main.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +public class Main { + + public static void main(String[] args) throws Exception { + IConfiguration configuration = new ConfigurationImpl(); + configuration.scenarioGenerator().generate(configuration); + System.exit(0); + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/RunningType.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/RunningType.java new file mode 100644 index 0000000000000000000000000000000000000000..37e4718615a28935a27c656d26ce8d9cbaa0db97 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/RunningType.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +public enum RunningType { + Container, DockerCompose; +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/ScenarioRunningScriptGenerator.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/ScenarioRunningScriptGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..bd8d0a3caf016fa99600715d044bdbd21fefe311 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/ScenarioRunningScriptGenerator.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException; + +public interface ScenarioRunningScriptGenerator { + void generate(IConfiguration configuration) throws GenerateFailedException; +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/ConfigureFileNotFoundException.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/ConfigureFileNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..fff6167b6b61836aad38bdfe15224ccb1d77cb18 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/ConfigureFileNotFoundException.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.exception; + +public class ConfigureFileNotFoundException extends Exception { + public ConfigureFileNotFoundException() { + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/GenerateAdditionFileException.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/GenerateAdditionFileException.java new file mode 100644 index 0000000000000000000000000000000000000000..6b2004e43be9c901fd36a96ded56ce153bb209eb --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/GenerateAdditionFileException.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.exception; + +public class GenerateAdditionFileException extends GenerateFailedException { +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/GenerateFailedException.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/GenerateFailedException.java new file mode 100644 index 0000000000000000000000000000000000000000..4e91585d0bfcc62ab10e8dc3153354c289c18133 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/exception/GenerateFailedException.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.exception; + +public class GenerateFailedException extends Exception { +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/util/StringUtils.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/util/StringUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..3d172c979c6d0dc36fba5e76408ad3e8cc3b59d1 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/util/StringUtils.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.util; + +public class StringUtils { + + public static boolean isBlank(String str) { + return str == null || str.length() == 0; + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/CaseConfiguration.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/CaseConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..6ada6408f2246514046f853a84f5f2dd921b2d6c --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/CaseConfiguration.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.vo; + +import java.util.List; +import java.util.Map; + +public class CaseConfiguration { + private String type; + private String entryService; + private String healthCheck; + private String framework; + @Deprecated private String version; + private String startScript; + private Map dependencies; + private List environment; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getEntryService() { + return entryService; + } + + public void setEntryService(String entryService) { + this.entryService = entryService; + } + + public String getFramework() { + return framework; + } + + public void setFramework(String framework) { + this.framework = framework; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getStartScript() { + return startScript; + } + + public void setStartScript(String startScript) { + this.startScript = startScript; + } + + public Map getDependencies() { + return dependencies; + } + + public void setDependencies(Map dependencies) { + this.dependencies = dependencies; + } + + public String getHealthCheck() { + return healthCheck; + } + + public void setHealthCheck(String healthCheck) { + this.healthCheck = healthCheck; + } + + public List getEnvironment() { + return environment; + } + + public void setEnvironment(List environment) { + this.environment = environment; + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DependencyComponent.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DependencyComponent.java new file mode 100644 index 0000000000000000000000000000000000000000..a170bf1333cee9d4486aa7ff42697637fe818a56 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DependencyComponent.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.vo; + +import java.util.List; + +public class DependencyComponent implements DockerServiceReader { + private String image; + private String host; + private String version; + private List expose; + private List volumes; + private List entrypoint; + private List environment; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public List getEnvironment() { + return environment; + } + + public void setEnvironment(List environment) { + this.environment = environment; + } + + @Override public List environment() { + return environment; + } + + @Override public String image() { + return host; + } + + public List getExpose() { + return expose; + } + + public void setExpose(List expose) { + this.expose = expose; + } + + public List getEntrypoint() { + return entrypoint; + } + + public void setEntrypoint(List entrypoint) { + this.entrypoint = entrypoint; + } + + public List getVolumes() { + return volumes; + } + + public void setVolumes(List volumes) { + this.volumes = volumes; + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerCompose.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerCompose.java new file mode 100644 index 0000000000000000000000000000000000000000..72d8624edde002eb0efc2c5e7d4467b1ca0a2384 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerCompose.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.vo; + +import java.util.HashMap; + +public class DockerCompose { + private String version; + private HashMap services; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public HashMap getServices() { + return services; + } + + public void setServices(HashMap services) { + this.services = services; + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerService.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerService.java new file mode 100644 index 0000000000000000000000000000000000000000..0b7a5f610b8bd4516ce0455c27087fd2861ce0f6 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerService.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.vo; + +import com.google.common.collect.Lists; + +import java.util.List; + +public class DockerService { + private String name; + private String version; + private String image; + private String host; + private List expose = Lists.newArrayList(); + @Deprecated private List ports; + private List environments = Lists.newArrayList(); + private List volumes = Lists.newArrayList(); + + @Deprecated private List links; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + + public List getExpose() { + return expose; + } + + public void setExpose(List expose) { + this.expose = expose; + } + + public List getPorts() { + return ports; + } + + public void setPorts(List ports) { + this.ports = ports; + } + + public List getEnvironments() { + return environments; + } + + public void setEnvironments(List environments) { + this.environments = environments; + } + + public List getVolumes() { + return volumes; + } + + public void setVolumes(List volumes) { + this.volumes = volumes; + } + + public List getLinks() { + return links; + } + + public void setLinks(List links) { + this.links = links; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } +} diff --git a/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerServiceReader.java b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerServiceReader.java new file mode 100644 index 0000000000000000000000000000000000000000..8464f88e2b304f68fa9315bf3fc2b569fac7b7d9 --- /dev/null +++ b/test/plugin/runner/src/main/java/org/apache/skywalking/plugin/test/helper/vo/DockerServiceReader.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.vo; + +import java.util.List; + +public interface DockerServiceReader { + + List environment(); + + String image(); +} diff --git a/test/plugin/runner/src/main/resources/container-start-script.template b/test/plugin/runner/src/main/resources/container-start-script.template new file mode 100644 index 0000000000000000000000000000000000000000..7a07fa359da77b7f94000b65e127856867e0af5d --- /dev/null +++ b/test/plugin/runner/src/main/resources/container-start-script.template @@ -0,0 +1,40 @@ +<#-- + ~ 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. +--> + +docker run \ + --memory=1024m \ + --name ${docker_container_name} \ + --env SCENARIO_NAME=${scenario_name} \ + --env SCENARIO_VERSION=${scenario_version} \ + --env SCENARIO_SUPPORT_FRAMEWORK=${scenario_name} \ + --env SCENARIO_ENTRY_SERVICE=${entry_service} \ + --env SCENARIO_HEALTH_CHECK_URL=${health_check} \ + -v ${agent_home}:/usr/local/skywalking/scenario/agent \ + -v ${scenario_home}:/usr/local/skywalking/scenario \ + ${docker_image_name}:${docker_image_version} 1>${scenario_home}/logs/container.log + +status="$?" + +container_name=`docker ps -aqf "name=${docker_container_name}"` + +<#noparse> +if [[ -z ${container_name} ]]; then + status=1 +else + docker container rm -f $container_name +fi + diff --git a/test/plugin/runner/src/main/resources/docker-compose.template b/test/plugin/runner/src/main/resources/docker-compose.template new file mode 100644 index 0000000000000000000000000000000000000000..41cd5e3972e678ac60ce1c3ede4ea2aff06f555d --- /dev/null +++ b/test/plugin/runner/src/main/resources/docker-compose.template @@ -0,0 +1,57 @@ +<#-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. +--> +version: 2.1 +services: + ${docker_container_name}: + image: ${docker_image_name}:latest + <#if links?size \gt 0> + links: + <#list links as link> + - ${link} + + + environment: + - SCENARIO_NAME:${scenario_name} + - SCENARIO_VERSION:${scenario_version} + - SCENARIO_ENTRY_SERVICE:${entry_service} + - SCENARIO_HEALTH_CHECK_URL:${health_check} + volumes: + - ${agent_home}:/usr/local/skywalking-agent-scenario/agent + - ${scenario_home}:/usr/local/skywalking-agent-scenario +<#list services as service> + ${service.name}: + image: ${service.image}:${service.version} + host: ${service.host} + <#if service.volumes?size \gt 0> + volumes: + <#list service.volumes as volume> + - ${volume} + + + <#if service.environments?size \gt 0> + environments: + <#list service.environments as environment> + - ${environment} + + + <#if service.expose?size \gt 0> + expose: + <#list service.expose as expose> + - ${expose} + + + \ No newline at end of file diff --git a/test/plugin/runner/src/main/resources/log4j2.xml b/test/plugin/runner/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..78634ba31c0ee3f3666fd7d4946fb48511d58e77 --- /dev/null +++ b/test/plugin/runner/src/main/resources/log4j2.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/runner/src/main/resources/scenario.sh b/test/plugin/runner/src/main/resources/scenario.sh new file mode 100644 index 0000000000000000000000000000000000000000..710c351896047412d7dc47d2752464e8a54aee91 --- /dev/null +++ b/test/plugin/runner/src/main/resources/scenario.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# 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. + +PRG="$0" +PRGDIR=`dirname "$PRG"` +[ -z "$SCENARIO_HOME" ] && SCENARIO_HOME=`cd "$PRGDIR" >/dev/null; pwd` + +state_house=$1 +testcase_name=${scenario_name}-${scenario_version} + +<#noparse>touch ${state_house}/${testcase_name}.RUNNING + +${running_script} + +<#noparse> +if [[ ${status} -eq 0 ]]; then + mv ${state_house}/${testcase_name}.RUNNING ${state_house}/${testcase_name}.FINISH +else + mv ${state_house}/${testcase_name}.RUNNING ${state_house}/${testcase_name}.FAILURE +fi + diff --git a/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerComposeRunningGeneratorTest.java b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerComposeRunningGeneratorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f1df6d91e639f91257185bac16ce462adeda3cc1 --- /dev/null +++ b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerComposeRunningGeneratorTest.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import java.io.File; +import java.io.InputStream; + +import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException; +import org.apache.skywalking.plugin.test.helper.vo.CaseConfiguration; +import org.apache.skywalking.plugin.test.helper.vo.CaseIConfigurationTest; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.yaml.snakeyaml.Yaml; + +import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class DockerComposeRunningGeneratorTest { + + private DockerComposeRunningGenerator dockerComposeRunningGenerator; + private InputStream configurationFile; + + @Mock + private IConfiguration configuration; + + public static final String TARGET_DIR = DockerComposeRunningGeneratorTest.class.getResource("/").getFile(); + + @Before + public void setUp() { + dockerComposeRunningGenerator = new DockerComposeRunningGenerator(); + + when(configuration.outputDir()).thenReturn(TARGET_DIR); + when(configuration.agentHome()).thenReturn("/agent/path"); + when(configuration.dockerImageName()).thenReturn("skyapm/agent-tomcat"); + when(configuration.entryService()).thenReturn("http://localhost:8080/entryService"); + when(configuration.healthCheck()).thenReturn("http://localhost:8080/healthCheck"); + when(configuration.testFramework()).thenReturn("http"); + when(configuration.scenarioVersion()).thenReturn("4.3.2"); + + configurationFile = CaseIConfigurationTest.class.getResourceAsStream("/configuration-test.yml"); + assertNotNull(configurationFile); + when(configuration.caseConfiguration()).thenReturn(new Yaml().loadAs(configurationFile, CaseConfiguration.class)); + } + + @Test + public void testGenerateDockerCompose() { + String runningScript = dockerComposeRunningGenerator.runningScript(configuration); + assertEquals(String.format("docker-compose -f %s/docker-compose.template up", TARGET_DIR), runningScript); + } + + @Test + public void testGenerateAdditionalFile() throws GenerateFailedException { + dockerComposeRunningGenerator.generateAdditionFiles(configuration); + assertTrue(new File(TARGET_DIR, "docker-compose.template").exists()); + } + + @After + public void tearDown() { + + } +} diff --git a/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerComposeV2RunningGeneratorTest.java b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerComposeV2RunningGeneratorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9bb0338558f5b990ce1b7aa71f4b55d440133d84 --- /dev/null +++ b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerComposeV2RunningGeneratorTest.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException; +import org.apache.skywalking.plugin.test.helper.vo.CaseConfiguration; +import org.apache.skywalking.plugin.test.helper.vo.CaseIConfigurationTest; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.InputStream; + +import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class DockerComposeV2RunningGeneratorTest { + private DockerComposeV2RunningGenerator dockerComposeRunningGenerator; + private InputStream configurationFile; + + @Mock + private IConfiguration configuration; + + public static final String TARGET_DIR = DockerComposeRunningGeneratorTest.class.getResource("/").getFile(); + + @Before + public void setUp() { + dockerComposeRunningGenerator = new DockerComposeV2RunningGenerator(); + + when(configuration.outputDir()).thenReturn(TARGET_DIR); + when(configuration.agentHome()).thenReturn("/agent/path"); + when(configuration.dockerImageName()).thenReturn("skyapm/agent-tomcat"); + when(configuration.entryService()).thenReturn("http://localhost:8080/entryService"); + when(configuration.healthCheck()).thenReturn("http://localhost:8080/healthCheck"); + when(configuration.testFramework()).thenReturn("http"); + when(configuration.scenarioVersion()).thenReturn("4.3.2"); + + when(configuration.scenarioName()).thenReturn("http"); + when(configuration.scenarioHome()).thenReturn("scenario_home"); + when(configuration.dockerContainerName()).thenReturn("docker_container_name"); +// when(configuration.serverAddr()).thenReturn("") + + + configurationFile = CaseIConfigurationTest.class.getResourceAsStream("/configuration-test.yml"); + assertNotNull(configurationFile); + when(configuration.caseConfiguration()).thenReturn(new Yaml().loadAs(configurationFile, CaseConfiguration.class)); + } + + @Test + public void testGenerateDockerCompose() { + String runningScript = dockerComposeRunningGenerator.runningScript(configuration); + assertEquals(String.format("docker-compose -f %s/docker-compose.yml up", TARGET_DIR), runningScript); + } + + @Test + public void testGenerateAdditionalFile() throws GenerateFailedException { + dockerComposeRunningGenerator.generateAdditionFiles(configuration); + assertTrue(new File(TARGET_DIR, "docker-compose.yml").exists()); + } + + @After + public void tearDown() { + + } +} diff --git a/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerContainerRunningGeneratorTest.java b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerContainerRunningGeneratorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..11db24472bb6608c9b28102f54880201f6c214c5 --- /dev/null +++ b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/DockerContainerRunningGeneratorTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class DockerContainerRunningGeneratorTest { + + private DockerContainerRunningGenerator generator; + + @Mock + private IConfiguration configuration; + + @Before + public void setUp() { + generator = new DockerContainerRunningGenerator(); + when(configuration.agentHome()).thenReturn("/agent/path"); + when(configuration.dockerImageName()).thenReturn("skyapm/agent-tomcat"); + when(configuration.entryService()).thenReturn("http://localhost:8080/entryService"); + when(configuration.healthCheck()).thenReturn("http://localhost:8080/healthCheck"); + when(configuration.testFramework()).thenReturn("http"); + when(configuration.scenarioVersion()).thenReturn("4.3.2"); + when(configuration.scenarioHome()).thenReturn("./scenario"); + when(configuration.scenarioName()).thenReturn("test"); + } + + @Test + public void testGenerateDockerContainerStartScript() { + String script = generator.runningScript(configuration); + assertNotNull(script); + } + +} diff --git a/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/vo/CaseIConfigurationTest.java b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/vo/CaseIConfigurationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..8d7aa7baf4469a3a7aa95f1b529633f0350404fb --- /dev/null +++ b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/vo/CaseIConfigurationTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.vo; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import org.junit.Before; +import org.junit.Test; +import org.yaml.snakeyaml.Yaml; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +public class CaseIConfigurationTest { + + private InputStream configurationFile; + + @Before + public void setUp() { + configurationFile = CaseIConfigurationTest.class.getResourceAsStream("/configuration-test.yml"); + assertNotNull(configurationFile); + } + + @Test + public void testReadCaseConfiguration() throws FileNotFoundException { + Yaml yaml = new Yaml(); + CaseConfiguration caseConfiguration = yaml.loadAs(configurationFile, CaseConfiguration.class); + assertNotNull(caseConfiguration); + + assertThat(caseConfiguration.getVersion(), is("4.0.3")); + assertThat(caseConfiguration.getFramework(), is("httpclient")); + assertThat(caseConfiguration.getDependencies().size(), is(1)); + } +} diff --git a/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/vo/DockerComposeTest.java b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/vo/DockerComposeTest.java new file mode 100644 index 0000000000000000000000000000000000000000..abe34afa9d6709d920eed32d01cff36e797618c5 --- /dev/null +++ b/test/plugin/runner/src/test/java/org/apache/skywalking/plugin/test/helper/vo/DockerComposeTest.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.helper.vo; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.introspector.Property; +import org.yaml.snakeyaml.nodes.NodeTuple; +import org.yaml.snakeyaml.nodes.Tag; +import org.yaml.snakeyaml.representer.Representer; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class DockerComposeTest { + private InputStream dockerCompose; + private String writeFile; + + @Before + public void setUp() { + writeFile = CaseIConfigurationTest.class.getResource("/").getFile() + "/file.yaml"; + dockerCompose = CaseIConfigurationTest.class.getResourceAsStream("/docker-compose-test.yml"); + assertNotNull(dockerCompose); + } + + @Test + public void readDockerCompose() { + Yaml yaml = new Yaml(); + DockerCompose dockerfile = yaml.loadAs(dockerCompose, DockerCompose.class); + assertNotNull(dockerfile); + assertThat(dockerfile.getServices().size(), is(2)); + } + + @Test + public void writeDockerCompose() throws IOException { + DumperOptions dumperOptions = new DumperOptions(); + dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + Representer representer = new Representer() { + @Override + protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, + Tag customTag) { + if (propertyValue == null) { + return null; + } else { + return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); + } + } + }; + + representer.addClassTag(DockerCompose.class, Tag.MAP); + Yaml yaml = new Yaml(representer, dumperOptions); + + DockerCompose dockerfile = yaml.loadAs(dockerCompose, DockerCompose.class); + FileWriter writer = new FileWriter(writeFile); + yaml.dump(dockerfile, writer); + + assertTrue(new File(writeFile).exists()); + } + + @After + public void tearDown(){ + new File(writeFile).deleteOnExit(); + } +} diff --git a/test/plugin/runner/src/test/resources/configuration-test.yml b/test/plugin/runner/src/test/resources/configuration-test.yml new file mode 100644 index 0000000000000000000000000000000000000000..7df290bc2a9412e59aa4a758bf21fa3e20a96a1f --- /dev/null +++ b/test/plugin/runner/src/test/resources/configuration-test.yml @@ -0,0 +1,30 @@ +# Licensed to the Apache 5Software 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. + +type: tomcat +entryService: http://localhost:8080/solrj-7.x-scenario/case +framework: solrj +dependencies: + solr: + image: solr:${CASE_SERVER_IMAGE_VERSION} + host: solr-server + environment: + - a:b + entrypoint: + - docker-entrypoint.sh + - solr-precreate + - mycore + volumes: + - c:d diff --git a/test/plugin/runner/src/test/resources/container-start-script.template b/test/plugin/runner/src/test/resources/container-start-script.template new file mode 100644 index 0000000000000000000000000000000000000000..7ff71ba7615976f4d6961faf57c8d18761586d8d --- /dev/null +++ b/test/plugin/runner/src/test/resources/container-start-script.template @@ -0,0 +1,29 @@ +<#-- + ~ 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. +--> + +docker run -itd \ + --name skywalking-agent-test-${scenario_name}-${scenario_version} \ + --env SCENARIO_VERSION=${scenario_version} \ + --env SCENARIO_SUPPORT_FRAMEWORK=${scenario_name} \ + --env SCENARIO_ENTRY_SERVICE=${entry_service} \ + --env SCENARIO_HEALTH_CHECK_URL=${health_check} \ + -v ${agent_home}:/usr/local/skywalking-agent-scenario/agent \ + -v ${scenario_home}/logs:/usr/local/skywalking-agent-scenario/logs \ + -v ${scenario_home}/reports:/usr/local/skywalking-agent-scenario/reports \ + -v ${scenario_home}/data:/usr/local/skywalking-agent-scenario/data \ + -v ${scenario_home}/packages:/usr/local/skywalking-agent-scenario/packages \ + ${docker_image_name}:latest diff --git a/test/plugin/runner/src/test/resources/docker-compose-test.yml b/test/plugin/runner/src/test/resources/docker-compose-test.yml new file mode 100644 index 0000000000000000000000000000000000000000..448178ce58e25d08fdb2f1ec5d79e72686647deb --- /dev/null +++ b/test/plugin/runner/src/test/resources/docker-compose-test.yml @@ -0,0 +1,38 @@ +# 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.o + +version: '2.1' +services: + async-testcase: + image: skywalking/httpclient-scenario:{CASES_IMAGE_VERSION} + expose: + - "18080" + ports: + - "{SERVER_OUTPUT_PORT}:8080" + environment: + - COLLECTOR_SERVER=mock-collector:19876 + links: + - mock-collector + volumes: + - "{AGENT_FILE_PATH}:/usr/local/tomcat/agent" + + mock-collector: + image: skyapm/mock-collector:{COLLECTOR_IMAGE_VERSION} + environment: + - GRPC_BIND_HOST=mock-collector + expose: + - "12800" + ports: + - "{COLLECTOR_OUTPUT_PORT}:12800" diff --git a/test/plugin/runner/src/test/resources/docker-compose.template b/test/plugin/runner/src/test/resources/docker-compose.template new file mode 100644 index 0000000000000000000000000000000000000000..909a32605e1b05ee20a0afcb6be322b2f62d2134 --- /dev/null +++ b/test/plugin/runner/src/test/resources/docker-compose.template @@ -0,0 +1,58 @@ +<#-- + ~ 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. +--> +version: 2.1 +services: + ${docker_container_name}: + image: ${docker_image_name}:latest + <#if links?size \gt 0> + links: + <#list links as link> + - ${link} + + + environment: + - SERVER_ADDR:${server_addr} + - SCENARIO_NAME:${scenario_name} + - SCENARIO_VERSION:${scenario_version} + - SCENARIO_ENTRY_SERVICE:${entry_service} + - SCENARIO_HEALTH_CHECK_URL:${health_check} + volumes: + - ${agent_home}:/usr/local/skywalking-agent-scenario/agent + - ${scenario_home}:/usr/local/skywalking-agent-scenario +<#list services as service> + ${service.name}: + image: ${service.image}:${service.version} + host: ${service.host} + <#if service.volumes?size \gt 0> + volumes: + <#list service.volumes as volume> + - ${volume} + + + <#if service.environments?size \gt 0> + environments: + <#list service.environments as environment> + - ${environment} + + + <#if service.expose?size \gt 0> + expose: + <#list service.expose as expose> + - ${expose} + + + \ No newline at end of file diff --git a/test/plugin/runner/src/test/resources/scenario.sh b/test/plugin/runner/src/test/resources/scenario.sh new file mode 100755 index 0000000000000000000000000000000000000000..b8df6b7dd1ce080f6d3af508688e511411963d5a --- /dev/null +++ b/test/plugin/runner/src/test/resources/scenario.sh @@ -0,0 +1,22 @@ +# 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. + +#!/usr/bin/env bash + +PRG="$0" +PRGDIR=`dirname "$PRG"` +[ -z "$SCENARIO_HOME" ] && SCENARIO_HOME=`cd "$PRGDIR" >/dev/null; pwd` + +${running_script} diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/httpclient-4.3.x-scenario/config/expectedData.yaml new file mode 100644 index 0000000000000000000000000000000000000000..74d170ee30fd2fef4b2c6855614e644715045122 --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/config/expectedData.yaml @@ -0,0 +1,105 @@ +# 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. +registryItems: + applications: + - {httpclient-4.3.x-scenario: 2} + instances: + - {httpclient-4.3.x-scenario: 1} + operationNames: + - httpclient-4.3.x-scenario: [/httpclient-4.3.x-scenario/case/httpclient, + /httpclient-4.3.x-scenario/healthCheck, + /httpclient-4.3.x-scenario/case/context-propagate] + heartbeat: [] +segmentItems: + - applicationCode: httpclient-4.3.x-scenario + segmentSize: 3 + segments: + - segmentId: not null + spans: + - operationName: /httpclient-4.3.x-scenario/healthCheck + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: 'http://localhost:8080/httpclient-4.3.x-scenario/healthCheck'} + - {key: http.method, value: HEAD} + - segmentId: not null + spans: + - operationName: /httpclient-4.3.x-scenario/case/context-propagate + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: 'http://localhost:8080/httpclient-4.3.x-scenario/case/context-propagate'} + - {key: http.method, value: GET} + refs: + - {parentEndpointId: 0, parentEndpoint: /httpclient-4.3.x-scenario/case/httpclient, + networkAddressId: 0, entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, + parentTraceSegmentId: not null, parentServiceInstanceId: 1, + networkAddress: 'localhost:8080', entryEndpoint: /httpclient-4.3.x-scenario/case/httpclient, + entryServiceInstanceId: 1} + - segmentId: not null + spans: + - operationName: /httpclient-4.3.x-scenario/case/context-propagate + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 2 + componentName: '' + isError: false + spanType: Exit + peer: localhost:8080 + peerId: 0 + tags: + - {key: url, value: 'http://localhost:8080/httpclient-4.3.x-scenario/case/context-propagate'} + - {key: http.method, value: GET} + - operationName: /httpclient-4.3.x-scenario/case/httpclient + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: 'http://localhost:8080/httpclient-4.3.x-scenario/case/httpclient'} + - {key: http.method, value: GET} \ No newline at end of file diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/configuration.yml b/test/plugin/scenarios/httpclient-4.3.x-scenario/configuration.yml new file mode 100644 index 0000000000000000000000000000000000000000..224363b2932834481911437369420dee7bbe0454 --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/configuration.yml @@ -0,0 +1,20 @@ +# 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. + +type: tomcat +entryService: http://localhost:8080/httpclient-4.3.x-scenario/case/httpclient +healthCheck: http://localhost:8080/httpclient-4.3.x-scenario/healthCheck +framework: httpclient diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/pom.xml b/test/plugin/scenarios/httpclient-4.3.x-scenario/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..9241d76e8d23060560f21637e17d579c6341f922 --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/pom.xml @@ -0,0 +1,164 @@ + + + + 4.0.0 + + org.apache.skywalking + httpclient-4.3.x-scenario + 5.0.0 + war + + + UTF-8 + 1.8 + + + Httpclient + 4.3 + + + skywalking-httpclient-4.3.x-scenario + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + org.apache.logging.log4j + log4j-api + 2.8.1 + + + org.apache.logging.log4j + log4j-core + 2.8.1 + + + org.apache.httpcomponents + httpclient + ${test.framework.version} + + + + + + httpclient-4.3.x-scenario-4.3 + + 4.3 + + + + httpclient-4.3.x-scenario-4.5.3 + + 4.5.3 + + + + httpclient-4.3.x-scenario-4.5.4 + + 4.5.4 + + + + httpclient-4.3.x-scenario-4.5.2 + + 4.5.2 + + + + httpclient-4.3.x-scenario-4.5.1 + + 4.5.1 + + + + httpclient-4.3.x-scenario-4.5 + + 4.5 + + + + httpclient-4.3.x-scenario-4.4.1 + + 4.4.1 + + + + httpclient-4.3.x-scenario-4.4 + + 4.4 + + + + httpclient-4.3.x-scenario-4.3.6 + + 4.3.6 + + + + httpclient-4.3.x-scenario-4.3.5 + + 4.3.5 + + + + httpclient-4.3.x-scenario-4.3.4 + + 4.3.4 + + + + httpclient-4.3.x-scenario-4.3.3 + + 4.3.3 + + + + httpclient-4.3.x-scenario-4.3.2 + + 4.3.2 + + + + httpclient-4.3.x-scenario-4.3.1 + + 4.3.1 + + + + + + httpclient-4.3.x-scenario + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/CaseServlet.java b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/CaseServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..33e7cc129e3cedfec2eecabef7ddb39bf35ab0ea --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/CaseServlet.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.httpclient; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +public class CaseServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + CloseableHttpClient httpclient = HttpClients.createDefault(); + + HttpGet httpGet = new HttpGet("http://localhost:8080" + req.getContextPath() + "/case/context-propagate"); + CloseableHttpResponse response1 = httpclient.execute(httpGet); + try { + HttpEntity entity1 = response1.getEntity(); + EntityUtils.consume(entity1); + } finally { + response1.close(); + } + + PrintWriter printWriter = resp.getWriter(); + printWriter.write("success"); + printWriter.flush(); + printWriter.close(); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doGet(req, resp); + } + +} diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/HealthCheckServlet.java b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/HealthCheckServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..0731aa788b8561ae71144a78b76a473bcd68d14c --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/HealthCheckServlet.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.apache.skywalking.apm.testcase.httpclient; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class HealthCheckServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + PrintWriter writer = resp.getWriter(); + writer.write("Success"); + writer.flush(); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doGet(req, resp); + } +} diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/ServletForContextPropagate.java b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/ServletForContextPropagate.java new file mode 100644 index 0000000000000000000000000000000000000000..734d80f0e5f2fcbcc1049e3addff1d304cb8213e --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/java/test/apache/skywalking/apm/testcase/httpclient/ServletForContextPropagate.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package test.apache.skywalking.apm.testcase.httpclient; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ServletForContextPropagate extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("application/json"); + PrintWriter out = resp.getWriter(); + out.print("{'test':'test'}"); + out.flush(); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doGet(req, resp); + } +} diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..4c6c06d4057c035b990f92da9f546ed432c06068 --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/webapp/WEB-INF/web.xml b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..3484a78446d40efd9e2fefbe4103b5eb02319484 --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,54 @@ + + + skywalking-httpclient-scenario + + + caseServlet + test.apache.skywalking.apm.testcase.httpclient.CaseServlet + + + + healthCheck + test.apache.skywalking.apm.testcase.httpclient.HealthCheckServlet + + + + healthCheck + /healthCheck + + + + caseServlet + /case/httpclient + + + + servletForContextPropagate + test.apache.skywalking.apm.testcase.httpclient.ServletForContextPropagate + + + + servletForContextPropagate + /case/context-propagate + + diff --git a/test/plugin/scenarios/httpclient-4.3.x-scenario/support-version.list b/test/plugin/scenarios/httpclient-4.3.x-scenario/support-version.list new file mode 100644 index 0000000000000000000000000000000000000000..f070580529e1b8ec2d4430e79821b70982eba7bc --- /dev/null +++ b/test/plugin/scenarios/httpclient-4.3.x-scenario/support-version.list @@ -0,0 +1,30 @@ +# 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. + +4.3 +4.5.3 +4.5.4 +4.5.2 +4.5.1 +4.5 +4.4.1 +4.4 +4.3.6 +4.3.5 +4.3.4 +4.3.3 +4.3.2 +4.3.1 \ No newline at end of file diff --git a/test/plugin/script/run.m4 b/test/plugin/script/run.m4 new file mode 100644 index 0000000000000000000000000000000000000000..dd7441de4023b4d23c0928f9df3c943fead66bd2 --- /dev/null +++ b/test/plugin/script/run.m4 @@ -0,0 +1,149 @@ +#!/bin/bash +# +# 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. +# +# ARG_OPTIONAL_BOOLEAN([build_agent], [], [no comment], [off]) +# ARG_OPTIONAL_BOOLEAN([build_scenario], [], [no comment], [off]) +# ARG_OPTIONAL_SINGLE([agent_home], [], [no comment]) +# ARG_OPTIONAL_SINGLE([parallel_run_size], [], [The size of running testcase at the same time], 1) +# ARG_POSITIONAL_INF([scenarios], [The scenario that you want to running]) +# DEFINE_SCRIPT_DIR([scenarios_home], [SCENARIO HOME]) +# ARG_HELP([The general script's help msg]) +# ARGBASH_GO +# [ + +home="$(cd "$(dirname $0)"; pwd)" + +mvnw=${home}/../../mvnw +agent_home=${home}"/../../skywalking-agent" +scenarios_home="${home}/scenarios" + +workspace="${home}/workspace" +task_state_house="${workspace}/.states" + + +plugin_autotest_helper="${home}/dist/plugin-autotest-helper.jar" + +prepareAndClean() { + echo "prepare and clear" + [[ -d ${workspace} ]] && rm -fr ${workspace} + + mkdir -p ${workspace}/{.states,testcases} + + if [[ ${#_arg_scenarios[@]} -lt 1 ]]; then + _arg_scenarios=`ls ./scenarios/|sed -e "s/\t/\n/g"` + fi + + # docker prune + docker container prune -f + docker network prune -f + docker volume prune -f +# docker image prune -f + + # build plugin/test + ${mvnw} clean package -DskipTests docker:build + if [[ ! -f ${plugin_autotest_helper} ]]; then + echo -e "\033[31mplugin/test build failure\033[0m" # ]] + exit 1; + fi +} + +waitForAvailable() { + while [[ `ls -l ${task_state_house} |grep -c RUNNING` -ge ${_arg_parallel_run_size} ]] + do + sleep 2 + done + + if [[ `ls -l ${task_state_house} |grep -c FAILURE` -gt 0 ]]; then + exit 1 + fi +} + +################################################ +start_stamp=`date +%s` + +prepareAndClean ## prepare to start + +echo "start submit job" +num_of_scenarios=0 +for scenario_name in ${_arg_scenarios} +do + scenario_home=${scenarios_home}/${scenario_name} && cd ${scenario_home} + + supported_version_file=${scenario_home}/support-version.list + if [[ ! -f $supported_version_file ]]; then + echo -e "\033[31m[ERROR] cannot found 'support-version.list' in directory ${scenario_name}\033[0m" # to escape ]] + continue + fi + + echo "scenario.name=${scenario_name}" + num_of_scenarios=$((num_of_scenarios+1)) + + supported_versions=`grep -v -E "^$|^#" ${supported_version_file}` + for version in ${supported_versions} + do + testcase_name="${scenario_name}-${version}" + + # testcase working directory, there are logs, reports, and packages. + case_work_base=${workspace}/testcases/${scenario_name}/${testcase_name} + mkdir -p ${case_work_base}/{data,packages,logs,reports} + + case_work_logs_dir=${case_work_base}/logs + + # copy expectedData.yml + cp ./config/expectedData.yaml ${case_work_base}/data + +# echo "build ${testcase_name}" + ${mvnw} clean package -P${testcase_name} > ${case_work_logs_dir}/build.log + + mv ./target/${scenario_name}.war ${case_work_base}/packages + + java -Dconfigure.file=${scenario_home}/configuration.yml \ + -Dscenario.home=${case_work_base} \ + -Dscenario.name=${scenario_name} \ + -Dscenario.version=${version} \ + -Doutput.dir=${case_work_base} \ + -Dagent.dir=${agent_home} \ + -jar ${plugin_autotest_helper} 1>${case_work_logs_dir}/helper.log 2>&2 + + [[ $? -ne 0 ]] && echo -e "\033[31m[ERROR] ${testcase_name}, generate script failure! \033[0m" && continue # ]] + + waitForAvailable + echo "start container of testcase.name=${testcase_name}" + bash ${case_work_base}/scenario.sh ${task_state_house} 1>${case_work_logs_dir}/${testcase_name}.log 2>&2 & + done + + echo -e "\033[33m${scenario_name} has already sumbitted\033[0m" # to escape ]] +done + +# wait to finish +while [[ `ls -l ${task_state_house} |grep -c RUNNING` -gt 0 ]]; do + sleep 1 +done + +if [[ `ls -l ${task_state_house} |grep -c FAILURE` -gt 0 ]]; then + exit 1 +fi + +elapsed=$(( `date +%s` - $start_stamp )) +num_of_testcases="`ls -l ${task_state_house} |grep -c FINISH`" + +printf "Scenarios: %d, Testcases: %d, parallel_run_size: %d, Elapsed: %02d:%02d:%02d \n" \ + ${num_of_scenarios} "${num_of_testcases}" "${_arg_parallel_run_size}" \ + $(( ${elapsed}/3600 )) $(( ${elapsed}%3600/60 )) $(( ${elapsed}%60 )) + +# ] diff --git a/test/plugin/validator/README.md b/test/plugin/validator/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c40707bc826e159089236b766f1ed24d1d1d0137 --- /dev/null +++ b/test/plugin/validator/README.md @@ -0,0 +1,36 @@ +# agent-integration-testtool +The agent-integration-testtool project is used that to validate the different of Skywalking Java Agent generate +data item between you expect and the actual generate. + +## Assert Exceptions +The following are the exceptions that may occur in the validate tools. +### Data file +* [IllegalDataFileException](./docs/exception/IllegalDataFileException.md) + +### Registry Item +#### Application +* [RegistryInstanceOfApplicationNotFoundException](./docs/exception/RegistryInstanceOfApplicationNotFoundException.md) +* [RegistryApplicationNotFoundException](./docs/exception/RegistryApplicationNotFoundException.md) +* [RegistryApplicationSizeNotEqualsException](./docs/exception/RegistryApplicationSizeNotEqualsException.md) + +#### Instance +* [RegistryInstanceOfApplicationNotFoundException](./docs/exception/RegistryInstanceOfApplicationNotFoundException.md) +* [RegistryInstanceSizeNotEqualsException](./docs/exception/RegistryInstanceSizeNotEqualsException.md) +* [RegistryInstancesNotEqualsException](./docs/exception/RegistryInstancesNotEqualsException.md) + +#### Operation name +* [ActualRegistryOperationNameEmptyException](./docs/exception/ActualRegistryOperationNameEmptyException.md) +* [RegistryOperationNameNotFoundException](./docs/exception/RegistryOperationNameNotFoundException.md) +* [RegistryOperationNamesNotFoundException](./docs/exception/RegistryOperationNamesNotFoundException.md) +* [RegistryOperationNamesOfApplicationNotFoundException](./docs/exception/RegistryOperationNamesOfApplicationNotFoundException.md) + +### Segment +* [ActualSegmentItemEmptyException](./docs/exception/ActualSegmentItemEmptyException.md) +* [SegmentItemNotFoundException](./docs/exception/SegmentItemNotFoundException.md) +* [SegmentNotFoundException](./docs/exception/SegmentNotFoundException.md) + +### Segment Ref +* [SegmentRefNotFoundException](./docs/exception/SegmentRefNotFoundException.md) +* [ParentSegmentNotFoundException](./docs/exception/ParentSegmentNotFoundException.md) +* [SegmentRefSizeNotEqualsException](./docs/exception/SegmentRefSizeNotEqualsException.md) +* [SegmentSizeNotEqualsException](./docs/exception/SegmentSizeNotEqualsException.md) diff --git a/test/plugin/validator/docs/exception/ActualRegistryOperationNameEmptyException.md b/test/plugin/validator/docs/exception/ActualRegistryOperationNameEmptyException.md new file mode 100644 index 0000000000000000000000000000000000000000..5f4c8841e424b3a8beddd0c066d6c61dac3f2943 --- /dev/null +++ b/test/plugin/validator/docs/exception/ActualRegistryOperationNameEmptyException.md @@ -0,0 +1,12 @@ +# ActualRegistryOperationNameEmptyException + +## Format +ActualRegistryOperationNameEmptyException APPLICATION
+expected: [ OPERATION_NAME_A, OPERATION_NAME_B, ... ]
+actual: Empty + +## Cause +The `ActualRegistryOperationNameEmptyException` caused by there is any registry operation name in the actual data file + +## Check Points +1. Check if the execute time of entry service of test case more than 40 seconds, Please make it less than 40 seconds. \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/ActualSegmentItemEmptyException.md b/test/plugin/validator/docs/exception/ActualSegmentItemEmptyException.md new file mode 100644 index 0000000000000000000000000000000000000000..bf3b186a3940e7f8a70645565eb43a4ffd5cf9e3 --- /dev/null +++ b/test/plugin/validator/docs/exception/ActualSegmentItemEmptyException.md @@ -0,0 +1,15 @@ +# ActualSegmentItemEmptyException + +## Format +ActualSegmentItemEmptyException
+expected:
+Segment Item[APPLICATION]
+ - segment size: EXPECTED_SIZE
+ +actual: Empty
+ +## Cause +The `ActualSegmentItemEmptyException` caused by the segment item is empty in the actual data file + +## Check Points +1. Check if the execute time of entry service of test case more than 40 seconds, Please make it less than 40 seconds. \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/IllegalDataFileException.md b/test/plugin/validator/docs/exception/IllegalDataFileException.md new file mode 100644 index 0000000000000000000000000000000000000000..1a30dc2a1bcb8322a3da5d8be7972d646e5ebb70 --- /dev/null +++ b/test/plugin/validator/docs/exception/IllegalDataFileException.md @@ -0,0 +1,11 @@ +# IllegalDataFileException + +## Format +IllegalDataFileException + +## Cause by +The IllegalDataFileException cause by the data file is an illegal format. + +## Check Points +1. Check the format of data file if the file name is `expectedData.yaml`. +2. Check the build status of the test case if the file name is `actualData.yaml`. You can get it from the `testcase-build.log` file diff --git a/test/plugin/validator/docs/exception/ParentSegmentNotFoundException.md b/test/plugin/validator/docs/exception/ParentSegmentNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..fcf75594ad02a84bcc4ab52ee5f8a2c34c534eaf --- /dev/null +++ b/test/plugin/validator/docs/exception/ParentSegmentNotFoundException.md @@ -0,0 +1,24 @@ +# ParentSegmentNotFoundException + +## Format +ParentSegmentNotFoundException
+expected: PARENT_SEGMENT_EXPRESS
+actual: NOT FOUND + +## Cause +The `ParentSegmentNotFoundException` caused by the parent segment express cannot found in the actual data file.
+e.g., +expected: +``` +"refs": [ + { + "parentTraceSegmentId": "${other_application[10]}", + ... + } +] +``` +actual: +The segment size of `other_application` less than 10 + +## Check Points +1. Check if the parent segment express is correct \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/RegistryApplicationNotFoundException.md b/test/plugin/validator/docs/exception/RegistryApplicationNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..07e57b2757a57eb68aaa7c6fb98dece63bcd269e --- /dev/null +++ b/test/plugin/validator/docs/exception/RegistryApplicationNotFoundException.md @@ -0,0 +1,27 @@ +# RegistryApplicationNotFoundException + +## Format +RegistryApplicationNotFoundException
+expected: EXPECTED_SERVICE
+actual: NOT FOUND + +## Cause by +The `RegistryApplicationNotFoundException` caused by one of application code that you write in the expected data file +cannot found in the actual data file. + + +## Check points +1. Check the application code is the value of `agent.service_name` that you configured. + +e.g., +the application that you write in the expected data file: +``` +registryItems: { + "test_application": { + } +} +``` +the application of `agent.service_name` that you configured: +`-Dskywalking.agent.service_name=another_application` + +2. Check the agent of someone project in the test case if it works. \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/RegistryApplicationSizeNotEqualsException.md b/test/plugin/validator/docs/exception/RegistryApplicationSizeNotEqualsException.md new file mode 100644 index 0000000000000000000000000000000000000000..56f00999d6521da70e3fc46d5a35a7a398a8b534 --- /dev/null +++ b/test/plugin/validator/docs/exception/RegistryApplicationSizeNotEqualsException.md @@ -0,0 +1,13 @@ +# RegistryApplicationSizeNotEqualsException + +## Format +RegistryApplicationSizeNotEqualsException APPLICATION
+expected: EXPECTED_SIZE
+actual: ACTUAL_SIZE + +## Cause +The `RegistryApplicationSizeNotEqualsException` caused by the size of the registry application is different between expected and actual. + +## Check Points +1. Check if the size of the registry application that you expected +2. Check if the `agent.service_name` is duplicated in the test case project \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/RegistryInstanceOfApplicationNotFoundException.md b/test/plugin/validator/docs/exception/RegistryInstanceOfApplicationNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..23f3d5f4c1efad7e750334db3a7893fd98b17dcf --- /dev/null +++ b/test/plugin/validator/docs/exception/RegistryInstanceOfApplicationNotFoundException.md @@ -0,0 +1,25 @@ +# RegistryInstanceOfApplicationNotFoundException + +## Format +RegistryInstanceOfApplicationNotFoundException
+expected: Instances of Service(APPLICATION)
+actual: NOT FOUND + +## Cause +The `RegistryApplicationNotFoundException` caused by one of application code that you write in the expected data file +cannot found in the actual data file. + + +## Check Points +1. Check the application code is the value of `agent.service_name` that you configured.
+e.g., +the application that you write in the expected data file: +``` +registryItems: { + "test_application": { + } +} +``` +the application of `agent.service_name` that you configured: `-Dskywalking.agent.service_name=another_application` + +2. Check the agent of someone project in the test case if it works. \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/RegistryInstanceSizeNotEqualsException.md b/test/plugin/validator/docs/exception/RegistryInstanceSizeNotEqualsException.md new file mode 100644 index 0000000000000000000000000000000000000000..19739a93753f3400cd299e943189cef73a6a5613 --- /dev/null +++ b/test/plugin/validator/docs/exception/RegistryInstanceSizeNotEqualsException.md @@ -0,0 +1,13 @@ +# RegistryInstanceSizeNotEqualsException + +## Format +RegistryInstanceSizeNotEqualsException APPLICATION
+expected: EXPECTED_SIZE
+actual: ACTUAL_SIZE + +## Cause +The `RegistryInstanceSizeNotEqualsException` caused by the size of the registry instance of one application is different between you expected and the actual + +## Check Points +1. Check the size of the registry instance that you expected + diff --git a/test/plugin/validator/docs/exception/RegistryInstancesNotEqualsException.md b/test/plugin/validator/docs/exception/RegistryInstancesNotEqualsException.md new file mode 100644 index 0000000000000000000000000000000000000000..b52ecb572a4365beb4378f9a37cc10a644fe7a62 --- /dev/null +++ b/test/plugin/validator/docs/exception/RegistryInstancesNotEqualsException.md @@ -0,0 +1,12 @@ +# RegistryInstancesNotEqualsException + +## Format +RegistryInstancesNotEqualsException
+expected: EXPECTED_INSTANCE_SIZE
+actual: ACTUAL_INSTANCE_SIZE + +## Cause by +The RegistryInstancesNotEqualsException cause by the instance size is different between expected and actual + +## Check Points +1. Check the instance size that your write if it is your expected. \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/RegistryOperationNameNotFoundException.md b/test/plugin/validator/docs/exception/RegistryOperationNameNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..39ecbfcb48bc3994a41346b2dbb5932bf57af80d --- /dev/null +++ b/test/plugin/validator/docs/exception/RegistryOperationNameNotFoundException.md @@ -0,0 +1,13 @@ +# RegistryOperationNameNotFoundException + +## Format +RegistryOperationNameNotFoundException APPLICATION
+expected: OPERATION_NAME
+actual: NOT FOUND + +## Cause +The `RegistryOperationNameNotFoundException` caused by the registry operation name that you expected cannot found in the actual data file + +## Check Points +1. Check if the registry operation name that you expected is correct +2. Check if the instrumentation that it generates the operation name works \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/RegistryOperationNamesNotFoundException.md b/test/plugin/validator/docs/exception/RegistryOperationNamesNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..13c5764b23c8d4374441f017acf1b08ca48a657a --- /dev/null +++ b/test/plugin/validator/docs/exception/RegistryOperationNamesNotFoundException.md @@ -0,0 +1,13 @@ +# RegistryOperationNamesNotFoundException + +## Format +RegistryOperationNamesNotFoundException
+expected:
+actual: Not Found
+ +## Cause by +The RegistryOperationNamesNotFoundException cause by the registry operation names of someone application cannot found + in the actual data file. + +## Check Points +1. Check all the instrumentations about test case if it works. \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/RegistryOperationNamesOfApplicationNotFoundException.md b/test/plugin/validator/docs/exception/RegistryOperationNamesOfApplicationNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..45136e69084a9f06e19d84984ccdf73f2e2b0ed7 --- /dev/null +++ b/test/plugin/validator/docs/exception/RegistryOperationNamesOfApplicationNotFoundException.md @@ -0,0 +1,12 @@ +# RegistryOperationNamesOfApplicationNotFoundException + +## Format +RegistryOperationNamesOfApplicationNotFoundException
+expected: [ OPERATION_NAME_A, OPERATION_NAME_B, ...]
+actual: NOT FOUND + +## Cause +The `RegistryOperationNamesOfApplicationNotFoundException` caused by the registry operation name of someone application does not exist in the actual data file. + +## Check Points +1. Check if the execute time of entry service of test case more than 40 seconds, Please make it less than 40 seconds. \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/SegmentItemNotFoundException.md b/test/plugin/validator/docs/exception/SegmentItemNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..2f08dccee8b35a59fd7dc75f4342e3a2e8365d42 --- /dev/null +++ b/test/plugin/validator/docs/exception/SegmentItemNotFoundException.md @@ -0,0 +1,15 @@ +# SegmentItemNotFoundException + +## Format +SegmentItemNotFoundException
+expected:
+Segment Item[APPLICATION]
+ - segment size: EXPECTED_SIZE
+ +actual: NOT FOUND + +## Cause +The `SegmentItemNotFoundException` caused by the segment item of you expected cannot found in the actual data file + +## Check Points +1. Check if the execute time of entry service of test case more than 40 seconds, Please make it less than 40 seconds. \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/SegmentNotFoundException.md b/test/plugin/validator/docs/exception/SegmentNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..c3c3e749b41813a13ec331ec35af4f43b13d9d12 --- /dev/null +++ b/test/plugin/validator/docs/exception/SegmentNotFoundException.md @@ -0,0 +1,31 @@ +# SegmentNotFoundException + +## Format +SegmentNotFoundException
+expected
+Segment:
+ - span[PARENT_SPAN_ID, SPAN_ID] OPERATION_NAME_A
+ - span[PARENT_SPAN_ID, SPAN_ID] OPERATION_NAME_B
+ - ......
+ +actual:
+Segment[SEGMENT_ID_A] validate failed:
+expected: span[PARENT_SPAN_ID, SPAN_ID] OPERATION_NAME
+actual: span[PARENT_SPAN_ID, SPAN_ID] OPERATION_NAME
+reason: [SPAN_FIELD] expected=>{EXPECTED_VALUE}, actual=>{ACTUAL_VALUE}
+ +Segment[SEGMENT_ID_B] validate failed:
+expected: span[PARENT_SPAN_ID, SPAN_ID] OPERATION_NAME
+actual: span[PARENT_SPAN_ID, SPAN_ID] OPERATION_NAME
+reason: [SPAN_FIELD] expected=>{EXPECTED_VALUE}, actual=>{ACTUAL_VALUE}
+ +......
+ +**NOTE**: The validate tool validates all similar segment similar to what you expect in the actual data file. The rule that the validate tool to check if the segment similar to what you expect is the span size equals. + +## Cause +The `SegmentNotFoundException` caused by the segment what you expect cannot found in the actual data file. + +## Check Points +1. Check if the span sequence of a segment is right +2. Check if the field value of the span is right \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/SegmentRefNotFoundException.md b/test/plugin/validator/docs/exception/SegmentRefNotFoundException.md new file mode 100644 index 0000000000000000000000000000000000000000..cd8e22fe92056b71e89b7c9dd2f537af2a25745e --- /dev/null +++ b/test/plugin/validator/docs/exception/SegmentRefNotFoundException.md @@ -0,0 +1,30 @@ +# SegmentRefNotFoundException + +## Format +SegmentRefNotFoundException
+expected:
+SegmentRef:
+ - entryServiceName: ENTRY_SERVICE_NAME
+ - networkAddress: NETWORK_ADDRESS
+ - parentServiceName: PARENT_SERVICE_NAME
+ - parentSpanId: PARENT_SPAN_ID
+ - parentTraceSegmentId: PARENT_TRACE_SEGMENT_ID
+ - refType: REF_TYPE
+ +actual:
+SegmentRef: [SEGMENT_REF_FIELD] expected=>{EXPECTED_SIZE}, actual=>{ACTUAL_SIZE}
+ - entryServiceName: ENTRY_SERVICE_NAME
+ - networkAddress: NETWORK_ADDRESS
+ - parentServiceName: PARENT_SERVICE_NAME
+ - parentSpanId: PARENT_SPAN_ID
+ - parentTraceSegmentId: PARENT_TRACE_SEGMENT_ID
+ - refType: REF_TYPE
+...... + +**NOTE**: The validate tool check all the segment ref of the span. + +## Cause +The `SegmentRefNotFoundException` caused by the segment ref cannot found in the actual data file + +## Check Points +1. Check if the field value of segment ref what you expect is correct \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/SegmentRefSizeNotEqualsException.md b/test/plugin/validator/docs/exception/SegmentRefSizeNotEqualsException.md new file mode 100644 index 0000000000000000000000000000000000000000..7005df4ec5b5a55a10b5638f48bdd58f83db2d18 --- /dev/null +++ b/test/plugin/validator/docs/exception/SegmentRefSizeNotEqualsException.md @@ -0,0 +1,34 @@ +# SegmentRefSizeNotEqualsException +## Format +SegmentRefSizeNotEqualsException
+expected: EXPECTED_SIZE
+actual: ACUTAL_SIZE + +## Cause +The `SegmentRefSizeNotEqualsException` caused by the size of `refs` is different between you expect and actual. + +e.g., +expected: +``` +"refs": [ + { + "parentTraceSegmentId": "${other_application[1]}", + ... + } +] +``` +actual: +``` +"refs": [ + { + "parentTraceSegmentId": "${other_application[1]}", + ... + }, + { + "parentTraceSegmentId": "${other_application[2]}", + ... + } +] +``` +## Check Points +1. Check if the size of segment ref is correct \ No newline at end of file diff --git a/test/plugin/validator/docs/exception/SegmentSizeNotEqualsException.md b/test/plugin/validator/docs/exception/SegmentSizeNotEqualsException.md new file mode 100644 index 0000000000000000000000000000000000000000..a03868e4abf4e32ad1581f07194eb3d576ffa058 --- /dev/null +++ b/test/plugin/validator/docs/exception/SegmentSizeNotEqualsException.md @@ -0,0 +1,12 @@ +# SegmentSizeNotEqualsException + +## Format +SegmentSizeNotEqualsException APPLICATION
+expected: EXPECTED_SIZE
+actual: ACTUAL_SIZE
+ +## Cause +The `SegmentSizeNotEqualsException` caused by the size is different between the size that you expected and the actual's + +## Check Points +1. Check if the size that you expected is right \ No newline at end of file diff --git a/test/plugin/validator/pom.xml b/test/plugin/validator/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..874aadbbdbcf7fccc523c8841218159c67ca5777 --- /dev/null +++ b/test/plugin/validator/pom.xml @@ -0,0 +1,81 @@ + + + + 4.0.0 + + + org.apache.skywalking.plugin + apache-skywalking-test-plugin + 1.0.0 + + + validator + jar + + skywalking-validator-tools + http://maven.apache.org + + + + com.google.code.gson + gson + 2.8.0 + + + + org.freemarker + freemarker + 2.3.23 + + + + + skywalking-validator-tools + + + org.apache.maven.plugins + maven-shade-plugin + 3.0.0 + + + package + + shade + + + + + + + org.apache.skywalking.plugin.test.agent.tool.Main + + + ../dist/${project.build.finalName}.jar + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + + + diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/ConfigHelper.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/ConfigHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..45dbf5ac65b04ebcaa61f9fb83ce1daa919b6dc4 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/ConfigHelper.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool; + +import java.io.File; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class ConfigHelper { + private static Logger logger = LogManager.getLogger(ConfigHelper.class); + + private ConfigHelper() { + } + + public static String testDate() { + return System.getProperty("testDate"); + } + + public static String testCases() { + String testCasesInput = System.getProperty("testCases", ""); + if (testCasesInput.length() > 0) { + return testCasesInput; + } + String testCasePath = System.getProperty("testCasePath", ""); + + if (testCasePath.length() == 0) { + logger.warn("test case dir is empty"); + return ""; + } + + File testCaseDir = new File(testCasePath); + if (!testCaseDir.exists() || !testCaseDir.isDirectory()) { + logger.warn("test case dir is not exists or is not directory"); + return ""; + } + + StringBuilder testCases = new StringBuilder(); + File[] testCasesDir = testCaseDir.listFiles(); + for (File file : testCasesDir) { + testCases.append(file.getName() + ","); + } + + return testCases.toString(); + } + + public static String testCaseBaseDir() { + return System.getProperty("testCasePath", ""); + } + + public static boolean isV2() { + return Boolean.getBoolean("v2"); + } + + public static String reportFilePath() { + return System.getProperty("reportFilePath"); + } + + public static String agentBranch() { + return System.getProperty("agentBranch"); + } + + public static String agentCommit() { + return System.getProperty("agentCommitId"); + } + + public static String casesBranch() { + return System.getProperty("casesBranch", "").replace("/", "-"); + } + + public static String caseCommitId() { + return System.getProperty("casesCommitId", ""); + } + + public static String committer() { + return System.getProperty("committer", ""); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/Main.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..d2db9fbc5612b38eaa1423d5432dac5aa57bc79e --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/Main.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool; + +import java.io.File; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.DataAssert; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Data; +import org.apache.skywalking.plugin.test.agent.tool.report.entity.Report; +import org.apache.skywalking.plugin.test.agent.tool.report.entity.TestCase; +import org.apache.skywalking.plugin.test.agent.tool.report.entity.TestCaseDesc; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class Main { + private static Logger logger = LogManager.getLogger(Main.class); + + public static void main(String[] args) { + Report report = new Report(); + String testCasePath = ConfigHelper.testCaseBaseDir(); + + boolean success = false; + if (ConfigHelper.isV2()) { + success |= verify(new File(testCasePath), TestCaseDesc.ParserV2.parse(), report).isSuccess(); + } else { + String[] testCases = ConfigHelper.testCases().split(","); + + for (String aCase : testCases) { + File casePath = new File(testCasePath, aCase); + File descFile = new File(casePath, "testcase.desc"); + success |= verify(casePath, TestCaseDesc.Parser.parse(descFile), report).isSuccess(); + } + } + + if (!ConfigHelper.isV2()) { + try { + report.generateReport(ConfigHelper.reportFilePath()); + } catch (Exception e) { + logger.error("Failed to generate report file", e); + } + } + System.exit(success ? 0 : 1); + } + + static TestCase verify(File casePath, TestCaseDesc testCaseDesc, Report report) { + TestCase testCase = new TestCase(testCaseDesc.getTestComponents()); + try { + logger.info("start to assert data of test case[{}]", testCase.getCaseName()); + File actualData = new File(casePath, "actualData.yaml"); + File expectedData = new File(casePath, "expectedData.yaml"); + + if (actualData.exists() && expectedData.exists()) { + try { + DataAssert.assertEquals(Data.Loader.loadData("expectedData.yaml", expectedData), + Data.Loader.loadData("actualData.yaml", actualData)); + testCase.testedSuccessfully(); + } catch (AssertFailedException e) { + logger.error("\nassert failed.\n{}\n", e.getCauseMessage()); + } + } else { + logger.error("assert failed. because actual data {} and expected data {}", actualData.exists() ? "founded" : "not founded", actualData.exists() ? "founded" : "not founded"); + } + } catch (Exception e) { + logger.error("assert test case {} failed.", testCase.getCaseName(), e); + } + report.addTestCase(testCaseDesc.getProjectName(), testCaseDesc.getTestFramework(), testCase); + return testCase; + } + +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/CaseVersionCategory.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/CaseVersionCategory.java new file mode 100644 index 0000000000000000000000000000000000000000..594fa1269583334332448cf05821d9faa20c390e --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/CaseVersionCategory.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.report.entity; + +import java.util.ArrayList; +import java.util.List; + +public class CaseVersionCategory { + private String name; + private List testCases; + + public CaseVersionCategory(String versionName) { + this.name = versionName; + testCases = new ArrayList<>(); + } + + public void addTestCases(TestCase testCase) { + this.testCases.add(testCase); + } + + public String getName() { + return name; + } + + public List getTestCases() { + return testCases; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/FrameworkCases.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/FrameworkCases.java new file mode 100644 index 0000000000000000000000000000000000000000..1de4cb2f12d4acf90a22174a3d390174b0cd68ad --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/FrameworkCases.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.report.entity; + +import java.util.ArrayList; +import java.util.List; + +public class FrameworkCases { + private String testFramework; + private int successCaseCount; + private int totalCaseCount; + private List caseByVersionCategories; + + public FrameworkCases(String testFramework) { + this.testFramework = testFramework; + this.caseByVersionCategories = new ArrayList<>(); + } + + public void addTestCase(String versionCategory, TestCase aCase) { + CaseVersionCategory caseVersionCategory = findCategoryForProject(versionCategory); + if (caseVersionCategory == null) { + caseVersionCategory = new CaseVersionCategory(versionCategory); + this.caseByVersionCategories.add(caseVersionCategory); + } + + caseVersionCategory.addTestCases(aCase); + + if (aCase.isSuccessfully()) { + successCaseCount++; + } + totalCaseCount++; + } + + private CaseVersionCategory findCategoryForProject(String projectName) { + for (CaseVersionCategory project : caseByVersionCategories) { + if (project.getName().equals(projectName)) { + return project; + } + } + + return null; + } + + public String getTestFramework() { + return testFramework; + } + + public List getCaseByVersionCategories() { + return caseByVersionCategories; + } + + public int getSuccessCaseCount() { + return successCaseCount; + } + + public int getTotalCaseCount() { + return totalCaseCount; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/Report.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/Report.java new file mode 100644 index 0000000000000000000000000000000000000000..738adfe675e1843454b12cbf0624d6d453a9bdad --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/Report.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.report.entity; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.plugin.test.agent.tool.ConfigHelper; + +public class Report { + private static Logger logger = LogManager.getLogger(Report.class); + private final String testDate; + private final String testBranch; + private final String commitId; + private final String caseBranch; + private final String caseCommit; + private final String committer; + private int successCaseCount; + private int totalCaseCount; + private List frameworkCases; + + public Report() { + this.testDate = formatTestDate(ConfigHelper.testDate()); + this.testBranch = ConfigHelper.agentBranch(); + this.commitId = ConfigHelper.agentCommit(); + this.caseBranch = ConfigHelper.casesBranch(); + this.caseCommit = ConfigHelper.caseCommitId(); + this.committer = ConfigHelper.committer(); + this.frameworkCases = new ArrayList<>(); + } + + public String getTestDate() { + return testDate; + } + + public String getTestBranch() { + return testBranch; + } + + public String getCommitId() { + return commitId; + } + + public List getFrameworkCases() { + return frameworkCases; + } + + private FrameworkCases findCasesByFrameworkName(String testFramework) { + for (FrameworkCases ascenario : frameworkCases) { + if (ascenario.getTestFramework().equalsIgnoreCase(testFramework)) { + return ascenario; + } + } + + return null; + } + + private String formatTestDate(String date) { + try { + Date testDate = new SimpleDateFormat("yyyy-MM-dd-HH-mm").parse(date); + return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(testDate); + } catch (ParseException e) { + logger.error("Failed to format date[{}].", date, e); + } + return date; + } + + public void generateReport(String path) throws IOException, TemplateException, ParseException { + File reportFile = generateReportFile(path); + + Configuration cfg = new Configuration(Configuration.VERSION_2_3_23); + cfg.setClassForTemplateLoading(this.getClass(), "/template"); + cfg.setDefaultEncoding("UTF-8"); + Template template = cfg.getTemplate("main-report.md.ftl"); + StringWriter stringWriter = new StringWriter(); + Map resultMap = new HashMap<>(); + resultMap.put("testReport", this); + template.process(resultMap, stringWriter); + FileWriter fileOutputStream = new FileWriter(reportFile, false); + fileOutputStream.write(stringWriter.getBuffer().toString()); + stringWriter.close(); + fileOutputStream.close(); + } + + /** + * File Path Year - Month - apache - testReport-2019-10-10-10-11-11.md - testReport-2019-10-10-10-11-12.md - + * ascrutae ... + * + * @return + */ + private File generateReportFile(String basePath) throws ParseException, IOException { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(testDate)); + File testReportDir = new File(new File(new File(basePath, calendar.get(Calendar.YEAR) + ""), (calendar.get(Calendar.MONTH) + 1) + ""), ConfigHelper.committer()); + if (!testReportDir.exists()) { + testReportDir.mkdirs(); + } + String fileName = "testReport-" + ConfigHelper.casesBranch() + "-" + ConfigHelper.testDate() + ".md"; + File testReportFile = new File(testReportDir, fileName); + if (!testReportFile.exists()) { + testReportFile.createNewFile(); + } + return testReportFile; + } + + public void addTestCase(String projectName, String framework, TestCase aCase) { + FrameworkCases frameworkCases = findCasesByFrameworkName(framework); + if (frameworkCases == null) { + frameworkCases = new FrameworkCases(framework); + this.frameworkCases.add(frameworkCases); + } + + frameworkCases.addTestCase(projectName, aCase); + + if (aCase.isSuccessfully()) { + successCaseCount++; + } + totalCaseCount++; + } + + public int getSuccessCaseCount() { + return successCaseCount; + } + + public int getTotalCaseCount() { + return totalCaseCount; + } + + public String getCaseBranch() { + return caseBranch; + } + + public String getCaseCommit() { + return caseCommit; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/TestCase.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/TestCase.java new file mode 100644 index 0000000000000000000000000000000000000000..cc51b7a70d31099a8aa701199054471161de7139 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/TestCase.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.report.entity; + +public class TestCase { + private String caseName; + private boolean success; + + public TestCase(String testComponents) { + this.caseName = testComponents; + } + + public String getCaseName() { + return caseName; + } + + public void testedSuccessfully() { + this.success = true; + } + + public boolean isSuccessfully() { + return success; + } + + public boolean isSuccess() { + return success; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/TestCaseDesc.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/TestCaseDesc.java new file mode 100644 index 0000000000000000000000000000000000000000..e7356514489289b726e2acd2e9116d68bafb21c6 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/report/entity/TestCaseDesc.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.report.entity; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class TestCaseDesc { + private static Logger logger = LogManager.getLogger(TestCaseDesc.class); + private String testFramework; + private String testComponents; + private String projectName; + + private TestCaseDesc() { + } + + public static class Parser { + public static TestCaseDesc parse(File caseDescFile) { + TestCaseDesc testCase = new TestCaseDesc(); + Properties properties = new Properties(); + if (caseDescFile.exists()) { + try { + properties.load(new FileInputStream(caseDescFile)); + } catch (IOException e) { + logger.error("Failed to parse case desc file[{}]", caseDescFile.getAbsoluteFile()); + return testCase; + } + } + + testCase.projectName = properties.getProperty("case.projectName", null); + testCase.testFramework = properties.getProperty("case.testFramework", null); + testCase.testComponents = properties.getProperty("case.testComponents", null); + logger.info("load case desc: projectName[{}] testFramework[{}], testComponents[{}], cooperativeFrameworks[{}]", + testCase.projectName, + testCase.testFramework, + testCase.testComponents); + return testCase; + } + } + + public static class ParserV2 { + public static TestCaseDesc parse() { + TestCaseDesc testCase = new TestCaseDesc(); + testCase.projectName = System.getProperty("case.projectName", null); + testCase.testFramework = System.getProperty("case.testFramework", null); + testCase.testComponents = System.getProperty("case.testComponents", null); + logger.info("load case desc: projectName[{}] testFramework[{}], testComponents[{}], cooperativeFrameworks[{}]", + testCase.projectName, + testCase.testFramework, + testCase.testComponents); + return testCase; + } + } + + public String getTestFramework() { + return testFramework; + } + + public String getTestComponents() { + return testComponents; + } + + public String getProjectName() { + return projectName; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ApplicationAssert.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ApplicationAssert.java new file mode 100644 index 0000000000000000000000000000000000000000..31e68e73e84e6b8099413e5f7cd03c620249233e --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ApplicationAssert.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import java.util.List; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.RegistryApplicationNotFoundException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.RegistryApplicationSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.RegistryApplication; + +public class ApplicationAssert { + public static void assertEquals(List expected, + List actual) { + + if (expected == null) { + return; + } + + for (RegistryApplication application : expected) { + RegistryApplication actualApplication = getMatchApplication(actual, application); + try { + ExpressParser.parse(application.expressValue()).assertValue("registry application", actualApplication.expressValue()); + } catch (ValueAssertFailedException e) { + throw new RegistryApplicationSizeNotEqualsException(application.applicationCode(), e); + } + } + } + + private static RegistryApplication getMatchApplication(List actual, + RegistryApplication application) { + for (RegistryApplication registryApplication : actual) { + if (registryApplication.applicationCode().equals(application.applicationCode())) { + return registryApplication; + } + } + throw new RegistryApplicationNotFoundException(application.applicationCode()); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssert.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssert.java new file mode 100644 index 0000000000000000000000000000000000000000..8933c255a5343342082c56ba39161cdf595ddaca --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssert.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import com.google.gson.GsonBuilder; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Data; + +public class DataAssert { + private static Logger logger = LogManager.getLogger(DataAssert.class); + + public static void assertEquals(Data excepted, Data actual) { + logger.info("excepted data:\n{}", new GsonBuilder().setPrettyPrinting().create().toJson(excepted)); + logger.info("actual data:\n{}", new GsonBuilder().setPrettyPrinting().create().toJson(actual)); + RegistryItemsAssert.assertEquals(excepted.registryItems(), actual.registryItems()); + SegmentItemsAssert.assertEquals(excepted.segmentItems(), actual.segmentItems()); + logger.info("{} assert successful.", "segment items"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ExpressParser.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ExpressParser.java new file mode 100644 index 0000000000000000000000000000000000000000..28b7d6746615b076695e0f9d7cc0a88e7e5a2bbf --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ExpressParser.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.ElementAssertor; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.EqualsAssertor; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.GreatThanAssertor; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.GreetEqualAssertor; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.NoopAssertor; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.NotEqualsAssertor; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element.NotNullAssertor; + +public class ExpressParser { + public static ElementAssertor parse(String express) { + if (express == null) { + return new NoopAssertor(); + } + + String expressTrim = express.trim(); + if (expressTrim.equals("not null")) { + return new NotNullAssertor(); + } + + if (expressTrim.equals("null")) { + return new NotNullAssertor(); + } + + String[] expressSegment = expressTrim.split(" "); + if (expressSegment.length == 1) { + return new EqualsAssertor(expressSegment[0]); + } else if (expressSegment.length == 2) { + String exceptedValue = expressSegment[1]; + switch (expressSegment[0].trim()) { + case "nq": + return new NotEqualsAssertor(exceptedValue); + case "eq": + return new EqualsAssertor(exceptedValue); + case "gt": + return new GreatThanAssertor(exceptedValue); + case "ge": + return new GreetEqualAssertor(exceptedValue); + } + } + + return new EqualsAssertor(express); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/InstanceAssert.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/InstanceAssert.java new file mode 100644 index 0000000000000000000000000000000000000000..ca0357632c1ac298ffdc77441a99326b24773bd1 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/InstanceAssert.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import java.util.List; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.RegistryInstanceOfApplicationNotFoundException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.RegistryInstanceSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.RegistryInstance; + +/** + * Created by xin on 2017/7/15. + */ +public class InstanceAssert { + public static void assertEquals(List expected, List actual) { + + if (expected == null) { + return; + } + + for (RegistryInstance instance : expected) { + RegistryInstance actualInstance = getMatchApplication(actual, instance); + try { + ExpressParser.parse(actualInstance.expressValue()).assertValue(String.format("The registry instance of %s", + instance.applicationCode()), actualInstance.expressValue()); + } catch (ValueAssertFailedException e) { + throw new RegistryInstanceSizeNotEqualsException(instance.applicationCode(), e); + } + } + } + + private static RegistryInstance getMatchApplication(List actual, + RegistryInstance application) { + for (RegistryInstance registryApplication : actual) { + if (registryApplication.applicationCode().equals(application.applicationCode())) { + return registryApplication; + } + } + throw new RegistryInstanceOfApplicationNotFoundException(application.applicationCode()); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/OperationNameAssert.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/OperationNameAssert.java new file mode 100644 index 0000000000000000000000000000000000000000..138626bd67bcc5181cd50307c3247b44ed38efd0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/OperationNameAssert.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import java.util.List; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ActualRegistryOperationNameEmptyException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.RegistryOperationNameNotFoundException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.RegistryOperationNamesOfApplicationNotFoundException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.RegistryOperationName; + +public class OperationNameAssert { + public static void assertEquals(List expected, List actual) { + if (expected == null) { + return; + } + + for (RegistryOperationName operationName : expected) { + RegistryOperationName actualOperationName = findActualRegistryOperationName(actual, operationName); + assertOperationEquals(actualOperationName.applicationCode(),operationName.operationName(), + actualOperationName.operationName()); + } + } + + private static void assertOperationEquals(String applicationCode, List expectedOperationName, + List actualOperationName) { + for (String operationName : expectedOperationName) { + if (!actualOperationName.contains(operationName)) { + throw new RegistryOperationNameNotFoundException(applicationCode, operationName); + } + } + } + + private static RegistryOperationName findActualRegistryOperationName( + List actual, RegistryOperationName registryOperationName) { + if (actual == null) { + throw new ActualRegistryOperationNameEmptyException(registryOperationName); + } + + for (RegistryOperationName operationName : actual) { + if (operationName.applicationCode().equals(registryOperationName.applicationCode())) { + return operationName; + } + } + + throw new RegistryOperationNamesOfApplicationNotFoundException(registryOperationName); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ParentSegmentIdExpressParser.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ParentSegmentIdExpressParser.java new file mode 100644 index 0000000000000000000000000000000000000000..01a5833bf766cba2972c08f9c26b55d70680f3a5 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/ParentSegmentIdExpressParser.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import java.util.List; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ParentSegmentNotFoundException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentItem; + +/** + * Created by xin on 2017/7/16. + */ +public class ParentSegmentIdExpressParser { + public static String parse(String express, List actual) { + if (!express.trim().startsWith("${") && !express.trim().endsWith("}")) { + return express; + } + + String parentSegmentExpress = express.trim().substring(2, express.trim().length() - 1); + + int startIndexOfIndex = parentSegmentExpress.indexOf("["); + String applicationCode = parentSegmentExpress.substring(0, startIndexOfIndex); + int endIndexOfIndex = parentSegmentExpress.indexOf("]", startIndexOfIndex); + int expectedSize = Integer.parseInt(parentSegmentExpress.substring(startIndexOfIndex + 1, endIndexOfIndex)); + for (SegmentItem segmentItem : actual) { + if (segmentItem.applicationCode().equals(applicationCode)) { + if (segmentItem.segments().size() <= expectedSize) { + throw new ParentSegmentNotFoundException(parentSegmentExpress); + } + + return segmentItem.segments().get(expectedSize).segmentId(); + } + } + return express; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/RegistryItemsAssert.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/RegistryItemsAssert.java new file mode 100644 index 0000000000000000000000000000000000000000..434fad26efbe9045955aa05db0b160f9ddca7d20 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/RegistryItemsAssert.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.RegistryItems; + +public class RegistryItemsAssert { + private static Logger logger = LogManager.getLogger(RegistryItemsAssert.class); + + public static void assertEquals(RegistryItems excepted, RegistryItems actual) { + ApplicationAssert.assertEquals(excepted.applications(), actual.applications()); + logger.info("{} assert successful.", "registry applications"); + InstanceAssert.assertEquals(excepted.instances(), actual.instances()); + logger.info("{} assert successful.", "registry instances"); + OperationNameAssert.assertEquals(excepted.operationNames(), actual.operationNames()); + logger.info("{} assert successful.", "registry operation name"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentAssert.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentAssert.java new file mode 100644 index 0000000000000000000000000000000000000000..8ce49c6cc9975440497fb6067adc20c4fa865233 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentAssert.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ActualSegmentRefIsEmptyException; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.KeyValueNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.LogEventKeyNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.LogEventSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.LogEventValueNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.LogSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.RefSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SegmentNotFoundException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SpanAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SpanSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.TagKeyNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.TagSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.TagValueNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.KeyValuePair; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.LogEvent; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Segment; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentItem; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentRef; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Span; + +public class SegmentAssert { + public static void assertEquals(SegmentItem expected, SegmentItem actual) { + if (expected.segments() == null) { + return; + } + + for (Segment segment : expected.segments()) { + Segment actualSegment = findSegment(actual, segment); + segment.setSegmentId(actualSegment.segmentId()); + } + } + + private static Segment findSegment(SegmentItem actual, Segment expectedSegment) { + List exceptions = new ArrayList<>(); + for (Segment actualSegment : actual.segments()) { + try { + if (spansEquals(expectedSegment.spans(), actualSegment.spans())) { + return actualSegment; + } + } catch (SpanSizeNotEqualsException e) { + } catch (SpanAssertFailedException e) { + exceptions.add(new SegmentPredictionFailedCause(e, actualSegment)); + } + } + + throw new SegmentNotFoundException(expectedSegment, exceptions); + } + + private static boolean spansEquals(List excepted, List actual) { + if (excepted == null) { + return true; + } + + if (actual == null || excepted.size() != actual.size()) { + throw new SpanSizeNotEqualsException(excepted.size(), (actual != null) ? actual.size() : 0); + } + + int equalSpans = 0; + for (int index = 0; index < excepted.size(); index++, equalSpans++) { + Span exceptedSpan = excepted.get(index); + Span actualSpan = actual.get(index); + try { + spanEquals(exceptedSpan, actualSpan); + } catch (AssertFailedException e) { + throw new SpanAssertFailedException(e, exceptedSpan, actualSpan); + } + } + + return true; + } + + private static void spanEquals(Span excepted, Span actualSpan) { + ExpressParser.parse(excepted.operationName()).assertValue("operation name", actualSpan.operationName()); + ExpressParser.parse(excepted.componentId()).assertValue("component id", actualSpan.componentId()); + ExpressParser.parse(excepted.componentName()).assertValue("component name", actualSpan.componentName()); + ExpressParser.parse(excepted.startTime()).assertValue("start time", actualSpan.startTime()); + ExpressParser.parse(excepted.endTime()).assertValue("end time", actualSpan.endTime()); + ExpressParser.parse(excepted.parentSpanId()).assertValue("parent span id", actualSpan.parentSpanId()); + ExpressParser.parse(excepted.spanId()).assertValue("span id", actualSpan.spanId()); + ExpressParser.parse(excepted.operationId()).assertValue("operation id", actualSpan.operationId()); + ExpressParser.parse(excepted.peer()).assertValue("peer", actualSpan.peer()); + ExpressParser.parse(excepted.spanLayer()).assertValue("span layer", actualSpan.spanLayer()); + ExpressParser.parse(excepted.peerId()).assertValue("peer id", actualSpan.peerId()); + tagsEquals(excepted.tags(), actualSpan.tags()); + logsEquals(excepted.logs(), actualSpan.logs()); + refEquals(excepted.refs(), actualSpan.refs()); + excepted.setActualRefs(actualSpan.refs()); + + } + + private static void refEquals(List excepted, List actual) { + if (excepted == null) { + return; + } + + if (actual == null) { + throw new ActualSegmentRefIsEmptyException(excepted.size()); + } + + if (excepted.size() != actual.size()) { + throw new RefSizeNotEqualsException(excepted.size(), actual.size()); + } + } + + private static void tagsEquals(List excepted, List actual) { + if (excepted.size() != actual.size()) { + throw new TagSizeNotEqualsException(excepted.size(), actual.size()); + } + + for (int index = 0; index < excepted.size(); index++) { + tagEquals(excepted.get(index), actual.get(index)); + } + } + + private static void logsEquals(List excepted, List actual) { + if (excepted.size() != actual.size()) { + throw new LogSizeNotEqualsException(excepted.size(), actual.size()); + } + + for (int index = 0; index < excepted.size(); index++) { + logEventEquals(excepted.get(index), actual.get(index)); + } + + } + + private static void logEventEquals(LogEvent exceptedEvent, LogEvent actualEvent) { + List exceptedKey = exceptedEvent.events(); + List actualKey = actualEvent.events(); + + if (exceptedKey.size() != actualKey.size()) { + throw new LogEventSizeNotEqualsException(exceptedKey.size(), actualKey.size()); + } + + for (int index = 0; index < exceptedKey.size(); index++) { + logEventPairEquals(exceptedKey.get(index), actualKey.get(index)); + } + } + + private static void keyValuePairEquals(KeyValuePair excepted, KeyValuePair actual) { + if (!excepted.key().equals(actual.key())) { + throw new KeyValueNotEqualsException(); + } + + ExpressParser.parse(excepted.value()).assertValue("", actual.value()); + } + + private static void logEventPairEquals(KeyValuePair excepted, KeyValuePair actual) { + try { + keyValuePairEquals(excepted, actual); + } catch (KeyValueNotEqualsException e) { + throw new LogEventKeyNotEqualsException(excepted.key(), actual.key()); + } catch (ValueAssertFailedException e) { + throw new LogEventValueNotEqualsException(excepted.key(), excepted.value(), actual.value()); + } + } + + private static void tagEquals(KeyValuePair excepted, KeyValuePair actual) { + try { + keyValuePairEquals(excepted, actual); + } catch (KeyValueNotEqualsException e) { + throw new TagKeyNotEqualsException(excepted.key(), actual.key()); + } catch (ValueAssertFailedException e) { + throw new TagValueNotEqualsException(excepted.key(), excepted.value(), actual.value()); + } + } + +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentItemsAssert.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentItemsAssert.java new file mode 100644 index 0000000000000000000000000000000000000000..bd33038e744371126297d7d11e675a20eb3af5a0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentItemsAssert.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ActualSegmentItemEmptyException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SegmentItemNotFoundException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SegmentSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Segment; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentItem; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentRef; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Span; + +/** + * Created by xin on 2017/7/15. + */ +public class SegmentItemsAssert { + private static Logger logger = LogManager.getLogger(SegmentItemsAssert.class); + + public static void assertEquals(List expected, List actual) { + if (expected == null) { + logger.info("ignore segment items. because expected segment item is null."); + return; + } + + for (SegmentItem item : expected) { + SegmentItem actualSegmentItem = findSegmentItem(actual, item); + try { + assertSegmentSize(item.segmentSize(), actualSegmentItem.segmentSize()); + } catch (ValueAssertFailedException e) { + throw new SegmentSizeNotEqualsException(item.applicationCode(), item.segmentSize(), actualSegmentItem.segmentSize()); + } + SegmentAssert.assertEquals(item, actualSegmentItem); + } + + for (SegmentItem item : expected) { + if (item.segments() == null) { + continue; + } + + for (Segment segment : item.segments()) { + convertParentSegmentId(segment, expected); + + for (Span span : segment.spans()) { + if (span.refs() == null || span.refs().size() == 0) { + continue; + } + SegmentRefAssert.assertEquals(span.refs(), span.actualRefs()); + } + } + } + } + + private static void convertParentSegmentId(Segment segment, List actual) { + for (Span span : segment.spans()) { + if (span.refs() == null || span.refs().size() == 0) { + continue; + } + + for (SegmentRef ref : span.refs()) { + String actualParentSegmentId = ParentSegmentIdExpressParser.parse(ref.parentTraceSegmentId(), actual); + ref.parentTraceSegmentId(actualParentSegmentId); + } + } + } + + private static void assertSegmentSize(String expected, String actual) { + if (expected == null) { + return; + } + ExpressParser.parse(expected).assertValue("segment size", actual); + } + + private static SegmentItem findSegmentItem(List actual, SegmentItem expected) { + if (actual == null) { + throw new ActualSegmentItemEmptyException(expected); + } + + for (SegmentItem segmentItem : actual) { + if (expected.applicationCode().equals(segmentItem.applicationCode())) { + return segmentItem; + } + } + + throw new SegmentItemNotFoundException(expected.applicationCode()); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentPredictionFailedCause.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentPredictionFailedCause.java new file mode 100644 index 0000000000000000000000000000000000000000..9fa3efde816d168ef62b733329bac5bc3976c36f --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentPredictionFailedCause.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SpanAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Segment; + +public class SegmentPredictionFailedCause { + private final Segment actualSegment; + private final SpanAssertFailedException spanAssertFailedCause; + + public SegmentPredictionFailedCause(SpanAssertFailedException spanAssertFailedCause, Segment actualSegment) { + this.spanAssertFailedCause = spanAssertFailedCause; + this.actualSegment = actualSegment; + } + + public Segment getActualSegment() { + return actualSegment; + } + + public SpanAssertFailedException getSpanAssertFailedCause() { + return spanAssertFailedCause; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentRefAssert.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentRefAssert.java new file mode 100644 index 0000000000000000000000000000000000000000..b131dbdc59b7d5704a4d34765e6b582a158de90a --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentRefAssert.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SegmentRefSizeNotEqualsException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SegmentRefAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SegmentRefNotFoundException; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentRef; + +public class SegmentRefAssert { + + public static void assertEquals(List excepted, List actual) { + if (excepted == null) { + return; + } + + if (actual == null || excepted.size() != actual.size()) { + throw new SegmentRefSizeNotEqualsException(excepted.size(), actual.size()); + } + + for (SegmentRef ref : excepted) { + findSegmentRef(actual, ref); + } + } + + private static SegmentRef findSegmentRef(List actual, SegmentRef expected) { + List causes = new ArrayList<>(); + for (SegmentRef segmentRef : actual) { + try { + if (segmentRefEquals(expected, segmentRef)) { + return segmentRef; + } + } catch (SegmentRefAssertFailedException e) { + causes.add(new SegmentRefAssertFailedCause(e, segmentRef)); + } + } + throw new SegmentRefNotFoundException(expected, causes); + } + + private static boolean segmentRefEquals(SegmentRef expected, SegmentRef actual) { + try { + ExpressParser.parse(expected.entryServiceName()).assertValue("entry service name", actual.entryServiceName()); + ExpressParser.parse(expected.networkAddress()).assertValue("network address", actual.networkAddress()); + ExpressParser.parse(expected.parentTraceSegmentId()).assertValue("parent segment id", actual.parentTraceSegmentId()); + ExpressParser.parse(expected.parentSpanId()).assertValue("span id", actual.parentSpanId()); + ExpressParser.parse(expected.entryServiceId()).assertValue("entry service id", actual.entryServiceId()); + ExpressParser.parse(expected.networkAddressId()).assertValue("network address id", actual.networkAddressId()); + ExpressParser.parse(expected.parentApplicationInstanceId()).assertValue("parent application instance id", actual.parentApplicationInstanceId()); + ExpressParser.parse(expected.parentServiceId()).assertValue("parent service id", actual.parentServiceId()); + ExpressParser.parse(expected.parentServiceName()).assertValue("parent service name", actual.parentServiceName()); + ExpressParser.parse(expected.refType()).assertValue("ref type", actual.refType()); + ExpressParser.parse(expected.entryApplicationInstanceId()).assertValue("entry application instance id", actual.entryApplicationInstanceId()); + return true; + } catch (ValueAssertFailedException e) { + throw new SegmentRefAssertFailedException(e, expected, actual); + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentRefAssertFailedCause.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentRefAssertFailedCause.java new file mode 100644 index 0000000000000000000000000000000000000000..571a4c834495f1b4a03ccba32b21998ed7a94f32 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/SegmentRefAssertFailedCause.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.SegmentRefAssertFailedException; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentRef; + +public class SegmentRefAssertFailedCause { + private final SegmentRefAssertFailedException failedCause; + private final SegmentRef actual; + + public SegmentRefAssertFailedCause(SegmentRefAssertFailedException failedCause, SegmentRef actual) { + this.failedCause = failedCause; + this.actual = actual; + } + + public SegmentRefAssertFailedException getFailedCause() { + return failedCause; + } + + public SegmentRef getActual() { + return actual; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/ElementAssertor.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/ElementAssertor.java new file mode 100644 index 0000000000000000000000000000000000000000..f433effee0d20480656ff589314a42708f046b57 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/ElementAssertor.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element; + +public abstract class ElementAssertor { + + public ElementAssertor(String exceptedValue) { + if (exceptedValue != null) { + this.exceptedValue = exceptedValue.trim(); + } + } + + protected String exceptedValue; + + public abstract void assertValue(String desc, String actualValue); +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/EqualsAssertor.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/EqualsAssertor.java new file mode 100644 index 0000000000000000000000000000000000000000..3d6f1c3deb2a992a7d6ad2fa60b9727099d52d56 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/EqualsAssertor.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; + +/** + * Created by xin on 2017/7/15. + */ +public class EqualsAssertor extends ElementAssertor { + + public EqualsAssertor(String exceptedValue) { + super(exceptedValue); + } + + @Override + public void assertValue(String desc, String actualValue) { + if (!exceptedValue.equals(actualValue)) { + throw new ValueAssertFailedException(desc, exceptedValue, actualValue); + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/GreatThanAssertor.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/GreatThanAssertor.java new file mode 100644 index 0000000000000000000000000000000000000000..e7c714653713e111a7f4e1bfdfa0953a4c5ac5cd --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/GreatThanAssertor.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; + +/** + * Created by xin on 2017/7/16. + */ +public class GreatThanAssertor extends ElementAssertor { + + public GreatThanAssertor(String exceptedValue) { + super(exceptedValue); + } + + @Override + public void assertValue(String desc, String actualValue) { + if (Long.parseLong(actualValue) <= Long.parseLong(exceptedValue)) { + throw new ValueAssertFailedException(desc," gt " + exceptedValue, actualValue); + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/GreetEqualAssertor.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/GreetEqualAssertor.java new file mode 100644 index 0000000000000000000000000000000000000000..140e368da2cb9b601aa6bf82c765042449a2714f --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/GreetEqualAssertor.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; + +public class GreetEqualAssertor extends ElementAssertor { + public GreetEqualAssertor(String exceptedValue) { + super(exceptedValue); + } + + @Override public void assertValue(String desc, String actualValue) { + if (Long.parseLong(actualValue) < Long.parseLong(exceptedValue)) { + throw new ValueAssertFailedException(desc, " ge " + exceptedValue, actualValue); + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NoopAssertor.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NoopAssertor.java new file mode 100644 index 0000000000000000000000000000000000000000..7ea49b1c8c59e102d2ed721f6b10730f0581a5bd --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NoopAssertor.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element; + +/** + * Created by xin on 2017/7/15. + */ +public class NoopAssertor extends ElementAssertor { + public NoopAssertor() { + super(null); + } + + @Override + public void assertValue(String desc, String actualValue) { + + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotEqualsAssertor.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotEqualsAssertor.java new file mode 100644 index 0000000000000000000000000000000000000000..8e8144a5e98dfe00847356dfbc97749467b15358 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotEqualsAssertor.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; + +/** + * Created by xin on 2017/7/15. + */ +public class NotEqualsAssertor extends ElementAssertor { + + public NotEqualsAssertor(String exceptedValue) { + super(exceptedValue); + } + + @Override + public void assertValue(String desc, String actualValue) { + if (exceptedValue.equals(actualValue.trim())) { + throw new ValueAssertFailedException(desc, " not eq " + exceptedValue, actualValue); + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotNullAssertor.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotNullAssertor.java new file mode 100644 index 0000000000000000000000000000000000000000..2beea95b0caa6845d21d1a175a45069dda3f8542 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NotNullAssertor.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; + +/** + * Created by xin on 2017/7/15. + */ +public class NotNullAssertor extends ElementAssertor { + public NotNullAssertor() { + super(null); + } + + @Override + public void assertValue(String desc, String actualValue) { + if (actualValue == null) { + throw new ValueAssertFailedException(desc, "not null", actualValue); + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NullAssertor.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NullAssertor.java new file mode 100644 index 0000000000000000000000000000000000000000..cf3f20b2b3cb8b164c2e80f0091ddec4c7d9e806 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/element/NullAssertor.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.element; + +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException; + +/** + * Created by xin on 2017/7/18. + */ +public class NullAssertor extends ElementAssertor { + public NullAssertor() { + super(null); + } + + @Override + public void assertValue(String desc, String actualValue) { + if (actualValue != null && actualValue.length() > 0) { + throw new ValueAssertFailedException(desc, "null", actualValue); + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualRegistryOperationNameEmptyException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualRegistryOperationNameEmptyException.java new file mode 100644 index 0000000000000000000000000000000000000000..c58886a48fd69d205f69c257e53381c4598aa8b4 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualRegistryOperationNameEmptyException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.RegistryOperationName; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class ActualRegistryOperationNameEmptyException extends AssertFailedException { + + private final RegistryOperationName registryOperationName; + + public ActualRegistryOperationNameEmptyException(RegistryOperationName registryOperationName) { + this.registryOperationName = registryOperationName; + } + + @Override public String getCauseMessage() { + return String.format("ActualRegistryOperationNameEmptyException\nexpected:%s\nactual:%s\n", + registryOperationName.operationName(), "Empty"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualSegmentItemEmptyException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualSegmentItemEmptyException.java new file mode 100644 index 0000000000000000000000000000000000000000..da75a62e3239deab4dade4688d9710d51c711c00 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualSegmentItemEmptyException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentItem; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class ActualSegmentItemEmptyException extends AssertFailedException { + + private final SegmentItem expected; + + public ActualSegmentItemEmptyException(SegmentItem expected) { + this.expected = expected; + } + + @Override public String getCauseMessage() { + return String.format("ActualSegmentItemEmptyException\nexpected: %s\nactual: %s", expected, "Empty"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualSegmentRefIsEmptyException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualSegmentRefIsEmptyException.java new file mode 100644 index 0000000000000000000000000000000000000000..e6cba981ee6e28dd743af1c77e274eb3763f95f9 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ActualSegmentRefIsEmptyException.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class ActualSegmentRefIsEmptyException extends AssertFailedException { + private final int expectedSize; + + public ActualSegmentRefIsEmptyException(int expectedSize) { + this.expectedSize = expectedSize; + } + + @Override public String getCauseMessage() { + return String.format("ActualSegmentRefIsEmptyException\nexpected: %d\nactual: %s\n", expectedSize, "Not found"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/KeyValueNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/KeyValueNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..e3eb65f2cc24aa63f41fb4252a095571659e843b --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/KeyValueNotEqualsException.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +public class KeyValueNotEqualsException extends RuntimeException { +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventKeyNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventKeyNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..a56dda0026a3f4781eae04c60c831264b9cb5c76 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventKeyNotEqualsException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class LogEventKeyNotEqualsException extends AssertFailedException { + private final String expected; + private final String actual; + + public LogEventKeyNotEqualsException(String expected, String actual) { + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("[log event key]: expected=>{%s}, actual=>{%s}\n", expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..faf4905da443b70e39994fcf0e95c872e1a9fcc0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventSizeNotEqualsException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class LogEventSizeNotEqualsException extends AssertFailedException { + private final int expected; + private final int actual; + + public LogEventSizeNotEqualsException(int expected, int actual) { + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("[log event size]: expected=>{%d}, actual=>{%d}\n", expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventValueNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventValueNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..c2986090abe917da2932c77d8eed709f63304712 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogEventValueNotEqualsException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class LogEventValueNotEqualsException extends AssertFailedException { + private final String eventKey; + private final String expected; + private final String actual; + + public LogEventValueNotEqualsException(String eventKey, String expected, String actual) { + this.eventKey = eventKey; + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("[log(%s} value]: expected=>{%s}, actual=>{%s}\n", eventKey, + expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..299a72e9d5234e54c595c0a77dd532363a4df79a --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/LogSizeNotEqualsException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class LogSizeNotEqualsException extends AssertFailedException { + private final int expected; + private final int actual; + + public LogSizeNotEqualsException(int expected, int actual) { + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("[log size]: expected=>{%d}, actual=>{%d}", expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ParentSegmentNotFoundException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ParentSegmentNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..d0fd6478b9ed61ce19310a07666424692c8802ca --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ParentSegmentNotFoundException.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class ParentSegmentNotFoundException extends AssertFailedException { + + private final String express; + + public ParentSegmentNotFoundException(String express) { + this.express = express; + } + + @Override public String getCauseMessage() { + return String.format("ParentSegmentNotFoundException\nexpected: %s\nactual: %s\n", express, "NOT FOUND"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RefSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RefSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..907fc25ce5db18f59d4f21756730b478b1db58af --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RefSizeNotEqualsException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class RefSizeNotEqualsException extends AssertFailedException { + + private final int expected; + private final int actual; + + public RefSizeNotEqualsException(int expected, int actual) { + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("[segment ref size]: expected=>{%s}, actual=>{%s}", expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryApplicationNotFoundException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryApplicationNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..e7685d804d639abcfa9dede46ab99294c30306e0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryApplicationNotFoundException.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class RegistryApplicationNotFoundException extends AssertFailedException { + private final String applicationCode; + + public RegistryApplicationNotFoundException(String applicationCode) { + this.applicationCode = applicationCode; + } + + @Override public String getCauseMessage() { + return String.format("RegistryApplicationNotFoundException\nexpected: %s\nactual: %s\n", applicationCode, + "Not Found"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryApplicationSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryApplicationSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..237dbb66a938afa85fb3517861127a47072df0c0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryApplicationSizeNotEqualsException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class RegistryApplicationSizeNotEqualsException extends AssertFailedException { + private final String applicationCode; + private final ValueAssertFailedException cause; + + public RegistryApplicationSizeNotEqualsException(String applicationCode, ValueAssertFailedException cause) { + this.applicationCode = applicationCode; + this.cause = cause; + } + + @Override public String getCauseMessage() { + return String.format("RegistryApplicationSizeNotEqualsException: %s\nexpected: %s\nactual: %s\n", + applicationCode, cause.getExpected(), cause.getActual()); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryInstanceOfApplicationNotFoundException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryInstanceOfApplicationNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..e25f46b46f1fc0ff8fa8bd54de7bab69b200ec25 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryInstanceOfApplicationNotFoundException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class RegistryInstanceOfApplicationNotFoundException extends AssertFailedException { + + private final String applicationCode; + + public RegistryInstanceOfApplicationNotFoundException(String applicationCode) { + this.applicationCode = applicationCode; + } + + @Override public String getCauseMessage() { + return String.format("RegistryInstanceOfApplicationNotFoundException\nexpected: Instances of Service(%s)" + + "\nactual: %s\n", + applicationCode, "NOT FOUND"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryInstanceSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryInstanceSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..66ad38b429bebe864cae5d6e21d22ba9b32939e0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryInstanceSizeNotEqualsException.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class RegistryInstanceSizeNotEqualsException extends AssertFailedException { + + private final String applicationCode; + private final ValueAssertFailedException cause; + + public RegistryInstanceSizeNotEqualsException(String applicationCode, ValueAssertFailedException cause) { + this.applicationCode = applicationCode; + this.cause = cause; + } + + @Override public String getCauseMessage() { + return String.format("RegistryInstanceSizeNotEqualsException %s\nexpected: %s\nactual: %s\n", + applicationCode, cause.getExpected(), cause.getActual()); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryOperationNameNotFoundException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryOperationNameNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..fe5a2863a5578821fa4da3a83316bbaac952461d --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryOperationNameNotFoundException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class RegistryOperationNameNotFoundException extends AssertFailedException { + private final String applicationCode; + private final String operationName; + + public RegistryOperationNameNotFoundException(String applicationCode, String operationName) { + this.applicationCode = applicationCode; + this.operationName = operationName; + } + + @Override public String getCauseMessage() { + return String.format("RegistryOperationNameNotFoundException %s\nexpected: %s\nactual: %s\n", applicationCode + , operationName, "NOT FOUND"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryOperationNamesOfApplicationNotFoundException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryOperationNamesOfApplicationNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..31e0867a8b9583af26e5cdb06a4ca2539571cd8b --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/RegistryOperationNamesOfApplicationNotFoundException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.RegistryOperationName; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class RegistryOperationNamesOfApplicationNotFoundException extends AssertFailedException { + private final RegistryOperationName applicationCode; + + public RegistryOperationNamesOfApplicationNotFoundException(RegistryOperationName applicationCode) { + this.applicationCode = applicationCode; + } + + @Override public String getCauseMessage() { + return String.format("RegistryOperationNamesOfApplicationNotFoundException %s\nexpected: %s\nactual: %s\n", + applicationCode.applicationCode(), applicationCode.operationName(), "NOT FOUND"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentItemNotFoundException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentItemNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..6e98e2cb2158e6fca3fe190cc5b49628b6b64527 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentItemNotFoundException.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class SegmentItemNotFoundException extends AssertFailedException { + private final String applicationCode; + + public SegmentItemNotFoundException(String applicationCode) { + this.applicationCode = applicationCode; + } + + @Override public String getCauseMessage() { + return String.format("SegmentItemNotFoundException\nexpected: %s\nactual: %s", applicationCode, "Not Found"); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentNotFoundException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..ad8a52eede57533e4bb77e7f80361b5d73dfb376 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentNotFoundException.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import java.util.List; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.SegmentPredictionFailedCause; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Segment; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Span; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class SegmentNotFoundException extends AssertFailedException { + private final Segment expectedSegment; + private final List failedCauses; + + public SegmentNotFoundException(Segment expectedSegment, List failedCauses) { + this.expectedSegment = expectedSegment; + this.failedCauses = failedCauses; + } + + @Override + public String getCauseMessage() { + StringBuilder expectedMessage = new StringBuilder("\n Segment:\n"); + for (Span span : expectedSegment.spans()) { + expectedMessage.append(String.format(" - span[%s, %s] %s\n", span.parentSpanId(), span.spanId(), + span.operationName())); + } + + StringBuilder causeMessage = new StringBuilder(); + for (SegmentPredictionFailedCause cause : failedCauses) { + Segment actualSegment = cause.getActualSegment(); + Span actualSpan = cause.getSpanAssertFailedCause().getActualSpan(); + Span expectedSpan = cause.getSpanAssertFailedCause().getExceptedSpan(); + + causeMessage.append(String.format("\n Segment[%s] e\n expected:\tSpan[%s, %s] %s\n " + + "actual:" + + "\tspan[%s, %s] %s\n reason:\t%s\n", + actualSegment.segmentId(), + expectedSpan.parentSpanId(), expectedSpan.spanId(), expectedSpan.operationName(), + actualSpan.parentSpanId(), actualSpan.spanId(), actualSpan.operationName(), + cause.getSpanAssertFailedCause().getCauseMessage())); + } + + return String.format("SegmentNotFoundException:\nexpected: %s\nactual: %s\n", expectedMessage, causeMessage); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefAssertFailedException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefAssertFailedException.java new file mode 100644 index 0000000000000000000000000000000000000000..ebd8913b481da9afc3f1d2bdc1034895f558afca --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefAssertFailedException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentRef; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class SegmentRefAssertFailedException extends AssertFailedException { + private final ValueAssertFailedException e; + private final SegmentRef expected; + private final SegmentRef actual; + + public SegmentRefAssertFailedException(ValueAssertFailedException e, SegmentRef expected, SegmentRef actual) { + this.e = e; + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return e.getCauseMessage(); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefNotFoundException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefNotFoundException.java new file mode 100644 index 0000000000000000000000000000000000000000..dbc8af05e76bac17da1fcf2cbf5367f447f6e799 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefNotFoundException.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import java.util.List; +import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.SegmentRefAssertFailedCause; +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.SegmentRef; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class SegmentRefNotFoundException extends AssertFailedException { + private final SegmentRef expected; + private final List causes; + + public SegmentRefNotFoundException(SegmentRef expected, List causes) { + this.expected = expected; + this.causes = causes; + } + + @Override + public String getCauseMessage() { + + StringBuilder actualMessage = new StringBuilder(); + for (SegmentRefAssertFailedCause cause : causes) { + SegmentRef actual = cause.getActual(); + String reason = cause.getFailedCause().getCauseMessage(); + + StringBuilder actualSegmentRef = new StringBuilder(String.format("\nSegmentRef:\t%s\n", reason)); + actualSegmentRef.append(String.format(" - entryServiceName:\t\t%s\n", actual.entryServiceName())) + .append(String.format(" - networkAddress:\t\t\t%s\n", actual.networkAddress())) + .append(String.format(" - parentServiceName:\t\t%s\n", actual.parentServiceName())) + .append(String.format(" - parentSpanId:\t\t\t%s\n", actual.parentSpanId())) + .append(String.format(" - parentTraceSegmentId:\t%s\n", actual.parentTraceSegmentId())) + .append(String.format(" - refType:\t\t\t\t\t%s", actual.refType())).toString(); + + actualMessage.append(String.format("%s\n", actualSegmentRef)); + } + + return String.format("SegmentRefNotFoundException\nexpected: %s\nactual: %s\n", expected, actualMessage); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..aac4e58c27a9977bb417c16e8cde5f45b9e3af3e --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentRefSizeNotEqualsException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class SegmentRefSizeNotEqualsException extends AssertFailedException { + private final int expected; + private final int actual; + + public SegmentRefSizeNotEqualsException(int expected, int actual) { + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("SegmentRefSizeNotEqualsException\nexpected:\t%s\nactual:\t%s\n", expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..e38424d066a8e03809514e9b1aa76a4492ba9f56 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SegmentSizeNotEqualsException.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class SegmentSizeNotEqualsException extends AssertFailedException { + private final String applicationCode; + private final String expected; + private final String actual; + + public SegmentSizeNotEqualsException(String applicationCode, String expected, String actual) { + this.applicationCode = applicationCode; + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("SegmentSizeNotEqualsException:\t%s\nexpected:\t%s\nactual:\t\t%s\n", + applicationCode, + expected, + actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SpanAssertFailedException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SpanAssertFailedException.java new file mode 100644 index 0000000000000000000000000000000000000000..e5ae4374417ffb6a01f3ad9eab23907de080688c --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SpanAssertFailedException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Span; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class SpanAssertFailedException extends AssertFailedException { + private final AssertFailedException failedCause; + private final Span exceptedSpan; + private final Span actualSpan; + + public SpanAssertFailedException(AssertFailedException failedCause, Span exceptedSpan, Span actualSpan) { + this.failedCause = failedCause; + this.exceptedSpan = exceptedSpan; + this.actualSpan = actualSpan; + } + + public Span getExceptedSpan() { + return exceptedSpan; + } + + public Span getActualSpan() { + return actualSpan; + } + + @Override + public String getCauseMessage() { + return failedCause.getCauseMessage(); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SpanSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SpanSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..3e199c10c485b53b34bc8c2a67193b21caed55d6 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/SpanSizeNotEqualsException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class SpanSizeNotEqualsException extends AssertFailedException { + + private final int expected; + private final int actual; + + public SpanSizeNotEqualsException(int expected, int actual) { + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("[span size]: expected=>{%s}, actual=>{%s}\n", expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagKeyNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagKeyNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..8eef92dd13649b75faea6cebd7cac8b992795067 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagKeyNotEqualsException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class TagKeyNotEqualsException extends AssertFailedException { + private final String expected; + private final String actual; + + public TagKeyNotEqualsException(String expected, String actual) { + this.expected = expected; + this.actual = actual; + } + + @Override + public String getCauseMessage() { + return String.format("[tag key]: expected=>{%s}, actual=>{%s}\n", expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagSizeNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagSizeNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..6869ae7cb1820e0f11fc59b41b1ee08dd4ca8c3b --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagSizeNotEqualsException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class TagSizeNotEqualsException extends AssertFailedException { + private final int expected; + private final int actual; + + public TagSizeNotEqualsException(int expected, int actual) { + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("[tag size]: expected=>{%s}, actual=>{%s}\n", expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagValueNotEqualsException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagValueNotEqualsException.java new file mode 100644 index 0000000000000000000000000000000000000000..2fd9ca06f9f0f61820b388a4d983b60a5a3ed1fb --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/TagValueNotEqualsException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class TagValueNotEqualsException extends AssertFailedException { + private final String tagKey; + private final String expected; + private final String actual; + + public TagValueNotEqualsException(String tagKey, String expected, String actual) { + this.tagKey = tagKey; + this.expected = expected; + this.actual = actual; + } + + @Override public String getCauseMessage() { + return String.format("[tag(%s) value]: expected=>{}, actual=>{%s}\n", tagKey, expected, + actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ValueAssertFailedException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ValueAssertFailedException.java new file mode 100644 index 0000000000000000000000000000000000000000..a413ea9482394bdb8e30ad7e0d512cb4056f335b --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/ValueAssertFailedException.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception; + +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class ValueAssertFailedException extends AssertFailedException { + private final String desc; + private final String expected; + private final String actual; + + public ValueAssertFailedException(String desc, String expected, String actual) { + this.desc = desc; + this.expected = expected; + this.actual = actual; + } + + public String getDesc() { + return desc; + } + + public String getExpected() { + return expected; + } + + public String getActual() { + return actual; + } + + @Override public String getCauseMessage() { + return String.format("[%s]: expected=>{%s}, actual=>{%s}", desc, expected, actual); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Data.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Data.java new file mode 100644 index 0000000000000000000000000000000000000000..e19df01916353593bade835adc39dc910bbe9ff0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Data.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.List; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.IllegalDataFileException; +import org.yaml.snakeyaml.TypeDescription; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; +import org.yaml.snakeyaml.representer.Representer; + +public interface Data { + RegistryItems registryItems(); + + List segmentItems(); + + class Loader { + public static Data loadData(String fileName, File file) { + try { + return loadData(new FileInputStream(file)); + } catch (Exception e) { + throw new IllegalDataFileException(fileName); + } + } + + public static Data loadData(InputStream inputStream) { + Constructor constructor = new Constructor(DataForRead.class); + TypeDescription configDescription = new TypeDescription(DataForRead.class); + configDescription.putListPropertyType("data", DataForRead.class); + + Representer representer = new Representer(); + representer.getPropertyUtils().setSkipMissingProperties(true); + Yaml yaml = new Yaml(constructor, representer); + Data result = yaml.loadAs(inputStream, DataForRead.class); + if (result == null) { + throw new RuntimeException(); + } else{ + return result; + } + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/DataForRead.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/DataForRead.java new file mode 100644 index 0000000000000000000000000000000000000000..a72e0c09fcea4fccf90489ec43785f6dc136a39f --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/DataForRead.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.ArrayList; +import java.util.List; + +public class DataForRead implements Data { + private RegistryItemsForRead registryItems; + private List segmentItems; + + public void setRegistryItems(RegistryItemsForRead registryItems) { + this.registryItems = registryItems; + } + + public RegistryItemsForRead getRegistryItems() { + return registryItems; + } + + public List getSegmentItems() { + return segmentItems; + } + + public void setSegmentItems(List segmentItems) { + this.segmentItems = segmentItems; + } + + @Override + public RegistryItemsForRead registryItems() { + return registryItems; + } + + @Override + public List segmentItems() { + if (this.segmentItems == null) { + return null; + } + + return new ArrayList<>(this.segmentItems); + } + +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/KeyValuePair.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/KeyValuePair.java new file mode 100644 index 0000000000000000000000000000000000000000..4c110f37c95a8a9aa57414b026d8b964d98aa289 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/KeyValuePair.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +/** + * Created by xin on 2017/7/15. + */ +public interface KeyValuePair { + String key(); + + String value(); + + class Impl implements KeyValuePair { + private String key; + private String value; + + public Impl(String key, String value) { + this.key = key; + this.value = value; + } + + @Override + public String key() { + return key; + } + + @Override + public String value() { + return value; + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/LogEvent.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/LogEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..3cb32b34bd6933577c9e075266d96d7efb503818 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/LogEvent.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by xin on 2017/7/15. + */ +public interface LogEvent { + List events(); + + class Impl implements LogEvent { + private List keyValuePairs; + + Impl() { + keyValuePairs = new ArrayList<>(); + } + + void add(String key, String value) { + keyValuePairs.add(new KeyValuePair.Impl(key, value)); + } + + @Override + public List events() { + return keyValuePairs; + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryApplication.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..259afbd712c2a7734bed09de100bf5b425519db9 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryApplication.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +public interface RegistryApplication { + String applicationCode(); + + String expressValue(); + + class Impl implements RegistryApplication { + private String applicationCode; + private String express; + + Impl(String code, String express) { + this.applicationCode = code; + this.express = express; + } + + @Override + public String applicationCode() { + return applicationCode; + } + + @Override public String expressValue() { + return express; + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryInstance.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryInstance.java new file mode 100644 index 0000000000000000000000000000000000000000..d3fca2e37948772f07a13ee69fddd3897cbd0944 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryInstance.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +public interface RegistryInstance { + + String applicationCode(); + + String expressValue(); + + class Impl implements RegistryInstance { + + private final String code; + private final String express; + + Impl(String code, String express) { + this.code = code; + this.express = express; + } + + @Override public String applicationCode() { + return code; + } + + @Override public String expressValue() { + return express; + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryItems.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryItems.java new file mode 100644 index 0000000000000000000000000000000000000000..743835af042c8a5a5dfac60fef0cd6800f1afd6c --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryItems.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.List; + +public interface RegistryItems { + List applications(); + + List instances(); + + List operationNames(); +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryItemsForRead.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryItemsForRead.java new file mode 100644 index 0000000000000000000000000000000000000000..c512a4b5283cabbdb12e2378c93ca148928f9cd7 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryItemsForRead.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class RegistryItemsForRead implements RegistryItems { + private List> applications; + private List> instances; + private List>> operationNames; + + public List> getApplications() { + return applications; + } + + public void setApplications(List> applications) { + this.applications = applications; + } + + public List> getInstances() { + return instances; + } + + public void setInstances(List> instances) { + this.instances = instances; + } + + public List>> getOperationNames() { + return operationNames; + } + + public void setOperationNames( + List>> operationNames) { + this.operationNames = operationNames; + } + + @Override + public List applications() { + if (this.applications == null) { + return null; + } + + List registryApplications = new ArrayList<>(); + for (Map registryApplication : applications) { + String applicationCode = new ArrayList(registryApplication.keySet()).get(0); + String express = String.valueOf(registryApplication.get(applicationCode)); + registryApplications.add(new RegistryApplication.Impl(applicationCode, express)); + } + return registryApplications; + } + + @Override + public List instances() { + if (this.instances == null) { + return null; + } + + List registryInstances = new ArrayList<>(); + instances.forEach((registryInstance) -> { + String applicationCode = new ArrayList(registryInstance.keySet()).get(0); + String express = String.valueOf(registryInstance.get(applicationCode)); + registryInstances.add(new RegistryInstance.Impl(applicationCode, express)); + }); + return registryInstances; + } + + @Override + public List operationNames() { + if (this.operationNames == null) { + return null; + } + + List registryOperationNames = new ArrayList<>(); + operationNames.forEach((registryInstance) -> { + String applicationCode = new ArrayList(registryInstance.keySet()).get(0); + List express = registryInstance.get(applicationCode); + registryOperationNames.add(new RegistryOperationName.Impl(applicationCode, express)); + }); + return registryOperationNames; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryOperationName.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryOperationName.java new file mode 100644 index 0000000000000000000000000000000000000000..930f7d9d32523e4e59ebc513a52b6ce10db552e0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/RegistryOperationName.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.List; + +public interface RegistryOperationName { + String applicationCode(); + + List operationName(); + + class Impl implements RegistryOperationName { + private final String code; + private final List express; + + Impl(String code, List express) { + this.code = code; + this.express = express; + } + + @Override public String applicationCode() { + return code; + } + + @Override public List operationName() { + return express; + } + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Segment.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Segment.java new file mode 100644 index 0000000000000000000000000000000000000000..5a36c0f0d826132cf3f13c0bf35e0e1b6b86bd5d --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Segment.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.List; + +public interface Segment { + String segmentId(); + + List spans(); + + void setSegmentId(String segmentId); +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentForRead.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentForRead.java new file mode 100644 index 0000000000000000000000000000000000000000..1a5dab692639ae1d37dbc590a7ff4cf6cbb66496 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentForRead.java @@ -0,0 +1,385 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class SegmentForRead implements Segment { + private String segmentId; + private List spans; + + @Override + public String segmentId() { + return segmentId; + } + + @Override public List spans() { + if (spans == null) { + return null; + } + return new ArrayList<>(spans); + } + + public static class SegmentRefForRead implements SegmentRef { + private String parentEndpointId; + private String parentEndpoint; + private String networkAddressId; + private String entryEndpointId; + private String refType; + private String parentSpanId; + private String parentTraceSegmentId; + private String parentServiceInstanceId; + private String networkAddress; + private String entryEndpoint; + private String entryServiceInstanceId; + + public SegmentRefForRead() { + } + + public SegmentRefForRead(Map ref) { + this.networkAddress = ref.get("networkAddress").toString(); + this.entryEndpoint = ref.get("entryEndpoint").toString(); + this.parentEndpoint = ref.get("parentEndpoint").toString(); + this.parentTraceSegmentId = ref.get("parentTraceSegmentId").toString(); + this.entryServiceInstanceId = ref.get("entryServiceInstanceId").toString(); + this.refType = ref.get("refType") == null ? null : ref.get("refType").toString(); + this.parentSpanId = ref.get("parentSpanId") == null ? null : ref.get("parentSpanId").toString(); + this.entryEndpointId = ref.get("entryEndpointId") == null ? null : ref.get("entryEndpointId").toString(); + this.parentEndpointId = ref.get("parentEndpointId") == null ? null : ref.get("parentEndpointId").toString(); + this.networkAddressId = ref.get("networkAddressId") == null ? null : ref.get("networkAddressId").toString(); + this.parentServiceInstanceId = ref.get("parentServiceInstanceId") == null ? null : ref.get("parentServiceInstanceId").toString(); + } + + public void setParentEndpointId(String parentEndpointId) { + this.parentEndpointId = parentEndpointId; + } + + public void setParentEndpoint(String parentEndpoint) { + this.parentEndpoint = parentEndpoint; + } + + public void setNetworkAddressId(String networkAddressId) { + this.networkAddressId = networkAddressId; + } + + public void setEntryEndpointId(String entryEndpointId) { + this.entryEndpointId = entryEndpointId; + } + + public void setRefType(String refType) { + this.refType = refType; + } + + public void setParentSpanId(String parentSpanId) { + this.parentSpanId = parentSpanId; + } + + public void setParentTraceSegmentId(String parentTraceSegmentId) { + this.parentTraceSegmentId = parentTraceSegmentId; + } + + public void setParentServiceInstanceId(String parentServiceInstanceId) { + this.parentServiceInstanceId = parentServiceInstanceId; + } + + public void setNetworkAddress(String networkAddress) { + this.networkAddress = networkAddress; + } + + public void setEntryEndpoint(String entryEndpoint) { + this.entryEndpoint = entryEndpoint; + } + + public void setEntryServiceInstanceId(String entryServiceInstanceId) { + this.entryServiceInstanceId = entryServiceInstanceId; + } + + @Override public String parentServiceId() { + return parentEndpointId; + } + + @Override public String parentServiceName() { + return parentEndpoint; + } + + @Override public String networkAddressId() { + return networkAddressId; + } + + @Override public String entryServiceId() { + return entryEndpointId; + } + + @Override public String refType() { + return refType; + } + + @Override public String parentSpanId() { + return parentSpanId; + } + + @Override public String parentTraceSegmentId() { + return parentTraceSegmentId; + } + + @Override public String parentApplicationInstanceId() { + return parentServiceInstanceId; + } + + @Override public String networkAddress() { + return networkAddress; + } + + @Override public String entryServiceName() { + return entryEndpoint; + } + + @Override public void parentTraceSegmentId(String parentTraceSegmentId) { + this.parentTraceSegmentId = parentTraceSegmentId; + } + + @Override public String entryApplicationInstanceId() { + return entryServiceInstanceId; + } + + @Override public String toString() { + StringBuilder actualSegmentRef = new StringBuilder("\nSegmentRef:\n"); + return actualSegmentRef.append(String.format(" - entryServiceName:\t\t%s\n", entryServiceName())) + .append(String.format(" - networkAddress:\t\t\t%s\n", networkAddress())) + .append(String.format(" - parentServiceName:\t\t%s\n", parentServiceName())) + .append(String.format(" - parentSpanId:\t\t\t%s\n", parentSpanId())) + .append(String.format(" - parentTraceSegmentId:\t%s\n", parentTraceSegmentId())) + .append(String.format(" - refType:\t\t\t\t\t%s", refType())).toString(); + } + } + + public static class SpanForRead implements Span { + private String operationName; + private String operationId; + private String parentSpanId; + private String spanId; + private String spanLayer; + private List> tags; + private List>>> logs; + private List> refs; + private List formatedRefs; + private List actualRefs; + private String startTime; + private String endTime; + private String componentId; + private String componentName; + private boolean isError; + private String spanType; + private String peer; + private String peerId; + + public void setOperationName(String operationName) { + this.operationName = operationName; + } + + public void setOperationId(String operationId) { + this.operationId = operationId; + } + + public void setParentSpanId(String parentSpanId) { + this.parentSpanId = parentSpanId; + } + + public void setSpanId(String spanId) { + this.spanId = spanId; + } + + public void setSpanLayer(String spanLayer) { + this.spanLayer = spanLayer; + } + + public void setTags(List> tags) { + this.tags = tags; + } + + public void setLogs(List>>> logs) { + this.logs = logs; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public void setComponentId(String componentId) { + this.componentId = componentId; + } + + public void setComponentName(String componentName) { + this.componentName = componentName; + } + + public void setError(boolean error) { + isError = error; + } + + public void setSpanType(String spanType) { + this.spanType = spanType; + } + + public void setPeer(String peer) { + this.peer = peer; + } + + public void setPeerId(String peerId) { + this.peerId = peerId; + } + + public void setRefs( + List> refs) { + this.refs = refs; + } + + @Override public String operationName() { + return operationName; + } + + @Override public String operationId() { + return operationId; + } + + @Override public String parentSpanId() { + return parentSpanId; + } + + @Override public String spanId() { + return spanId; + } + + @Override public String spanLayer() { + return spanLayer; + } + + @Override public List tags() { + if (tags == null) { + return new ArrayList<>(); + } + List result = new ArrayList<>(); + for (Map tag : tags) { + result.add(new KeyValuePair.Impl(tag.get("key"), tag.get("value"))); + } + return result; + } + + @Override public List logs() { + if (logs == null) { + return new ArrayList<>(); + } + List result = new ArrayList<>(); + for (Map>> log : logs) { + List> events = log.get("logEvent"); + LogEvent.Impl logEvent = new LogEvent.Impl(); + for (Map event : events) { + logEvent.add(event.get("key"), event.get("value")); + } + result.add(logEvent); + } + + return result; + } + + @Override public String startTime() { + return startTime; + } + + @Override public String endTime() { + return endTime; + } + + @Override public String componentId() { + return componentId; + } + + @Override public String componentName() { + return componentName; + } + + @Override public boolean error() { + return isError; + } + + @Override public String spanType() { + return spanType; + } + + @Override public String peer() { + return peer; + } + + @Override public String peerId() { + return peerId; + } + + @Override public List refs() { + if (formatedRefs == null && refs != null) { + List segmentRefs = new ArrayList<>(); + for (Map ref : refs) { + segmentRefs.add(new SegmentRefForRead(ref)); + } + + this.formatedRefs = segmentRefs; + } + return formatedRefs; + } + + @Override public void setActualRefs(List refs) { + this.actualRefs = refs; + } + + @Override public List actualRefs() { + return actualRefs; + } + } + + public static class LogEventForRead { + private List> logEvent; + + public List> getLogEvent() { + return logEvent; + } + + public void setLogEvent(List> logEvent) { + this.logEvent = logEvent; + } + } + + public String getSegmentId() { + return segmentId; + } + + public List getSpans() { + return spans; + } + + @Override public void setSegmentId(String segmentId) { + this.segmentId = segmentId; + } + + public void setSpans(List spans) { + this.spans = spans; + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentItem.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentItem.java new file mode 100644 index 0000000000000000000000000000000000000000..99490dcd01c8515bdbabe1a6299690ff8e3bf006 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentItem.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.List; + +/** + * Created by xin on 2017/7/15. + */ +public interface SegmentItem { + String applicationCode(); + + String segmentSize(); + + List segments(); +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentItemForRead.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentItemForRead.java new file mode 100644 index 0000000000000000000000000000000000000000..63c208288087bc645aa8d5fdf35ba20c47bdf095 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentItemForRead.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.ArrayList; +import java.util.List; + +public class SegmentItemForRead implements SegmentItem { + private String applicationCode; + private String segmentSize; + private List segments; + + public List getSegments() { + return segments; + } + + public void setSegments(List segments) { + this.segments = segments; + } + + public String getApplicationCode() { + return applicationCode; + } + + public void setApplicationCode(String applicationCode) { + this.applicationCode = applicationCode; + } + + public String getSegmentSize() { + return segmentSize; + } + + public void setSegmentSize(String segmentSize) { + this.segmentSize = segmentSize; + } + + @Override + public String applicationCode() { + return applicationCode; + } + + @Override + public String segmentSize() { + return segmentSize; + } + + @Override + public List segments() { + if (segments == null) { + return null; + } + return new ArrayList<>(segments); + } + + @Override public String toString() { + StringBuilder message = new StringBuilder(String.format("\nSegment Item[%s]", applicationCode)); + message.append(String.format(" - segment size:\t\t%s\n", segmentSize)); + return message.toString(); + } +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentRef.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentRef.java new file mode 100644 index 0000000000000000000000000000000000000000..58e6a8d6424fe76f06d00d1de8fc662925a713ac --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/SegmentRef.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +/** + * Created by xin on 2017/7/15. + */ +public interface SegmentRef { + + String parentServiceId(); + + String parentServiceName(); + + String networkAddressId(); + + String entryServiceId(); + + String refType(); + + String parentSpanId(); + + String parentTraceSegmentId(); + + String parentApplicationInstanceId(); + + String networkAddress(); + + String entryServiceName(); + + void parentTraceSegmentId(String parentTraceSegmentId); + + String entryApplicationInstanceId(); +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Span.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Span.java new file mode 100644 index 0000000000000000000000000000000000000000..b175967514c2d005889a15a29e7b7d3d7e3a17c0 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Span.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.skywalking.plugin.test.agent.tool.validator.entity; + +import java.util.List; + +public interface Span { + String operationName(); + + String operationId(); + + String parentSpanId(); + + String spanId(); + + String spanLayer(); + + List tags(); + + List logs(); + + String startTime(); + + String endTime(); + + String componentId(); + + String componentName(); + + boolean error(); + + String spanType(); + + String peer(); + + String peerId(); + + List refs(); + + void setActualRefs(List refs); + + List actualRefs(); +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/exception/AssertFailedException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/exception/AssertFailedException.java new file mode 100644 index 0000000000000000000000000000000000000000..506628c873973dd35ecb3ff996d68a10b63957c1 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/exception/AssertFailedException.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.exception; + +/** + * Created by xin on 2017/7/15. + */ +public abstract class AssertFailedException extends RuntimeException { + protected AssertFailedException(String message) { + super(message); + } + + protected AssertFailedException(){ + } + + public abstract String getCauseMessage(); +} diff --git a/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/exception/IllegalDataFileException.java b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/exception/IllegalDataFileException.java new file mode 100644 index 0000000000000000000000000000000000000000..a80fa67e8634031ef87cc3448f80fb9d67ffbf87 --- /dev/null +++ b/test/plugin/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/exception/IllegalDataFileException.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.exception; + +public class IllegalDataFileException extends AssertFailedException { + private final String fileName; + + public IllegalDataFileException(String fileName) { + this.fileName = fileName; + } + + @Override + public String getCauseMessage() { + return String.format("IllegalDataFileException %s ", fileName); + } +} diff --git a/test/plugin/validator/src/main/resources/log4j2.xml b/test/plugin/validator/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..bcce5194075d092647b3f466826f47ef950c9b80 --- /dev/null +++ b/test/plugin/validator/src/main/resources/log4j2.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/validator/src/main/resources/template/main-report.md.ftl b/test/plugin/validator/src/main/resources/template/main-report.md.ftl new file mode 100644 index 0000000000000000000000000000000000000000..149e1cc294e9bd36d123e00671c3c5aa98a142ff --- /dev/null +++ b/test/plugin/validator/src/main/resources/template/main-report.md.ftl @@ -0,0 +1,43 @@ +# 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. + +# Test Report - ${testReport.testDate} + +- tests : **${testReport.successCaseCount} passed**. **${testReport.totalCaseCount - testReport.successCaseCount} failed** +- branch name : **[${testReport.testBranch}](https://github.com/apache/incubator-skywalking/tree/${testReport.testBranch})** +- commit id : **[${testReport.commitId}](https://github.com/apache/incubator-skywalking/commit/${testReport.commitId})** +- cases branch: **[${testReport.caseBranch}](https://github.com/SkywalkingTest/skywalking-autotest-scenarios/tree/${testReport.caseBranch})** +- cases commit id: **[${testReport.caseCommit}](https://github.com/SkywalkingTest/skywalking-autotest-scenarios/commit/${testReport.caseCommit})** + +## Cases List + +| Case description | Status | Cases| +|:-----|:-----:|:-----:| +<#list testReport.frameworkCases as frameworkCases> +|${frameworkCases.testFramework}| **${frameworkCases.successCaseCount} passed. ${frameworkCases.totalCaseCount - frameworkCases.successCaseCount} failed**| [click me](#${frameworkCases.testFramework?lower_case}) | + + +<#list testReport.frameworkCases as frameworkCases> +## ${frameworkCases.testFramework} + +### <#list frameworkCases.caseByVersionCategories as versionCategory> +| Version | Passed | Failed| +|:------------- |:-------:|:-----:| +<#list versionCategory.testCases as item> +| ${item.caseName} | <#if item.success>:heavy_check_mark:|<#if !item.success>:heavy_check_mark:| + + + + diff --git a/test/plugin/validator/src/test/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssertTest.java b/test/plugin/validator/src/test/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssertTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c32220ad170195320e4b52df95858a75fcb9c0bf --- /dev/null +++ b/test/plugin/validator/src/test/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/DataAssertTest.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.skywalking.plugin.test.agent.tool.validator.assertor; + +import java.io.File; + +import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Data; +import org.junit.Test; +import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException; + +public class DataAssertTest { + + @Test + public void testAssertFunction() { + try { + File actualData = new File(DataAssertTest.class.getResource("/actualData.yaml").getFile()); + File expectedData = new File(DataAssertTest.class.getResource("/expectedData.yaml").getFile()); + + DataAssert.assertEquals(Data.Loader.loadData("expectedData.yaml", expectedData), Data.Loader.loadData("actualData.yaml", actualData)); + } catch (AssertFailedException e) { + System.out.println(String.format("\nassert failed.\n%s\n", e.getCauseMessage())); + + } + } + +} \ No newline at end of file diff --git a/test/plugin/validator/src/test/resources/actualData.yaml b/test/plugin/validator/src/test/resources/actualData.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7eaa18e68fe5b20548a35326c935a4801d74c903 --- /dev/null +++ b/test/plugin/validator/src/test/resources/actualData.yaml @@ -0,0 +1,295 @@ +# 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. +{ + "registryItems": { + "applications": [ + { + "vertx-core-3.x-scenario": 2 + } + ], + "instances": [ + { + "vertx-core-3.x-scenario": 1 + } + ], + "operationNames": [ + { + "vertx-core-3.x-scenario": [ + "/vertx-core-3-scenario/vertx-core/core-case", + "/vertx-core-3-scenario/vertx-core/executeTest", + "cluster-message-receiver" + ] + } + ] + }, + "segmentItems": [ + { + "applicationCode": "vertx-core-3.x-scenario", + "segmentSize": "8", + "segments": [ + { + "segmentId": "1.159.15542729582940000", + "spans": [ + { + "operationName": "#local-message-receiver", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "RPCFramework", + "refs": [ + { + "parentEndpointId": 0, + "parentEndpoint": "local-message-receiver", + "networkAddressId": 0, + "entryEndpointId": 0, + "refType": "CrossThread", + "parentSpanId": 0, + "parentTraceSegmentId": "1.158.15542729582900006", + "parentServiceInstanceId": 1, + "networkAddress": "", + "entryEndpoint": "local-message-receiver", + "entryServiceInstanceId": 1 + } + ], + "startTime": "1554272958294", + "endTime": "1554272958294", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Local", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "1.158.15542729582900006", + "spans": [ + { + "operationName": "local-message-receiver", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "RPCFramework", + "startTime": "1554272958290", + "endTime": "1554272958305", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Local", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "1.158.15542729581640000", + "spans": [ + { + "operationName": "/vertx-core-3-scenario/vertx-core/executeTest", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "Http", + "tags": [ + { + "key": "http.method", + "value": "GET" + }, + { + "key": "url", + "value": "http://localhost:8080/vertx-core-3-scenario/vertx-core/executeTest" + } + ], + "startTime": "1554272958168", + "endTime": "1554272958339", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Exit", + "peer": "/vertx-core-3-scenario/vertx-core/executeTest", + "peerId": "0" + } + ] + }, + { + "segmentId": "1.158.15542729581890002", + "spans": [ + { + "operationName": "/vertx-core-3-scenario/vertx-core/core-case", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "Http", + "tags": [ + { + "key": "http.method", + "value": "GET" + }, + { + "key": "url", + "value": "http://localhost:18080/vertx-core-3-scenario/vertx-core/core-case" + } + ], + "startTime": "1554272958190", + "endTime": "1554272958340", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Entry", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "1.81.15542729583180000", + "spans": [ + { + "operationName": "cluster-message-receiver", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "RPCFramework", + "refs": [ + { + "parentEndpointId": 0, + "parentEndpoint": "cluster-message-receiver", + "networkAddressId": 0, + "entryEndpointId": 0, + "refType": "CrossProcess", + "parentSpanId": 0, + "parentTraceSegmentId": "1.158.15542729582940008", + "parentServiceInstanceId": 1, + "networkAddress": "localhost:45171", + "entryEndpoint": "cluster-message-receiver", + "entryServiceInstanceId": 1 + } + ], + "startTime": "1554272958318", + "endTime": "1554272958320", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Entry", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "1.158.15542729583390010", + "spans": [ + { + "operationName": "#/vertx-core-3-scenario/vertx-core/executeTest", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "Http", + "refs": [ + { + "parentEndpointId": 0, + "parentEndpoint": "/vertx-core-3-scenario/vertx-core/executeTest", + "networkAddressId": 0, + "entryEndpointId": 0, + "refType": "CrossThread", + "parentSpanId": 0, + "parentTraceSegmentId": "1.158.15542729581640000", + "parentServiceInstanceId": 1, + "networkAddress": "", + "entryEndpoint": "/vertx-core-3-scenario/vertx-core/executeTest", + "entryServiceInstanceId": 1 + } + ], + "startTime": "1554272958339", + "endTime": "1554272958340", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Local", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "1.158.15542729582940008", + "spans": [ + { + "operationName": "cluster-message-receiver", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "RPCFramework", + "startTime": "1554272958294", + "endTime": "1554272958324", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Exit", + "peer": "localhost:45171", + "peerId": "0" + } + ] + }, + { + "segmentId": "1.158.15542729582860004", + "spans": [ + { + "operationName": "/vertx-core-3-scenario/vertx-core/executeTest", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "Http", + "tags": [ + { + "key": "http.method", + "value": "GET" + }, + { + "key": "url", + "value": "http://localhost:8080/vertx-core-3-scenario/vertx-core/executeTest" + } + ], + "refs": [ + { + "parentEndpointId": 0, + "parentEndpoint": "/vertx-core-3-scenario/vertx-core/executeTest", + "networkAddressId": 0, + "entryEndpointId": 0, + "refType": "CrossProcess", + "parentSpanId": 0, + "parentTraceSegmentId": "1.158.15542729581640000", + "parentServiceInstanceId": 1, + "networkAddress": "/vertx-core-3-scenario/vertx-core/executeTest", + "entryEndpoint": "/vertx-core-3-scenario/vertx-core/executeTest", + "entryServiceInstanceId": 1 + } + ], + "startTime": "1554272958286", + "endTime": "1554272958325", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Entry", + "peer": "", + "peerId": "0" + } + ] + } + ] + } + ] +} diff --git a/test/plugin/validator/src/test/resources/expectedData.yaml b/test/plugin/validator/src/test/resources/expectedData.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f3bdefdd5cd17f1b6bfe003997a8bc3f125dd5ea --- /dev/null +++ b/test/plugin/validator/src/test/resources/expectedData.yaml @@ -0,0 +1,292 @@ +# 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. +{ + "registryItems": { + "applications": [ + { + "vertx-core-3.x-scenario": 2 + } + ], + "instances": [ + { + "vertx-core-3.x-scenario": 1 + } + ], + "operationNames": [ + { + "vertx-core-3.x-scenario": [ + "/vertx-core-3-scenario/vertx-core/executeTest", + "/vertx-core-3-scenario/vertx-core/core-case", + "cluster-message-receiver" + ] + } + ] + }, + "segmentItems": [ + { + "applicationCode": "vertx-core-3.x-scenario", + "segmentSize": "8", + "segments": [ + { + "segmentId": "nq 0", + "spans": [ + { + "operationName": "#local-message-receiver", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "RPCFramework", + "refs": [ + { + "parentEndpointId": 0, + "parentEndpoint": "local-message-receiver", + "networkAddressId": 0, + "entryEndpointId": 0, + "refType": "CrossThread", + "parentSpanId": 0, + "parentTraceSegmentId": "not null", + "parentServiceInstanceId": 1, + "networkAddress": "", + "entryEndpoint": "local-message-receiver", + "entryServiceInstanceId": 1 + } + ], + "startTime": "nq 0", + "endTime": "nq 0", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Local", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "nq 0", + "spans": [ + { + "operationName": "local-message-receiver", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "RPCFramework", + "startTime": "nq 0", + "endTime": "nq 0", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Local", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "nq 0", + "spans": [ + { + "operationName": "/vertx-core-3-scenario/vertx-core/executeTest", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "Http", + "tags": [ + { + "key": "http.method", + "value": "GET" + }, + { + "key": "url", + "value": "http://localhost:8080/vertx-core-3-scenario/vertx-core/executeTest" + } + ], + "startTime": "nq 0", + "endTime": "nq 0", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Exit", + "peer": "/vertx-core-3-scenario/vertx-core/executeTest", + "peerId": "0" + } + ] + }, + { + "segmentId": "nq 0", + "spans": [ + { + "operationName": "/vertx-core-3-scenario/vertx-core/core-case", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "Http", + "tags": [ + { + "key": "http.method", + "value": "GET" + }, + { + "key": "url", + "value": "http://localhost:18080/vertx-core-3-scenario/vertx-core/core-case" + } + ], + "startTime": "nq 0", + "endTime": "nq 0", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Entry", + "peerId": "0" + } + ] + }, + { + "segmentId": "nq 0", + "spans": [ + { + "operationName": "cluster-message-receiver", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "RPCFramework", + "refs": [ + { + "parentEndpointId": 0, + "parentEndpoint": "cluster-message-receiver", + "networkAddressId": 0, + "entryEndpointId": 0, + "refType": "CrossProcess", + "parentSpanId": 0, + "parentTraceSegmentId": "not null", + "parentServiceInstanceId": 1, + "networkAddress": "not null", + "entryEndpoint": "cluster-message-receiver", + "entryServiceInstanceId": 1 + } + ], + "startTime": "nq 0", + "endTime": "nq 0", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Entry", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "nq 0", + "spans": [ + { + "operationName": "#/vertx-core-3-scenario/vertx-core/executeTest", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "Http", + "refs": [ + { + "parentEndpointId": 0, + "parentEndpoint": "/vertx-core-3-scenario/vertx-core/executeTest", + "networkAddressId": 0, + "entryEndpointId": 0, + "refType": "CrossThread", + "parentSpanId": 0, + "parentTraceSegmentId": "not null", + "parentServiceInstanceId": 1, + "networkAddress": "", + "entryEndpoint": "/vertx-core-3-scenario/vertx-core/executeTest", + "entryServiceInstanceId": 1 + } + ], + "startTime": "nq 0", + "endTime": "nq 0", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Local", + "peer": "", + "peerId": "0" + } + ] + }, + { + "segmentId": "nq 0", + "spans": [ + { + "operationName": "cluster-message-receiver", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "RPCFramework", + "startTime": "nq 0", + "endTime": "nq 0", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Exit", + "peerId": "0" + } + ] + }, + { + "segmentId": "nq 0", + "spans": [ + { + "operationName": "/vertx-core-3-scenario/vertx-core/executeTest", + "operationId": "0", + "parentSpanId": "-1", + "spanId": "0", + "spanLayer": "Http", + "tags": [ + { + "key": "http.method", + "value": "GET" + }, + { + "key": "url", + "value": "http://localhost:8080/vertx-core-3-scenario/vertx-core/executeTest" + } + ], + "refs": [ + { + "parentEndpointId": 0, + "parentEndpoint": "/vertx-core-3-scenario/vertx-core/executeTest", + "networkAddressId": 0, + "entryEndpointId": 0, + "refType": "CrossProcess", + "parentSpanId": 0, + "parentTraceSegmentId": "not null", + "parentServiceInstanceId": 1, + "networkAddress": "/vertx-core-3-scenario/vertx-core/executeTest", + "entryEndpoint": "/vertx-core-3-scenario/vertx-core/executeTest", + "entryServiceInstanceId": 1 + } + ], + "startTime": "nq 0", + "endTime": "nq 0", + "componentId": "59", + "componentName": "", + "isError": false, + "spanType": "Entry", + "peerId": "0" + } + ] + } + ] + } + ] +}