From 4ec2cb07edfad686a9cfcb790ea3d94a0d8b38d2 Mon Sep 17 00:00:00 2001 From: aderm <394102339@qq.com> Date: Thu, 12 Dec 2019 12:52:00 +0800 Subject: [PATCH] [test/plugin] immigrate test cassandra scenario. (#4040) * [test/plugin] immigrate test cassandra scenario. * update support list doc. * delete space error. * disable jmx report. * remove jmx dependence. * Disable jmx report. * Update support list doc. --- .github/workflows/plugins-test.yaml | 4 +- .../java-agent/Supported-list.md | 2 +- .../bin/startup.sh | 21 + .../config/expectedData.yaml | 495 ++++++++++++++++++ .../configuration.yml | 30 ++ .../pom.xml | 140 +++++ .../src/main/assembly/assembly.xml | 41 ++ .../apm/testcase/cassandra/Application.java | 37 ++ .../cassandra/controller/CaseController.java | 172 ++++++ .../src/main/resources/application.yaml | 23 + .../src/main/resources/log4j2.xml | 30 ++ .../support-version.list | 19 + 12 files changed, 1012 insertions(+), 2 deletions(-) create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/bin/startup.sh create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/config/expectedData.yaml create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/configuration.yml create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/pom.xml create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/assembly/assembly.xml create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/cassandra/Application.java create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/cassandra/controller/CaseController.java create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/resources/application.yaml create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/resources/log4j2.xml create mode 100644 test/plugin/scenarios/cassandra-java-driver-3.x-scenario/support-version.list diff --git a/.github/workflows/plugins-test.yaml b/.github/workflows/plugins-test.yaml index c1bccd2602..d902865ee8 100644 --- a/.github/workflows/plugins-test.yaml +++ b/.github/workflows/plugins-test.yaml @@ -157,7 +157,7 @@ jobs: run: bash test/plugin/run.sh armeria-0.96plus-scenario - Hystrix_SofaRPC_Spring30x: + Cassandra_Hystrix_SofaRPC_Spring30x: runs-on: ubuntu-18.04 timeout-minutes: 90 strategy: @@ -179,6 +179,8 @@ jobs: 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 cassandra 3.7.0-3.7.2 (3) + run: bash test/plugin/run.sh cassandra-java-driver-3.x-scenario - name: Run hystrix 1.4.20-1.5.12 (20) run: bash test/plugin/run.sh hystrix-scenario - name: Run sofarpc 5.4.0-5.6.2 (23) diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index 19ccd83735..a9c12b4642 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -63,7 +63,7 @@ * [Solr](https://github.com/apache/lucene-solr/) * [SolrJ](https://github.com/apache/lucene-solr/tree/master/solr/solrj) 7.x * [Cassandra](https://github.com/apache/cassandra) 3.x - * [cassandra-java-driver](https://github.com/datastax/java-driver) 3.6.0-3.7.2 + * [cassandra-java-driver](https://github.com/datastax/java-driver) 3.7.0-3.7.2 * Service Discovery * [Netflix Eureka](https://github.com/Netflix/eureka) * Distributed Coordination diff --git a/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/bin/startup.sh b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/bin/startup.sh new file mode 100644 index 0000000000..eeefef5d33 --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-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/cassandra-java-driver-3.x-scenario.jar & \ No newline at end of file diff --git a/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/config/expectedData.yaml new file mode 100644 index 0000000000..81ce9aaa01 --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/config/expectedData.yaml @@ -0,0 +1,495 @@ +# 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: + - {cassandra-java-driver-3.x-scenario: 2} + instances: + - {cassandra-java-driver-3.x-scenario: 1} + operationNames: + - cassandra-java-driver-3.x-scenario: [Cassandra/execute, Cassandra/executeAsync, /cassandra-java-driver-3.x-scenario/case/cassandra] + heartbeat: [] +segmentItems: + - applicationCode: cassandra-java-driver-3.x-scenario + segmentSize: ge 1 + segments: + - segmentId: not null + spans: + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 1 + spanId: 2 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/execute + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: ''} + - {key: db.statement, value: 'CREATE KEYSPACE IF NOT EXISTS demo WITH replication = {''class'': ''SimpleStrategy'', ''replication_factor'': 1}'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 3 + spanId: 4 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/execute + operationId: 0 + parentSpanId: 0 + spanId: 3 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: ''} + - {key: db.statement, value: 'CREATE TABLE IF NOT EXISTS demo.test(id TEXT PRIMARY KEY, value TEXT)'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 5 + spanId: 6 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/execute + operationId: 0 + parentSpanId: 0 + spanId: 5 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: demo} + - {key: db.statement, value: 'INSERT INTO demo.test(id, value) VALUES(?,?)'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 7 + spanId: 8 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/execute + operationId: 0 + parentSpanId: 0 + spanId: 7 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: demo} + - {key: db.statement, value: 'SELECT * FROM demo.test WHERE id = ?'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 9 + spanId: 10 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/execute + operationId: 0 + parentSpanId: 0 + spanId: 9 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: demo} + - {key: db.statement, value: 'DELETE FROM demo.test WHERE id = ?'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 11 + spanId: 12 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/execute + operationId: 0 + parentSpanId: 0 + spanId: 11 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: ''} + - {key: db.statement, value: DROP TABLE IF EXISTS demo.test} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 13 + spanId: 14 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/execute + operationId: 0 + parentSpanId: 0 + spanId: 13 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: ''} + - {key: db.statement, value: DROP KEYSPACE IF EXISTS demo} + - operationName: Cassandra/executeAsync + operationId: 0 + parentSpanId: 0 + spanId: 15 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: ''} + - {key: db.statement, value: 'CREATE KEYSPACE IF NOT EXISTS demo WITH replication + = {''class'': ''SimpleStrategy'', ''replication_factor'': 1}'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 0 + spanId: 16 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/executeAsync + operationId: 0 + parentSpanId: 0 + spanId: 17 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: ''} + - {key: db.statement, value: 'CREATE TABLE IF NOT EXISTS demo.test(id TEXT PRIMARY + KEY, value TEXT)'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 0 + spanId: 18 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/executeAsync + operationId: 0 + parentSpanId: 0 + spanId: 19 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: demo} + - {key: db.statement, value: 'INSERT INTO demo.test(id, value) VALUES(?,?)'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 0 + spanId: 20 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/executeAsync + operationId: 0 + parentSpanId: 0 + spanId: 21 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: demo} + - {key: db.statement, value: 'SELECT * FROM demo.test WHERE id = ?'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 0 + spanId: 22 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/executeAsync + operationId: 0 + parentSpanId: 0 + spanId: 23 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: demo} + - {key: db.statement, value: 'DELETE FROM demo.test WHERE id = ?'} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 0 + spanId: 24 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/executeAsync + operationId: 0 + parentSpanId: 0 + spanId: 25 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: ''} + - {key: db.statement, value: DROP TABLE IF EXISTS demo.test} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 0 + spanId: 26 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: Cassandra/executeAsync + operationId: 0 + parentSpanId: 0 + spanId: 27 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Exit + peer: cassandra-server:9042 + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - {key: db.instance, value: ''} + - {key: db.statement, value: DROP KEYSPACE IF EXISTS demo} + - operationName: Cassandra/getUninterruptibly + operationId: 0 + parentSpanId: 0 + spanId: 28 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 69 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: db.type, value: cassandra} + - operationName: /cassandra-java-driver-3.x-scenario/case/cassandra + 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/cassandra-java-driver-3.x-scenario/case/cassandra'} + - {key: http.method, value: GET} diff --git a/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/configuration.yml b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/configuration.yml new file mode 100644 index 0000000000..b7fadbf140 --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/configuration.yml @@ -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. + +type: jvm +entryService: http://localhost:8080/cassandra-java-driver-3.x-scenario/case/cassandra +healthCheck: http://localhost:8080/cassandra-java-driver-3.x-scenario/case/healthCheck +startScript: ./bin/startup.sh +framework: cassandra-java-driver-3.x-scenario +environment: +- cassandra.host=cassandra-server +- cassandra.port=9042 +dependencies: + cassandra-server: + image: cassandra:3.11.4 + hostname: cassandra-server + expose: + - 9042 diff --git a/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/pom.xml b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/pom.xml new file mode 100644 index 0000000000..36e6e6256e --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/pom.xml @@ -0,0 +1,140 @@ + + + + + org.apache.skywalking.apm.testcase + cassandra-java-driver-3.x-scenario + 1.0.0 + jar + + 4.0.0 + + + UTF-8 + 1.8 + + 3.7.2 + + 2.1.6.RELEASE + + + skywalking-cassandra-java-driver-3.x-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + com.datastax.cassandra + cassandra-driver-core + ${test.framework.version} + + + com.datastax.cassandra + cassandra-driver-mapping + ${test.framework.version} + + + cassandra-driver-core + com.datastax.cassandra + + + + + com.datastax.cassandra + cassandra-driver-extras + ${test.framework.version} + + + cassandra-driver-core + com.datastax.cassandra + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + + cassandra-java-driver-3.x-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/cassandra-java-driver-3.x-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000000..5389b84a18 --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/cassandra-java-driver-3.x-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/cassandra/Application.java b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/cassandra/Application.java new file mode 100644 index 0000000000..e305aee795 --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/cassandra/Application.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.apm.testcase.cassandra; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author aderm + */ +@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/cassandra-java-driver-3.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/cassandra/controller/CaseController.java b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/cassandra/controller/CaseController.java new file mode 100644 index 0000000000..48150a4742 --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/cassandra/controller/CaseController.java @@ -0,0 +1,172 @@ +/* + * 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.cassandra.controller; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.PreparedStatement; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.ResultSetFuture; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/case") +public class CaseController { + + @Value("${cassandra.host}") + private String host; + + @Value("${cassandra.port}") + private int port; + + private static final String TEST_EXIST_SQL = "SELECT now() FROM system.local"; + private static final String CREATE_KEYSPACE_SQL = "CREATE KEYSPACE IF NOT EXISTS demo WITH replication = " + + "{'class': 'SimpleStrategy', 'replication_factor': 1}"; + private static final String CREATE_TABLE_SQL = "CREATE TABLE IF NOT EXISTS demo.test(id TEXT PRIMARY KEY, value TEXT)"; + private static final String INSERT_DATA_SQL = "INSERT INTO demo.test(id, value) VALUES(?,?)"; + private static final String SELECT_DATA_SQL = "SELECT * FROM demo.test WHERE id = ?"; + private static final String DELETE_DATA_SQL = "DELETE FROM demo.test WHERE id = ?"; + private static final String DROP_TABLE_SQL = "DROP TABLE IF EXISTS demo.test"; + private static final String DROP_KEYSPACE = "DROP KEYSPACE IF EXISTS demo"; + + private static final Logger logger = LogManager.getLogger(CaseController.class); + private static final String SUCCESS = "Success"; + + @RequestMapping("/cassandra") + @ResponseBody + public String testcase() { + logger.info("cassandra contact points: {}:{}", host, port); + + Cluster cluster = null; + Session session = null; + try { + cluster = Cluster.builder().addContactPoint(host).withPort(port).withoutJMXReporting().build(); + session = cluster.connect(); + logger.info("cassandra connection open"); + + execute(session); + executeAsync(session); + + return SUCCESS; + } finally { + if (session != null) { + session.close(); + } + if (cluster != null) { + cluster.close(); + } + logger.info("cassandra connection close"); + } + } + + private void execute(Session session) { + logger.info("execute in sync"); + + ResultSet createKeyspaceDataResultSet = session.execute(CREATE_KEYSPACE_SQL); + logger.info("CREATE KEYSPACE result: " + createKeyspaceDataResultSet.toString()); + + ResultSet createTableDataResultSet = session.execute(CREATE_TABLE_SQL); + logger.info("CREATE TABLE result: " + createTableDataResultSet.toString()); + + PreparedStatement insertDataPreparedStatement = session.prepare(INSERT_DATA_SQL); + ResultSet insertDataResultSet = session.execute(insertDataPreparedStatement.bind("101", "foobar")); + logger.info("INSERT result: " + insertDataResultSet.toString()); + + PreparedStatement selectDataPreparedStatement = session.prepare(SELECT_DATA_SQL); + ResultSet resultSet = session.execute(selectDataPreparedStatement.bind("101")); + Row row = resultSet.one(); + logger.info("SELECT result: id: {}, value: {}", row.getString("id"), row.getString("value")); + + PreparedStatement deleteDataPreparedStatement = session.prepare(DELETE_DATA_SQL); + ResultSet deleteDataResultSet = session.execute(deleteDataPreparedStatement.bind("101")); + logger.info("DELETE result: " + deleteDataResultSet.toString()); + + ResultSet dropTableDataResultSet = session.execute(DROP_TABLE_SQL); + logger.info("DROP TABLE result: " + dropTableDataResultSet.toString()); + + ResultSet dropKeyspaceDataResultSet = session.execute(DROP_KEYSPACE); + logger.info("DROP KEYSPACE result: " + dropKeyspaceDataResultSet.toString()); + } + + private void executeAsync(Session session) { + logger.info("execute in async"); + + ResultSetFuture createKeyspaceDataResultSetFuture = session.executeAsync(CREATE_KEYSPACE_SQL); + ResultSet createKeyspaceDataResultSet = createKeyspaceDataResultSetFuture.getUninterruptibly(); + logger.info("CREATE KEYSPACE result: " + createKeyspaceDataResultSet.toString()); + + ResultSetFuture createTableDataResultSetFuture = session.executeAsync(CREATE_TABLE_SQL); + ResultSet createTableDataResultSet = createTableDataResultSetFuture.getUninterruptibly(); + logger.info("CREATE TABLE result: " + createTableDataResultSet.toString()); + + PreparedStatement insertDataPreparedStatement = session.prepare(INSERT_DATA_SQL); + ResultSetFuture insertDataResultSetFuture = session.executeAsync(insertDataPreparedStatement.bind("101", "foobar")); + ResultSet insertDataResultSet = insertDataResultSetFuture.getUninterruptibly(); + logger.info("INSERT result: " + insertDataResultSet.toString()); + + PreparedStatement selectDataPreparedStatement = session.prepare(SELECT_DATA_SQL); + ResultSetFuture resultSetFuture = session.executeAsync(selectDataPreparedStatement.bind("101")); + ResultSet resultSet = resultSetFuture.getUninterruptibly(); + Row row = resultSet.one(); + logger.info("SELECT result: id: {}, value: {}", row.getString("id"), row.getString("value")); + + PreparedStatement deleteDataPreparedStatement = session.prepare(DELETE_DATA_SQL); + ResultSetFuture deleteDataResultSetFuture = session.executeAsync(deleteDataPreparedStatement.bind("101")); + ResultSet deleteDataResultSet = deleteDataResultSetFuture.getUninterruptibly(); + logger.info("DELETE result: " + deleteDataResultSet.toString()); + + ResultSetFuture dropTableDataResultSetFuture = session.executeAsync(DROP_TABLE_SQL); + ResultSet dropTableDataResultSet = dropTableDataResultSetFuture.getUninterruptibly(); + logger.info("DROP TABLE result: " + dropTableDataResultSet.toString()); + + ResultSetFuture dropKeyspaceDataResultSetFuture = session.executeAsync(DROP_KEYSPACE); + ResultSet dropKeyspaceDataResultSet = dropKeyspaceDataResultSetFuture.getUninterruptibly(); + logger.info("DROP KEYSPACE result: " + dropKeyspaceDataResultSet.toString()); + } + + @RequestMapping("/healthCheck") + @ResponseBody + public String healthCheck() { + Cluster cluster = null; + Session session = null; + try { + cluster = Cluster.builder().addContactPoint(host).withPort(port).withoutJMXReporting().build(); + session = cluster.connect(); + logger.info("cassandra connection open"); + + PreparedStatement testPreparedStatement = session.prepare(TEST_EXIST_SQL); + logger.info("Test result:" + testPreparedStatement.toString()); + } finally { + if (session != null) { + session.close(); + } + if (cluster != null) { + cluster.close(); + } + logger.info("cassandra connection close"); + } + return SUCCESS; + } +} diff --git a/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/resources/application.yaml new file mode 100644 index 0000000000..b34a437f2f --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-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: /cassandra-java-driver-3.x-scenario +logging: + config: classpath:log4j2.xml diff --git a/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..b5cda5ae8a --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + diff --git a/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/support-version.list b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/support-version.list new file mode 100644 index 0000000000..2ac3826f51 --- /dev/null +++ b/test/plugin/scenarios/cassandra-java-driver-3.x-scenario/support-version.list @@ -0,0 +1,19 @@ +# 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. + +3.7.0 +3.7.1 +3.7.2