mirror of
https://github.com/wassname/ray.git
synced 2026-07-02 01:20:20 +08:00
[Java] support java actor class inheritance (#12001)
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user