diff --git a/java/runtime/src/main/java/org/ray/runtime/functionmanager/RayFunction.java b/java/runtime/src/main/java/org/ray/runtime/functionmanager/RayFunction.java index 3d0704c6b..2f39ec3dc 100644 --- a/java/runtime/src/main/java/org/ray/runtime/functionmanager/RayFunction.java +++ b/java/runtime/src/main/java/org/ray/runtime/functionmanager/RayFunction.java @@ -58,12 +58,17 @@ public class RayFunction { } public RayRemote getRayRemoteAnnotation() { - RayRemote rayRemote = executable.getAnnotation(RayRemote.class); - if (rayRemote == null) { - // If the method doesn't have a annotation, get the annotation from - // its wrapping class. + RayRemote rayRemote; + + // If this method is a constructor, the task of it should be a actorCreationTask. + // And the annotation of actorCreationTask should inherit from class. + // Otherwise, it's a normal method, and it shouldn't inherit annotation from class. + if (isConstructor()) { rayRemote = executable.getDeclaringClass().getAnnotation(RayRemote.class); + } else { + rayRemote = executable.getAnnotation(RayRemote.class); } + return rayRemote; } diff --git a/java/runtime/src/test/java/org/ray/runtime/functionmanager/FunctionManagerTest.java b/java/runtime/src/test/java/org/ray/runtime/functionmanager/FunctionManagerTest.java index 85f482544..08e4d6415 100644 --- a/java/runtime/src/test/java/org/ray/runtime/functionmanager/FunctionManagerTest.java +++ b/java/runtime/src/test/java/org/ray/runtime/functionmanager/FunctionManagerTest.java @@ -74,7 +74,7 @@ public class FunctionManagerTest { func = functionManager.getFunction(UniqueId.NIL, barFunc); Assert.assertFalse(func.isConstructor()); Assert.assertEquals(func.getFunctionDescriptor(), barDescriptor); - Assert.assertNotNull(func.getRayRemoteAnnotation()); + Assert.assertNull(func.getRayRemoteAnnotation()); // Test actor constructor func = functionManager.getFunction(UniqueId.NIL, barConstructor); @@ -95,7 +95,7 @@ public class FunctionManagerTest { func = functionManager.getFunction(UniqueId.NIL, barDescriptor); Assert.assertFalse(func.isConstructor()); Assert.assertEquals(func.getFunctionDescriptor(), barDescriptor); - Assert.assertNotNull(func.getRayRemoteAnnotation()); + Assert.assertNull(func.getRayRemoteAnnotation()); // Test actor constructor func = functionManager.getFunction(UniqueId.NIL, barConstructorDescriptor); diff --git a/java/test/src/main/java/org/ray/api/test/ResourcesManagementTest.java b/java/test/src/main/java/org/ray/api/test/ResourcesManagementTest.java index 001723fec..69d0f57a7 100644 --- a/java/test/src/main/java/org/ray/api/test/ResourcesManagementTest.java +++ b/java/test/src/main/java/org/ray/api/test/ResourcesManagementTest.java @@ -45,6 +45,13 @@ public class ResourcesManagementTest { } } + @RayRemote(resources = {@ResourceItem(name = "RES-A", value = 4)}) + public static class Echo3 { + public Integer echo(Integer number) { + return number; + } + } + @Test public void testMethods() { // This is a case that can satisfy required resources. @@ -75,5 +82,14 @@ public class ResourcesManagementTest { Assert.assertEquals(1, waitResult.getUnready().size()); } + @Test + public void testActorAndMemberMethods() { + // Note(qwang): This case depends on the following line. + // https://github.com/ray-project/ray/blob/master/java/test/src/main/java/org/ray/api/test/TestListener.java#L13 + // If we change the static resources configuration item, this case may not pass. + // Then we should change this case too. + RayActor echo3 = Ray.createActor(Echo3::new); + Assert.assertEquals(100, (int) Ray.call(Echo3::echo, echo3, 100).get()); + } } diff --git a/java/test/src/main/java/org/ray/api/test/TestListener.java b/java/test/src/main/java/org/ray/api/test/TestListener.java index 3fb16bf4f..efc419b34 100644 --- a/java/test/src/main/java/org/ray/api/test/TestListener.java +++ b/java/test/src/main/java/org/ray/api/test/TestListener.java @@ -10,7 +10,7 @@ public class TestListener extends RunListener { @Override public void testRunStarted(Description description) { System.setProperty("ray.home", "../.."); - System.setProperty("ray.resources", "CPU:4"); + System.setProperty("ray.resources", "CPU:4,RES-A:4"); Ray.init(); }