Add plugin for Spring 6, set development baseline to JDK 17, remove Powermock entirely (#444)

This commit is contained in:
kezhenxu94 2023-01-31 19:29:32 +08:00 committed by GitHub
parent 8a7fe75624
commit 62266673ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
360 changed files with 4950 additions and 2247 deletions

View File

@ -44,19 +44,27 @@ runs:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-agent-test-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-agent-test-
- uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17
- name: Build SkyWalking Agent
shell: bash
run: |
echo "::group::Build SkyWalking Agent"
# Retry one more time due to frequent "maven connection reset"
./mvnw --batch-mode clean package -Dmaven.test.skip || \
./mvnw --batch-mode clean package -Dmaven.test.skip
./mvnw -q --batch-mode clean package -Dmaven.test.skip || \
./mvnw -q --batch-mode clean package -Dmaven.test.skip
echo "::endgroup::"
- uses: actions/upload-artifact@v2
name: Upload Agent
with:
name: skywalking-agent
path: skywalking-agent
- uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 8
- name: Build Docker Image
shell: bash
run: |

View File

@ -51,5 +51,11 @@ runs:
shell: bash
run: |
echo "::group::Run Plugin Test ${{ inputs.test_case }}"
bash test/plugin/run.sh --image_version=${{ inputs.java_version }}-1.0.0 ${{ inputs.test_case }}
bash test/plugin/run.sh ${{ inputs.test_case }}
echo "::endgroup::"
- uses: actions/upload-artifact@v2
name: Upload Agent
if: always()
with:
path: test/plugin/workspace
name: test-plugin-workspace-${{ inputs.test_case }}

View File

@ -20,9 +20,6 @@ on:
pull_request:
schedule:
- cron: '0 18 * * *' # TimeZone: UTC 0
push:
branches:
- test/ci/*
concurrency:
group: ci-it-${{ github.event.pull_request.number || github.ref }}
@ -51,10 +48,7 @@ jobs:
fail-fast: true
matrix:
os: [ ubuntu, macos, windows ]
java-version: [ 8 ]
include:
- os: ubuntu
java-version: 11
java-version: [ 17 ]
steps:
- uses: actions/checkout@v2
with:
@ -67,15 +61,11 @@ jobs:
restore-keys: ${{ runner.os }}-maven-ci-
- uses: actions/setup-java@v2
with:
distribution: adopt
distribution: temurin
java-version: ${{ matrix.java-version }}
- name: Check Javaagent Plugin List
run: tools/plugin/check-javaagent-plugin-list.sh
- name: Install and Test
if: matrix.java-version == '8' && matrix.os != 'windows'
run: ./mvnw -q --batch-mode clean verify install javadoc:javadoc
- name: Install and Test
if: matrix.java-version == '11' || matrix.os == 'windows'
run: ./mvnw -q --batch-mode clean verify install
ci:

View File

@ -48,6 +48,11 @@ jobs:
with:
submodules: true
- uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:

View File

@ -37,14 +37,19 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17
- name: Build SkyWalking agent docker image
run: make build docker.java8
- name: Build consumer & provider images
shell: bash
run: |
echo "::group::Install SNAPSHOT apm-application-toolkit"
./mvnw -DskipTests -N install
./mvnw -f apm-application-toolkit -DskipTests -am install
./mvnw -B -Dmaven.test.skip -N install
./mvnw -B -pl :apm-test-tools -Dmaven.test.skip -am install
./mvnw -B -f apm-application-toolkit -Dmaven.test.skip -am install
echo "::endgroup::"
echo "::group::"
SW_VERSION=$(./mvnw -q -DforceStdout -N org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version)

View File

@ -27,9 +27,6 @@ on:
- 'test/plugin/**'
- '**/pom.xml'
- '!**.md'
push:
branches:
- test/ci/*
concurrency:
group: plugins-jdk17-${{ github.event.pull_request.number || github.ref }}

View File

@ -0,0 +1,70 @@
# 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.
name: Test
on:
pull_request:
paths:
- '.github/workflows/plugins-*.yaml'
- 'apm-application-toolkit/**'
- 'apm-commons/**'
- 'apm-protocol/**'
- 'apm-sniffer/**'
- 'test/plugin/**'
- '**/pom.xml'
- '!**.md'
concurrency:
group: plugins-jdk17-1-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Build
uses: ./.github/actions/build
with:
base_image_java: eclipse-temurin:17-jdk
base_image_tomcat: tomcat:10.1-jdk17-temurin
test:
needs: [ build ]
name: ${{ matrix.case }}
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
matrix:
case:
- spring-6.x-scenario
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Run Test
uses: ./.github/actions/run
with:
test_case: ${{ matrix.case }}

View File

@ -27,9 +27,6 @@ on:
- 'test/plugin/**'
- '**/pom.xml'
- '!**.md'
push:
branches:
- test/ci/*
concurrency:
group: plugins-0-${{ github.event.pull_request.number || github.ref }}
@ -95,7 +92,7 @@ jobs:
submodules: true
- uses: actions/setup-java@v2
with:
distribution: adopt
distribution: temurin
java-version: 8
- name: Run Plugin Test
uses: ./.github/actions/run

View File

@ -27,9 +27,6 @@ on:
- 'test/plugin/**'
- '**/pom.xml'
- '!**.md'
push:
branches:
- test/ci/*
concurrency:
group: plugins-1-${{ github.event.pull_request.number || github.ref }}
@ -87,7 +84,7 @@ jobs:
submodules: true
- uses: actions/setup-java@v2
with:
distribution: adopt
distribution: temurin
java-version: 8
- name: Run Plugin Test
uses: ./.github/actions/run

View File

@ -27,9 +27,6 @@ on:
- 'test/plugin/**'
- '**/pom.xml'
- '!**.md'
push:
branches:
- test/ci/*
concurrency:
group: plugins-2-${{ github.event.pull_request.number || github.ref }}
@ -86,7 +83,7 @@ jobs:
submodules: true
- uses: actions/setup-java@v2
with:
distribution: adopt
distribution: temurin
java-version: 8
- name: Run Plugin Test
uses: ./.github/actions/run

View File

@ -27,9 +27,6 @@ on:
- 'test/plugin/**'
- '**/pom.xml'
- '!**.md'
push:
branches:
- test/ci/*
concurrency:
group: plugins-3-${{ github.event.pull_request.number || github.ref }}
@ -114,7 +111,7 @@ jobs:
submodules: true
- uses: actions/setup-java@v2
with:
distribution: adopt
distribution: temurin
java-version: 8
- name: Install Oracle Libs
if: matrix.case == 'oracle-scenario'

View File

@ -27,9 +27,6 @@ on:
- 'test/plugin/**'
- '**/pom.xml'
- '!**.md'
push:
branches:
- test/ci/*
concurrency:
group: plugins-tomcat10-${{ github.event.pull_request.number || github.ref }}
@ -64,7 +61,7 @@ jobs:
submodules: true
- uses: actions/setup-java@v2
with:
distribution: adopt
distribution: temurin
java-version: 8
- name: Run Plugin Test
uses: ./.github/actions/run

View File

@ -22,6 +22,7 @@ header:
copyright-owner: Apache Software Foundation
paths-ignore:
- 'org.mockito.plugins.MockMaker'
- '.github/PULL_REQUEST_TEMPLATE'
- '**/.gitignore'
- '.gitmodules'

View File

@ -6,7 +6,10 @@ Release Notes.
------------------
* Enhance lettuce plugin to adopt uniform tags.
* Expose complete Tracing APIs in the tracing toolkit
* Expose complete Tracing APIs in the tracing toolkit.
* Add plugin to trace Spring 6 and Resttemplate 6.
* Move the baseline to JDK 17 for development, the runtime baseline is still Java 8 compatible.
* Remove Powermock entirely from the test cases.
#### Documentation
* Update docs of Tracing APIs, reorganize the API docs into six parts

View File

@ -44,5 +44,11 @@
<artifactId>micrometer-core</artifactId>
<version>${micrometer-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-test-tools</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -18,17 +18,16 @@
package org.apache.skywalking.apm.meter.micrometer;
import io.micrometer.core.instrument.Counter;
import java.util.Arrays;
import org.apache.skywalking.apm.agent.test.helper.FieldGetter;
import org.junit.Assert;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
import java.util.Arrays;
import io.micrometer.core.instrument.Counter;
public class SkywalkingCounterTest {
@Test
public void testCounter() {
public void testCounter() throws IllegalAccessException, NoSuchFieldException {
// Creating a simplified micrometer counter
final SkywalkingMeterRegistry registry = new SkywalkingMeterRegistry();
Counter counter = registry.counter("test_counter", "skywalking", "test");
@ -36,21 +35,19 @@ public class SkywalkingCounterTest {
// Check Skywalking counter type
Assert.assertTrue(counter instanceof SkywalkingCounter);
final SkywalkingCounter skywalkingCounter = (SkywalkingCounter) counter;
final org.apache.skywalking.apm.toolkit.meter.Counter realCounter =
Whitebox.getInternalState(skywalkingCounter, "counter");
final org.apache.skywalking.apm.toolkit.meter.Counter realCounter = FieldGetter.getValue(skywalkingCounter, "counter");
Assert.assertNotNull(realCounter);
}
@Test
public void testRateCounter() {
public void testRateCounter() throws IllegalAccessException, NoSuchFieldException {
final SkywalkingMeterRegistry registry = new SkywalkingMeterRegistry(new SkywalkingConfig(Arrays.asList("test_rate_counter")));
final Counter counter = registry.counter("test_rate_counter", "skywalking", "test");
// Check Skywalking counter type
Assert.assertTrue(counter instanceof SkywalkingCounter);
final SkywalkingCounter skywalkingCounter = (SkywalkingCounter) counter;
final org.apache.skywalking.apm.toolkit.meter.Counter realCounter =
Whitebox.getInternalState(skywalkingCounter, "counter");
final org.apache.skywalking.apm.toolkit.meter.Counter realCounter = FieldGetter.getValue(skywalkingCounter, "counter");
Assert.assertNotNull(realCounter);
}
}

View File

@ -88,7 +88,6 @@ public class SkywalkingMeterRegistryTest {
.register(registry);
}
/**
* Working on {@link io.micrometer.core.instrument.Gauge} check
*/

View File

@ -33,6 +33,12 @@
<artifactId>jmh-generator-annprocess</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-junit4</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -29,43 +29,37 @@ import org.apache.skywalking.apm.commons.datacarrier.partition.ProducerThreadPar
import org.apache.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner;
import org.junit.Assert;
import org.junit.Test;
import org.powermock.api.support.membermodification.MemberModifier;
public class DataCarrierTest {
@Test
public void testCreateDataCarrier() throws IllegalAccessException {
public void testCreateDataCarrier() throws IllegalAccessException, NoSuchFieldException {
DataCarrier<SampleData> carrier = new DataCarrier<>(5, 100, BufferStrategy.IF_POSSIBLE);
Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels")
.get(carrier));
Channels<SampleData> channels = FieldGetter.getValue(carrier, "channels");
Assert.assertEquals(5, channels.getChannelSize());
QueueBuffer<SampleData> buffer = channels.getBuffer(0);
Assert.assertEquals(100, buffer.getBufferSize());
Assert.assertEquals(MemberModifier.field(buffer.getClass(), "strategy").get(buffer), BufferStrategy.IF_POSSIBLE);
Assert.assertEquals(MemberModifier.field(buffer.getClass(), "strategy")
.get(buffer), BufferStrategy.IF_POSSIBLE);
Assert.assertEquals(FieldGetter.getValue(buffer, "strategy"), BufferStrategy.IF_POSSIBLE);
Assert.assertEquals(FieldGetter.getValue(buffer, "strategy"), BufferStrategy.IF_POSSIBLE);
Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner")
.get(channels)
.getClass(), SimpleRollingPartitioner.class);
Assert.assertEquals(FieldGetter.getValue(channels, "dataPartitioner")
.getClass(), SimpleRollingPartitioner.class);
carrier.setPartitioner(new ProducerThreadPartitioner<SampleData>());
Assert.assertEquals(MemberModifier.field(Channels.class, "dataPartitioner")
.get(channels)
.getClass(), ProducerThreadPartitioner.class);
Assert.assertEquals(FieldGetter.getValue(channels, "dataPartitioner")
.getClass(), ProducerThreadPartitioner.class);
}
@Test
public void testProduce() throws IllegalAccessException {
public void testProduce() throws IllegalAccessException, NoSuchFieldException {
DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100);
Assert.assertTrue(carrier.produce(new SampleData().setName("a")));
Assert.assertTrue(carrier.produce(new SampleData().setName("b")));
Assert.assertTrue(carrier.produce(new SampleData().setName("c")));
Assert.assertTrue(carrier.produce(new SampleData().setName("d")));
Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels")
.get(carrier));
Channels<SampleData> channels = FieldGetter.getValue(carrier, "channels");
QueueBuffer<SampleData> buffer1 = channels.getBuffer(0);
List result = new ArrayList();
@ -80,7 +74,7 @@ public class DataCarrierTest {
}
@Test
public void testIfPossibleProduce() throws IllegalAccessException {
public void testIfPossibleProduce() throws IllegalAccessException, NoSuchFieldException {
DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100, BufferStrategy.IF_POSSIBLE);
for (int i = 0; i < 200; i++) {
@ -91,8 +85,7 @@ public class DataCarrierTest {
Assert.assertFalse(carrier.produce(new SampleData().setName("d" + i + "_2")));
}
Channels<SampleData> channels = (Channels<SampleData>) (MemberModifier.field(DataCarrier.class, "channels")
.get(carrier));
Channels<SampleData> channels = FieldGetter.getValue(carrier, "channels");
QueueBuffer<SampleData> buffer1 = channels.getBuffer(0);
List result = new ArrayList();
buffer1.obtain(result);

View File

@ -18,29 +18,25 @@
package org.apache.skywalking.apm.commons.datacarrier;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
import uk.org.webcompere.systemstubs.rules.EnvironmentVariablesRule;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
@RunWith(PowerMockRunner.class)
@PrepareForTest(EnvUtil.class)
@RunWith(MockitoJUnitRunner.class)
public class EnvUtilTest {
@Rule
public EnvironmentVariablesRule environmentVariablesRule = new EnvironmentVariablesRule();
@Before
public void before() {
PowerMockito.mockStatic(System.class);
when(System.getenv("myInt")).thenReturn("123");
when(System.getenv("wrongInt")).thenReturn("wrong123");
when(System.getenv("myLong")).thenReturn("12345678901234567");
when(System.getenv("wrongLong")).thenReturn("wrong123");
environmentVariablesRule.set("myInt", "123");
environmentVariablesRule.set("wrongInt", "wrong123");
environmentVariablesRule.set("myLong", "12345678901234567");
environmentVariablesRule.set("wrongLong", "wrong123");
}
@Test
@ -55,4 +51,4 @@ public class EnvUtilTest {
assertEquals(987654321987654321L, EnvUtil.getLong("wrongLong", 987654321987654321L));
}
}
}

View File

@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.commons.datacarrier;
import java.lang.reflect.Field;
public class FieldGetter {
public static <T> T getValue(Object instance,
String fieldName) throws IllegalAccessException, NoSuchFieldException {
Field field = instance.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return (T) field.get(instance);
}
}

View File

@ -18,41 +18,39 @@
package org.apache.skywalking.apm.commons.datacarrier.consumer;
import org.apache.skywalking.apm.commons.datacarrier.FieldGetter;
import org.apache.skywalking.apm.commons.datacarrier.SampleData;
import org.apache.skywalking.apm.commons.datacarrier.buffer.BufferStrategy;
import org.apache.skywalking.apm.commons.datacarrier.buffer.Channels;
import org.apache.skywalking.apm.commons.datacarrier.partition.SimpleRollingPartitioner;
import org.junit.Assert;
import org.junit.Test;
import org.powermock.api.support.membermodification.MemberModifier;
public class ConsumeDriverTest {
@Test
public void testBeginConsumeDriver() throws IllegalAccessException {
public void testBeginConsumeDriver() throws IllegalAccessException, NoSuchFieldException {
Channels<SampleData> channels = new Channels<SampleData>(2, 100, new SimpleRollingPartitioner<SampleData>(), BufferStrategy.BLOCKING);
ConsumeDriver<SampleData> pool = new ConsumeDriver<SampleData>("default", channels, new SampleConsumer(), 2, 20);
pool.begin(channels);
ConsumerThread[] threads = (ConsumerThread[]) MemberModifier.field(ConsumeDriver.class, "consumerThreads")
.get(pool);
ConsumerThread[] threads = FieldGetter.getValue(pool, "consumerThreads");
Assert.assertEquals(2, threads.length);
Assert.assertTrue(threads[0].isAlive());
Assert.assertTrue(threads[1].isAlive());
}
@Test
public void testCloseConsumeDriver() throws InterruptedException, IllegalAccessException {
public void testCloseConsumeDriver() throws InterruptedException, IllegalAccessException, NoSuchFieldException {
Channels<SampleData> channels = new Channels<SampleData>(2, 100, new SimpleRollingPartitioner<SampleData>(), BufferStrategy.BLOCKING);
ConsumeDriver<SampleData> pool = new ConsumeDriver<SampleData>("default", channels, new SampleConsumer(), 2, 20);
pool.begin(channels);
Thread.sleep(5000);
pool.close(channels);
ConsumerThread[] threads = (ConsumerThread[]) MemberModifier.field(ConsumeDriver.class, "consumerThreads")
.get(pool);
ConsumerThread[] threads = FieldGetter.getValue(pool, "consumerThreads");
Assert.assertEquals(2, threads.length);
Assert.assertFalse((Boolean) MemberModifier.field(ConsumerThread.class, "running").get(threads[0]));
Assert.assertFalse((Boolean) MemberModifier.field(ConsumerThread.class, "running").get(threads[1]));
Assert.assertFalse(FieldGetter.getValue(threads[0], "running"));
Assert.assertFalse(FieldGetter.getValue(threads[1], "running"));
}
}

View File

@ -24,10 +24,10 @@ import java.util.List;
import java.util.Properties;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.skywalking.apm.commons.datacarrier.DataCarrier;
import org.apache.skywalking.apm.commons.datacarrier.FieldGetter;
import org.apache.skywalking.apm.commons.datacarrier.SampleData;
import org.junit.Assert;
import org.junit.Test;
import org.powermock.api.support.membermodification.MemberModifier;
public class ConsumerTest {
public static LinkedBlockingQueue<SampleData> BUFFER = new LinkedBlockingQueue<SampleData>();
@ -35,7 +35,7 @@ public class ConsumerTest {
public static boolean IS_OCCUR_ERROR = false;
@Test
public void testConsumerLessThanChannel() throws IllegalAccessException {
public void testConsumerLessThanChannel() throws IllegalAccessException, NoSuchFieldException {
final DataCarrier<SampleData> carrier = new DataCarrier<SampleData>(2, 100);
@ -127,11 +127,10 @@ public class ConsumerTest {
}
}
private IConsumer getConsumer(DataCarrier<SampleData> carrier) throws IllegalAccessException {
ConsumeDriver pool = (ConsumeDriver) MemberModifier.field(DataCarrier.class, "driver").get(carrier);
ConsumerThread[] threads = (ConsumerThread[]) MemberModifier.field(ConsumeDriver.class, "consumerThreads")
.get(pool);
private IConsumer getConsumer(DataCarrier<SampleData> carrier) throws IllegalAccessException, NoSuchFieldException {
ConsumeDriver pool = FieldGetter.getValue(carrier, "driver");
ConsumerThread[] threads = FieldGetter.getValue(pool, "consumerThreads");
return (IConsumer) MemberModifier.field(ConsumerThread.class, "consumer").get(threads[0]);
return FieldGetter.getValue(threads[0], "consumer");
}
}

View File

@ -127,7 +127,6 @@ public class ConfigInitializer {
return collection;
}
/**
* Convert string value to typical type.
*

View File

@ -21,10 +21,10 @@ package org.apache.skywalking.apm.util;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.internal.util.collections.Sets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@ -68,8 +68,8 @@ public class ConfigInitializerTest {
Assert.assertArrayEquals(new Integer[]{1, 2, 3, 4}, TestPropertiesObject.Level1Object.LIST_INT_ATTR_ED2.toArray());
Assert.assertArrayEquals(new String[]{}, TestPropertiesObject.Level1Object.SET_STR_EMPTY_ATTR.toArray());
Assert.assertArrayEquals(new Boolean[]{true, false}, TestPropertiesObject.Level1Object.LIST_BOOL_ATTR.toArray());
Assert.assertEquals(Sets.newSet("a", "b", "c", "d"), TestPropertiesObject.Level1Object.SET_STR_ATTR);
Assert.assertEquals(Sets.newSet(1, 2, 3, 4), TestPropertiesObject.Level1Object.SET_INT_ATTR);
Assert.assertEquals(new HashSet<>(Arrays.asList("a", "b", "c", "d")), TestPropertiesObject.Level1Object.SET_STR_ATTR);
Assert.assertEquals(new HashSet<>(Arrays.asList(1, 2, 3, 4)), TestPropertiesObject.Level1Object.SET_INT_ATTR);
Assert.assertArrayEquals(new Boolean[]{true}, TestPropertiesObject.Level1Object.SET_BOOL_ATTR.toArray());
Assert.assertEquals(TestColorEnum.RED, TestPropertiesObject.Level1Object.Level2Object.ENUM_ATTR);
//make sure that when descs is empty,toString() work right;

View File

@ -36,7 +36,7 @@ public enum ExceptionCheckContext {
public boolean isError(Throwable throwable) {
Class<? extends Throwable> clazz = throwable.getClass();
return errorStatusExceptions.contains(clazz) || (!ignoredExceptions.contains(clazz));
return errorStatusExceptions.contains(clazz) || !ignoredExceptions.contains(clazz);
}
public void registerIgnoredException(Throwable throwable) {

View File

@ -101,7 +101,6 @@ public abstract class AbstractClassEnhancePluginDefine {
return newClassBuilder;
}
/**
* Begin to define how to enhance class. After invoke this method, only means definition is finished.
*

View File

@ -63,7 +63,6 @@ public class ProfileTaskChannelService implements BootService, Runnable, GRPCCha
// gRPC stub
private volatile ProfileTaskGrpc.ProfileTaskBlockingStub profileTaskBlockingStub;
// segment snapshot sender
private final BlockingQueue<TracingThreadSnapshot> snapshotQueue = new LinkedBlockingQueue<>(
Config.Profile.SNAPSHOT_TRANSPORT_BUFFER_SIZE);

View File

@ -103,7 +103,7 @@ public class ThreadProfiler {
}
// if is first dump, check is can start profiling
if (dumpSequence == 0 && (!executionContext.isStartProfileable())) {
if (dumpSequence == 0 && !executionContext.isStartProfileable()) {
return null;
}

View File

@ -28,7 +28,6 @@ import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import org.apache.skywalking.apm.agent.core.conf.Config;
/**
* Add agent version(Described in MANIFEST.MF) to the connection establish stage.
*/

View File

@ -56,7 +56,6 @@ public class IOUtils {
return output.toByteArray();
}
/**
* Copy bytes from an <code>InputStream</code> to an
* <code>OutputStream</code>.

View File

@ -22,13 +22,13 @@ import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
import org.apache.skywalking.apm.agent.core.conf.dynamic.watcher.IgnoreSuffixPatternsWatcher;
import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
public class IgnoreSuffixPatternsWatcherTest {
@ -48,9 +48,9 @@ public class IgnoreSuffixPatternsWatcherTest {
}
@Test
public void testConfigModifyEvent() {
IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher = Whitebox.getInternalState(contextManagerExtendService
, "ignoreSuffixPatternsWatcher");
public void testConfigModifyEvent() throws IllegalAccessException, NoSuchFieldException {
IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher =
FieldGetter.getValue(contextManagerExtendService, "ignoreSuffixPatternsWatcher");
ignoreSuffixPatternsWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
".txt,.log",
AgentConfigChangeWatcher.EventType.MODIFY
@ -60,9 +60,9 @@ public class IgnoreSuffixPatternsWatcherTest {
}
@Test
public void testConfigDeleteEvent() {
IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher = Whitebox.getInternalState(contextManagerExtendService
, "ignoreSuffixPatternsWatcher");
public void testConfigDeleteEvent() throws IllegalAccessException, NoSuchFieldException {
IgnoreSuffixPatternsWatcher ignoreSuffixPatternsWatcher =
FieldGetter.getValue(contextManagerExtendService, "ignoreSuffixPatternsWatcher");
ignoreSuffixPatternsWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
null,
AgentConfigChangeWatcher.EventType.DELETE

View File

@ -21,6 +21,7 @@ package org.apache.skywalking.apm.agent.core.conf.watcher;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.dynamic.AgentConfigChangeWatcher;
import org.apache.skywalking.apm.agent.core.conf.dynamic.watcher.SamplingRateWatcher;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.apache.skywalking.apm.agent.core.sampling.SamplingService;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.junit.AfterClass;
@ -28,7 +29,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
public class SamplingRateWatcherTest {
@ -48,9 +48,8 @@ public class SamplingRateWatcherTest {
}
@Test
public void testConfigModifyEvent() {
SamplingRateWatcher samplingRateWatcher = Whitebox.getInternalState(
samplingService, "samplingRateWatcher");
public void testConfigModifyEvent() throws IllegalAccessException, NoSuchFieldException {
SamplingRateWatcher samplingRateWatcher = FieldGetter.getValue(samplingService, "samplingRateWatcher");
samplingRateWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
"10",
AgentConfigChangeWatcher.EventType.MODIFY
@ -60,9 +59,9 @@ public class SamplingRateWatcherTest {
}
@Test
public void testConfigDeleteEvent() {
SamplingRateWatcher samplingRateWatcher = Whitebox.getInternalState(
samplingService, "samplingRateWatcher");
public void testConfigDeleteEvent() throws IllegalAccessException, NoSuchFieldException {
SamplingRateWatcher samplingRateWatcher =
FieldGetter.getValue(samplingService, "samplingRateWatcher");
samplingRateWatcher.notify(new AgentConfigChangeWatcher.ConfigChangeEvent(
null,
AgentConfigChangeWatcher.EventType.DELETE

View File

@ -18,19 +18,18 @@
package org.apache.skywalking.apm.agent.core.context;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.NoopSpan;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@RunWith(PowerMockRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class ExtensionContextTest {
@Test
@ -87,9 +86,7 @@ public class ExtensionContextTest {
context.handle(span);
verify(span, times(0)).skipAnalysis();
PowerMockito.mockStatic(System.class);
PowerMockito.when(System.currentTimeMillis()).thenReturn(1602743904804L + 500);
span = PowerMockito.mock(NoopSpan.class);
span = mock(NoopSpan.class);
context.deserialize("0-1602743904804");
context.handle(span);
verify(span, times(0)).tag(Tags.TRANSMISSION_LATENCY, "500");

View File

@ -21,11 +21,11 @@ package org.apache.skywalking.apm.agent.core.context.status;
import java.util.Set;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.powermock.api.support.membermodification.MemberModifier;
public class ExceptionCheckStrategyTest {
@ -37,13 +37,11 @@ public class ExceptionCheckStrategyTest {
}
@After
public void after() throws IllegalAccessException {
((Set) MemberModifier
.field(ExceptionCheckContext.class, "ignoredExceptions")
.get(ExceptionCheckContext.INSTANCE)).clear();
((Set) MemberModifier
.field(ExceptionCheckContext.class, "errorStatusExceptions")
.get(ExceptionCheckContext.INSTANCE)).clear();
public void after() throws IllegalAccessException, NoSuchFieldException {
((Set) FieldGetter.getValue(
ExceptionCheckContext.INSTANCE, "ignoredExceptions")).clear();
((Set) FieldGetter.getValue(
ExceptionCheckContext.INSTANCE, "errorStatusExceptions")).clear();
}
@Test

View File

@ -21,11 +21,11 @@ package org.apache.skywalking.apm.agent.core.context.status;
import java.util.Set;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.powermock.api.support.membermodification.MemberModifier;
public class StatusCheckServiceCheckTest {
@ -44,13 +44,11 @@ public class StatusCheckServiceCheckTest {
}
@After
public void after() throws IllegalAccessException {
((Set) MemberModifier
.field(ExceptionCheckContext.class, "ignoredExceptions")
.get(ExceptionCheckContext.INSTANCE)).clear();
((Set) MemberModifier
.field(ExceptionCheckContext.class, "errorStatusExceptions")
.get(ExceptionCheckContext.INSTANCE)).clear();
public void after() throws IllegalAccessException, NoSuchFieldException {
((Set) FieldGetter.getValue(
ExceptionCheckContext.INSTANCE, "ignoredExceptions")).clear();
((Set) FieldGetter.getValue(
ExceptionCheckContext.INSTANCE, "errorStatusExceptions")).clear();
}
@Test

View File

@ -18,17 +18,16 @@
package org.apache.skywalking.apm.agent.core.context.status;
import static org.apache.skywalking.apm.agent.core.context.status.StatusChecker.HIERARCHY_MATCH;
import static org.apache.skywalking.apm.agent.core.context.status.StatusChecker.OFF;
import java.util.Set;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.powermock.api.support.membermodification.MemberModifier;
import static org.apache.skywalking.apm.agent.core.context.status.StatusChecker.HIERARCHY_MATCH;
import static org.apache.skywalking.apm.agent.core.context.status.StatusChecker.OFF;
public class StatusCheckerTest {
@ -40,13 +39,11 @@ public class StatusCheckerTest {
}
@After
public void after() throws IllegalAccessException {
((Set) MemberModifier
.field(ExceptionCheckContext.class, "ignoredExceptions")
.get(ExceptionCheckContext.INSTANCE)).clear();
((Set) MemberModifier
.field(ExceptionCheckContext.class, "errorStatusExceptions")
.get(ExceptionCheckContext.INSTANCE)).clear();
public void after() throws IllegalAccessException, NoSuchFieldException {
((Set) FieldGetter.getValue(
ExceptionCheckContext.INSTANCE, "ignoredExceptions")).clear();
((Set) FieldGetter.getValue(
ExceptionCheckContext.INSTANCE, "errorStatusExceptions")).clear();
}
@Test
@ -58,20 +55,18 @@ public class StatusCheckerTest {
}
@Test
public void checkInheritNamedAndAnnotationMatchStatusChecker() throws IllegalAccessException {
public void checkInheritNamedAndAnnotationMatchStatusChecker() throws IllegalAccessException, NoSuchFieldException {
Assert.assertTrue(HIERARCHY_MATCH.checkStatus(new Throwable()));
Assert.assertTrue(HIERARCHY_MATCH.checkStatus(new IllegalArgumentException()));
Assert.assertFalse(HIERARCHY_MATCH.checkStatus(new TestNamedMatchException()));
Assert.assertFalse(HIERARCHY_MATCH.checkStatus(new TestHierarchyMatchException()));
Assert.assertFalse(HIERARCHY_MATCH.checkStatus(new TestAnnotationMatchException()));
Set ignoredExceptions = (Set) MemberModifier
.field(ExceptionCheckContext.class, "ignoredExceptions")
.get(ExceptionCheckContext.INSTANCE);
Set errorStatusExceptions = (Set) MemberModifier
.field(ExceptionCheckContext.class, "errorStatusExceptions")
.get(ExceptionCheckContext.INSTANCE);
Set ignoredExceptions = FieldGetter.getValue(
ExceptionCheckContext.INSTANCE, "ignoredExceptions");
Set errorStatusExceptions = FieldGetter.getValue(
ExceptionCheckContext.INSTANCE, "errorStatusExceptions");
Assert.assertTrue(ignoredExceptions.size() > 0);
Assert.assertTrue(errorStatusExceptions.size() > 0);
}
}
}

View File

@ -22,11 +22,9 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.ArgumentMatchers.anyString;
import java.io.PrintStream;
import static org.mockito.Matchers.anyString;
public class SystemOutWriterTest {
private static PrintStream OUT_REF;

View File

@ -18,36 +18,41 @@
package org.apache.skywalking.apm.agent.core.logging.core;
import static org.junit.Assert.assertTrue;
import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer;
import org.apache.skywalking.apm.agent.core.plugin.PluginFinder;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.BDDMockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import static org.junit.Assert.assertTrue;
@RunWith(PowerMockRunner.class)
@PrepareForTest(value = {
SnifferConfigInitializer.class,
PluginFinder.class,
AgentPackagePath.class
})
@RunWith(MockitoJUnitRunner.class)
public class WriterFactoryTest {
private MockedStatic<SnifferConfigInitializer> mockedSnifferConfigInitializer =
Mockito.mockStatic(SnifferConfigInitializer.class);
private MockedStatic<PluginFinder> mockedPluginFinder =
Mockito.mockStatic(PluginFinder.class);
private MockedStatic<AgentPackagePath> mockedAgentPackagePath =
Mockito.mockStatic(AgentPackagePath.class);
@After
public void tearDown() {
mockedSnifferConfigInitializer.close();
mockedPluginFinder.close();
mockedAgentPackagePath.close();
}
@Test
public void alwaysReturnSystemLogWriteWithSetLoggingDir() {
Config.Logging.OUTPUT = LogOutput.CONSOLE;
PowerMockito.mockStatic(SnifferConfigInitializer.class);
PowerMockito.mockStatic(PluginFinder.class);
PowerMockito.mockStatic(AgentPackagePath.class);
BDDMockito.given(SnifferConfigInitializer.isInitCompleted()).willReturn(true);
BDDMockito.given(PluginFinder.isPluginInitCompleted()).willReturn(true);
BDDMockito.given(AgentPackagePath.isPathFound()).willReturn(true);
mockedSnifferConfigInitializer.when(SnifferConfigInitializer::isInitCompleted).thenReturn(true);
mockedPluginFinder.when(PluginFinder::isPluginInitCompleted).thenReturn(true);
mockedAgentPackagePath.when(AgentPackagePath::isPathFound).thenReturn(true);
assertTrue(SnifferConfigInitializer.isInitCompleted());
assertTrue(PluginFinder.isPluginInitCompleted());
@ -60,12 +65,9 @@ public class WriterFactoryTest {
@Test
public void returnFileWriterWriteWithBlankLoggingDir() {
Config.Logging.OUTPUT = LogOutput.FILE;
PowerMockito.mockStatic(SnifferConfigInitializer.class);
PowerMockito.mockStatic(PluginFinder.class);
PowerMockito.mockStatic(AgentPackagePath.class);
BDDMockito.given(SnifferConfigInitializer.isInitCompleted()).willReturn(true);
BDDMockito.given(PluginFinder.isPluginInitCompleted()).willReturn(true);
BDDMockito.given(AgentPackagePath.isPathFound()).willReturn(true);
mockedSnifferConfigInitializer.when(SnifferConfigInitializer::isInitCompleted).thenReturn(true);
mockedPluginFinder.when(PluginFinder::isPluginInitCompleted).thenReturn(true);
mockedAgentPackagePath.when(AgentPackagePath::isPathFound).thenReturn(true);
assertTrue(SnifferConfigInitializer.isInitCompleted());
assertTrue(PluginFinder.isPluginInitCompleted());
@ -74,4 +76,4 @@ public class WriterFactoryTest {
IWriter logWriter = WriterFactory.getLogWriter();
assertTrue(logWriter instanceof FileWriter);
}
}
}

View File

@ -18,7 +18,11 @@
package org.apache.skywalking.apm.agent.core.meter;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.network.language.agent.v3.Label;
import org.apache.skywalking.apm.network.language.agent.v3.MeterData;
@ -29,11 +33,6 @@ import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.powermock.reflect.Whitebox;
public class CounterTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
@ -44,9 +43,9 @@ public class CounterTest {
}
@After
public void after() {
public void after() throws IllegalAccessException, NoSuchFieldException {
final MeterService meterService = ServiceManager.INSTANCE.findService(MeterService.class);
((ConcurrentHashMap<MeterId, BaseMeter>) Whitebox.getInternalState(meterService, "meterMap")).clear();
((ConcurrentHashMap<MeterId, BaseMeter>) FieldGetter.getValue(meterService, "meterMap")).clear();
}
@Test

View File

@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.network.language.agent.v3.Label;
import org.apache.skywalking.apm.network.language.agent.v3.MeterData;
@ -31,7 +32,6 @@ import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
public class GaugeTest {
@Rule
@ -43,9 +43,9 @@ public class GaugeTest {
}
@After
public void after() {
public void after() throws IllegalAccessException, NoSuchFieldException {
final MeterService meterService = ServiceManager.INSTANCE.findService(MeterService.class);
((ConcurrentHashMap<MeterId, BaseMeter>) Whitebox.getInternalState(meterService, "meterMap")).clear();
((ConcurrentHashMap<MeterId, BaseMeter>) FieldGetter.getValue(meterService, "meterMap")).clear();
}
@Test

View File

@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.network.language.agent.v3.Label;
import org.apache.skywalking.apm.network.language.agent.v3.MeterData;
@ -31,7 +32,6 @@ import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
public class HistogramTest {
@Rule
@ -43,18 +43,18 @@ public class HistogramTest {
}
@After
public void after() {
public void after() throws IllegalAccessException, NoSuchFieldException {
final MeterService meterService = ServiceManager.INSTANCE.findService(MeterService.class);
((ConcurrentHashMap<MeterId, BaseMeter>) Whitebox.getInternalState(meterService, "meterMap")).clear();
((ConcurrentHashMap<MeterId, BaseMeter>) FieldGetter.getValue(meterService, "meterMap")).clear();
}
@Test
public void testBuckets() {
public void testBuckets() throws IllegalAccessException, NoSuchFieldException {
final MeterId meterId = new MeterId("test", MeterType.COUNTER, Arrays.asList(new MeterTag("k1", "v1")));
// Check buckets
final Histogram histogram = MeterFactory.histogram("test").steps(Arrays.asList(2d, 5d)).minValue(2d).build();
final Histogram.Bucket[] buckets = (Histogram.Bucket[]) Whitebox.getInternalState(histogram, "buckets");
final Histogram.Bucket[] buckets = FieldGetter.getValue(histogram, "buckets");
Assert.assertEquals(2, buckets.length);
Assert.assertEquals(buckets[0], new Histogram.Bucket(2));
Assert.assertEquals(buckets[1], new Histogram.Bucket(5));

View File

@ -21,15 +21,15 @@ package org.apache.skywalking.apm.agent.core.meter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.apache.skywalking.apm.network.language.agent.v3.Label;
import org.junit.Assert;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
public class MeterIdTest {
@Test
public void testTransformTags() {
public void testTransformTags() throws IllegalAccessException, NoSuchFieldException {
MeterId meterId = new MeterId("test", MeterType.COUNTER, Arrays.asList(new MeterTag("k1", "v1")));
// Label message check
@ -41,7 +41,7 @@ public class MeterIdTest {
Assert.assertEquals(MeterType.COUNTER, meterId.getType());
// Must cache the Label message
final List<Label> cacheLabels = (List<Label>) Whitebox.getInternalState(meterId, "labels");
final List<Label> cacheLabels = FieldGetter.getValue(meterId, "labels");
Assert.assertEquals(labels, cacheLabels);
// Check empty tags

View File

@ -18,10 +18,19 @@
package org.apache.skywalking.apm.agent.core.meter;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcServerRule;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.spy;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.apache.skywalking.apm.agent.core.remote.GRPCChannelStatus;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.agent.core.test.tools.TracingSegmentRunner;
@ -38,26 +47,20 @@ import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.reflect.Whitebox;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcServerRule;
@RunWith(TracingSegmentRunner.class)
public class MeterServiceTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
@Rule
public GrpcServerRule grpcServerRule = new GrpcServerRule().directExecutor();
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
private MeterService registryService = new MeterService();
private List<MeterData> upstreamMeters;
@ -104,11 +107,17 @@ public class MeterServiceTest {
spy(sender);
spy(registryService);
Whitebox.setInternalState(
sender, "meterReportServiceStub", MeterReportServiceGrpc.newStub(grpcServerRule.getChannel()));
Whitebox.setInternalState(sender, "status", GRPCChannelStatus.CONNECTED);
Field meterReportServiceStub = MeterSender.class.getDeclaredField("meterReportServiceStub");
Field status = MeterSender.class.getDeclaredField("status");
Field senderField = MeterService.class.getDeclaredField("sender");
Stream.of(meterReportServiceStub, status, senderField).forEach(field -> {
field.setAccessible(true);
});
Whitebox.setInternalState(registryService, "sender", sender);
meterReportServiceStub.set(
sender, MeterReportServiceGrpc.newStub(grpcServerRule.getChannel()));
status.set(sender, GRPCChannelStatus.CONNECTED);
senderField.set(registryService, sender);
upstreamMeters = new ArrayList<>();
}
@ -153,7 +162,7 @@ public class MeterServiceTest {
@Test
public void testMeterSizeAndShutdown() throws Throwable {
final Map<MeterId, BaseMeter> map = Whitebox.getInternalState(registryService, "meterMap");
final Map<MeterId, BaseMeter> map = FieldGetter.getValue(registryService, "meterMap");
map.clear();
// Check max meter size

View File

@ -21,6 +21,7 @@ package org.apache.skywalking.apm.agent.core.remote;
import com.google.protobuf.InvalidProtocolBufferException;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcServerRule;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
@ -29,6 +30,7 @@ import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.context.util.FieldGetter;
import org.apache.skywalking.apm.agent.core.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.agent.core.test.tools.SegmentStorage;
import org.apache.skywalking.apm.agent.core.test.tools.SegmentStoragePoint;
@ -45,7 +47,6 @@ import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.reflect.Whitebox;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@ -101,12 +102,17 @@ public class TraceSegmentServiceClientTest {
@Before
public void setUp() throws Throwable {
Whitebox.setInternalState(ServiceManager.INSTANCE.findService(GRPCChannelManager.class), "reconnect", false);
Field reconnect = GRPCChannelManager.class.getDeclaredField("reconnect");
reconnect.setAccessible(true);
reconnect.setBoolean(ServiceManager.INSTANCE.findService(GRPCChannelManager.class), false);
spy(serviceClient);
Whitebox.setInternalState(
serviceClient, "serviceStub", TraceSegmentReportServiceGrpc.newStub(grpcServerRule.getChannel()));
Whitebox.setInternalState(serviceClient, "status", GRPCChannelStatus.CONNECTED);
Field serviceStub = TraceSegmentServiceClient.class.getDeclaredField("serviceStub");
Field status = TraceSegmentServiceClient.class.getDeclaredField("status");
serviceStub.setAccessible(true);
status.setAccessible(true);
serviceStub.set(serviceClient, TraceSegmentReportServiceGrpc.newStub(grpcServerRule.getChannel()));
status.set(serviceClient, GRPCChannelStatus.CONNECTED);
upstreamSegments = new ArrayList<>();
}
@ -136,7 +142,7 @@ public class TraceSegmentServiceClientTest {
}
@Test
public void testSendTraceSegmentWithException() throws InvalidProtocolBufferException {
public void testSendTraceSegmentWithException() throws InvalidProtocolBufferException, IllegalAccessException, NoSuchFieldException {
grpcServerRule.getServiceRegistry().addService(serviceImplBase);
AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null);
@ -150,7 +156,7 @@ public class TraceSegmentServiceClientTest {
assertThat(upstreamSegments.size(), is(0));
boolean reconnect = Whitebox.getInternalState(
boolean reconnect = FieldGetter.getValue(
ServiceManager.INSTANCE.findService(GRPCChannelManager.class), "reconnect");
assertThat(reconnect, is(true));

View File

@ -18,38 +18,56 @@
package org.apache.skywalking.apm.agent.core.test.tools;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.LinkedList;
import org.apache.skywalking.apm.agent.core.context.TracingThreadListener;
import org.junit.rules.ExternalResource;
import org.powermock.reflect.Whitebox;
import org.apache.skywalking.apm.agent.core.boot.BootService;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.context.IgnoredTracerContext;
import org.apache.skywalking.apm.agent.core.context.TracingContext;
import org.apache.skywalking.apm.agent.core.context.TracingContextListener;
import org.apache.skywalking.apm.agent.core.context.TracingThreadListener;
import org.junit.rules.ExternalResource;
public class AgentServiceRule extends ExternalResource {
@Override
protected void after() {
super.after();
Whitebox.setInternalState(ServiceManager.INSTANCE, "bootedServices", new HashMap<Class, BootService>());
Whitebox.setInternalState(TracingContext.ListenerManager.class, "LISTENERS", new LinkedList<TracingContextListener>());
Whitebox.setInternalState(IgnoredTracerContext.ListenerManager.class, "LISTENERS", new LinkedList<TracingContextListener>());
Whitebox.setInternalState(TracingContext.TracingThreadListenerManager.class, "LISTENERS", new LinkedList<TracingThreadListener>());
reset();
}
@Override
protected void before() throws Throwable {
super.before();
Whitebox.setInternalState(ServiceManager.INSTANCE, "bootedServices", new HashMap<Class, BootService>());
Whitebox.setInternalState(TracingContext.ListenerManager.class, "LISTENERS", new LinkedList<TracingContextListener>());
Whitebox.setInternalState(IgnoredTracerContext.ListenerManager.class, "LISTENERS", new LinkedList<TracingContextListener>());
Whitebox.setInternalState(TracingContext.TracingThreadListenerManager.class, "LISTENERS", new LinkedList<TracingThreadListener>());
reset();
ServiceManager.INSTANCE.boot();
}
private void reset() {
try {
Field bootedServices = ServiceManager.class.getDeclaredField("bootedServices");
bootedServices.setAccessible(true);
bootedServices.set(ServiceManager.INSTANCE, new HashMap<Class<?>, BootService>());
Field listeners = TracingContext.ListenerManager.class.getDeclaredField("LISTENERS");
listeners.setAccessible(true);
listeners.set(TracingContext.ListenerManager.class,
new LinkedList<TracingContextListener>());
listeners = IgnoredTracerContext.ListenerManager.class.getDeclaredField("LISTENERS");
listeners.setAccessible(true);
listeners.set(IgnoredTracerContext.ListenerManager.class,
new LinkedList<TracingContextListener>());
listeners =
TracingContext.TracingThreadListenerManager.class.getDeclaredField("LISTENERS");
listeners.setAccessible(true);
listeners.set(TracingContext.TracingThreadListenerManager.class, new LinkedList<TracingThreadListener>());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -36,8 +36,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import javax.jms.Destination;
import javax.jms.JMSException;
@ -48,8 +46,7 @@ import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class ActiveMQProducerInterceptorTest {
@SegmentStoragePoint

View File

@ -35,13 +35,10 @@ import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import static org.hamcrest.CoreMatchers.is;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class MessageConsumerDequeueInterceptorTest {
@SegmentStoragePoint
@ -124,4 +121,4 @@ public class MessageConsumerDequeueInterceptorTest {
Assert.assertThat(traceSegments.size(), is(1));
}
}
}

View File

@ -17,6 +17,9 @@
package org.apache.skywalking.apm.plugin.asynchttpclient.v2;
import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
@ -35,24 +38,14 @@ import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.apache.skywalking.apm.network.trace.component.OfficialComponent;
import org.asynchttpclient.Request;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.Response;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import static org.apache.skywalking.apm.agent.test.tools.SpanAssert.assertComponent;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest(Response.class)
@RunWith(TracingSegmentRunner.class)
public class ExecuteInterceptorTest {
@SegmentStoragePoint

View File

@ -38,17 +38,18 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class GenericRequestorInterceptorTest {
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
public GenericRequestorInterceptor interceptor = new GenericRequestorInterceptor();

View File

@ -39,11 +39,8 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class SpecificRequestorInterceptorTest {
@SegmentStoragePoint

View File

@ -21,10 +21,8 @@ package org.apache.skywalking.apm.plugin.baidu.brpc3;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@ -44,18 +42,18 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import com.baidu.brpc.protocol.Request;
import com.baidu.brpc.protocol.Response;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class ClientInterceptorTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@Mock
@ -63,8 +61,10 @@ public class ClientInterceptorTest {
private ClientInterceptor clientInterceptor;
private Request request = PowerMockito.mock(Request.class);
private Response response = PowerMockito.mock(Response.class);
@Mock
private Request request;
@Mock
private Response response;
@Mock
private MethodInterceptResult methodInterceptResult;

View File

@ -21,11 +21,10 @@ package org.apache.skywalking.apm.plugin.baidu.brpc3;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.List;
import java.util.Map;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.SW8CarrierItem;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
@ -48,19 +47,19 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import com.baidu.brpc.interceptor.InterceptorChain;
import com.baidu.brpc.protocol.Request;
import com.baidu.brpc.protocol.Response;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class ServerInterceptorTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@Mock
@ -68,10 +67,13 @@ public class ServerInterceptorTest {
private ServerInterceptor serverInterceptor;
private Request request = PowerMockito.mock(Request.class);
private Response response = PowerMockito.mock(Response.class);
@Mock
private Request request;
@Mock
private Response response;
private InterceptorChain interceptorChain = PowerMockito.mock(InterceptorChain.class);
@Mock
private InterceptorChain interceptorChain;
@Mock
private MethodInterceptResult methodInterceptResult;
@ -83,7 +85,7 @@ public class ServerInterceptorTest {
public void setUp() throws Exception {
serverInterceptor = new ServerInterceptor();
Map<String, Object> kvAttachment = PowerMockito.mock(Map.class);
Map<String, Object> kvAttachment = mock(Map.class);
when(kvAttachment.get(SW8CarrierItem.HEADER_NAME)).thenReturn("1-My40LjU=-MS4yLjM=-3-c2VydmljZQ"
+ "==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA=");
when(request.getKvAttachment()).thenReturn(kvAttachment);

View File

@ -32,8 +32,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@ -42,8 +40,7 @@ import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class CanalInterceptorTest {
private CanalInterceptor canalInterceptor;

View File

@ -25,11 +25,11 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Method;
@RunWith(PowerMockRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class ClusterConnectInterceptorTest {
private ClusterConnectInterceptor interceptor;
@ -62,4 +62,4 @@ public class ClusterConnectInterceptorTest {
ConnectionInfo connectionInfo = (ConnectionInfo) ret.getSkyWalkingDynamicField();
Assert.assertThat(connectionInfo.getKeyspace(), Is.is("test"));
}
}
}

View File

@ -25,19 +25,19 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
@RunWith(PowerMockRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class ClusterConstructorWithStateListenerArgInterceptorTest {
@Mock
private ClusterConstructorWithStateListenerArgInterceptor interceptor;
@Mock
@Spy
private EnhancedInstance enhancedInstance = new EnhancedInstance() {
private ConnectionInfo connectionInfo;
@ -71,4 +71,4 @@ public class ClusterConstructorWithStateListenerArgInterceptorTest {
ConnectionInfo connectionInfo = (ConnectionInfo) enhancedInstance.getSkyWalkingDynamicField();
Assert.assertThat(connectionInfo.getContactPoints(), Is.is("172.20.0.2:9042"));
}
}
}

View File

@ -18,6 +18,9 @@
package org.apache.skywalking.apm.plugin.cassandra.java.driver.v3;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@ -34,19 +37,17 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class DefaultResultSetFutureGetUninterruptiblyInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@ -73,7 +74,7 @@ public class DefaultResultSetFutureGetUninterruptiblyInterceptorTest {
assertThat(SegmentHelper.getSpans(segment).size(), is(1));
AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0);
SpanAssert.assertLayer(span, SpanLayer.DB);
assertThat(span.getOperationName(), is(Constants.CASSANDRA_OP_PREFIX));
assertThat(span.getOperationName(), is(Constants.CASSANDRA_OP_PREFIX + "executeAsync"));
SpanAssert.assertTag(span, 0, Constants.CASSANDRA_DB_TYPE);
}
}
}

View File

@ -18,7 +18,9 @@
package org.apache.skywalking.apm.plugin.cassandra.java.driver.v3;
import com.datastax.driver.core.SimpleStatement;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@ -35,19 +37,18 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import com.datastax.driver.core.SimpleStatement;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@ -80,9 +81,9 @@ public class SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptorTest
assertThat(SegmentHelper.getSpans(segment).size(), is(1));
AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0);
SpanAssert.assertLayer(span, SpanLayer.DB);
assertThat(span.getOperationName(), is(Constants.CASSANDRA_OP_PREFIX));
assertThat(span.getOperationName(), is(Constants.CASSANDRA_OP_PREFIX + "executeAsync"));
SpanAssert.assertTag(span, 0, Constants.CASSANDRA_DB_TYPE);
SpanAssert.assertTag(span, 1, "test");
SpanAssert.assertTag(span, 2, "SELECT * FROM test");
}
}
}

View File

@ -25,8 +25,6 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
@ -45,12 +43,12 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import com.fasterxml.jackson.core.JsonProcessingException;
import ru.yandex.clickhouse.ClickHouseStatementImpl;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class ClickHouseStatementMethodInterceptorTest {
private final static String SQL = "SELECT 1";
@ -70,6 +68,9 @@ public class ClickHouseStatementMethodInterceptorTest {
private final ClickHouseStatementMethodInterceptor interceptor = new ClickHouseStatementMethodInterceptor();
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@Mock
@ -125,4 +126,4 @@ public class ClickHouseStatementMethodInterceptorTest {
SpanAssert.assertTag(span, 1, "default");
SpanAssert.assertTag(span, 2, SQL);
}
}
}

View File

@ -21,17 +21,16 @@ package org.apache.skywalking.apm.plugin.jdbc.clickhouse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
import ru.yandex.clickhouse.settings.ClickHouseProperties;
@RunWith(PowerMockRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class InitConnectionMethodInterceptorTest {
private final EnhancedInstance enhancedInstance = new EnhancedInstance() {
@ -69,4 +68,4 @@ public class InitConnectionMethodInterceptorTest {
assertEquals("default", connectionInfo.getDatabaseName());
assertEquals("ClickHouse", connectionInfo.getDBType());
}
}
}

View File

@ -49,10 +49,10 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
public static final String ARGUMENTS = "arguments";
/**
* <h2>Consumer:</h2> The serialized trace context data will
* Consumer: The serialized trace context data will
* inject to the {@link RpcContext#attachments} for transport to provider side.
* <p>
* <h2>Provider:</h2> The serialized trace context data will extract from
* Provider: The serialized trace context data will extract from
* {@link RpcContext#attachments}. current trace segment will ref if the serialization context data is not null.
*/
@Override

View File

@ -18,12 +18,17 @@
package org.apache.skywalking.apm.plugin.dubbo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import java.util.List;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.context.ContextManagerExtendService;
@ -45,26 +50,20 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.apache.skywalking.apm.plugin.asf.dubbo.DubboInterceptor;
import org.hamcrest.CoreMatchers;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.springframework.util.Assert;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest({RpcContext.class})
@RunWith(TracingSegmentRunner.class)
public class DubboInterceptorTest {
@SegmentStoragePoint
@ -72,6 +71,10 @@ public class DubboInterceptorTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
private static MockedStatic<RpcContext> RPC_CONTEXT_MOCK;
@Mock
private EnhancedInstance enhancedInstance;
@ -92,18 +95,22 @@ public class DubboInterceptorTest {
private Object[] allArguments;
private Class[] argumentTypes;
@BeforeClass
public static void beforeClass() {
RPC_CONTEXT_MOCK = Mockito.mockStatic(RpcContext.class);
}
@Before
public void setUp() throws Exception {
dubboInterceptor = new DubboInterceptor();
PowerMockito.mockStatic(RpcContext.class);
when(invoker.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:20880/org.apache.skywalking.apm.test.TestDubboService"));
when(invocation.getMethodName()).thenReturn("test");
when(invocation.getParameterTypes()).thenReturn(new Class[] {String.class});
when(invocation.getArguments()).thenReturn(new Object[] {"abc"});
PowerMockito.when(RpcContext.getContext()).thenReturn(rpcContext);
RPC_CONTEXT_MOCK.when(RpcContext::getContext).thenReturn(rpcContext);
when(rpcContext.isConsumerSide()).thenReturn(true);
when(rpcContext.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:20880/org.apache.skywalking.apm.test.TestDubboService"));
allArguments = new Object[] {
invoker,
invocation
@ -115,6 +122,11 @@ public class DubboInterceptorTest {
Config.Agent.SERVICE_NAME = "DubboTestCases-APP";
}
@AfterClass
public static void afterClass() {
RPC_CONTEXT_MOCK.close();
}
@Test
public void testServiceFromPlugin() {
PluginBootService service = ServiceManager.INSTANCE.findService(PluginBootService.class);

View File

@ -50,10 +50,10 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
public static final String ARGUMENTS = "arguments";
/**
* <h2>Consumer:</h2> The serialized trace context data will
* Consumer: The serialized trace context data will
* inject to the {@link RpcContext#getClientAttachment} for transport to provider side.
* <p>
* <h2>Provider:</h2> The serialized trace context data will extract from
* Provider: The serialized trace context data will extract from
* {@link RpcContext#getServerAttachment}. current trace segment will ref if the serialization context data is not
* null.
*/

View File

@ -18,14 +18,17 @@
package org.apache.skywalking.apm.plugin.dubbo3;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import java.util.List;
import org.apache.dubbo.rpc.RpcContextAttachment;
import org.apache.dubbo.rpc.RpcServiceContext;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
@ -49,26 +52,20 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.apache.skywalking.apm.plugin.asf.dubbo3.DubboInterceptor;
import org.hamcrest.CoreMatchers;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.springframework.util.Assert;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest({RpcContext.class})
@RunWith(TracingSegmentRunner.class)
public class DubboInterceptorTest {
@SegmentStoragePoint
@ -76,6 +73,10 @@ public class DubboInterceptorTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
private static MockedStatic<RpcContext> RPC_CONTEXT_MOCK;
@Mock
private EnhancedInstance enhancedInstance;
@ -105,11 +106,20 @@ public class DubboInterceptorTest {
private static final URL CONSUMER_URL = URL.valueOf("dubbo://127.0.0.1:20880/org.apache.skywalking.apm.test.TestDubboService?side=consumer");
private static final URL PROVIDER_URL = URL.valueOf("dubbo://127.0.0.1:20880/org.apache.skywalking.apm.test.TestDubboService?side=provider");
@BeforeClass
public static void beforeClass() {
RPC_CONTEXT_MOCK = Mockito.mockStatic(RpcContext.class);
}
@AfterClass
public static void afterClass() {
RPC_CONTEXT_MOCK.close();
}
@Before
public void setUp() throws Exception {
dubboInterceptor = new DubboInterceptor();
PowerMockito.mockStatic(RpcContext.class);
when(consumerInvoker.getUrl()).thenReturn(CONSUMER_URL);
when(consumerInvocation.getMethodName()).thenReturn("test");
when(consumerInvocation.getParameterTypes()).thenReturn(new Class[] {String.class});

View File

@ -44,10 +44,10 @@ import org.apache.skywalking.apm.util.StringUtil;
*/
public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
/**
* <h2>Consumer:</h2> The serialized trace context data will
* Consumer: The serialized trace context data will
* inject to the {@link RpcContext#attachments} for transport to provider side.
* <p>
* <h2>Provider:</h2> The serialized trace context data will extract from
* Provider: The serialized trace context data will extract from
* {@link RpcContext#attachments}. current trace segment will ref if the serialize context data is not null.
*/
@Override

View File

@ -18,11 +18,11 @@
package org.apache.skywalking.apm.plugin.dubbo;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcContext;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
import org.apache.skywalking.apm.agent.core.conf.Config;
@ -44,26 +44,25 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.hamcrest.CoreMatchers;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.springframework.util.Assert;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcContext;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest({RpcContext.class})
@RunWith(TracingSegmentRunner.class)
public class DubboInterceptorTest {
@SegmentStoragePoint
@ -71,6 +70,10 @@ public class DubboInterceptorTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
private static MockedStatic<RpcContext> RPC_CONTEXT_MOCK;
@Mock
private EnhancedInstance enhancedInstance;
@ -91,17 +94,20 @@ public class DubboInterceptorTest {
private Object[] allArguments;
private Class[] argumentTypes;
@BeforeClass
public static void beforeClass() {
RPC_CONTEXT_MOCK = Mockito.mockStatic(RpcContext.class);
}
@Before
public void setUp() throws Exception {
dubboInterceptor = new DubboInterceptor();
PowerMockito.mockStatic(RpcContext.class);
when(invoker.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:20880/org.apache.skywalking.apm.test.TestDubboService"));
when(invocation.getMethodName()).thenReturn("test");
when(invocation.getParameterTypes()).thenReturn(new Class[] {String.class});
when(invocation.getArguments()).thenReturn(new Object[] {"abc"});
PowerMockito.when(RpcContext.getContext()).thenReturn(rpcContext);
RPC_CONTEXT_MOCK.when(RpcContext::getContext).thenReturn(rpcContext);
when(rpcContext.isConsumerSide()).thenReturn(true);
allArguments = new Object[] {
invoker,
@ -114,6 +120,11 @@ public class DubboInterceptorTest {
Config.Agent.SERVICE_NAME = "DubboTestCases-APP";
}
@AfterClass
public static void afterClass() {
RPC_CONTEXT_MOCK.close();
}
@Test
public void testServiceFromPlugin() {
PluginBootService service = ServiceManager.INSTANCE.findService(PluginBootService.class);

View File

@ -34,16 +34,13 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class JobExecutorInterceptorTest {
@SegmentStoragePoint

View File

@ -18,6 +18,12 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine.TRANSPORT_CLIENT;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.LocalSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@ -39,19 +45,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine.TRANSPORT_CLIENT;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class AdapterActionFutureActionGetMethodsInterceptorTest {
@SegmentStoragePoint
@ -59,6 +56,8 @@ public class AdapterActionFutureActionGetMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -20,8 +20,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -43,11 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class ClusterClientGetSettingsMethodsInterceptorTest {
@SegmentStoragePoint
@ -55,6 +53,8 @@ public class ClusterClientGetSettingsMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -20,8 +20,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -43,11 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class ClusterClientHealthMethodsInterceptorTest {
@SegmentStoragePoint
@ -55,6 +53,8 @@ public class ClusterClientHealthMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -21,8 +21,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -45,15 +44,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest(value = {
Settings.class
})
@RunWith(TracingSegmentRunner.class)
public class ClusterClientPutSettingsMethodsInterceptorTest {
@SegmentStoragePoint
@ -61,6 +55,8 @@ public class ClusterClientPutSettingsMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,11 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@ -37,18 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class IndicesClientAnalyzeMethodsInterceptorTest {
@SegmentStoragePoint
@ -56,6 +53,8 @@ public class IndicesClientAnalyzeMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,10 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -39,16 +43,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class IndicesClientCreateMethodsInterceptorTest {
@SegmentStoragePoint
@ -56,6 +54,8 @@ public class IndicesClientCreateMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,9 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -38,15 +41,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class IndicesClientDeleteMethodsInterceptorTest {
@SegmentStoragePoint
@ -54,6 +52,8 @@ public class IndicesClientDeleteMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,12 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@ -37,19 +43,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.ArrayList;
import java.util.List;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientClearScrollMethodsInterceptorTest {
@SegmentStoragePoint
@ -57,6 +54,8 @@ public class RestHighLevelClientClearScrollMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,9 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpHost;
@ -27,24 +30,17 @@ import org.elasticsearch.client.Node;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest(value = {
RestClientBuilder.class,
HttpHost.class
})
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientConInterceptorTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private RestClientBuilder restClientBuilder;

View File

@ -17,6 +17,11 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@ -37,18 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientDeleteByQueryMethodsInterceptorTest {
@SegmentStoragePoint
@ -56,6 +53,8 @@ public class RestHighLevelClientDeleteByQueryMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,10 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -38,16 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientGetMethodsInterceptorTest {
@SegmentStoragePoint
@ -55,6 +53,8 @@ public class RestHighLevelClientGetMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,10 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -38,16 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientIndexMethodsInterceptorTest {
@SegmentStoragePoint
@ -55,6 +53,8 @@ public class RestHighLevelClientIndexMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,10 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -38,18 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest(SearchRequest.class)
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientSearchMethodsInterceptorTest {
@SegmentStoragePoint
@ -57,6 +53,8 @@ public class RestHighLevelClientSearchMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,11 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@ -37,18 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientSearchScrollMethodsInterceptorTest {
@SegmentStoragePoint
@ -56,6 +53,8 @@ public class RestHighLevelClientSearchScrollMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,11 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@ -37,18 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientSearchTemplateMethodsInterceptorTest {
@SegmentStoragePoint
@ -56,6 +53,8 @@ public class RestHighLevelClientSearchTemplateMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -17,6 +17,10 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan;
@ -38,16 +42,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class RestHighLevelClientUpdateMethodsInterceptorTest {
@SegmentStoragePoint
@ -55,6 +53,8 @@ public class RestHighLevelClientUpdateMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -18,6 +18,11 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine.TRANSPORT_CLIENT;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import java.net.InetSocketAddress;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
@ -47,17 +52,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine.TRANSPORT_CLIENT;
import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class TransportActionNodeProxyExecuteMethodsInterceptorTest {
@SegmentStoragePoint
@ -65,6 +63,8 @@ public class TransportActionNodeProxyExecuteMethodsInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private EnhancedInstance enhancedInstance;

View File

@ -18,28 +18,25 @@
package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.apache.skywalking.apm.plugin.elasticsearch.v6.TransportClientEnhanceInfo;
import org.elasticsearch.common.settings.Settings;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest(value = {
Settings.class
})
@RunWith(TracingSegmentRunner.class)
public class TransportServiceConInterceptorTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private Settings settings;

View File

@ -41,9 +41,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import java.nio.charset.Charset;
import java.util.Collection;
@ -57,9 +54,7 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest({Response.class})
@RunWith(TracingSegmentRunner.class)
public class DefaultHttpClientInterceptorTest {
@SegmentStoragePoint

View File

@ -18,7 +18,10 @@
package org.apache.skywalking.apm.plugin.feign.http.v9;
import feign.RequestTemplate;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.junit.After;
@ -26,15 +29,10 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
import feign.RequestTemplate;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class PathVarInterceptorTest {
private PathVarInterceptor pathVarInterceptor;

View File

@ -68,7 +68,6 @@ public class CodecUtils {
* CarrierItem}, and so on.
*
* @param swContextCarrier the swContextCarrier to encode
* @return
*/
static Buf encode(SWContextCarrier swContextCarrier) {
if (StringUtil.isNotEmpty(swContextCarrier.getOperationName())
@ -105,7 +104,6 @@ public class CodecUtils {
* For convenient, we use {@link ByteBuffer} to wrap byte array.
*
* @param buf the byte array to decode
* @return
*/
static SWContextCarrier decode(Buf buf) {
try {

View File

@ -28,8 +28,6 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
@ -38,8 +36,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class ClientTracingFilterInterceptorTest extends AbstractTracingFilterTest {
@SegmentStoragePoint

View File

@ -31,16 +31,13 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import scala.runtime.AbstractFunction0;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class ServerTracingFilterInterceptorTest extends AbstractTracingFilterTest {
@SegmentStoragePoint

View File

@ -21,33 +21,45 @@ package org.apache.skywalking.apm.plugin.guava.eventbus;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.MockitoRule;
@RunWith(PowerMockRunner.class)
@PrepareForTest(ContextManager.class)
@RunWith(MockitoJUnitRunner.class)
public class EventBusDispatchInterceptorTest {
private EventBusDispatchInterceptor interceptor;
private Object originalEventObj;
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private ContextSnapshot contextSnapshot;
private MockedStatic<ContextManager> mockedContextManager;
@Before
public void setUp() throws Exception {
interceptor = new EventBusDispatchInterceptor();
originalEventObj = new Object();
mockStatic(ContextManager.class);
when(ContextManager.capture()).thenReturn(contextSnapshot);
mockedContextManager = Mockito.mockStatic(ContextManager.class);
mockedContextManager.when(ContextManager::capture).thenReturn(contextSnapshot);
}
@After
public void tearDown() {
mockedContextManager.close();
}
@Test
@ -66,4 +78,4 @@ public class EventBusDispatchInterceptorTest {
assertNull(arguments[0]);
}
}
}

View File

@ -20,15 +20,14 @@ package org.apache.skywalking.apm.plugin.guava.eventbus;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(PowerMockRunner.class)
@RunWith(MockitoJUnitRunner.class)
public class EventBusSubscriberConstructorInterceptorTest {
private EventBusSubscriberConstructorInterceptor interceptor;
@ -65,4 +64,4 @@ public class EventBusSubscriberConstructorInterceptorTest {
assertEquals("test", subscriberInfo.getMethodName());
assertEquals(Object.class.getName(), subscriberInfo.getClassName());
}
}
}

View File

@ -36,11 +36,8 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@RunWith(TracingSegmentRunner.class)
public class EventBusSubscriberInterceptorTest {
@Rule
@ -87,4 +84,4 @@ public class EventBusSubscriberInterceptorTest {
assertThat(spans, notNullValue());
assertThat(spans.size(), is(1));
}
}
}

View File

@ -18,6 +18,13 @@
package org.apache.skywalking.apm.plugin.httpClient.v4;
import static junit.framework.TestCase.assertNotNull;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.net.URI;
import java.util.List;
import org.apache.http.HttpHost;
@ -46,22 +53,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static junit.framework.TestCase.assertNotNull;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
@PrepareForTest(HttpHost.class)
@RunWith(TracingSegmentRunner.class)
public class HttpClientExecuteInterceptorTest {
@SegmentStoragePoint
@ -69,6 +64,8 @@ public class HttpClientExecuteInterceptorTest {
@Rule
public AgentServiceRule agentServiceRule = new AgentServiceRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
private HttpClientExecuteInterceptor httpClientExecuteInterceptor;
@Mock
@ -93,7 +90,6 @@ public class HttpClientExecuteInterceptorTest {
httpClientExecuteInterceptor = new HttpClientExecuteInterceptor();
HttpClientPluginConfig.Plugin.HttpClient.COLLECT_HTTP_PARAMS = true;
PowerMockito.mock(HttpHost.class);
when(statusLine.getStatusCode()).thenReturn(200);
when(httpResponse.getStatusLine()).thenReturn(statusLine);
when(httpHost.getHostName()).thenReturn("127.0.0.1");

Some files were not shown because too many files have changed in this diff Show More