[Java] support java actor class inheritance (#12001)

This commit is contained in:
chaokunyang
2020-11-23 14:07:10 +08:00
committed by GitHub
parent 643c07e451
commit 9d133e874c
3 changed files with 133 additions and 27 deletions
@@ -144,4 +144,40 @@ public class ActorTest extends BaseTest {
// Free deletes big objects from plasma store.
Assert.expectThrows(UnreconstructableException.class, () -> largeValue.get());
}
public interface ChildClassInterface {
default String interfaceName() {
return ChildClassInterface.class.getName();
}
}
public static class ChildClass extends Counter implements ChildClassInterface {
public ChildClass(int initValue) {
super(initValue);
}
@Override
public void increase(int delta) {
super.increase(-delta);
}
}
@Test(groups = {"cluster"})
public void testInheritance() {
ActorHandle<ChildClass> counter = Ray.actor(ChildClass::new, 100).remote();
counter.task(ChildClass::increase, 10).remote();
Assert.assertEquals(counter.task(ChildClass::getValue).remote().get(), Integer.valueOf(90));
// Since `increase` method is overrided, call by super class method reference should still
// execute child class methods.
counter.task(Counter::increase, 10).remote();
Assert.assertEquals(counter.task(Counter::getValue).remote().get(), Integer.valueOf(80));
// test interface default methods
Assert.assertEquals(counter.task(ChildClassInterface::interfaceName).remote().get(),
ChildClassInterface.class.getName());
}
}