diff --git a/boot/src/test/kotlin/integration/ProbeIntegrationTest.kt b/boot/src/test/kotlin/integration/ProbeIntegrationTest.kt index c210ea7d..d1829805 100644 --- a/boot/src/test/kotlin/integration/ProbeIntegrationTest.kt +++ b/boot/src/test/kotlin/integration/ProbeIntegrationTest.kt @@ -31,7 +31,6 @@ import io.vertx.kotlin.coroutines.await import io.vertx.serviceproxy.ServiceProxyBuilder import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout -import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach @@ -83,9 +82,13 @@ abstract class ProbeIntegrationTest { private const val servicePort = 12800 private val accessToken: String? by lazy { fetchAccessToken() } + @Synchronized @BeforeAll @JvmStatic fun setup() = runBlocking { + if (::vertx.isInitialized) { + return@runBlocking + } vertx = Vertx.vertx() socket = setupTcp(vertx) TCPServiceSocket(vertx, socket) @@ -136,14 +139,6 @@ abstract class ProbeIntegrationTest { .build(LiveViewService::class.java) } - @AfterAll - @JvmStatic - fun tearDown() { - runBlocking { - vertx.close().await() - } - } - fun getLiveViewSubscription(viewId: String): MessageConsumer { val listenAddress = toLiveViewSubscription(viewId) diff --git a/boot/src/test/kotlin/integration/breakpoint/LambdaTest.kt b/boot/src/test/kotlin/integration/breakpoint/LambdaTest.kt index 3464c72a..f9b052c7 100644 --- a/boot/src/test/kotlin/integration/breakpoint/LambdaTest.kt +++ b/boot/src/test/kotlin/integration/breakpoint/LambdaTest.kt @@ -22,6 +22,8 @@ import io.vertx.kotlin.coroutines.await import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Execution +import org.junit.jupiter.api.parallel.ExecutionMode import spp.protocol.instrument.LiveBreakpoint import spp.protocol.instrument.event.LiveBreakpointHit import spp.protocol.instrument.event.LiveInstrumentEvent @@ -31,6 +33,7 @@ import spp.protocol.instrument.location.LocationScope import spp.protocol.instrument.throttle.InstrumentThrottle import java.util.concurrent.atomic.AtomicInteger +@Execution(ExecutionMode.SAME_THREAD) class LambdaTest : ProbeIntegrationTest() { private fun doLambdaOnlyTest() { @@ -71,7 +74,7 @@ class LambdaTest : ProbeIntegrationTest() { LiveBreakpoint( location = LiveSourceLocation( source = LambdaTest::class.java.name, - line = 42, + line = 45, scope = LocationScope.LAMBDA, service = "spp-test-probe" ), @@ -115,7 +118,7 @@ class LambdaTest : ProbeIntegrationTest() { LiveBreakpoint( location = LiveSourceLocation( source = LambdaTest::class.java.name, - line = 92, + line = 95, scope = LocationScope.LINE, service = "spp-test-probe" ), @@ -159,7 +162,7 @@ class LambdaTest : ProbeIntegrationTest() { LiveBreakpoint( location = LiveSourceLocation( source = LambdaTest::class.java.name, - line = 136, + line = 139, scope = LocationScope.LAMBDA, service = "spp-test-probe" ), @@ -206,7 +209,7 @@ class LambdaTest : ProbeIntegrationTest() { LiveBreakpoint( location = LiveSourceLocation( source = LambdaTest::class.java.name, - line = 180, + line = 183, scope = LocationScope.BOTH, service = "spp-test-probe" ), diff --git a/boot/src/test/kotlin/integration/breakpoint/NonExistentClassTest.kt b/boot/src/test/kotlin/integration/breakpoint/NonExistentClassTest.kt index c6fd16ff..295259d7 100644 --- a/boot/src/test/kotlin/integration/breakpoint/NonExistentClassTest.kt +++ b/boot/src/test/kotlin/integration/breakpoint/NonExistentClassTest.kt @@ -24,10 +24,12 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.junit.jupiter.api.fail +import org.junit.jupiter.api.parallel.Isolated import spp.protocol.instrument.LiveBreakpoint import spp.protocol.instrument.location.LiveSourceLocation import spp.protocol.service.error.LiveInstrumentException +@Isolated class NonExistentClassTest : ProbeIntegrationTest() { @Test diff --git a/boot/src/test/kotlin/integration/meter/MeterGaugeTest.kt b/boot/src/test/kotlin/integration/meter/MeterGaugeTest.kt index ff4884ac..ac32d4ee 100644 --- a/boot/src/test/kotlin/integration/meter/MeterGaugeTest.kt +++ b/boot/src/test/kotlin/integration/meter/MeterGaugeTest.kt @@ -21,7 +21,8 @@ import io.vertx.core.json.JsonObject import io.vertx.junit5.VertxTestContext import io.vertx.kotlin.coroutines.await import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test import spp.protocol.instrument.LiveMeter import spp.protocol.instrument.location.LiveSourceLocation @@ -43,11 +44,14 @@ class MeterGaugeTest : ProbeIntegrationTest() { @Suppress("UNUSED_VARIABLE") private fun doTest() { var i = 11 + addLineLabel("done") { Throwable().stackTrace[0].lineNumber } } @Test fun `number supplier gauge`(): Unit = runBlocking { - val meterId = testNameAsUniqueInstrumentId + setupLineLabels { + doTest() + } val supplier = object : Supplier, Serializable { override fun get(): Double = System.currentTimeMillis().toDouble() @@ -62,10 +66,10 @@ class MeterGaugeTest : ProbeIntegrationTest() { MetricValue(MetricValueType.NUMBER_SUPPLIER, encodedSupplier), location = LiveSourceLocation( MeterGaugeTest::class.java.name, - 46, + getLineNumber("done"), "spp-test-probe" ), - id = meterId, + id = testNameAsUniqueInstrumentId, applyImmediately = true ) @@ -99,10 +103,9 @@ class MeterGaugeTest : ProbeIntegrationTest() { val meta = rawMetrics.getJsonObject("meta") assertEquals(liveMeter.id!!, meta.getString("metricsName")) - //check within a second + //check within 5 seconds val suppliedTime = rawMetrics.getLong("value") - assertTrue(suppliedTime >= System.currentTimeMillis() - 1000) - assertTrue(suppliedTime <= System.currentTimeMillis()) + assertEquals(System.currentTimeMillis().toDouble(), suppliedTime.toDouble(), 5000.0) } testContext.completeNow() } @@ -114,23 +117,25 @@ class MeterGaugeTest : ProbeIntegrationTest() { errorOnTimeout(testContext) //clean up - assertNotNull(instrumentService.removeLiveInstrument(meterId).await()) + assertNotNull(instrumentService.removeLiveInstrument(liveMeter.id!!).await()) assertNotNull(viewService.removeLiveView(subscriptionId).await()) } @Test fun `number expression gauge`(): Unit = runBlocking { - val meterId = testNameAsUniqueInstrumentId + setupLineLabels { + doTest() + } val liveMeter = LiveMeter( MeterType.GAUGE, MetricValue(MetricValueType.NUMBER_EXPRESSION, "localVariables[i]"), location = LiveSourceLocation( MeterGaugeTest::class.java.name, - 46, + getLineNumber("done"), "spp-test-probe" ), - id = meterId, + id = testNameAsUniqueInstrumentId, applyImmediately = true ) @@ -177,7 +182,7 @@ class MeterGaugeTest : ProbeIntegrationTest() { errorOnTimeout(testContext) //clean up - assertNotNull(instrumentService.removeLiveInstrument(meterId).await()) + assertNotNull(instrumentService.removeLiveInstrument(liveMeter.id!!).await()) assertNotNull(viewService.removeLiveView(subscriptionId).await()) } } diff --git a/boot/src/test/kotlin/integration/meter/MeterMethodTimerTest.kt b/boot/src/test/kotlin/integration/meter/MeterMethodTimerTest.kt index d51aaee6..f8e38505 100644 --- a/boot/src/test/kotlin/integration/meter/MeterMethodTimerTest.kt +++ b/boot/src/test/kotlin/integration/meter/MeterMethodTimerTest.kt @@ -23,6 +23,7 @@ import io.vertx.kotlin.coroutines.await import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Isolated import spp.protocol.instrument.LiveMeter import spp.protocol.instrument.location.LiveSourceLocation import spp.protocol.instrument.meter.MeterType @@ -34,6 +35,7 @@ import spp.protocol.view.LiveViewEvent import spp.protocol.view.rule.MethodTimerAvgRule import spp.protocol.view.rule.MethodTimerCountRule +@Isolated class MeterMethodTimerTest : ProbeIntegrationTest() { private fun doTest() { @@ -77,12 +79,12 @@ class MeterMethodTimerTest : ProbeIntegrationTest() { val liveViewEvent = LiveViewEvent(it.body()) val rawMetrics = JsonArray(liveViewEvent.metricsData) testContext.verify { - val avg = rawMetrics.getJsonObject(0) - assertTrue(avg.getString("metric_type").endsWith("_avg")) - assertEquals(200.0, avg.getDouble("value"), 5.0) - val rate = rawMetrics.getJsonObject(1) - assertEquals(10.0, rate.getDouble("summation")) + if (rate.getDouble("summation").toInt() == 10) { + val avg = rawMetrics.getJsonObject(0) + assertTrue(avg.getString("metric_type").endsWith("_avg")) + assertEquals(200.0, avg.getDouble("value"), 100.0) + } } testContext.completeNow() } diff --git a/boot/src/test/kotlin/integration/meter/MeterMonitorTest.kt b/boot/src/test/kotlin/integration/meter/MeterMonitorTest.kt index 19df4d84..9fe2569a 100644 --- a/boot/src/test/kotlin/integration/meter/MeterMonitorTest.kt +++ b/boot/src/test/kotlin/integration/meter/MeterMonitorTest.kt @@ -264,7 +264,7 @@ class MeterMonitorTest : ProbeIntegrationTest() { assertEquals(avgMeterId, meta.getString("metricsName")) assertTrue(rawMetrics.getDouble("value") > 0.0) - assertEquals(100.0, rawMetrics.getDouble("value"), 250.0) + assertEquals(100.0, rawMetrics.getDouble("value"), 400.0) //todo: more accurate } testContext.completeNow() } diff --git a/boot/src/test/resources/junit-platform.properties b/boot/src/test/resources/junit-platform.properties new file mode 100644 index 00000000..63b9bce0 --- /dev/null +++ b/boot/src/test/resources/junit-platform.properties @@ -0,0 +1,4 @@ +junit.jupiter.execution.parallel.enabled=true +junit.jupiter.execution.parallel.config.strategy=dynamic +junit.jupiter.execution.parallel.mode.default=concurrent +junit.jupiter.execution.parallel.mode.classes.default=concurrent \ No newline at end of file diff --git a/boot/src/test/resources/spp-test-probe.yml b/boot/src/test/resources/spp-test-probe.yml index d0fa9d9f..633e83d8 100644 --- a/boot/src/test/resources/spp-test-probe.yml +++ b/boot/src/test/resources/spp-test-probe.yml @@ -8,6 +8,7 @@ spp: platform_port: ${SPP_PROBE_PLATFORM_PORT:-12800} quiet_mode: ${SPP_PROBE_QUIET_MODE:-false} install_directory: ${SPP_PROBE_INSTALL_DIRECTORY:-/tmp/spp-probe} + transformed_dump_directory: ${SPP_PROBE_TRANSFORMED_DUMP_DIRECTORY:-/tmp/spp-probe/transformed-classes} skywalking: logging: level: ${SW_LOGGING_LEVEL:-DEBUG} diff --git a/services/src/main/kotlin/spp/probe/services/common/ContextReceiver.kt b/services/src/main/kotlin/spp/probe/services/common/ContextReceiver.kt index dc88288e..685915b3 100644 --- a/services/src/main/kotlin/spp/probe/services/common/ContextReceiver.kt +++ b/services/src/main/kotlin/spp/probe/services/common/ContextReceiver.kt @@ -286,7 +286,19 @@ object ContextReceiver { value.toDouble() } else { //todo: remove instrument - log.error("Unsupported expression value type: ${value?.javaClass?.name}") + log.error(buildString { + append("Non-number value for gauge.") + append(" Live meter: ") + append(liveMeter.id) + append(" Expression: ") + append(liveMeter.metricValue!!.value) + append(" Value: ") + append(value) + append(" Type: ") + append(value?.javaClass?.name) + append(" Context: ") + append(contextMap) + }) Double.MIN_VALUE } }.apply { tagMap.forEach { tag(it.key, it.value) } }.build() diff --git a/services/src/test/kotlin/spp/probe/services/common/serialize/AbstractSerializeTest.kt b/services/src/test/kotlin/spp/probe/services/common/serialize/AbstractSerializeTest.kt index 0f3319e2..74e66ab2 100644 --- a/services/src/test/kotlin/spp/probe/services/common/serialize/AbstractSerializeTest.kt +++ b/services/src/test/kotlin/spp/probe/services/common/serialize/AbstractSerializeTest.kt @@ -33,6 +33,8 @@ interface AbstractSerializeTest { ProbeConfiguration.variableControl.put("max_object_depth", 5) ProbeConfiguration.variableControl.put("max_object_size", 1024L * 1024L) //1MB ProbeConfiguration.variableControl.put("max_collection_length", 100) - ProbeConfiguration.instrumentation = Mockito.mock(Instrumentation::class.java) + ProbeConfiguration.instrumentation = Mockito.mock(Instrumentation::class.java).apply { + Mockito.`when`(this.getObjectSize(Mockito.any())).thenReturn(0) + } } } diff --git a/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxCollectionLengthTest.kt b/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxCollectionLengthTest.kt index 036cfd22..54cd7536 100644 --- a/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxCollectionLengthTest.kt +++ b/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxCollectionLengthTest.kt @@ -20,9 +20,11 @@ import io.vertx.core.json.JsonArray import io.vertx.core.json.JsonObject import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Isolated import spp.probe.ProbeConfiguration import spp.probe.services.common.ModelSerializer +@Isolated class CustomMaxCollectionLengthTest : AbstractSerializeTest { @Test diff --git a/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxObjectDepthTest.kt b/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxObjectDepthTest.kt index 32dc3d0e..5fd04fad 100644 --- a/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxObjectDepthTest.kt +++ b/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxObjectDepthTest.kt @@ -20,9 +20,11 @@ import io.vertx.core.json.JsonObject import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Isolated import spp.probe.ProbeConfiguration import spp.probe.services.common.ModelSerializer +@Isolated class CustomMaxObjectDepthTest : AbstractSerializeTest { @Test diff --git a/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxObjectSizeTest.kt b/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxObjectSizeTest.kt index 2e567ef9..1f48391c 100644 --- a/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxObjectSizeTest.kt +++ b/services/src/test/kotlin/spp/probe/services/common/serialize/CustomMaxObjectSizeTest.kt @@ -20,11 +20,13 @@ import io.vertx.core.json.JsonObject import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Isolated import org.mockito.Mockito import spp.probe.ProbeConfiguration import spp.probe.services.common.ModelSerializer import java.lang.instrument.Instrumentation +@Isolated class CustomMaxObjectSizeTest : AbstractSerializeTest { @Test diff --git a/services/src/test/kotlin/spp/probe/services/common/serialize/MaxObjectSizeTest.kt b/services/src/test/kotlin/spp/probe/services/common/serialize/MaxObjectSizeTest.kt index 7baadea7..a7349e72 100644 --- a/services/src/test/kotlin/spp/probe/services/common/serialize/MaxObjectSizeTest.kt +++ b/services/src/test/kotlin/spp/probe/services/common/serialize/MaxObjectSizeTest.kt @@ -20,11 +20,13 @@ import io.vertx.core.json.JsonObject import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Isolated import org.mockito.Mockito import spp.probe.ProbeConfiguration import spp.probe.services.common.ModelSerializer import java.lang.instrument.Instrumentation +@Isolated class MaxObjectSizeTest : AbstractSerializeTest { @Test diff --git a/services/src/test/kotlin/spp/probe/services/common/serialize/ObjectMapTest.kt b/services/src/test/kotlin/spp/probe/services/common/serialize/ObjectMapTest.kt index 077f43e9..16702766 100644 --- a/services/src/test/kotlin/spp/probe/services/common/serialize/ObjectMapTest.kt +++ b/services/src/test/kotlin/spp/probe/services/common/serialize/ObjectMapTest.kt @@ -20,20 +20,13 @@ import io.vertx.core.json.JsonObject import org.apache.skywalking.apm.agent.core.meter.* import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import org.mockito.Mockito -import spp.probe.ProbeConfiguration import spp.probe.services.common.ModelSerializer -import java.lang.instrument.Instrumentation import java.util.concurrent.ConcurrentHashMap class ObjectMapTest : AbstractSerializeTest { @Test fun `sw meter map`() { - ProbeConfiguration.instrumentation = Mockito.mock(Instrumentation::class.java).apply { - Mockito.`when`(this.getObjectSize(Mockito.any())).thenReturn(1024) - } - val map = ConcurrentHashMap() val meterId1 = MeterId("test1", MeterType.COUNTER, emptyList()) map[meterId1] = Counter(meterId1, CounterMode.RATE).apply { increment(2.0) } diff --git a/services/src/test/kotlin/spp/probe/services/instrument/ProbeInstrumentTest.kt b/services/src/test/kotlin/spp/probe/services/instrument/ProbeInstrumentTest.kt index 236695b5..6fd4876f 100644 --- a/services/src/test/kotlin/spp/probe/services/instrument/ProbeInstrumentTest.kt +++ b/services/src/test/kotlin/spp/probe/services/instrument/ProbeInstrumentTest.kt @@ -20,6 +20,7 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.Isolated import org.mockito.Mockito import org.springframework.expression.spel.SpelCompilerMode import org.springframework.expression.spel.SpelParserConfiguration @@ -32,6 +33,7 @@ import spp.protocol.instrument.location.LiveSourceLocation import java.lang.instrument.Instrumentation import java.util.function.BiConsumer +@Isolated class ProbeInstrumentTest { companion object { private val parser = SpelExpressionParser( diff --git a/services/src/test/resources/junit-platform.properties b/services/src/test/resources/junit-platform.properties new file mode 100644 index 00000000..63b9bce0 --- /dev/null +++ b/services/src/test/resources/junit-platform.properties @@ -0,0 +1,4 @@ +junit.jupiter.execution.parallel.enabled=true +junit.jupiter.execution.parallel.config.strategy=dynamic +junit.jupiter.execution.parallel.mode.default=concurrent +junit.jupiter.execution.parallel.mode.classes.default=concurrent \ No newline at end of file