Skip to content

Commit

Permalink
[Runtime env][Java] Add unit tests for specifying jars for tasks. (ra…
Browse files Browse the repository at this point in the history
…y-project#24712)

It seems that we have already supported specifying java jars for normal tasks, this PR only needs to add unit tests for that.
  • Loading branch information
jovany-wang authored May 13, 2022
1 parent c62e00e commit 3208cfc
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions java/test/src/main/java/io/ray/test/RuntimeEnvTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.ray.api.Ray;
import io.ray.api.runtimeenv.RuntimeEnv;
import io.ray.runtime.util.SystemUtil;
import java.util.List;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -193,4 +194,56 @@ public void testZipPackageInActor() {
testDownloadAndLoadPackage(
"https://github.com/ray-project/test_packages/raw/main/raw_resources/java-1.0-SNAPSHOT.zip");
}

private static boolean findClasses(List<String> classNames) {
try {
for (String name : classNames) {
Class.forName(name);
}
} catch (ClassNotFoundException e) {
return false;
}
return true;
}

private static void testDownloadAndLoadPackagesForTask(
List<String> urls, List<String> classNames) {
try {
Ray.init();
final RuntimeEnv runtimeEnv = new RuntimeEnv.Builder().addJars(urls).build();
boolean ret =
Ray.task(RuntimeEnvTest::findClasses, classNames)
.setRuntimeEnv(runtimeEnv)
.remote()
.get();
Assert.assertTrue(ret);
} finally {
Ray.shutdown();
}
}

private static void testDownloadAndLoadPackagesForTask(String url, String className) {
testDownloadAndLoadPackagesForTask(ImmutableList.of(url), ImmutableList.of(className));
}

public void testJarPackageForTask() {
testDownloadAndLoadPackagesForTask(
"https://github.com/ray-project/test_packages/raw/main/raw_resources/bar.jar",
"io.testpackages.Bar");
}

public void testZipPackageForTask() {
testDownloadAndLoadPackagesForTask(
"https://github.com/ray-project/test_packages/raw/main/raw_resources/foo.zip",
"io.testpackages.Foo");
}

/// This case tests that a task needs 2 jars for load different classes.
public void testMultipleJars() {
testDownloadAndLoadPackagesForTask(
ImmutableList.of(
"https://github.com/ray-project/test_packages/raw/main/raw_resources/bar.jar",
"https://github.com/ray-project/test_packages/raw/main/raw_resources/foo.jar"),
ImmutableList.of("io.testpackages.Bar", "io.testpackages.Foo"));
}
}

0 comments on commit 3208cfc

Please sign in to comment.