Skip to content

Commit

Permalink
Use stubs instead of mocks (#8052)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanchooly authored Dec 3, 2024
1 parent 7698f2f commit 310d00c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 0 additions & 1 deletion dd-java-agent/instrumentation/grpc-1.5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ dependencies {
testImplementation group: 'io.grpc', name: 'grpc-stub', version: grpcVersion
testImplementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
testImplementation project(':dd-java-agent:agent-debugger:debugger-bootstrap')
testImplementation libs.bundles.mockito

latestDepTestImplementation sourceSets.test.output // include the protobuf generated classes
latestDepTestCompileOnly group: 'io.grpc', name: 'grpc-core', version: '1.+'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ import io.grpc.Server
import io.grpc.inprocess.InProcessChannelBuilder
import io.grpc.inprocess.InProcessServerBuilder
import io.grpc.stub.StreamObserver
import org.mockito.internal.util.MockUtil

import java.lang.reflect.Method
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference

import static datadog.trace.api.config.TraceInstrumentationConfig.*
import org.mockito.Mockito

abstract class GrpcCodeOriginTest extends VersionedNamingTestBase {
private CodeOriginRecorder codeOriginRecorder
def codeOriginRecorder

@Override
final String service() {
Expand Down Expand Up @@ -157,8 +156,7 @@ abstract class GrpcCodeOriginTest extends VersionedNamingTestBase {
}.flatten().sort()


def invocations = MockUtil.getInvocationContainer(codeOriginRecorder)
assert invocations.invocations.stream().anyMatch { it.method.name == "captureCodeOrigin" }
assert codeOriginRecorder.invoked
assertTraces(2) {
trace((hasClientMessageSpans() ? clientMessageCount * serverMessageCount : 0) + 1) {
span {
Expand Down Expand Up @@ -253,7 +251,20 @@ abstract class GrpcCodeOriginTest extends VersionedNamingTestBase {

void codeOriginSetup() {
injectSysConfig(CODE_ORIGIN_FOR_SPANS_ENABLED, "true", true)
codeOriginRecorder = Mockito.mock(CodeOriginRecorder)
codeOriginRecorder = new CodeOriginRecorder() {
def invoked = false
@Override
String captureCodeOrigin(boolean entry) {
invoked = true
return "done"
}

@Override
String captureCodeOrigin(Method method, boolean entry) {
invoked = true
return "done"
}
}
DebuggerContext.initCodeOrigin(codeOriginRecorder)
}
}
Expand Down

0 comments on commit 310d00c

Please sign in to comment.