From 23bc69cd48e4fea34ad65bb5154960734c969f27 Mon Sep 17 00:00:00 2001 From: Daming Date: Fri, 8 Nov 2019 14:48:40 +0800 Subject: [PATCH] Provide archetypes for plugin testcase (#3802) * provide archetypes for testcase --- docs/en/guides/Plugin-test.md | 10 ++ test/plugin/archetypes/jvm/pom.xml | 41 +++++++ .../META-INF/maven/archetype-metadata.xml | 65 ++++++++++ .../archetype-resources/bin/startup.sh | 21 ++++ .../config/expectedData.yaml | 27 +++++ .../archetype-resources/configuration.yml | 23 ++++ .../resources/archetype-resources/pom.xml | 83 +++++++++++++ .../src/main/assembly/assembly.xml | 41 +++++++ .../src/main/java/Application.java | 35 ++++++ .../main/java/controller/CaseController.java | 49 ++++++++ .../src/main/resources/application.properties | 21 ++++ .../src/main/resources/log4j2.xml | 30 +++++ .../archetype-resources/support-version.list | 17 +++ test/plugin/archetypes/pom.xml | 38 ++++++ test/plugin/archetypes/tomcat/pom.xml | 41 +++++++ .../META-INF/maven/archetype-metadata.xml | 64 ++++++++++ .../config/expectedData.yaml | 27 +++++ .../archetype-resources/configuration.yml | 22 ++++ .../resources/archetype-resources/pom.xml | 68 +++++++++++ .../src/main/java/CaseServlet.java | 43 +++++++ .../src/main/java/HealthCheckServlet.java | 40 +++++++ .../src/main/resources/log4j2.xml | 30 +++++ .../src/main/webapp/WEB-INF/web.xml | 44 +++++++ .../archetype-resources/support-version.list | 17 +++ test/plugin/generator.sh | 111 ++++++++++++++++++ 25 files changed, 1008 insertions(+) create mode 100644 test/plugin/archetypes/jvm/pom.xml create mode 100644 test/plugin/archetypes/jvm/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/bin/startup.sh create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/config/expectedData.yaml create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/configuration.yml create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/pom.xml create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/assembly/assembly.xml create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/java/Application.java create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/java/controller/CaseController.java create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/resources/application.properties create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/resources/log4j2.xml create mode 100644 test/plugin/archetypes/jvm/src/main/resources/archetype-resources/support-version.list create mode 100644 test/plugin/archetypes/pom.xml create mode 100644 test/plugin/archetypes/tomcat/pom.xml create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/config/expectedData.yaml create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/configuration.yml create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/pom.xml create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/java/CaseServlet.java create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/java/HealthCheckServlet.java create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/resources/log4j2.xml create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml create mode 100644 test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/support-version.list create mode 100644 test/plugin/generator.sh diff --git a/docs/en/guides/Plugin-test.md b/docs/en/guides/Plugin-test.md index 412ba9ae3..0a5b6b894 100644 --- a/docs/en/guides/Plugin-test.md +++ b/docs/en/guides/Plugin-test.md @@ -359,6 +359,16 @@ java -jar ${agent_opts} "-Dskywalking.agent.service_name=jettyclient-scenario" ## Best Practices + +### How To Use The Archetype To Create A Test Case Project +We provided archetypes and a script to make creating a project easier. It creates a completed project of a test case. So that we only need to focus on cases. +First, we can use followed command to get usage about the script. + +`bash ${SKYWALKING_HOME}/test/plugin/generator.sh -h` + +Then, runs and generates a project, named by `scenario_name`, in `./scenarios`. + + ### Recommendations for pom ```xml diff --git a/test/plugin/archetypes/jvm/pom.xml b/test/plugin/archetypes/jvm/pom.xml new file mode 100644 index 000000000..628fe3c8a --- /dev/null +++ b/test/plugin/archetypes/jvm/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.apache.skywalking.plugin + archetypes + 1.0.0 + + + jvm + + + + + org.apache.maven.archetype + archetype-packaging + 3.1.1 + + + + diff --git a/test/plugin/archetypes/jvm/src/main/resources/META-INF/maven/archetype-metadata.xml b/test/plugin/archetypes/jvm/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..8641ffbe2 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,65 @@ + + + + + + + org.apache.skywalking.apm.testcase + + + ${scenario_name} + + + 1.0.0 + + + org.apache.skywalking.apm.testcase.${scenario_name} + + + + + ${scenario_name} + + + + + + + + configuration.yml + support-version.list + bin/startup.sh + + + + config + + + src/main/java + + + src/main/resources + + + \ No newline at end of file diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/bin/startup.sh b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/bin/startup.sh new file mode 100644 index 000000000..94904d813 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/bin/startup.sh @@ -0,0 +1,21 @@ +#!/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)" + +java -jar ${agent_opts} ${home}/../libs${scenario_name}.jar & \ No newline at end of file diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/config/expectedData.yaml b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/config/expectedData.yaml new file mode 100644 index 000000000..d6474510c --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/config/expectedData.yaml @@ -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. +registryItems: + applications: + - {${scenario_name}: 2} + instances: + - {${scenario_name}: 1} + operationNames: + - canal-scenario: [] + heartbeat: [] +segmentItems: + - applicationCode: ${scenario_name} + segmentSize: + segments: diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/configuration.yml b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/configuration.yml new file mode 100644 index 000000000..38559c636 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/configuration.yml @@ -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. + +type: jvm +entryService: http://localhost:8080/${scenario_name}/case/${scenario_case} +healthCheck: http://localhost:8080/${scenario_name}/case/healthCheck +startScript: ./bin/startup.sh +framework: ${scenario_name} +environment: +dependencies: \ No newline at end of file diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/pom.xml b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..1bf9d5b68 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,83 @@ + + + + + org.apache.skywalking.apm.testcase + ${artifactId} + 1.0.0 + + + 4.0.0 + + ${scenario_name} + + 4.3.8.RELEASE + 1.5.2.RELEASE + + + + + org.springframework.boot + spring-boot-starter + ${spring-boot-version} + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + ${spring-boot-version} + + + org.springframework.boot + spring-boot-starter-tomcat + ${spring-boot-version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot-version} + + + + + ${scenario_name} + + + org.springframework.boot + spring-boot-maven-plugin + 1.5.9.RELEASE + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/assembly/assembly.xml b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/assembly/assembly.xml new file mode 100644 index 000000000..5431e8248 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/${scenario_name}.jar + ./libs + 0775 + + + diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/java/Application.java b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/java/Application.java new file mode 100644 index 000000000..3e144e961 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/java/Application.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 $package; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + try { + SpringApplication.run(Application.class, args); + } catch (Exception e) { + // Never do this + } + } +} diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/java/controller/CaseController.java b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/java/controller/CaseController.java new file mode 100644 index 000000000..e5e6e228a --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/java/controller/CaseController.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 $package; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/case") +@PropertySource("classpath:application.properties") +public class CaseController { + private static final Logger logger = LogManager.getLogger(CaseController.class); + private static final String SUCCESS = "Success"; + + @RequestMapping("/${scenario_case}") + @ResponseBody + public String testcase() { + // your codes + return SUCCESS; + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() { + // your codes + return SUCCESS; + } + +} diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/resources/application.properties b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/resources/application.properties new file mode 100644 index 000000000..6debe4824 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/resources/application.properties @@ -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. +# +# + +server.port=8080 +server.contextPath=/${scenario_name} +logging.config=classpath:log4j2.xml \ No newline at end of file diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/resources/log4j2.xml b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/resources/log4j2.xml new file mode 100644 index 000000000..b5cda5ae8 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + diff --git a/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/support-version.list b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/support-version.list new file mode 100644 index 000000000..085c4d8e0 --- /dev/null +++ b/test/plugin/archetypes/jvm/src/main/resources/archetype-resources/support-version.list @@ -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 +# "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. + +# lists your version here \ No newline at end of file diff --git a/test/plugin/archetypes/pom.xml b/test/plugin/archetypes/pom.xml new file mode 100644 index 000000000..f0a7aac6a --- /dev/null +++ b/test/plugin/archetypes/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + pom + + org.apache.skywalking.plugin + archetypes + 1.0.0 + + + tomcat + jvm + + + + true + + diff --git a/test/plugin/archetypes/tomcat/pom.xml b/test/plugin/archetypes/tomcat/pom.xml new file mode 100644 index 000000000..bbc7b80ad --- /dev/null +++ b/test/plugin/archetypes/tomcat/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.apache.skywalking.plugin + archetypes + 1.0.0 + + + tomcat + + + + + org.apache.maven.archetype + archetype-packaging + 3.1.1 + + + + diff --git a/test/plugin/archetypes/tomcat/src/main/resources/META-INF/maven/archetype-metadata.xml b/test/plugin/archetypes/tomcat/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..a30eb9d20 --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,64 @@ + + + + + + + org.apache.skywalking.apm.testcase + + + ${scenario_name} + + + 1.0.0 + + + org.apache.skywalking.apm.testcase.${scenario_name} + + + + + ${scenario_name} + + + + + + + + configuration.yml + support-version.list + + + + config + + + src/main/java + + + src/main/resources + + + \ No newline at end of file diff --git a/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/config/expectedData.yaml b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/config/expectedData.yaml new file mode 100644 index 000000000..d6474510c --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/config/expectedData.yaml @@ -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. +registryItems: + applications: + - {${scenario_name}: 2} + instances: + - {${scenario_name}: 1} + operationNames: + - canal-scenario: [] + heartbeat: [] +segmentItems: + - applicationCode: ${scenario_name} + segmentSize: + segments: diff --git a/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/configuration.yml b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/configuration.yml new file mode 100644 index 000000000..af2c8f7d6 --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/configuration.yml @@ -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. + +type: jvm +entryService: http://localhost:8080/${scenario_name}/case/${scenario_case} +healthCheck: http://localhost:8080/${scenario_name}/case/healthCheck +framework: ${scenario_name} +environment: +dependencies: \ No newline at end of file diff --git a/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/pom.xml b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..48fe3612a --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,68 @@ + + + + + org.apache.skywalking.apm.testcase + ${artifactId} + 1.0.0 + war + + 4.0.0 + + + UTF-8 + 1.8 + YOUR VERSION + + + + + 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 + + + + + ${scenario_name} + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + + diff --git a/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/java/CaseServlet.java b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/java/CaseServlet.java new file mode 100644 index 000000000..a9257aada --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/java/CaseServlet.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 $package; + +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 CaseServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + 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/archetypes/tomcat/src/main/resources/archetype-resources/src/main/java/HealthCheckServlet.java b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/java/HealthCheckServlet.java new file mode 100644 index 000000000..4c8575606 --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/java/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 $package; + +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/archetypes/tomcat/src/main/resources/archetype-resources/src/main/resources/log4j2.xml b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/resources/log4j2.xml new file mode 100644 index 000000000..4c6c06d40 --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..318be17d6 --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,44 @@ + + + skywalking-httpclient-scenario + + + caseServlet + ${package}.CaseServlet + + + + healthCheck + ${package}.HealthCheckServlet + + + + healthCheck + /case/healthCheck + + + + caseServlet + /case/${scenario_case} + + diff --git a/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/support-version.list b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/support-version.list new file mode 100644 index 000000000..085c4d8e0 --- /dev/null +++ b/test/plugin/archetypes/tomcat/src/main/resources/archetype-resources/support-version.list @@ -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 +# "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. + +# lists your version here \ No newline at end of file diff --git a/test/plugin/generator.sh b/test/plugin/generator.sh new file mode 100644 index 000000000..0588b940f --- /dev/null +++ b/test/plugin/generator.sh @@ -0,0 +1,111 @@ +#!/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 +# limitation under the License. + +wkdir="$(cd "$(dirname $0)"; pwd)" +MVNW=${wkdir}/../../../mvnw + +type="jvm" +artifactId= +scenario_home= +scenario_case= +scenarios_home=${wkdir}/scenarios + +exitWithMessage() { + echo $1>&2 + exit 1 +} + +print_help() { + echo -e "Usage: bash generator.sh -n my-scenario -c mycase -type jvm -a my" + echo -e "\t--type:\t\t\tchooses a type of container, 'jvm' or 'tomcat', which is 'jvm-container' or 'tomcat-container'.(required)" + echo -e "\t-a| --artifactId:\tgives an artifactId for your project." + echo -e "\t-n| --scenario_name:\tsets the scenario name.(required)" + echo -e "\t-c| --scenario_case:\tsets the entry name of scenario." + exit 0 +} + +parse_commandline() { + _positionals_count=0 + while test $# -gt 0 + do + _key="$1" + case "$_key" in + --type=*) + type="${_key##--type=}" + ;; + --type) + test $# -lt 2 && exitWithMessage "Missing value for the optional argument '$_key'." + type="$2" + shift + ;; + --artifactId=*) + artifactId="${_key##--artifactId=}" + ;; + -a| --artifactId) + test $# -lt 2 && exitWithMessage "Missing value for the optional argument '$_key'." + artifactId="$2" + shift + ;; + --scenario_name=*) + scenario_name="${_key##--scenario_name=}" + ;; + -n| --scenario_name) + test $# -lt 2 && exitWithMessage "Missing value for the optional argument '$_key'." + scenario_name="$2" + echo "$2" + shift + ;; + -c| --scenario_case) + test $# -lt 2 && exitWithMessage "Missing value for the optional argument '$_key'." + scenario_case="$2" + shift + ;; + --scenario_case=*) + scenario_name="${_key##--scenario_case=}" + ;; + -h|--help) + print_help + exit 0 + ;; + esac + shift + done +} + +parse_commandline "$@" + +echo "${type} ${scenario_name}" +[[ -z ${type} ]] && print_help +[[ -z ${scenario_name} ]] && print_help +[[ -z ${artifactId} ]] && artifactId=${scenario_name} +[[ -z ${scenario_case} ]] && scenario_case=${scenario_name} + +${MVNW} -f ./pom.xml install + +package="org.apache.skywalking.apm.testcase.${artifactId%%-scenario}" +${MVNW} archetype:generate \ + -Dfilter=org.apache.skywalking.apm.testcase:${artifactId}:"1.0.0" \ + -DarchetypeGroupId=org.apache.skywalking.plugin \ + -DoutputDirectory=${scenarios_home} \ + -Dscenario_name=${scenario_name} \ + -Dscenario_case=${scenario_case} \ + -DarchetypeArtifactId=${type} \ + -DarchetypeCatalog=local \ + -DinteractiveMode=false \ + -DarchetypeVersion=1.0.0 \ + -Dpackage=${package} -- GitLab