From 4beaac001be40fd9bd5d0d095323e4077e352a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E5=8B=87=E5=8D=87=20pengys?= <8082209@qq.com> Date: Wed, 10 Apr 2019 10:15:54 +0800 Subject: [PATCH] Integration test for elastic search client. (#2464) * Integration test for elastic search client. * Just test verify command. * CI command order change. * Remove maven clean. * no message * Create Jenkinsfile to try the apache build for our CI. --- .travis.yml | 5 +- Jenkinsfile | 73 +++++++++++++++++++ oap-server/pom.xml | 40 +++++++++- .../server-library/library-client/pom.xml | 51 ++++++++++++- .../elasticsearch/ITElasticSearchClient.java | 46 ++++++++++++ .../src/test/resources/log4j2.xml | 31 ++++++++ 6 files changed, 241 insertions(+), 5 deletions(-) create mode 100644 Jenkinsfile create mode 100644 oap-server/server-library/library-client/src/test/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ITElasticSearchClient.java create mode 100644 oap-server/server-library/library-client/src/test/resources/log4j2.xml diff --git a/.travis.yml b/.travis.yml index 6255a9d0f..2eebca22b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,5 @@ language: java install: - jdk_switcher use oraclejdk8 - - ./mvnw clean install -Dmaven.test.skip=true --quiet - - ./mvnw javadoc:javadoc -Dmaven.test.skip=true --quiet - - ./mvnw org.jacoco:jacoco-maven-plugin:0.8.3:prepare-agent test org.jacoco:jacoco-maven-plugin:0.8.3:report coveralls:report --quiet + - ./mvnw org.jacoco:jacoco-maven-plugin:0.8.3:prepare-agent clean install org.jacoco:jacoco-maven-plugin:0.8.3:report coveralls:report --quiet + - ./mvnw javadoc:javadoc -Dmaven.test.skip=true --quiet \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..255dfb938 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +pipeline { + agent { + label 'ubuntu' + } + + tools { + jdk 'JDK 1.8 (latest)' + } + + options { + buildDiscarder(logRotator( + numToKeepStr: '30', + )) + timestamps() + skipStagesAfterUnstable() + timeout time: 30, unit: 'MINUTES' + } + + stages { + stage('SCM Checkout') { + steps { + deleteDir() + checkout scm + } + } + + stage('Check environment') { + steps { + sh 'env' + sh 'pwd' + sh 'ls' + sh 'git status' + } + } + + stage('Run install') { + steps { + sh './mvnw org.jacoco:jacoco-maven-plugin:0.8.3:prepare-agent clean install org.jacoco:jacoco-maven-plugin:0.8.3:report coveralls:report --quiet --batch-mode -nsu' + } + } + + stage('Run install') { + steps { + sh './mvnw javadoc:javadoc -Dmaven.test.skip=true --quiet' + } + } + } + + post { + always { + junit '**/target/surefire-reports/*.xml' + deleteDir() + } + } +} \ No newline at end of file diff --git a/oap-server/pom.xml b/oap-server/pom.xml index dba03700a..07e9640d5 100644 --- a/oap-server/pom.xml +++ b/oap-server/pom.xml @@ -17,7 +17,8 @@ ~ --> - + apm org.apache.skywalking @@ -69,6 +70,8 @@ 2.9.1 2.6.2 3.9.0 + + 0.28.0 @@ -322,4 +325,39 @@ + + + + + + io.fabric8 + docker-maven-plugin + ${maven-docker-plugin.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + IT*.class + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + \ No newline at end of file diff --git a/oap-server/server-library/library-client/pom.xml b/oap-server/server-library/library-client/pom.xml index 50b33191d..0e6955adf 100644 --- a/oap-server/server-library/library-client/pom.xml +++ b/oap-server/server-library/library-client/pom.xml @@ -17,7 +17,8 @@ ~ --> - + server-library org.apache.skywalking @@ -54,4 +55,52 @@ jcl-over-slf4j + + + + + io.fabric8 + docker-maven-plugin + + all + default + true + IfNotPresent + + + + prepare-elasticsearch + pre-integration-test + + start + + + + + elastic/elasticsearch:${elasticsearch.version} + elastic-client-integration-test + + + 9200:9200 + + + started + + + + + + + + + remove-it-database + post-integration-test + + stop + + + + + + \ No newline at end of file diff --git a/oap-server/server-library/library-client/src/test/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ITElasticSearchClient.java b/oap-server/server-library/library-client/src/test/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ITElasticSearchClient.java new file mode 100644 index 000000000..7bacf5875 --- /dev/null +++ b/oap-server/server-library/library-client/src/test/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ITElasticSearchClient.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.server.library.client.elasticsearch; + +import java.io.IOException; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.common.xcontent.*; +import org.junit.*; + +/** + * @author peng-yongsheng + */ +public class ITElasticSearchClient { + + @Test + public void test() throws IOException { + ElasticSearchClient client = new ElasticSearchClient("localhost:9200", null, null, null); + client.connect(); + + XContentBuilder builder = XContentFactory.jsonBuilder().startObject(); + builder.field("key", "value"); + builder.endObject(); + client.forceInsert("test_index", "201904091521", builder); + + GetResponse response = client.get("test_index", "201904091521"); + + Assert.assertTrue(response.getSource().containsKey("key")); + Assert.assertEquals("value", response.getSource().get("key")); + } +} diff --git a/oap-server/server-library/library-client/src/test/resources/log4j2.xml b/oap-server/server-library/library-client/src/test/resources/log4j2.xml new file mode 100644 index 000000000..6eb5b3fb9 --- /dev/null +++ b/oap-server/server-library/library-client/src/test/resources/log4j2.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + +