From f6566fd085fad3e1ce01c57b3160574257ba14f1 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Wed, 18 Sep 2019 15:05:06 +0800 Subject: [PATCH 01/10] Add pulsar-scenario. --- pulsar-scenario/config/docker-compose.yml | 31 +++ pulsar-scenario/config/expectedData.yaml | 84 ++++++++ pulsar-scenario/docker/Dockerfile | 24 +++ pulsar-scenario/docker/docker-entrypoint.sh | 3 + pulsar-scenario/docker/start_up.sh | 15 ++ pulsar-scenario/pom.xml | 188 ++++++++++++++++++ .../testcase/pulsar/Application.java | 38 ++++ .../pulsar/controller/CaseController.java | 87 ++++++++ .../src/main/resources/application.properties | 20 ++ pulsar-scenario/src/main/resources/log4j2.xml | 34 ++++ pulsar-scenario/testcase.yml | 26 +++ 11 files changed, 550 insertions(+) create mode 100644 pulsar-scenario/config/docker-compose.yml create mode 100644 pulsar-scenario/config/expectedData.yaml create mode 100644 pulsar-scenario/docker/Dockerfile create mode 100644 pulsar-scenario/docker/docker-entrypoint.sh create mode 100644 pulsar-scenario/docker/start_up.sh create mode 100644 pulsar-scenario/pom.xml create mode 100644 pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/Application.java create mode 100644 pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java create mode 100644 pulsar-scenario/src/main/resources/application.properties create mode 100644 pulsar-scenario/src/main/resources/log4j2.xml create mode 100644 pulsar-scenario/testcase.yml diff --git a/pulsar-scenario/config/docker-compose.yml b/pulsar-scenario/config/docker-compose.yml new file mode 100644 index 00000000..18b0285a --- /dev/null +++ b/pulsar-scenario/config/docker-compose.yml @@ -0,0 +1,31 @@ +version: '2.1' +services: + pulsar-scenario: + image: skywalking/pulsar-scenario:{CASES_IMAGE_VERSION} + expose: + - "8082" + ports: + - "{SERVER_OUTPUT_PORT}:8082" + environment: + - COLLECTOR_SERVER=mock-collector:19876 + links: + - mock-collector + volumes: + - {AGENT_FILE_PATH}:/usr/local/pulsar-scenario/agent + depends_on: + mock-collector: + condition: service_healthy + + mock-collector: + image: skyapm/mock-collector:{COLLECTOR_IMAGE_VERSION} + environment: + - GRPC_BIND_HOST=mock-collector + expose: + - "12800" + ports: + - "{COLLECTOR_OUTPUT_PORT}:12800" + healthcheck: + test: ["CMD", "curl", "-f", "http://127.0.0.1:12800/receiveData"] + interval: 5s + timeout: 10s + retries: 5 diff --git a/pulsar-scenario/config/expectedData.yaml b/pulsar-scenario/config/expectedData.yaml new file mode 100644 index 00000000..88576a8f --- /dev/null +++ b/pulsar-scenario/config/expectedData.yaml @@ -0,0 +1,84 @@ +registryItems: + applications: + - {pulsar-scenario: nq 0} + instances: + - {pulsar-scenario: nq 0} + operationNames: + - pulsar-scenario: [Pulsar/persistent://public/default/test/Producer, /case/kafka-case, Kafka/persistent://public/default/test/Consumer/test] +segmentItems: +- applicationCode: pulsar-scenario + segmentSize: ge 3 + segments: + - segmentId: not null + spans: + - operationName: Pulsar/persistent://public/default/test/Producer + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: MQ + startTime: nq 0 + endTime: nq 0 + componentId: 40 + componentName: '' + isError: false + spanType: Exit + peer: pulsar://127.0.0.1:6650 + peerId: 0 + tags: + - {key: mq.broker, value: 'pulsar://127.0.0.1:6650'} + - {key: mq.topic, value: 'persistent://public/default/test'} + - operationName: /case/pulsar-case + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 14 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: 'http://localhost:{SERVER_OUTPUT_PORT}/pulsar-scenario/case/pulsar-case'} + - {key: http.method, value: GET} + - segmentId: not null + spans: + - operationName: Pulsar/Producer/SendCallback + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Unknown + startTime: nq 0 + endTime: nq 0 + componentId: 40 + componentName: '' + isError: false + spanType: Local + peer: '' + peerId: 0 + tags: + - {key: mq.topic, value: 'persistent://public/default/test'} + refs: + - {parentEndpointId: 0, parentEndpoint: /case/pulsar-case, networkAddressId: 0, entryEndpointId: 0, refType: CrossThread, parentSpanId: 1, parentTraceSegmentId: '${pulsar-scenario[0]}', parentServiceInstanceId: nq 0, networkAddress: '', entryEndpoint: /case/pulsar-case, entryServiceInstanceId: nq 0 } + - segmentId: not null + spans: + - operationName: Pulsar/persistent://public/default/test/Consumer/test + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: MQ + startTime: nq 0 + endTime: nq 0 + componentId: 41 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: mq.broker, value: 'pulsar://127.0.0.1:6650'} + - {key: mq.topic, value: 'persistent://public/default/test'} + refs: + - {parentEndpointId: 0, parentEndpoint: /case/pulsar-case, networkAddressId: 0, entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: '${pulsar-scenario[0]}', parentServiceInstanceId: nq 0, networkAddress: 'pulsar://127.0.0.1:6650', entryEndpoint: /case/pulsar-case, entryServiceInstanceId: nq 0} diff --git a/pulsar-scenario/docker/Dockerfile b/pulsar-scenario/docker/Dockerfile new file mode 100644 index 00000000..4d7bfb46 --- /dev/null +++ b/pulsar-scenario/docker/Dockerfile @@ -0,0 +1,24 @@ +FROM openjdk:8-jdk + +ENV COLLECTOR_SERVER=127.0.0.1:12800 \ + PULSAR_VERSION=2.4.1 +WORKDIR /usr/local/pulsar-scenario +# download the pulsar +RUN wget -q "http://mirror.bit.edu.cn/apache/pulsar/pulsar-${PULSAR_VERSION}/apache-pulsar-${PULSAR_VERSION}-bin.tar.gz" -O "/usr/local/pulsar-scenario/apache-pulsar-${PULSAR_VERSION}-bin.tar.gz" && tar -xvf /usr/local/pulsar-scenario/apache-pulsar-${PULSAR_VERSION}-bin.tar.gz + +# copy required packages +ADD start_up.sh /usr/local/pulsar-scenario/ +ADD pulsar-scenario.jar /usr/local/pulsar-scenario +ADD docker-entrypoint.sh / + +RUN chmod +x /docker-entrypoint.sh + +VOLUME /usr/local/pulsar-scenario/agent + +# port +EXPOSE 8082 + +# +#ENTRYPOINT /docker-entrypoint.sh + +CMD sh /usr/local/pulsar-scenario/start_up.sh diff --git a/pulsar-scenario/docker/docker-entrypoint.sh b/pulsar-scenario/docker/docker-entrypoint.sh new file mode 100644 index 00000000..de15a491 --- /dev/null +++ b/pulsar-scenario/docker/docker-entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec "$@" \ No newline at end of file diff --git a/pulsar-scenario/docker/start_up.sh b/pulsar-scenario/docker/start_up.sh new file mode 100644 index 00000000..797fdfc7 --- /dev/null +++ b/pulsar-scenario/docker/start_up.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +PULSAR_SCENARIO_HOME=/usr/local/pulsar-scenario +PULSAR_HOME=${PULSAR_SCENARIO_HOME}/apache-pulsar-${PULSAR_VERSION} + +#start pulsar standalone +echo "start pulsar standalone" +(cd ${PULSAR_HOME} && bin/pulsar-daemon start standalone) > /dev/null + +export AGENT_FILE_PATH=${PULSAR_SCENARIO_HOME}/agent +if [ -f "${AGENT_FILE_PATH}/skywalking-agent.jar" ]; then + PULSAR_SCENARIO_OPTS=" -javaagent:${AGENT_FILE_PATH}/skywalking-agent.jar -Dskywalking.collector.grpc_channel_check_interval=2 -Dskywalking.collector.app_and_service_register_check_interval=2 -Dcollector.discovery_check_interval=2 -Dskywalking.collector.backend_service=${COLLECTOR_SERVER} -Dskywalking.agent.service_name=pulsar-scenario " +fi + +java ${PULSAR_SCENARIO_OPTS} -jar ${PULSAR_SCENARIO_HOME}/pulsar-scenario.jar diff --git a/pulsar-scenario/pom.xml b/pulsar-scenario/pom.xml new file mode 100644 index 00000000..60e5868c --- /dev/null +++ b/pulsar-scenario/pom.xml @@ -0,0 +1,188 @@ + + + + + 4.0.0 + + org.apache.skywalking + pulsar-scenario + 5.0.0-2018 + skywalking-pulsar-scenario + + + UTF-8 + + 2.4.0 + ${test.framework.version} + + 2.6.2 + 4.3.8.RELEASE + 1.5.2.RELEASE + + + + + org.apache.pulsar + pulsar-client + ${test.framework.version} + + + + org.springframework.boot + spring-boot-starter + ${spring-boot-version} + + + org.apache.logging.log4j + log4j-api + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} + + + org.apache.logging.log4j + log4j-jcl + ${log4j.version} + + + org.springframework.boot + spring-boot-starter-tomcat + ${spring-boot-version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot-version} + + + + + + + pulsar-scenario-2.2.0 + + 2.2.0 + + + + pulsar-scenario-2.2.1 + + 2.2.1 + + + + pulsar-scenario-2.3.0 + + 2.3.0 + + + + pulsar-scenario-2.3.1 + + 2.3.1 + + + + pulsar-scenario-2.3.2 + + 2.3.2 + + + + pulsar-scenario-2.4.0 + + 2.4.0 + + + + pulsar-scenario-2.4.1 + + 2.4.1 + + + + + + pulsar-scenario + + + org.springframework.boot + spring-boot-maven-plugin + 1.5.9.RELEASE + + + + repackage + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.8 + 1.8 + ${project.build.sourceEncoding} + + + + com.spotify + docker-maven-plugin + 0.4.13 + + skywalking/pulsar-scenario + + ${docker.image.version} + + ${project.basedir}/docker + + + / + ${project.build.directory} + ${project.build.finalName}.jar + + + + + + + + + + spring-snapshots + http://repo.spring.io/snapshot + + + spring-milestones + http://repo.spring.io/milestone + + + diff --git a/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/Application.java b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/Application.java new file mode 100644 index 00000000..985d9ba5 --- /dev/null +++ b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/Application.java @@ -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. + * + */ + +package test.apache.skywalking.testcase.pulsar; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@EnableAutoConfiguration +@SpringBootApplication() +@ComponentScan("test.apache.skywalking.testcase.pulsar") +public class Application { + + public static void main(String[] args) { + try { + SpringApplication.run(Application.class, args); + } catch (Exception e) { + // Never do this + } + } +} diff --git a/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java new file mode 100644 index 00000000..01ec6b13 --- /dev/null +++ b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.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 test.apache.skywalking.testcase.pulsar.controller; + + +import java.util.concurrent.TimeUnit; +import javax.annotation.PostConstruct; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.pulsar.client.api.Consumer; +import org.apache.pulsar.client.api.Message; +import org.apache.pulsar.client.api.Producer; +import org.apache.pulsar.client.api.PulsarClient; +import org.apache.pulsar.client.api.PulsarClientException; + +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 Logger logger = LogManager.getLogger(CaseController.class); + + private String serviceUrl; + + private String topicName; + + @PostConstruct + private void setUp() { + serviceUrl = "pulsar://127.0.0.1:6650"; + topicName = "persistent://public/default/test"; + } + + @RequestMapping("/pulsar-case") + @ResponseBody + public String pulsarCase() throws PulsarClientException { + PulsarClient pulsarClient = PulsarClient.builder() + .serviceUrl(serviceUrl) + .build(); + + Producer producer = pulsarClient.newProducer() + .topic(topicName) + .create(); + + Consumer consumer = pulsarClient.newConsumer() + .topic(topicName) + .subscriptionName("test") + .subscribe(); + + producer.newMessage() + .key("testKey") + .value(Integer.toString(1).getBytes()) + .property("TEST", "TEST") + .send(); + + Message msg = consumer.receive(3, TimeUnit.SECONDS); + producer.close(); + consumer.close(); + + if (msg != null) { + return String.format("Success, consumer received message with key=%s and value=%s", msg.getKey(), new String(msg.getValue())); + } else { + return "Failed, consumer can't receive the message in 3 seconds"; + } + } +} diff --git a/pulsar-scenario/src/main/resources/application.properties b/pulsar-scenario/src/main/resources/application.properties new file mode 100644 index 00000000..740d890d --- /dev/null +++ b/pulsar-scenario/src/main/resources/application.properties @@ -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. +# +# + +server.port=8082 +server.contextPath=/pulsar-scenario \ No newline at end of file diff --git a/pulsar-scenario/src/main/resources/log4j2.xml b/pulsar-scenario/src/main/resources/log4j2.xml new file mode 100644 index 00000000..97b22611 --- /dev/null +++ b/pulsar-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pulsar-scenario/testcase.yml b/pulsar-scenario/testcase.yml new file mode 100644 index 00000000..d147e9a8 --- /dev/null +++ b/pulsar-scenario/testcase.yml @@ -0,0 +1,26 @@ +# +# Test case project define. +# +# Note: Test case project must a project that support output service. +# +testcase: + # + # The request url of current test cases. + # + request_url: http://localhost:{SERVER_OUTPUT_PORT}/pulsar-scenario/case/pulsar-case + # + # The framework name that need tested. + # + test_framework: Pulsar + # + # The framework version list of current test case supported + # + support_versions: + - 2.2.0 + - 2.2.1 + - 2.3.0 + - 2.3.1 + - 2.3.2 + - 2.4.0 + - 2.4.1 + From 3dc8520febe34e8d56da3f5c20ea20eedc990c66 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Wed, 18 Sep 2019 15:18:50 +0800 Subject: [PATCH 02/10] Add logs for received messages and add PULSAR_SERVICE_URL ENV --- pulsar-scenario/docker/Dockerfile | 1 + pulsar-scenario/docker/start_up.sh | 2 +- .../testcase/pulsar/controller/CaseController.java | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pulsar-scenario/docker/Dockerfile b/pulsar-scenario/docker/Dockerfile index 4d7bfb46..d1bfd491 100644 --- a/pulsar-scenario/docker/Dockerfile +++ b/pulsar-scenario/docker/Dockerfile @@ -1,6 +1,7 @@ FROM openjdk:8-jdk ENV COLLECTOR_SERVER=127.0.0.1:12800 \ + PULSAR_SERVICE_URL=pulsar://127.0.0.1:6650 \ PULSAR_VERSION=2.4.1 WORKDIR /usr/local/pulsar-scenario # download the pulsar diff --git a/pulsar-scenario/docker/start_up.sh b/pulsar-scenario/docker/start_up.sh index 797fdfc7..ccd34609 100644 --- a/pulsar-scenario/docker/start_up.sh +++ b/pulsar-scenario/docker/start_up.sh @@ -12,4 +12,4 @@ if [ -f "${AGENT_FILE_PATH}/skywalking-agent.jar" ]; then PULSAR_SCENARIO_OPTS=" -javaagent:${AGENT_FILE_PATH}/skywalking-agent.jar -Dskywalking.collector.grpc_channel_check_interval=2 -Dskywalking.collector.app_and_service_register_check_interval=2 -Dcollector.discovery_check_interval=2 -Dskywalking.collector.backend_service=${COLLECTOR_SERVER} -Dskywalking.agent.service_name=pulsar-scenario " fi -java ${PULSAR_SCENARIO_OPTS} -jar ${PULSAR_SCENARIO_HOME}/pulsar-scenario.jar +java ${PULSAR_SCENARIO_OPTS} -Dservice.url=${PULSAR_SERVICE_URL} -jar ${PULSAR_SCENARIO_HOME}/pulsar-scenario.jar diff --git a/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java index 01ec6b13..762ada1a 100644 --- a/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java +++ b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java @@ -30,6 +30,7 @@ import org.apache.pulsar.client.api.PulsarClient; import org.apache.pulsar.client.api.PulsarClientException; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -42,13 +43,13 @@ public class CaseController { private Logger logger = LogManager.getLogger(CaseController.class); + @Value("${service.url:pulsar://127.0.0.1:6650}") private String serviceUrl; private String topicName; @PostConstruct private void setUp() { - serviceUrl = "pulsar://127.0.0.1:6650"; topicName = "persistent://public/default/test"; } @@ -75,10 +76,13 @@ public String pulsarCase() throws PulsarClientException { .send(); Message msg = consumer.receive(3, TimeUnit.SECONDS); + producer.close(); consumer.close(); if (msg != null) { + logger.info("properties: {}", msg.getProperty("TEST")); + logger.info("messageId = {}, key = {}, value = {}", msg.getMessageId(), msg.getKey(), new String(msg.getValue())); return String.format("Success, consumer received message with key=%s and value=%s", msg.getKey(), new String(msg.getValue())); } else { return "Failed, consumer can't receive the message in 3 seconds"; From a69f9772e92b429e95f63c34bd6695552f81aa07 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Fri, 20 Sep 2019 17:39:31 +0800 Subject: [PATCH 03/10] Fix test issues --- pulsar-scenario/config/expectedData.yaml | 8 ++++---- .../testcase/pulsar/controller/CaseController.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pulsar-scenario/config/expectedData.yaml b/pulsar-scenario/config/expectedData.yaml index 88576a8f..401f4eb2 100644 --- a/pulsar-scenario/config/expectedData.yaml +++ b/pulsar-scenario/config/expectedData.yaml @@ -4,7 +4,7 @@ registryItems: instances: - {pulsar-scenario: nq 0} operationNames: - - pulsar-scenario: [Pulsar/persistent://public/default/test/Producer, /case/kafka-case, Kafka/persistent://public/default/test/Consumer/test] + - pulsar-scenario: [Pulsar/persistent://public/default/test/Producer, /case/pulsar-case, Pulsar/persistent://public/default/test/Consumer/test] segmentItems: - applicationCode: pulsar-scenario segmentSize: ge 3 @@ -26,7 +26,7 @@ segmentItems: peerId: 0 tags: - {key: mq.broker, value: 'pulsar://127.0.0.1:6650'} - - {key: mq.topic, value: 'persistent://public/default/test'} + - {key: mq.topic, value: 'test'} - operationName: /case/pulsar-case operationId: 0 parentSpanId: -1 @@ -59,7 +59,7 @@ segmentItems: peer: '' peerId: 0 tags: - - {key: mq.topic, value: 'persistent://public/default/test'} + - {key: mq.topic, value: 'test'} refs: - {parentEndpointId: 0, parentEndpoint: /case/pulsar-case, networkAddressId: 0, entryEndpointId: 0, refType: CrossThread, parentSpanId: 1, parentTraceSegmentId: '${pulsar-scenario[0]}', parentServiceInstanceId: nq 0, networkAddress: '', entryEndpoint: /case/pulsar-case, entryServiceInstanceId: nq 0 } - segmentId: not null @@ -79,6 +79,6 @@ segmentItems: peerId: 0 tags: - {key: mq.broker, value: 'pulsar://127.0.0.1:6650'} - - {key: mq.topic, value: 'persistent://public/default/test'} + - {key: mq.topic, value: 'test'} refs: - {parentEndpointId: 0, parentEndpoint: /case/pulsar-case, networkAddressId: 0, entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: '${pulsar-scenario[0]}', parentServiceInstanceId: nq 0, networkAddress: 'pulsar://127.0.0.1:6650', entryEndpoint: /case/pulsar-case, entryServiceInstanceId: nq 0} diff --git a/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java index 762ada1a..99b97932 100644 --- a/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java +++ b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java @@ -50,7 +50,7 @@ public class CaseController { @PostConstruct private void setUp() { - topicName = "persistent://public/default/test"; + topicName = "test"; } @RequestMapping("/pulsar-case") From 208af5a67c648f01a90a8cf8bd5f44b9003f4c7d Mon Sep 17 00:00:00 2001 From: lipenghui Date: Fri, 20 Sep 2019 18:37:42 +0800 Subject: [PATCH 04/10] Fix test issues --- pulsar-scenario/config/expectedData.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pulsar-scenario/config/expectedData.yaml b/pulsar-scenario/config/expectedData.yaml index 401f4eb2..acbd5b44 100644 --- a/pulsar-scenario/config/expectedData.yaml +++ b/pulsar-scenario/config/expectedData.yaml @@ -4,14 +4,14 @@ registryItems: instances: - {pulsar-scenario: nq 0} operationNames: - - pulsar-scenario: [Pulsar/persistent://public/default/test/Producer, /case/pulsar-case, Pulsar/persistent://public/default/test/Consumer/test] + - pulsar-scenario: [Pulsar/test/Producer, /case/pulsar-case, Pulsar/test/Consumer/test] segmentItems: - applicationCode: pulsar-scenario segmentSize: ge 3 segments: - segmentId: not null spans: - - operationName: Pulsar/persistent://public/default/test/Producer + - operationName: Pulsar/test/Producer operationId: 0 parentSpanId: 0 spanId: 1 @@ -64,7 +64,7 @@ segmentItems: - {parentEndpointId: 0, parentEndpoint: /case/pulsar-case, networkAddressId: 0, entryEndpointId: 0, refType: CrossThread, parentSpanId: 1, parentTraceSegmentId: '${pulsar-scenario[0]}', parentServiceInstanceId: nq 0, networkAddress: '', entryEndpoint: /case/pulsar-case, entryServiceInstanceId: nq 0 } - segmentId: not null spans: - - operationName: Pulsar/persistent://public/default/test/Consumer/test + - operationName: Pulsar/test/Consumer/test operationId: 0 parentSpanId: -1 spanId: 0 From e48edd689e17b3005a7c6e8761074f8eeac488b1 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Fri, 20 Sep 2019 19:19:20 +0800 Subject: [PATCH 05/10] Fix test issues --- pulsar-scenario/config/expectedData.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pulsar-scenario/config/expectedData.yaml b/pulsar-scenario/config/expectedData.yaml index acbd5b44..df39780d 100644 --- a/pulsar-scenario/config/expectedData.yaml +++ b/pulsar-scenario/config/expectedData.yaml @@ -18,7 +18,7 @@ segmentItems: spanLayer: MQ startTime: nq 0 endTime: nq 0 - componentId: 40 + componentId: 73 componentName: '' isError: false spanType: Exit @@ -52,7 +52,7 @@ segmentItems: spanLayer: Unknown startTime: nq 0 endTime: nq 0 - componentId: 40 + componentId: 73 componentName: '' isError: false spanType: Local @@ -71,7 +71,7 @@ segmentItems: spanLayer: MQ startTime: nq 0 endTime: nq 0 - componentId: 41 + componentId: 74 componentName: '' isError: false spanType: Entry From 8f05c4e3216417fe73595be7b7c870ded45de926 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Mon, 23 Sep 2019 17:23:00 +0800 Subject: [PATCH 06/10] Fix test issues --- .../pulsar/controller/CaseController.java | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java index 99b97932..2c99061a 100644 --- a/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java +++ b/pulsar-scenario/src/main/java/test/apache/skywalking/testcase/pulsar/controller/CaseController.java @@ -18,9 +18,8 @@ package test.apache.skywalking.testcase.pulsar.controller; - +import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import javax.annotation.PostConstruct; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -46,26 +45,22 @@ public class CaseController { @Value("${service.url:pulsar://127.0.0.1:6650}") private String serviceUrl; - private String topicName; - - @PostConstruct - private void setUp() { - topicName = "test"; - } - @RequestMapping("/pulsar-case") @ResponseBody - public String pulsarCase() throws PulsarClientException { + public String pulsarCase() throws PulsarClientException, InterruptedException { + + String topic = "test"; + PulsarClient pulsarClient = PulsarClient.builder() .serviceUrl(serviceUrl) .build(); Producer producer = pulsarClient.newProducer() - .topic(topicName) + .topic(topic) .create(); Consumer consumer = pulsarClient.newConsumer() - .topic(topicName) + .topic(topic) .subscriptionName("test") .subscribe(); @@ -75,17 +70,40 @@ public String pulsarCase() throws PulsarClientException { .property("TEST", "TEST") .send(); - Message msg = consumer.receive(3, TimeUnit.SECONDS); + CountDownLatch latch = new CountDownLatch(1); + + Thread t = new Thread(() -> { + try { + Message msg = consumer.receive(3, TimeUnit.SECONDS); + if (msg != null) { + String propertiesFormat = "key = %s, value = %s"; + StringBuilder builder = new StringBuilder(); + msg.getProperties().forEach((k, v) -> builder.append(String.format(propertiesFormat, k, v)).append(", ")); + logger.info("Received message with messageId = {}, key = {}, value = {}, properties = {}", + msg.getMessageId(), msg.getKey(), new String(msg.getValue()), builder.toString()); + + } + consumer.acknowledge(msg); + } catch (PulsarClientException e) { + logger.error("Receive message error", e); + } finally { + latch.countDown(); + } + }); + + t.start(); + + try { + latch.await(3, TimeUnit.SECONDS); + } catch (InterruptedException e) { + logger.error("Can get message from consumer", e); + t.interrupt(); + throw e; + } producer.close(); consumer.close(); - if (msg != null) { - logger.info("properties: {}", msg.getProperty("TEST")); - logger.info("messageId = {}, key = {}, value = {}", msg.getMessageId(), msg.getKey(), new String(msg.getValue())); - return String.format("Success, consumer received message with key=%s and value=%s", msg.getKey(), new String(msg.getValue())); - } else { - return "Failed, consumer can't receive the message in 3 seconds"; - } + return "Success"; } } From dbfd054408d456c9e50806509bf57504cc0cf2a4 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Mon, 23 Sep 2019 17:58:21 +0800 Subject: [PATCH 07/10] Fix tests issue --- pulsar-scenario/config/expectedData.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pulsar-scenario/config/expectedData.yaml b/pulsar-scenario/config/expectedData.yaml index df39780d..55ef539d 100644 --- a/pulsar-scenario/config/expectedData.yaml +++ b/pulsar-scenario/config/expectedData.yaml @@ -45,7 +45,7 @@ segmentItems: - {key: http.method, value: GET} - segmentId: not null spans: - - operationName: Pulsar/Producer/SendCallback + - operationName: Pulsar/Producer/Callback operationId: 0 parentSpanId: -1 spanId: 0 From 68798a99c55104fefe74377f403c50921cd37d84 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Mon, 23 Sep 2019 19:11:34 +0800 Subject: [PATCH 08/10] Fix tests issue --- pulsar-scenario/config/expectedData.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pulsar-scenario/config/expectedData.yaml b/pulsar-scenario/config/expectedData.yaml index 55ef539d..03d3472a 100644 --- a/pulsar-scenario/config/expectedData.yaml +++ b/pulsar-scenario/config/expectedData.yaml @@ -49,7 +49,7 @@ segmentItems: operationId: 0 parentSpanId: -1 spanId: 0 - spanLayer: Unknown + spanLayer: MQ startTime: nq 0 endTime: nq 0 componentId: 73 From 13ed35070219d03d4da11fdac42b1cde2775df27 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Mon, 23 Sep 2019 20:42:46 +0800 Subject: [PATCH 09/10] Fix tests issue --- pulsar-scenario/config/expectedData.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pulsar-scenario/config/expectedData.yaml b/pulsar-scenario/config/expectedData.yaml index 03d3472a..6d63862b 100644 --- a/pulsar-scenario/config/expectedData.yaml +++ b/pulsar-scenario/config/expectedData.yaml @@ -25,7 +25,7 @@ segmentItems: peer: pulsar://127.0.0.1:6650 peerId: 0 tags: - - {key: mq.broker, value: 'pulsar://127.0.0.1:6650'} + - {key: mq.broker, value: not null} - {key: mq.topic, value: 'test'} - operationName: /case/pulsar-case operationId: 0 @@ -78,7 +78,7 @@ segmentItems: peer: '' peerId: 0 tags: - - {key: mq.broker, value: 'pulsar://127.0.0.1:6650'} + - {key: mq.broker, value: not null} - {key: mq.topic, value: 'test'} refs: - {parentEndpointId: 0, parentEndpoint: /case/pulsar-case, networkAddressId: 0, entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: '${pulsar-scenario[0]}', parentServiceInstanceId: nq 0, networkAddress: 'pulsar://127.0.0.1:6650', entryEndpoint: /case/pulsar-case, entryServiceInstanceId: nq 0} From a5731397356122ee0868a9b107f7ded28e46dd03 Mon Sep 17 00:00:00 2001 From: lipenghui Date: Tue, 24 Sep 2019 10:35:41 +0800 Subject: [PATCH 10/10] Fix tests issue --- pulsar-scenario/config/expectedData.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pulsar-scenario/config/expectedData.yaml b/pulsar-scenario/config/expectedData.yaml index 6d63862b..4b13c689 100644 --- a/pulsar-scenario/config/expectedData.yaml +++ b/pulsar-scenario/config/expectedData.yaml @@ -22,7 +22,7 @@ segmentItems: componentName: '' isError: false spanType: Exit - peer: pulsar://127.0.0.1:6650 + peer: not null peerId: 0 tags: - {key: mq.broker, value: not null} @@ -81,4 +81,4 @@ segmentItems: - {key: mq.broker, value: not null} - {key: mq.topic, value: 'test'} refs: - - {parentEndpointId: 0, parentEndpoint: /case/pulsar-case, networkAddressId: 0, entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: '${pulsar-scenario[0]}', parentServiceInstanceId: nq 0, networkAddress: 'pulsar://127.0.0.1:6650', entryEndpoint: /case/pulsar-case, entryServiceInstanceId: nq 0} + - {parentEndpointId: 0, parentEndpoint: /case/pulsar-case, networkAddressId: 0, entryEndpointId: 0, refType: CrossProcess, parentSpanId: 1, parentTraceSegmentId: '${pulsar-scenario[0]}', parentServiceInstanceId: nq 0, networkAddress: not null, entryEndpoint: /case/pulsar-case, entryServiceInstanceId: nq 0}