Browse Source

Remove duplicate GcUtils class (#10871)

Lauri Tulmin 11 months ago
parent
commit
c3f8f7f13a

+ 1 - 2
javaagent/build.gradle.kts

@@ -89,8 +89,7 @@ dependencies {
   testCompileOnly(project(":javaagent-bootstrap"))
   testCompileOnly(project(":javaagent-extension-api"))
 
-  testImplementation("com.google.guava:guava")
-  testImplementation("io.opentelemetry:opentelemetry-sdk")
+  testImplementation(project(":testing-common"))
   testImplementation("io.opentracing.contrib.dropwizard:dropwizard-opentracing:0.2.2")
 }
 

+ 1 - 1
javaagent/src/test/groovy/io/opentelemetry/javaagent/classloading/ClassLoadingTest.groovy

@@ -5,9 +5,9 @@
 
 package io.opentelemetry.javaagent.classloading
 
+import io.opentelemetry.instrumentation.test.utils.GcUtils
 import io.opentelemetry.javaagent.ClassToInstrument
 import io.opentelemetry.javaagent.ClassToInstrumentChild
-import io.opentelemetry.javaagent.util.GcUtils
 import spock.lang.Specification
 
 import java.lang.ref.WeakReference

+ 0 - 31
javaagent/src/test/java/io/opentelemetry/javaagent/util/GcUtils.java

@@ -1,31 +0,0 @@
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.util;
-
-import java.lang.ref.WeakReference;
-import java.time.Duration;
-import java.time.temporal.ChronoUnit;
-import java.util.concurrent.TimeoutException;
-
-public final class GcUtils {
-  public static void awaitGc(WeakReference<?> ref, Duration timeout)
-      throws InterruptedException, TimeoutException {
-    long start = System.currentTimeMillis();
-    while (ref.get() != null
-        && !timeout.minus(System.currentTimeMillis() - start, ChronoUnit.MILLIS).isNegative()) {
-      if (Thread.interrupted()) {
-        throw new InterruptedException();
-      }
-      System.gc();
-      System.runFinalization();
-    }
-    if (ref.get() != null) {
-      throw new TimeoutException("reference was not cleared in time");
-    }
-  }
-
-  private GcUtils() {}
-}

+ 0 - 1
testing-common/src/main/java/io/opentelemetry/instrumentation/test/utils/GcUtils.java

@@ -28,7 +28,6 @@ public final class GcUtils {
         throw new InterruptedException();
       }
       System.gc();
-      System.runFinalization();
     }
     if (ref.get() != null) {
       throw new TimeoutException("reference was not cleared in time");