提交 72153230 编写于 作者: D Daming 提交者: wu-sheng

[test/plugin]support plugin testcases run in docker-compose (#3612)

* support docker-compose

* sync

* support docker-compose

* force rm container

* solrj-7.x-scenario

* fix license header

* fix actualData.yml

* verify Jenkins run on distribution

* test Jenkinsfile v2

* test Jenkinsfile v3, God bless

* test V4, God Bless

* test v5

* rollback

* update opertaion of post
上级 7e7ab42e
......@@ -70,12 +70,6 @@ pipeline {
}
}
stage('dubbo 2.5.x-2.6.x (10)') {
steps {
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} dubbo-2.5.x-scenario'
}
}
stage('dubbo 2.7.x (4)') {
steps {
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} dubbo-2.7.x-scenario'
......@@ -103,7 +97,7 @@ pipeline {
}
post {
always {
cleanup {
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} --cleanup'
deleteDir()
}
......
/*
* 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 'skywalking'
}
options {
timestamps()
timeout(time: 5, unit: 'HOURS')
}
tools {
jdk 'JDK 1.8 (latest)'
}
environment {
MAVEN_OPTS = '-Dmaven.repo.local=.m2/repository -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:-UseGCOverheadLimit -Xmx3g'
}
stages {
stage('Checkout Source Code') {
steps {
deleteDir()
checkout scm
sh 'git submodule update --init'
}
}
stage('Compile agent Codes') {
steps {
sh './mvnw -Pagent clean package -DskipTests'
}
}
stage('Compile plugin-test tools Codes') {
steps {
sh './mvnw -f test/plugin/pom.xml clean package -DskipTests -Dbuild_id=${BUILD_ID} docker:build'
}
}
stage('Run Agent Plugin Tests') {
parallel {
stage('Group1') {
stages {
stage('dubbo 2.5.x-2.6.x (10)') {
steps {
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} dubbo-2.5.x-scenario'
}
}
}
}
stage('Group2') {
stages {
stage('solrj 7.x (12)') {
steps {
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} solrj-7.x-scenario'
}
}
}
}
}
}
}
post {
cleanup {
sh 'bash test/plugin/run.sh --build_id=${BUILD_ID} --cleanup'
deleteDir()
}
}
}
\ No newline at end of file
......@@ -97,7 +97,7 @@ pipeline {
}
post {
always {
cleanup {
// "Abort old build on update" will interrupt the job completely,
// we need to clean up when there are containers started by the e2e tests
sh 'docker ps'
......
......@@ -31,6 +31,7 @@ function exitAndClean() {
function healthCheck() {
HEALTH_CHECK_URL=$1
STATUS_CODE="-1"
for ((i=1; i<=30; i++));
do
......@@ -42,7 +43,7 @@ function healthCheck() {
sleep 2
done
exitOnError "${SCENARIO_NAME}-${SCENARIO_VERSION} health check failed!"
exitOnError "${SCENARIO_NAME}-${SCENARIO_VERSION} url=${HEALTH_CHECK_URL}, status=${STATUS_CODE} health check failed!"
}
if [[ -z "${SCENARIO_START_SCRIPT}" ]]; then
......
......@@ -31,7 +31,7 @@
<packaging>pom</packaging>
<modules>
<module>runner</module>
<module>runner-helper</module>
<module>validator</module>
<module>mock-collector</module>
<module>containers</module>
......
......@@ -110,7 +110,7 @@ waitForAvailable() {
do_cleanup() {
docker images -q "skywalking/agent-test-*:${build_id}" | xargs -r docker rmi -f
[[ -d ${home}/dist ]] && rm -rf ${home}/dist
[[ -d ${home}/workspce ]] && rm -rf ${home}/workspace
[[ -d ${home}/workspace ]] && rm -rf ${home}/workspace
}
start_stamp=`date +%s`
......@@ -132,9 +132,9 @@ task_state_house="${workspace}/.states"
[[ -d ${workspace} ]] && rm -rf $workspace
mkdir -p ${task_state_house}
plugin_autotest_helper="${home}/dist/plugin-autotest-helper.jar"
if [[ ! -f ${plugin_autotest_helper} ]]; then
exitWithMessage "Plugin autotest tools not exists, Please re-try it with '-f'"
plugin_runner_helper="${home}/dist/plugin-runner-helper.jar"
if [[ ! -f ${plugin_runner_helper} ]]; then
exitWithMessage "Plugin Runner tools not exists, Please re-try it with '-f'"
print_helper
fi
......@@ -174,7 +174,7 @@ do
-Doutput.dir=${case_work_base} \
-Dagent.dir=${agent_home} \
-Ddocker.image.version=${build_id} \
${plugin_autotest_helper} 1>${case_work_logs_dir}/helper.log
${plugin_runner_helper} 1>${case_work_logs_dir}/helper.log
[[ $? -ne 0 ]] && exitWithMessage "${testcase_name}, generate script failure!"
......
......@@ -27,8 +27,8 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>runner</artifactId>
<name>plugin-autotest-helper</name>
<artifactId>runner-helper</artifactId>
<name>plugin-runner-helper</name>
<dependencies>
<dependency>
......@@ -59,7 +59,7 @@
</dependencies>
<build>
<finalName>plugin-autotest-helper</finalName>
<finalName>plugin-runner-helper</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......
......@@ -19,7 +19,6 @@ package org.apache.skywalking.plugin.test.helper;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.UUID;
import org.apache.skywalking.plugin.test.helper.exception.ConfigureFileNotFoundException;
import org.apache.skywalking.plugin.test.helper.util.StringUtils;
......@@ -27,7 +26,6 @@ import org.apache.skywalking.plugin.test.helper.vo.CaseConfiguration;
import org.yaml.snakeyaml.Yaml;
public class ConfigurationImpl implements IConfiguration {
private CaseConfiguration configuration;
private final String scenarioHome;
......@@ -55,7 +53,7 @@ public class ConfigurationImpl implements IConfiguration {
@Override public ScenarioRunningScriptGenerator scenarioGenerator() {
switch (runningType()) {
case DockerCompose:
return new DockerComposeV2RunningGenerator();
return new DockerComposeRunningGenerator();
case Container:
return new DockerContainerRunningGenerator();
default:
......@@ -108,9 +106,10 @@ public class ConfigurationImpl implements IConfiguration {
return System.getProperty("docker.image.version", "latest");
}
@Override
public String dockerContainerName() {
return scenarioName() + "-" + scenarioVersion() + "-" + Long.toHexString(System.nanoTime());
return scenarioName() + "-" + scenarioVersion() + "-" + dockerImageVersion();
}
@Override public String scenarioHome() {
......@@ -120,4 +119,5 @@ public class ConfigurationImpl implements IConfiguration {
@Override public String outputDir(){
return System.getProperty("output.dir");
}
}
......@@ -28,16 +28,17 @@ import org.apache.skywalking.plugin.test.helper.vo.DockerService;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DockerComposeV2RunningGenerator extends AbstractRunningGenerator {
public class DockerComposeRunningGenerator extends AbstractRunningGenerator {
private static Logger logger = LogManager.getLogger(MethodHandles.lookup().lookupClass());
protected DockerComposeV2RunningGenerator() {
protected DockerComposeRunningGenerator() {
}
@Override
......@@ -49,19 +50,26 @@ public class DockerComposeV2RunningGenerator extends AbstractRunningGenerator {
root.put("scenario_name", configuration.scenarioName());
root.put("scenario_version", configuration.scenarioVersion());
root.put("entry_service", configuration.entryService());
root.put("start_script", configuration.startScript());
root.put("health_check", configuration.healthCheck());
root.put("test_framework", configuration.testFramework());
root.put("expose", configuration.caseConfiguration().getExpose());
root.put("hostname", configuration.caseConfiguration().getHostname());
root.put("depends_on", configuration.caseConfiguration().getDepends_on());
root.put("environments", configuration.caseConfiguration().getEnvironment());
root.put("docker_image_name", configuration.dockerImageName());
root.put("docker_image_version", configuration.dockerImageVersion());
root.put("docker_container_name", configuration.dockerContainerName());
ArrayList<String> links = Lists.newArrayList();
configuration.caseConfiguration().getDependencies().forEach((k, service) -> {
links.add(service.getHost());
links.add(service.getHostname());
});
root.put("links", links);
root.put("services", convertDockerServices(configuration.caseConfiguration().getDependencies()));
root.put("services", convertDockerServices(configuration.scenarioVersion(),
configuration.caseConfiguration().getDependencies()));
Configuration cfg = new Configuration(Configuration.VERSION_2_3_28);
try {
......@@ -81,28 +89,46 @@ public class DockerComposeV2RunningGenerator extends AbstractRunningGenerator {
}
}
protected List<DockerService> convertDockerServices(Map<String, DependencyComponent> componentMap) {
protected List<DockerService> convertDockerServices(final String version, Map<String, DependencyComponent> componentMap) {
ArrayList<DockerService> services = Lists.newArrayList();
componentMap.forEach((name, dependency) -> {
DockerService service = new DockerService();
String imageName = dependency.getImage()
.replace("${CASE_SERVER_IMAGE_VERSION}", version);
service.setName(name);
service.setVersion(dependency.getVersion());
service.setImage(dependency.getImage());
service.setHost(dependency.getHost());
service.setExpose(nullToEmpty(dependency.getExpose()));
service.setVolumes(nullToEmpty(dependency.getVolumes()));
service.setEnvironments(nullToEmpty(dependency.getEnvironment()));
service.setImageName(imageName);
service.setExpose(dependency.getExpose());
service.setLinks(dependency.getDepends_on());
service.setHostname(dependency.getHostname());
service.setDepends_on(dependency.getDepends_on());
service.setEntrypoint(dependency.getEntrypoint());
service.setHealthcheck(dependency.getHealthcheck());
service.setEnvironment(dependency.getEnvironment());
services.add(service);
});
return services;
}
private static final List<String> nullToEmpty(List<String> list) {
return list == null ? Lists.newArrayList() : list;
}
@Override
public String runningScript(IConfiguration configuration) {
return String.format("docker-compose -f %s up", configuration.outputDir() + File.separator +
"docker-compose.yml");
String docker_compose_file = configuration.outputDir() + File.separator + "docker-compose.yml";
Map<String, Object> root = new HashMap<>();
root.put("scenario_name", configuration.scenarioName());
root.put("scenario_home", configuration.scenarioHome());
root.put("scenario_version", configuration.scenarioVersion());
root.put("docker_compose_file", docker_compose_file);
root.put("build_id", configuration.dockerImageVersion());
root.put("docker_container_name", configuration.dockerContainerName());
StringWriter out = null;
try {
out = new StringWriter();
cfg.getTemplate("compose-start-script.template").process(root, out);
} catch (Exception e) {
logger.error("Failed to generate running script.", e);
}
return out.toString();
}
}
......@@ -24,10 +24,12 @@ public class CaseConfiguration {
private String entryService;
private String healthCheck;
private String framework;
@Deprecated private String version;
private String hostname;
private String startScript;
private Map<String, DependencyComponent> dependencies;
private List<String> environment;
private List<String> expose;
private List<String> depends_on;
public String getType() {
return type;
......@@ -45,6 +47,14 @@ public class CaseConfiguration {
this.entryService = entryService;
}
public String getHealthCheck() {
return healthCheck;
}
public void setHealthCheck(String healthCheck) {
this.healthCheck = healthCheck;
}
public String getFramework() {
return framework;
}
......@@ -53,12 +63,12 @@ public class CaseConfiguration {
this.framework = framework;
}
public String getVersion() {
return version;
public String getHostname() {
return hostname;
}
public void setVersion(String version) {
this.version = version;
public void setHostname(String hostname) {
this.hostname = hostname;
}
public String getStartScript() {
......@@ -77,14 +87,6 @@ public class CaseConfiguration {
this.dependencies = dependencies;
}
public String getHealthCheck() {
return healthCheck;
}
public void setHealthCheck(String healthCheck) {
this.healthCheck = healthCheck;
}
public List<String> getEnvironment() {
return environment;
}
......@@ -92,4 +94,20 @@ public class CaseConfiguration {
public void setEnvironment(List<String> environment) {
this.environment = environment;
}
public List<String> getExpose() {
return expose;
}
public void setExpose(List<String> expose) {
this.expose = expose;
}
public List<String> getDepends_on() {
return depends_on;
}
public void setDepends_on(List<String> depends_on) {
this.depends_on = depends_on;
}
}
......@@ -18,22 +18,16 @@ package org.apache.skywalking.plugin.test.helper.vo;
import java.util.List;
public class DependencyComponent implements DockerServiceReader {
public class DependencyComponent {
private String image;
private String host;
private String hostname;
private String version;
private List<String> links;
private List<String> expose;
private List<String> volumes;
private List<String> entrypoint;
private List<String> environment;
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
private List<String> depends_on;
private List<String> healthcheck;
public String getImage() {
return image;
......@@ -43,28 +37,28 @@ public class DependencyComponent implements DockerServiceReader {
this.image = image;
}
public String getHost() {
return host;
public String getHostname() {
return hostname;
}
public void setHost(String host) {
this.host = host;
public void setHostname(String hostname) {
this.hostname = hostname;
}
public List<String> getEnvironment() {
return environment;
public String getVersion() {
return version;
}
public void setEnvironment(List<String> environment) {
this.environment = environment;
public void setVersion(String version) {
this.version = version;
}
@Override public List<String> environment() {
return environment;
public List<String> getLinks() {
return links;
}
@Override public String image() {
return host;
public void setLinks(List<String> links) {
this.links = links;
}
public List<String> getExpose() {
......@@ -83,11 +77,27 @@ public class DependencyComponent implements DockerServiceReader {
this.entrypoint = entrypoint;
}
public List<String> getVolumes() {
return volumes;
public List<String> getEnvironment() {
return environment;
}
public void setEnvironment(List<String> environment) {
this.environment = environment;
}
public List<String> getDepends_on() {
return depends_on;
}
public void setDepends_on(List<String> depends_on) {
this.depends_on = depends_on;
}
public List<String> getHealthcheck() {
return healthcheck;
}
public void setVolumes(List<String> volumes) {
this.volumes = volumes;
public void setHealthcheck(List<String> healthcheck) {
this.healthcheck = healthcheck;
}
}
......@@ -16,21 +16,18 @@
*/
package org.apache.skywalking.plugin.test.helper.vo;
import com.google.common.collect.Lists;
import java.util.List;
public class DockerService {
private String name;
private String version;
private String image;
private String host;
private List<String> expose = Lists.newArrayList();
@Deprecated private List<String> ports;
private List<String> environments = Lists.newArrayList();
private List<String> volumes = Lists.newArrayList();
@Deprecated private List<String> links;
private String imageName;
private String hostname;
private List<String> links;
private List<String> expose;
private List<String> entrypoint;
private List<String> healthcheck;
private List<String> depends_on;
private List<String> environment;
public String getName() {
return name;
......@@ -40,67 +37,67 @@ public class DockerService {
this.name = name;
}
public String getVersion() {
return version;
public String getImageName() {
return imageName;
}
public void setVersion(String version) {
this.version = version;
public void setImageName(String imageName) {
this.imageName = imageName;
}
public String getImage() {
return image;
public String getHostname() {
return hostname;
}
public void setImage(String image) {
this.image = image;
public void setHostname(String hostname) {
this.hostname = hostname;
}
public List<String> getExpose() {
return expose;
public List<String> getLinks() {
return links;
}
public void setExpose(List<String> expose) {
this.expose = expose;
public void setLinks(List<String> links) {
this.links = links;
}
public List<String> getPorts() {
return ports;
public List<String> getExpose() {
return expose;
}
public void setPorts(List<String> ports) {
this.ports = ports;
public void setExpose(List<String> expose) {
this.expose = expose;
}
public List<String> getEnvironments() {
return environments;
public List<String> getEntrypoint() {
return entrypoint;
}
public void setEnvironments(List<String> environments) {
this.environments = environments;
public void setEntrypoint(List<String> entrypoint) {
this.entrypoint = entrypoint;
}
public List<String> getVolumes() {
return volumes;
public List<String> getHealthcheck() {
return healthcheck;
}
public void setVolumes(List<String> volumes) {
this.volumes = volumes;
public void setHealthcheck(List<String> healthcheck) {
this.healthcheck = healthcheck;
}
public List<String> getLinks() {
return links;
public List<String> getDepends_on() {
return depends_on;
}
public void setLinks(List<String> links) {
this.links = links;
public void setDepends_on(List<String> depends_on) {
this.depends_on = depends_on;
}
public String getHost() {
return host;
public List<String> getEnvironment() {
return environment;
}
public void setHost(String host) {
this.host = host;
public void setEnvironment(List<String> environment) {
this.environment = environment;
}
}
......@@ -15,15 +15,20 @@
~ limitations under the License.
-->
docker run -itd \
--name skywalking-agent-test-${scenario_name}-${scenario_version} \
--env SCENARIO_VERSION=${scenario_version} \
--env SCENARIO_SUPPORT_FRAMEWORK=${scenario_name} \
--env SCENARIO_ENTRY_SERVICE=${entry_service} \
--env SCENARIO_HEALTH_CHECK_URL=${health_check} \
-v ${agent_home}:/usr/local/skywalking-agent-scenario/agent \
-v ${scenario_home}/logs:/usr/local/skywalking-agent-scenario/logs \
-v ${scenario_home}/reports:/usr/local/skywalking-agent-scenario/reports \
-v ${scenario_home}/data:/usr/local/skywalking-agent-scenario/data \
-v ${scenario_home}/packages:/usr/local/skywalking-agent-scenario/packages \
${docker_image_name}:latest
compose_file="${docker_compose_file}"
project_name="${build_id}"
docker_container_name="${docker_container_name}_1"
<#noparse>
container_name="${project_name}_${docker_container_name}"
docker-compose -p ${project_name} -f ${compose_file} up -d
container=`docker ps -qf "name=${container_name}"`
status=`docker wait ${container}`
if [[ $status -ne 0 ]]; then
docker logs ${container} >&2
fi
docker-compose -p ${project_name} -f ${compose_file} kill
docker-compose -p ${project_name} -f ${compose_file} rm -f
</#noparse>
\ No newline at end of file
......@@ -14,49 +14,77 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
version: 2.1
version: '2.1'
services:
${docker_container_name}:
image: ${docker_image_name}:latest
<#if links?size \gt 0>
<#if hostname??>
hostname: ${hostname}
</#if>
<#if links??>
links:
<#list links as link>
- ${link}
</#list>
</#if>
environment:
<#if environments?size \gt 0>
<#if environments??>
<#list environments as env>
- ${env}
</#list>
</#if>
- SCENARIO_NAME:${scenario_name}
- SCENARIO_VERSION:${scenario_version}
- SCENARIO_ENTRY_SERVICE:${entry_service}
- SCENARIO_HEALTH_CHECK_URL:${health_check}
- SCENARIO_START_SCRIPT=${start_script}
- SCENARIO_NAME=${scenario_name}
- SCENARIO_VERSION=${scenario_version}
- SCENARIO_ENTRY_SERVICE=${entry_service}
- SCENARIO_HEALTH_CHECK_URL=${health_check}
volumes:
- ${agent_home}:/usr/local/skywalking-agent-scenario/agent
- ${scenario_home}:/usr/local/skywalking-agent-scenario
- ${agent_home}:/usr/local/skywalking/scenario/agent
- ${scenario_home}:/usr/local/skywalking/scenario
<#if depends_on??>
depends_on:
<#list depends_on as item>
- ${item}
</#list>
</#if>
<#list services as service>
${service.name}:
image: ${service.image}:${service.version}
host: ${service.host}
<#if service.volumes?size \gt 0>
image: ${service.imageName}
hostname: ${service.hostname}
<#if service.volumes??>
volumes:
<#list service.volumes as volume>
- ${volume}
</#list>
</#if>
<#if service.environments?size \gt 0>
environments:
<#if service.environments??>
environment:
<#list service.environments as environment>
- ${environment}
</#list>
</#if>
<#if service.expose?size \gt 0>
<#if service.expose??>
expose:
<#list service.expose as expose>
- ${expose}
</#list>
</#if>
<#if service.depends_on??>
depends_on:
<#list service.depends_on as item>
- ${item}
</#list>
</#if>
<#if service.entrypoint??>
entrypoint:
<#list service.entrypoint as item>
- ${item}
</#list>
</#if>
<#if service.healthcheck??>
healthcheck:
<#list service.healthcheck as item>
- ${item}
</#list>
</#if>
</#list>
\ No newline at end of file
......@@ -16,63 +16,48 @@
*/
package org.apache.skywalking.plugin.test.helper;
import java.io.File;
import java.io.InputStream;
import org.apache.skywalking.plugin.test.helper.exception.ConfigureFileNotFoundException;
import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException;
import org.apache.skywalking.plugin.test.helper.vo.CaseConfiguration;
import org.apache.skywalking.plugin.test.helper.vo.CaseIConfigurationTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.yaml.snakeyaml.Yaml;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileNotFoundException;
@RunWith(MockitoJUnitRunner.class)
public class DockerComposeRunningGeneratorTest {
import static org.junit.Assert.assertTrue;
public class DockerComposeV2RunningGeneratorTest {
private DockerComposeRunningGenerator dockerComposeRunningGenerator;
private InputStream configurationFile;
@Mock
private IConfiguration configuration;
public static final String TARGET_DIR = DockerComposeRunningGeneratorTest.class.getResource("/").getFile();
public static final String TARGET_DIR = DockerComposeV2RunningGeneratorTest.class.getResource("/").getFile();
@Before
public void setUp() {
public void setUp() throws FileNotFoundException, ConfigureFileNotFoundException {
dockerComposeRunningGenerator = new DockerComposeRunningGenerator();
when(configuration.outputDir()).thenReturn(TARGET_DIR);
when(configuration.agentHome()).thenReturn("/agent/path");
when(configuration.dockerImageName()).thenReturn("skyapm/agent-tomcat");
when(configuration.entryService()).thenReturn("http://localhost:8080/entryService");
when(configuration.healthCheck()).thenReturn("http://localhost:8080/healthCheck");
when(configuration.testFramework()).thenReturn("http");
when(configuration.scenarioVersion()).thenReturn("4.3.2");
System.setProperty("configure.file", TARGET_DIR + "configuration-test.yml");
System.setProperty("scenario.home", "/solrj-scenario");
System.setProperty("scenario.name", "solrj-scenario");
System.setProperty("scenario.version", "7.7.1");
System.setProperty("agent.dir", "/usr/local/skywalking-agent/");
System.setProperty("output.dir", TARGET_DIR);
configurationFile = CaseIConfigurationTest.class.getResourceAsStream("/configuration-test.yml");
assertNotNull(configurationFile);
when(configuration.caseConfiguration()).thenReturn(new Yaml().loadAs(configurationFile, CaseConfiguration.class));
configuration = new ConfigurationImpl();
}
@Test
public void testGenerateDockerCompose() {
String runningScript = dockerComposeRunningGenerator.runningScript(configuration);
assertEquals(String.format("docker-compose -f %s/docker-compose.template up", TARGET_DIR), runningScript);
// assertEquals(String.format("docker-compose -f %s/docker-compose.yml up", TARGET_DIR), runningScript);
}
@Test
public void testGenerateAdditionalFile() throws GenerateFailedException {
dockerComposeRunningGenerator.generateAdditionFiles(configuration);
assertTrue(new File(TARGET_DIR, "docker-compose.template").exists());
assertTrue(new File(TARGET_DIR, "docker-compose.yml").exists());
}
@After
......
......@@ -42,8 +42,7 @@ public class CaseIConfigurationTest {
CaseConfiguration caseConfiguration = yaml.loadAs(configurationFile, CaseConfiguration.class);
assertNotNull(caseConfiguration);
assertThat(caseConfiguration.getVersion(), is("4.0.3"));
assertThat(caseConfiguration.getFramework(), is("httpclient"));
assertThat(caseConfiguration.getFramework(), is("solrj"));
assertThat(caseConfiguration.getDependencies().size(), is(1));
}
}
# Licensed to the Apache 5Software Foundation (ASF) under one or more
# 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
......@@ -13,18 +13,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
type: tomcat
entryService: http://localhost:8080/solrj-7.x-scenario/case
type: jvm
entryService: http://localhost:8080/solrj-7.x-scenario/case/solrj
healthCheck: http://localhost:8080/solrj-7.x-scenario/heathcheck
startScript: ./bin/startup.sh
framework: solrj
environment:
- SOLR_SERVER=http://solr-server:8983
dependencies:
solr:
image: solr:${CASE_SERVER_IMAGE_VERSION}
host: solr-server
environment:
- a:b
hostname: solr-server
entrypoint:
- docker-entrypoint.sh
- solr-precreate
- mycore
volumes:
- c:d
/*
* 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.plugin.test.helper;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException;
import org.apache.skywalking.plugin.test.helper.vo.DockerCompose;
import org.apache.skywalking.plugin.test.helper.vo.DockerService;
import org.apache.skywalking.plugin.test.helper.vo.DockerServiceReader;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
public class DockerComposeRunningGenerator extends AbstractRunningGenerator {
@Override
public void generateAdditionFiles(IConfiguration configuration) throws GenerateFailedException {
DockerCompose dockerCompose = convertDockerCompose(configuration);
try {
getFileWriter().dump(dockerCompose, new FileWriter(new File(configuration.outputDir(), "docker-compose" +
".yml")));
} catch (IOException e) {
throw new GenerateFailedException();
}
}
private DockerCompose convertDockerCompose(IConfiguration configuration) {
DockerCompose dockerCompose = new DockerCompose();
dockerCompose.setVersion("2.1");
HashMap<String, DockerService> dockerServices = new HashMap<>();
DockerService container = new DockerService();
container.setImage(String.format("%s:latest", configuration.dockerImageName()));
configuration.caseConfiguration().getDependencies().forEach((name, dependencyComponent) -> {
DockerService dockerService = new DockerService();
DockerServiceReader serviceReader = dependencyComponent;
dockerService.setEnvironments(serviceReader.environment());
dockerService.setImage(serviceReader.image());
dockerServices.put(name, dockerService);
});
container.setLinks(new ArrayList<>(configuration.caseConfiguration().getDependencies().keySet()));
List<String> environment = new ArrayList<String>();
environment.add(String.format("SCENARIO_VERSION=%s", configuration.scenarioVersion()));
environment.add(String.format("SCENARIO_SUPPORT_FRAMEWORK=%s", configuration.testFramework()));
environment.add(String.format("SCENARIO_ENTRY_SERVICE=%s", configuration.entryService()));
environment.add(String.format("SCENARIO_HEALTH_CHECK_URL=%s", configuration.healthCheck()));
List<String> volumes = new ArrayList<>();
volumes.add(String.format("%s:/usr/local/skywalking-agent-scenario/agent", configuration.agentHome()));
container.setVolumes(volumes);
container.setEnvironments(environment);
dockerServices.put(String.format("skywalking-agent-test-%s-%s", configuration.testFramework(),
configuration.scenarioVersion())
, container);
dockerCompose.setServices(dockerServices);
return dockerCompose;
}
private Yaml getFileWriter() {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Representer representer = new Representer() {
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
Tag customTag) {
if (propertyValue == null) {
return null;
} else {
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
}
};
representer.addClassTag(DockerCompose.class, Tag.MAP);
return new Yaml(representer, dumperOptions);
}
@Override
public String runningScript(IConfiguration configuration) {
return String.format("docker-compose -f %s up", configuration.outputDir() + File.separator + "docker-compose" +
".yml");
}
}
/*
* 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.plugin.test.helper.vo;
import java.util.HashMap;
public class DockerCompose {
private String version;
private HashMap<String, DockerService> services;
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public HashMap<String, DockerService> getServices() {
return services;
}
public void setServices(HashMap<String, DockerService> services) {
this.services = services;
}
}
/*
* 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.plugin.test.helper;
import org.apache.skywalking.plugin.test.helper.exception.GenerateFailedException;
import org.apache.skywalking.plugin.test.helper.vo.CaseConfiguration;
import org.apache.skywalking.plugin.test.helper.vo.CaseIConfigurationTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.InputStream;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class DockerComposeV2RunningGeneratorTest {
private DockerComposeV2RunningGenerator dockerComposeRunningGenerator;
private InputStream configurationFile;
@Mock
private IConfiguration configuration;
public static final String TARGET_DIR = DockerComposeRunningGeneratorTest.class.getResource("/").getFile();
@Before
public void setUp() {
dockerComposeRunningGenerator = new DockerComposeV2RunningGenerator();
when(configuration.outputDir()).thenReturn(TARGET_DIR);
when(configuration.agentHome()).thenReturn("/agent/path");
when(configuration.dockerImageName()).thenReturn("skyapm/agent-tomcat");
when(configuration.entryService()).thenReturn("http://localhost:8080/entryService");
when(configuration.healthCheck()).thenReturn("http://localhost:8080/healthCheck");
when(configuration.testFramework()).thenReturn("http");
when(configuration.scenarioVersion()).thenReturn("4.3.2");
when(configuration.scenarioName()).thenReturn("http");
when(configuration.scenarioHome()).thenReturn("scenario_home");
when(configuration.dockerContainerName()).thenReturn("docker_container_name");
// when(configuration.serverAddr()).thenReturn("")
configurationFile = CaseIConfigurationTest.class.getResourceAsStream("/configuration-test.yml");
assertNotNull(configurationFile);
when(configuration.caseConfiguration()).thenReturn(new Yaml().loadAs(configurationFile, CaseConfiguration.class));
}
@Test
public void testGenerateDockerCompose() {
String runningScript = dockerComposeRunningGenerator.runningScript(configuration);
assertEquals(String.format("docker-compose -f %s/docker-compose.yml up", TARGET_DIR), runningScript);
}
@Test
public void testGenerateAdditionalFile() throws GenerateFailedException {
dockerComposeRunningGenerator.generateAdditionFiles(configuration);
assertTrue(new File(TARGET_DIR, "docker-compose.yml").exists());
}
@After
public void tearDown() {
}
}
/*
* 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.plugin.test.helper.vo;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class DockerComposeTest {
private InputStream dockerCompose;
private String writeFile;
@Before
public void setUp() {
writeFile = CaseIConfigurationTest.class.getResource("/").getFile() + "/file.yaml";
dockerCompose = CaseIConfigurationTest.class.getResourceAsStream("/docker-compose-test.yml");
assertNotNull(dockerCompose);
}
@Test
public void readDockerCompose() {
Yaml yaml = new Yaml();
DockerCompose dockerfile = yaml.loadAs(dockerCompose, DockerCompose.class);
assertNotNull(dockerfile);
assertThat(dockerfile.getServices().size(), is(2));
}
@Test
public void writeDockerCompose() throws IOException {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Representer representer = new Representer() {
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
Tag customTag) {
if (propertyValue == null) {
return null;
} else {
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
}
};
representer.addClassTag(DockerCompose.class, Tag.MAP);
Yaml yaml = new Yaml(representer, dumperOptions);
DockerCompose dockerfile = yaml.loadAs(dockerCompose, DockerCompose.class);
FileWriter writer = new FileWriter(writeFile);
yaml.dump(dockerfile, writer);
assertTrue(new File(writeFile).exists());
}
@After
public void tearDown(){
new File(writeFile).deleteOnExit();
}
}
#!/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/solrj-7.x-scenario.jar &
# 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:
- {solrj-7.x-scenario: nq 0}
instances:
- {solrj-7.x-scenario: nq 0}
operationNames:
- solrj-7.x-scenario: [/solrj-scenario/case/solrj, solrJ/mycore/update/COMMIT, solrJ/mycore/update/DELETE_BY_IDS,
solrJ/mycore/select, solrJ/mycore/update/DELETE_BY_QUERY, solrJ/mycore/get,
/solrj-scenario/case/healthcheck, solrJ/mycore/update/OPTIMIZE, solrJ/mycore/update/ADD]
heartbeat: []
segmentItems:
- applicationCode: solrj-7.x-scenario
segmentSize: 2
segments:
- segmentId: not null
spans:
- operationName: /solrj-scenario/case/healthcheck
operationId: 0
parentSpanId: -1
spanId: 0
spanLayer: Http
startTime: gt 0
endTime: gt 0
componentId: 1
componentName: ''
isError: false
spanType: Entry
peer: ''
peerId: 0
tags:
- {key: url, value: 'http://localhost:8080/solrj-scenario/case/healthcheck'}
- {key: http.method, value: HEAD}
- segmentId: not null
spans:
- operationName: solrJ/mycore/update/ADD
operationId: 0
parentSpanId: 0
spanId: 1
spanLayer: Database
startTime: gt 0
endTime: gt 0
componentId: 63
componentName: ''
isError: false
spanType: Exit
peer: solr-server:8983
peerId: 0
tags:
- {key: db.type, value: Solr}
- {key: QTime, value: gt 0}
- operationName: solrJ/mycore/update/COMMIT
operationId: 0
parentSpanId: 0
spanId: 2
spanLayer: Database
startTime: gt 0
endTime: gt 0
componentId: 63
componentName: ''
isError: false
spanType: Exit
peer: solr-server:8983
peerId: 0
tags:
- {key: db.type, value: Solr}
- {key: QTime, value: gt 0}
- operationName: solrJ/mycore/update/OPTIMIZE
operationId: 0
parentSpanId: 0
spanId: 3
spanLayer: Database
startTime: gt 0
endTime: gt 0
componentId: 63
componentName: ''
isError: false
spanType: Exit
peer: solr-server:8983
peerId: 0
tags:
- {key: db.type, value: Solr}
- {key: QTime, value: gt 0}
- operationName: solrJ/mycore/select
operationId: 0
parentSpanId: 0
spanId: 4
spanLayer: Database
startTime: gt 0
endTime: gt 0
componentId: 63
componentName: ''
isError: false
spanType: Exit
peer: solr-server:8983
peerId: 0
tags:
- {key: db.type, value: Solr}
- {key: start, value: '0'}
- {key: qt, value: /select}
- {key: numFound, value: '100'}
- operationName: solrJ/mycore/get
operationId: 0
parentSpanId: 0
spanId: 5
spanLayer: Database
startTime: gt 0
endTime: gt 0
componentId: 63
componentName: ''
isError: false
spanType: Exit
peer: solr-server:8983
peerId: 0
tags:
- {key: db.type, value: Solr}
- {key: start, value: '0'}
- {key: qt, value: /get}
- {key: numFound, value: '1'}
- operationName: solrJ/mycore/update/DELETE_BY_IDS
operationId: 0
parentSpanId: 0
spanId: 6
spanLayer: Database
startTime: gt 0
endTime: gt 0
componentId: 63
componentName: ''
isError: false
spanType: Exit
peer: solr-server:8983
peerId: 0
tags:
- {key: db.type, value: Solr}
- {key: QTime, value: 'gt 0'}
- operationName: solrJ/mycore/update/DELETE_BY_QUERY
operationId: 0
parentSpanId: 0
spanId: 7
spanLayer: Database
startTime: gt 0
endTime: gt 0
componentId: 63
componentName: ''
isError: false
spanType: Exit
peer: solr-server:8983
peerId: 0
tags:
- {key: db.type, value: Solr}
- {key: QTime, value: 'gt 0'}
- operationName: /solrj-scenario/case/solrj
operationId: 0
parentSpanId: -1
spanId: 0
spanLayer: Http
startTime: gt 0
endTime: gt 0
componentId: 1
componentName: ''
isError: false
spanType: Entry
peer: ''
peerId: 0
tags:
- {key: url, value: 'http://localhost:8080/solrj-scenario/case/solrj'}
- {key: http.method, value: GET}
\ No newline at end of file
# 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/solrj-scenario/case/solrj
healthCheck: http://localhost:8080/solrj-scenario/case/healthcheck
startScript: ./bin/startup.sh
framework: solrj
environment:
- SOLR_SERVER=solr-server:8983
dependencies:
solr-server:
image: solr:${CASE_SERVER_IMAGE_VERSION}
hostname: solr-server
entrypoint:
- docker-entrypoint.sh
- solr-precreate
- mycore
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.skywalking</groupId>
<artifactId>solrj-scenario</artifactId>
<version>5.0.0</version>
<name>skywalking-solrj-scenario</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<test.framework.version>7.7.1</test.framework.version>
<docker.image.version>${test.framework.version}</docker.image.version>
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
<lombok.version>1.16.20</lombok.version>
<log4j.version>2.6.2</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${test.framework.version}</version>
</dependency>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
<build>
<finalName>solrj-7.x-scenario</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.9.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assemble</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<#--
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
......@@ -13,46 +14,28 @@
~ 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.
-->
version: 2.1
services:
${docker_container_name}:
image: ${docker_image_name}:latest
<#if links?size \gt 0>
links:
<#list links as link>
- ${link}
</#list>
</#if>
environment:
- SERVER_ADDR:${server_addr}
- SCENARIO_NAME:${scenario_name}
- SCENARIO_VERSION:${scenario_version}
- SCENARIO_ENTRY_SERVICE:${entry_service}
- SCENARIO_HEALTH_CHECK_URL:${health_check}
volumes:
- ${agent_home}:/usr/local/skywalking-agent-scenario/agent
- ${scenario_home}:/usr/local/skywalking-agent-scenario
<#list services as service>
${service.name}:
image: ${service.image}:${service.version}
host: ${service.host}
<#if service.volumes?size \gt 0>
volumes:
<#list service.volumes as volume>
- ${volume}
</#list>
</#if>
<#if service.environments?size \gt 0>
environments:
<#list service.environments as environment>
- ${environment}
</#list>
</#if>
<#if service.expose?size \gt 0>
expose:
<#list service.expose as expose>
- ${expose}
</#list>
</#if>
</#list>
\ No newline at end of file
~
-->
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>./bin</directory>
<fileMode>0775</fileMode>
</fileSet>
</fileSets>
<files>
<file>
<source>${project.build.directory}/solrj-7.x-scenario.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
</files>
</assembly>
......@@ -13,14 +13,24 @@
* 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.plugin.test.helper.vo;
import java.util.List;
package org.apache.skywalking.apm.testcase.solrj;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
public interface DockerServiceReader {
List<String> environment();
@SpringBootApplication
public class Application {
String image();
public static void main(String[] args) {
try {
SpringApplication.run(Application.class, args);
} catch (Exception e) {
// Never do this
}
}
}
/*
* 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.solrj.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/solrj-scenario/case")
public class CaseController {
private Logger logger = LogManager.getLogger(CaseController.class);
@Value("${SOLR_SERVER}")
private String host;
private String collection = "mycore";
@GetMapping("/healthcheck")
public String healthcheck() throws Exception {
return "Success";
}
@GetMapping("/solrj")
public String solrj() throws SolrServerException, IOException {
HttpSolrClient client = getClient();
add(client);
commit(client);
optimize(client);
search(client);
get(client);
deleteById(client);
deleteByQuery(client);
client.close();
return "Success";
}
public String add(HttpSolrClient client) throws SolrServerException, IOException {
List<SolrInputDocument> docs = new ArrayList<>();
for (int i=0; i<100; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
docs.add(doc);
}
client.add(collection, docs);
return "Success";
}
public String commit(HttpSolrClient client) throws SolrServerException, IOException {
client.commit(collection);
return "Success";
}
public String optimize(HttpSolrClient client) throws SolrServerException, IOException {
client.optimize(collection);
return "Success";
}
public String search(HttpSolrClient client) throws IOException, SolrServerException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CommonParams.Q, "*:*");
params.set(CommonParams.OMIT_HEADER, true);
QueryResponse response = client.query(collection, params);
return "Success";
}
public String get(HttpSolrClient client) throws SolrServerException, IOException {
client.getById(collection, "1"); //
return "Success";
}
public String deleteById(HttpSolrClient client) throws SolrServerException, IOException {
client.deleteById(collection, "2"); //
return "Success";
}
public String deleteByQuery(HttpSolrClient client) throws SolrServerException, IOException {
client.deleteByQuery(collection, "*:*"); //
return "Success";
}
private final HttpSolrClient getClient() {
return new HttpSolrClient.Builder(String.format("http://%s/solr/", host)).build();
}
}
# 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
contextPath: /solrj-scenario
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_ERR">
<PatternLayout charset="UTF-8" pattern="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="WARN">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
# 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.
7.7.1
7.7.0
7.6.0
7.5.0
7.4.0
7.3.1
7.3.0
7.2.1
7.2.0
7.1.0
7.0.1
7.0.0
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册