Skip to content

Commit

Permalink
test extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahchen6 committed Dec 20, 2024
1 parent 158de7f commit 2da77e1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dd-java-agent/agent-jmxfetch/integrations-core
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import datadog.trace.api.Config
import datadog.trace.api.DDSpanTypes
import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
import datadog.trace.bootstrap.instrumentation.api.Tags
import datadog.trace.test.util.TestSourceFileExtension
import org.apache.derby.jdbc.EmbeddedDataSource
import org.h2.jdbcx.JdbcDataSource
import org.junit.jupiter.api.extension.ExtendWith
import spock.lang.Shared
import test.TestConnection
import test.WrappedConnection
Expand All @@ -24,6 +26,7 @@ import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
import static datadog.trace.api.config.TraceInstrumentationConfig.DB_CLIENT_HOST_SPLIT_BY_INSTANCE

@ExtendWith(TestSourceFileExtension)
abstract class JDBCInstrumentationTest extends VersionedNamingTestBase {

@Shared
Expand Down Expand Up @@ -752,7 +755,7 @@ abstract class JDBCInstrumentationTest extends VersionedNamingTestBase {
for (int i = 0; i < numQueries; ++i) {
res[i] == 3
}
assertTraces(5) {
assertTraces(6) {
trace(1) {
span {
operationName this.operation(dbType)
Expand Down Expand Up @@ -849,6 +852,7 @@ abstract class JDBCInstrumentationTest extends VersionedNamingTestBase {
protected abstract boolean dbmTraceInjected()
}
@ExtendWith(TestSourceFileExtension)
class JDBCInstrumentationV0Test extends JDBCInstrumentationTest {
@Override
Expand All @@ -872,6 +876,7 @@ class JDBCInstrumentationV0Test extends JDBCInstrumentationTest {
}
}
TestSourceFileExtension
class JDBCInstrumentationV1ForkedTest extends JDBCInstrumentationTest {
@Override
Expand All @@ -895,6 +900,7 @@ class JDBCInstrumentationV1ForkedTest extends JDBCInstrumentationTest {
}
}
@ExtendWith(TestSourceFileExtension)
class JDBCInstrumentationDBMTraceInjectedForkedTest extends JDBCInstrumentationTest {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package datadog.trace.test.util

import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.api.extension.TestWatcher

class TestSourceFileExtension implements TestWatcher {
TestSourceFileExtension() {
System.out.println("TestSourceFileExtension initialized!")
}

@Override
void testSuccessful(ExtensionContext context) {
System.out.println("test was successful!")
getTestData(context)
}

@Override
void testFailed(ExtensionContext context, Throwable cause) {
System.out.println("test failed!")
getTestData(context)
}

@Override
void testAborted(ExtensionContext context, Throwable cause) {
System.out.println("test aborted!")
getTestData(context)
}

@Override
void testDisabled(ExtensionContext context, Optional<String> reason) {
System.out.println("test disabled!")
getTestData(context)
}

private static void getTestData(ExtensionContext context) {
String testClassName = context.getTestClass().get().getSimpleName()
String testMethodName = context.getTestMethod().get().getName()
String className = context.getClass()
String requiredTestClassName = context.getRequiredTestClass().getName()
String requiredTestMethodName = context.getRequiredTestMethod().getName()

System.out.println("--------------------------")
System.out.println("testClassName: " + testClassName)
System.out.println("testMethodName: " + testMethodName)
System.out.println("className: " + className)
System.out.println("requiredTestClassName: " + requiredTestClassName)
System.out.println("requiredTestMethodName: " + requiredTestMethodName)
System.out.println("--------------------------")
}
}

0 comments on commit 2da77e1

Please sign in to comment.