Skip to content

Commit

Permalink
NCLSUP-1147 Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Oct 3, 2024
1 parent 5a03c86 commit 3618109
Show file tree
Hide file tree
Showing 6 changed files with 6,490 additions and 14 deletions.
45 changes: 34 additions & 11 deletions common/src/testFixtures/java/org/jboss/gm/common/JVMTestSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,29 @@ public class JVMTestSetup {

public static final Path JDK8_BIN_DIR = JDK8_DIR.resolve("bin");

public static final String JDK17_BASEDIR = "jdk-17.0.12+7";

public static final Path JDK17_DIR = GRADLE_JDK_HOME.resolve(JDK17_BASEDIR);

public static final Path JDK17_BIN_DIR = JDK17_DIR.resolve("bin");

/**
* This method will, on Linux, download and cache if it doesn't exist a JDK8 installation from AdoptOpenJDK.
*
* This method will, on Linux, download and cache if it doesn't exist JDK8 and 17 installations.
* <br/>
* This location ($HOME/.gradle/jdks) was chosen to match https://docs.gradle.org/current/userguide/toolchains.html.
* It utilises the same directory structure and location thereby matching potential prior downloads.
*/
public static void setupJVM() throws IOException {
String filename = null;
UnArchiver ua = null;
String filename;
UnArchiver ua = new TarGZipUnArchiver();

if (SystemUtils.IS_OS_LINUX) {
filename = "OpenJDK8U-jdk_x64_linux_hotspot_8u272b10.tar.gz";
ua = new TarGZipUnArchiver();
} else if (SystemUtils.IS_OS_WINDOWS) {
filename = "OpenJDK8U-jdk_x64_windows_hotspot_8u272b10.zip";
ua = new ZipUnArchiver();
} else {
if (!SystemUtils.IS_OS_LINUX) {
throw new ManipulationUncheckedException("Unknown OS");
}

if (!Files.exists(JDK8_BIN_DIR)) {
Files.createDirectories(JDK8_DIR);
filename = "OpenJDK8U-jdk_x64_linux_hotspot_8u272b10.tar.gz";

Path destFile = GRADLE_JDK_HOME.resolve(filename);

Expand All @@ -66,7 +67,29 @@ public static void setupJVM() throws IOException {

ua.extract();
}
if (!Files.exists(JDK17_BIN_DIR)) {
Files.createDirectories(JDK17_DIR);
filename = "OpenJDK17U-jdk_x64_linux_hotspot_17.0.12_7.tar.gz";

Path destFile = GRADLE_JDK_HOME.resolve(filename);

destFile.toFile().deleteOnExit();

Unirest.get(
"https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.12%2B7/" + filename)
.asFile(destFile.toString());

((LogEnabled) ua).enableLogging(new ConsoleLoggerManager().getLoggerForComponent("plexus-archiver"));
ua.setSourceFile(destFile.toFile());
ua.setDestDirectory(GRADLE_JDK_HOME.toFile());

assertThat(destFile).isRegularFile();
assertThat(GRADLE_JDK_HOME).isDirectory();

ua.extract();
}

assertThat(JDK8_BIN_DIR).isDirectory();
assertThat(JDK17_BIN_DIR).isDirectory();
}
}
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=abc10bcedb58806e8654210f96031db541bcd2d6fc3161e81cb0572d6a15e821
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.jboss.gm.manipulation;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.gradle.util.GradleVersion;
import org.jboss.gm.common.JVMTestSetup;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;

import static org.assertj.core.api.Assertions.assertThat;
import static org.jboss.gm.common.JVMTestSetup.JDK17_DIR;
import static org.junit.Assume.assumeTrue;

public class OpenTelemetryJavaInstrumentationProjectFunctionalTest {

@Rule
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();//.muteForSuccessfulTests();

@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

@Rule
public final TestRule restoreSystemProperties = new RestoreSystemProperties();

@BeforeClass
public static void setupJVM() throws IOException {
JVMTestSetup.setupJVM();
}

@Test
public void testOpenTelemetryJavaInstrumentation() throws IOException, URISyntaxException, GitAPIException {
assumeTrue(GradleVersion.current().compareTo(GradleVersion.version("8.0")) >= 0);

final File opentelemetryProjectRoot = tempDir.newFolder("opentelemetry-java-instrumentation-project");

final File publishDirectory = tempDir.newFolder("publish");
System.setProperty("AProxDeployUrl", "file://" + publishDirectory.toString());

try (Git ignored = Git.cloneRepository()
.setURI("https://github.com/open-telemetry/opentelemetry-java-instrumentation.git")
.setDirectory(opentelemetryProjectRoot)
.setBranch("refs/tags/v2.5.0")
.setDepth(1)
.call()) {
System.out.println("Cloned opentelemetry-java-instrumentation to " + opentelemetryProjectRoot);
}

TestUtils.copyDirectory("opentelemetry-java-instrumentation", opentelemetryProjectRoot);

final BuildResult buildResult = TestUtils.createGradleRunner()
.withProjectDir(opentelemetryProjectRoot)
.withArguments("-Potel.stable=true", "-Dorg.gradle.java.home=" + JDK17_DIR, "publish", "-x", "test")
.forwardOutput()
.withDebug(false)
.withPluginClasspath()
.build();

assertThat(buildResult.task(":bom:publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(new File(publishDirectory, "io/opentelemetry/javaagent/opentelemetry-javaagent/2.5.0.redhat-00001/opentelemetry-javaagent-2.5.0.redhat-00001.jar")).exists();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

import java.time.Duration

plugins {
// including this plugin directly instead of by an init script, which allows to use the freshly build version
id("org.jboss.gm.manipulation")

id("idea")

id("otel.spotless-conventions")
/* workaround for
What went wrong:
Could not determine the dependencies of task ':smoke-tests-otel-starter:spring-boot-3.2:bootJar'.
> Could not create task ':smoke-tests-otel-starter:spring-boot-3.2:collectReachabilityMetadata'.
> Cannot set the value of task ':smoke-tests-otel-starter:spring-boot-3.2:collectReachabilityMetadata' property 'metadataService' of type org.graalvm.buildtools.gradle.internal.GraalVMReachabilityMetadataService using a provider of type org.graalvm.buildtools.gradle.internal.GraalVMReachabilityMetadataService.
See https://github.com/gradle/gradle/issues/17559#issuecomment-1327991512
*/
id("org.graalvm.buildtools.native") apply false
}

allprojects {
apply(plugin="org.jboss.gm.manipulation")
}

apply(from = "version.gradle.kts")

description = "OpenTelemetry instrumentations for Java"

if (project.findProperty("skipTests") as String? == "true") {
subprojects {
tasks.withType<Test>().configureEach {
enabled = false
}
}
}

tasks {
val listTestsInPartition by registering {
group = "Help"
description = "List test tasks in given partition"

// total of 4 partitions (see modulo 4 below)
var testPartition = (project.findProperty("testPartition") as String?)?.toInt()
if (testPartition == null) {
throw GradleException("Test partition must be specified")
} else if (testPartition < 0 || testPartition >= 4) {
throw GradleException("Invalid test partition")
}

val partitionTasks = ArrayList<Test>()
var testPartitionCounter = 0
subprojects {
// relying on predictable ordering of subprojects
// (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14CB4)
// since we are splitting these tasks across different github action jobs
val enabled = testPartitionCounter++ % 4 == testPartition
if (enabled) {
tasks.withType<Test>().configureEach {
partitionTasks.add(this)
}
}
}

doLast {
File("test-tasks.txt").printWriter().use { writer ->
partitionTasks.forEach { task ->
var taskPath = task.project.path + ":" + task.name
// smoke tests are run separately
// :instrumentation:test runs all instrumentation tests
if (taskPath != ":smoke-tests:test" && taskPath != ":instrumentation:test") {
writer.println(taskPath)
}
}
}
}

// disable all tasks to stop build
subprojects {
tasks.configureEach {
enabled = false
}
}
}
}

if (gradle.startParameter.taskNames.any { it.equals("listTestsInPartition") }) {
// disable all tasks to stop build
project.tasks.configureEach {
if (this.name != "listTestsInPartition") {
enabled = false
}
}
}
Loading

0 comments on commit 3618109

Please sign in to comment.