From 17da2e2eec1bbd9057067738b8a74a0e6808eafa Mon Sep 17 00:00:00 2001 From: aderm <394102339@qq.com> Date: Thu, 5 Dec 2019 22:47:14 +0800 Subject: [PATCH] [test/plugin] immigrate test oracle scenario. (#4006) * [test/plugin] immigrate test oracle scenario. * repair ojdbc14.jar download url. * 1.update ojdbc14.jar site;2.Adjust task position. * fix curl download problem by add -L. * Merge run steps. --- .github/workflows/plugins-test.yaml | 11 +- .../scenarios/oracle-scenario/bin/startup.sh | 21 +++ .../oracle-scenario/config/expectedData.yaml | 133 +++++++++++++++++ .../oracle-scenario/configuration.yml | 31 ++++ test/plugin/scenarios/oracle-scenario/pom.xml | 118 +++++++++++++++ .../src/main/assembly/assembly.xml | 41 +++++ .../apm/testcase/oracle/Application.java | 34 +++++ .../oracle/controller/CaseController.java | 141 ++++++++++++++++++ .../src/main/resources/application.yaml | 23 +++ .../src/main/resources/log4j2.xml | 30 ++++ .../oracle-scenario/support-version.list | 17 +++ 11 files changed, 597 insertions(+), 3 deletions(-) create mode 100644 test/plugin/scenarios/oracle-scenario/bin/startup.sh create mode 100644 test/plugin/scenarios/oracle-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/oracle-scenario/configuration.yml create mode 100644 test/plugin/scenarios/oracle-scenario/pom.xml create mode 100644 test/plugin/scenarios/oracle-scenario/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/oracle-scenario/src/main/java/org/apache/skywalking/apm/testcase/oracle/Application.java create mode 100644 test/plugin/scenarios/oracle-scenario/src/main/java/org/apache/skywalking/apm/testcase/oracle/controller/CaseController.java create mode 100644 test/plugin/scenarios/oracle-scenario/src/main/resources/application.yaml create mode 100644 test/plugin/scenarios/oracle-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/oracle-scenario/support-version.list diff --git a/.github/workflows/plugins-test.yaml b/.github/workflows/plugins-test.yaml index 884c509745..f9f0455562 100644 --- a/.github/workflows/plugins-test.yaml +++ b/.github/workflows/plugins-test.yaml @@ -445,7 +445,7 @@ jobs: - name: Run elasticsearch-6.x-scenario 6.7.1-6.8.4 (7) run: bash test/plugin/run.sh elasticsearch-6.x-scenario - Kafka: + Oracle_Kafka: runs-on: ubuntu-18.04 timeout-minutes: 90 strategy: @@ -465,8 +465,13 @@ jobs: java-version: 8 - name: Build SkyWalking Agent run: ./mvnw clean package -DskipTests -Pagent >/dev/null - - name: Build the Docker image - run: ./mvnw -f test/plugin/pom.xml clean package -DskipTests docker:build -DBUILD_NO=local >/dev/null + - name: Run oracle 10.2.0.4.0 (1) + run: | + curl -L -o ./skywalking-agent/plugins/apm-oracle-10.x-plugin-1.0.1.jar https://github.com/SkyAPM/java-plugin-extensions/releases/download/1.0.1/apm-oracle-10.x-plugin-1.0.1.jar + curl -O https://skyapm.github.io/ci-assist/jars/ojdbc14-10.2.0.4.0.jar + ./mvnw install:install-file -Dfile=ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar + ./mvnw -f test/plugin/pom.xml clean package -DskipTests docker:build -DBUILD_NO=local >/dev/null + bash test/plugin/run.sh oracle-scenario - name: Run kafka 0.11.0.0-2.3.0 (16) run: bash test/plugin/run.sh kafka-scenario diff --git a/test/plugin/scenarios/oracle-scenario/bin/startup.sh b/test/plugin/scenarios/oracle-scenario/bin/startup.sh new file mode 100644 index 0000000000..a8f932fa0d --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/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/oracle-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/oracle-scenario/config/expectedData.yaml b/test/plugin/scenarios/oracle-scenario/config/expectedData.yaml new file mode 100644 index 0000000000..fbedc4c8f3 --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/config/expectedData.yaml @@ -0,0 +1,133 @@ +# 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: + - {oracle-scenario: nq 0} + instances: + - {oracle-scenario: 1} + operationNames: + - oracle-scenario: [Oracle/JDBI/Connection/close, Oracle/JDBI/PreparedStatement/executeQuery, + Oracle/JDBI/PreparedStatement/execute, Oracle/JDBI/Statement/execute, + /oracle-scenario/case/oracle] +segmentItems: +- applicationCode: oracle-scenario + segmentSize: ge 1 + segments: + - segmentId: not null + spans: + - operationName: Oracle/JDBI/Statement/execute + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 34 + componentName: '' + isError: false + spanType: Exit + peer: oracle-server:1521 + peerId: 0 + tags: + - {key: db.type, value: sql} + - {key: db.instance, value: xe} + - key: db.statement + value: "CREATE TABLE test_007(\nid VARCHAR(1) PRIMARY KEY, \nvalue VARCHAR(1)\ + \ NOT NULL)" + - operationName: Oracle/JDBI/PreparedStatement/execute + operationId: 0 + parentSpanId: 0 + spanId: 2 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 34 + componentName: '' + isError: false + spanType: Exit + peer: oracle-server:1521 + peerId: 0 + tags: + - {key: db.type, value: sql} + - {key: db.instance, value: xe} + - {key: db.statement, value: 'INSERT INTO test_007(id, value) VALUES(?,?)'} + - operationName: Oracle/JDBI/PreparedStatement/executeQuery + operationId: 0 + parentSpanId: 0 + spanId: 3 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 34 + componentName: '' + isError: false + spanType: Exit + peer: oracle-server:1521 + peerId: 0 + tags: + - {key: db.type, value: sql} + - {key: db.instance, value: xe} + - {key: db.statement, value: 'SELECT id, value FROM test_007 WHERE id=?'} + - operationName: Oracle/JDBI/Statement/execute + operationId: 0 + parentSpanId: 0 + spanId: 4 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 34 + componentName: '' + isError: false + spanType: Exit + peer: oracle-server:1521 + peerId: 0 + tags: + - {key: db.type, value: sql} + - {key: db.instance, value: xe} + - {key: db.statement, value: 'DROP table test_007'} + - operationName: Oracle/JDBI/Connection/close + operationId: 0 + parentSpanId: 0 + spanId: 5 + spanLayer: Database + tags: + - {key: db.type,value: sql} + - {key: db.instance,value: xe} + - {key: db.statement,value: ''} + startTime: nq 0 + endTime: nq 0 + componentId: 34 + componentName: '' + isError: false + spanType: Exit + peer: oracle-server:1521 + peerId: 0 + - operationName: /oracle-scenario/case/oracle + 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/oracle-scenario/case/oracle'} + - {key: http.method, value: GET} diff --git a/test/plugin/scenarios/oracle-scenario/configuration.yml b/test/plugin/scenarios/oracle-scenario/configuration.yml new file mode 100644 index 0000000000..5e4f21737d --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/configuration.yml @@ -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. + +type: jvm +entryService: http://localhost:8080/oracle-scenario/case/oracle +healthCheck: http://localhost:8080/oracle-scenario/case/healthCheck +startScript: ./bin/startup.sh +framework: oracle-scenario +environment: + - oracle.address=oracle-server:1521 + - oracle.username=system + - oracle.password=oracle +dependencies: + oracle-server: + image: deepdiver/docker-oracle-xe-11g + hostname: oracle-server + expose: + - "1521" diff --git a/test/plugin/scenarios/oracle-scenario/pom.xml b/test/plugin/scenarios/oracle-scenario/pom.xml new file mode 100644 index 0000000000..d47f5d1fda --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/pom.xml @@ -0,0 +1,118 @@ + + + + + org.apache.skywalking.apm.testcase + oracle-scenario + 1.0.0 + jar + + 4.0.0 + + + UTF-8 + 1.8 + + 10.2.0.4.0 + + 2.1.6.RELEASE + + + skywalking-oracle-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-version} + pom + import + + + + + + + com.oracle + ojdbc14 + ${test.framework.version} + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + + oracle-scenario + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + ./target/ + + + + + + + diff --git a/test/plugin/scenarios/oracle-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/oracle-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000000..694ee49bc3 --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/oracle-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/oracle-scenario/src/main/java/org/apache/skywalking/apm/testcase/oracle/Application.java b/test/plugin/scenarios/oracle-scenario/src/main/java/org/apache/skywalking/apm/testcase/oracle/Application.java new file mode 100644 index 0000000000..31bce49f55 --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/src/main/java/org/apache/skywalking/apm/testcase/oracle/Application.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.apm.testcase.oracle; + +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/scenarios/oracle-scenario/src/main/java/org/apache/skywalking/apm/testcase/oracle/controller/CaseController.java b/test/plugin/scenarios/oracle-scenario/src/main/java/org/apache/skywalking/apm/testcase/oracle/controller/CaseController.java new file mode 100644 index 0000000000..feb1c030e4 --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/src/main/java/org/apache/skywalking/apm/testcase/oracle/controller/CaseController.java @@ -0,0 +1,141 @@ +/* + * 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.apm.testcase.oracle.controller; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import javax.annotation.PostConstruct; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@RestController +@RequestMapping("/case") +public class CaseController { + + private static final Logger logger = LogManager.getLogger(CaseController.class); + + @Value("${oracle.address}") + private String oracleHostAndPort; + + @Value("${oracle.username}") + private String oracleUsername; + + @Value("${oracle.password}") + private String oraclePassword; + + private String connectURL; + private static final String TEST_EXIST_SQL = "SELECT * FROM dual"; + private static final String CREATE_TABLE_SQL = "CREATE TABLE test_007(\n" + + "id VARCHAR(1) PRIMARY KEY, \n" + + "value VARCHAR(1) NOT NULL)"; + private static final String INSERT_DATA_SQL = "INSERT INTO test_007(id, value) VALUES(?,?)"; + private static final String QUERY_DATA_SQL = "SELECT id, value FROM test_007 WHERE id=?"; + private static final String DROP_TABLE_SQL = "DROP table test_007"; + + private static final String SUCCESS = "Success"; + + @PostConstruct + public void setUp() throws ClassNotFoundException { + Class.forName("oracle.jdbc.driver.OracleDriver"); + connectURL = "jdbc:oracle:thin:@" + oracleHostAndPort + ":xe"; + } + + @RequestMapping("/oracle") + @ResponseBody + public String testcase() { + Connection connection = null; + try { + // create table by using statement + connection = DriverManager.getConnection(connectURL, oracleUsername, oraclePassword); + Statement statement = connection.createStatement(); + statement.execute(CREATE_TABLE_SQL); + statement.close(); + + // insert table by using PreparedStatement + PreparedStatement insertDataPreparedStatement = connection.prepareStatement(INSERT_DATA_SQL); + insertDataPreparedStatement.setString(1, "1"); + insertDataPreparedStatement.setString(2, "1"); + insertDataPreparedStatement.execute(); + insertDataPreparedStatement.close(); + + // query data by using PreparedStatement + PreparedStatement queryDataPreparedStatement = connection.prepareStatement(QUERY_DATA_SQL); + queryDataPreparedStatement.setString(1, "1"); + ResultSet resultSet = queryDataPreparedStatement.executeQuery(); + resultSet.next(); + logger.info("Query id[{}]: value={}", "1", resultSet.getString(2)); + queryDataPreparedStatement.close(); + + // drop table by using statement + Statement dropTableStatement = connection.createStatement(); + dropTableStatement.execute(DROP_TABLE_SQL); + dropTableStatement.close(); + } catch (SQLException e) { + String message = "Failed to execute sql"; + logger.error(message); + throw new RuntimeException(message); + } finally { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + String message = "Failed to close connection"; + logger.error(message); + throw new RuntimeException(message); + } + } + } + return SUCCESS; + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() { + Connection connection = null; + try { + connection = DriverManager.getConnection(connectURL, oracleUsername, oraclePassword); + PreparedStatement preparedStatement = connection.prepareStatement(TEST_EXIST_SQL); + preparedStatement.execute(); + preparedStatement.close(); + } catch (SQLException e) { + String message = "Failed to execute sql"; + logger.error(message); + throw new RuntimeException(message); + } finally { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + String message = "Failed to close connection"; + logger.error(message); + throw new RuntimeException(message); + } + } + } + return SUCCESS; + } +} diff --git a/test/plugin/scenarios/oracle-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/oracle-scenario/src/main/resources/application.yaml new file mode 100644 index 0000000000..3bf1f53f66 --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/src/main/resources/application.yaml @@ -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. +# +# +server: + port: 8080 + servlet: + context-path: /oracle-scenario +logging: + config: classpath:log4j2.xml \ No newline at end of file diff --git a/test/plugin/scenarios/oracle-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/oracle-scenario/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..9849ed5a8a --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/oracle-scenario/support-version.list b/test/plugin/scenarios/oracle-scenario/support-version.list new file mode 100644 index 0000000000..1da30f00ae --- /dev/null +++ b/test/plugin/scenarios/oracle-scenario/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. + +10.2.0.4.0 -- GitLab