From eb27994e7834bfab6e5f634ac7ef9ee6c7d955e7 Mon Sep 17 00:00:00 2001 From: Artur Souza Date: Mon, 9 Mar 2020 12:36:56 -0700 Subject: [PATCH] Fixing bug in exception handling from actor impl. (#247) --- .../io/dapr/actors/runtime/ActorManager.java | 4 +- .../dapr/actors/runtime/ActorManagerTest.java | 86 ++++++++++++++++++- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorManager.java b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorManager.java index f102d28ec..e2495856a 100644 --- a/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorManager.java +++ b/sdk-actors/src/main/java/io/dapr/actors/runtime/ActorManager.java @@ -285,8 +285,10 @@ class ActorManager { // Actor methods must have a one or no parameter, which is guaranteed at this point. return method.invoke(actor, input); } + } catch (RuntimeException e) { + throw e; } catch (Exception e) { - return Mono.error(e); + throw new RuntimeException(e); } }); } diff --git a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorManagerTest.java b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorManagerTest.java index 59673a83e..3fc37c25a 100644 --- a/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorManagerTest.java +++ b/sdk-actors/src/test/java/io/dapr/actors/runtime/ActorManagerTest.java @@ -8,13 +8,13 @@ package io.dapr.actors.runtime; import io.dapr.actors.ActorId; import io.dapr.actors.ActorType; import io.dapr.serializer.DefaultObjectSerializer; -import org.junit.Assert; -import org.junit.Test; -import reactor.core.publisher.Mono; - import java.io.IOException; import java.time.Duration; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Assert; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import reactor.core.publisher.Mono; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -35,6 +35,12 @@ public class ActorManagerTest { int getCount(); void incrementCount(int delta); + + void throwsException(); + + Mono throwsExceptionHotMono(); + + Mono throwsExceptionMono(); } public static class NotRemindableActor extends AbstractActor { @@ -63,6 +69,21 @@ public class ActorManagerTest { this.timeCount = timeCount + delta; } + @Override + public void throwsException() { + throw new IllegalArgumentException(); + } + + @Override + public Mono throwsExceptionHotMono() { + throw new IllegalArgumentException(); + } + + @Override + public Mono throwsExceptionMono() { + return Mono.error(new IllegalArgumentException()); + } + public MyActorImpl(ActorRuntimeContext runtimeContext, ActorId id) { super(runtimeContext, id); super.registerActorTimer( @@ -107,6 +128,63 @@ public class ActorManagerTest { this.context.getObjectSerializer().deserialize(response, String.class)); } + @Test + public void activateThenInvokeWithActorImplException() throws Exception { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + + Assertions.assertThrows(RuntimeException.class, () -> { + this.manager.invokeMethod(actorId, "throwsException", null).block(); + }); + } + + @Test + public void activateThenInvokeWithActorImplExceptionButNotSubscribed() throws Exception { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + + // Nothing happens because we don't call block(). + this.manager.invokeMethod(actorId, "throwsException", null); + } + + @Test + public void activateThenInvokeWithActorImplHotMonoException() throws Exception { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + + Assertions.assertThrows(RuntimeException.class, () -> { + this.manager.invokeMethod(actorId, "throwsExceptionHotMono", null).block(); + }); + } + + @Test + public void activateThenInvokeWithActorImplHotMonoExceptionNotSubscribed() throws Exception { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + + // Nothing happens because we don't call block(). + this.manager.invokeMethod(actorId, "throwsExceptionHotMono", null); + } + + @Test + public void activateThenInvokeWithActorImplMonoException() throws Exception { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + + Assertions.assertThrows(RuntimeException.class, () -> { + this.manager.invokeMethod(actorId, "throwsExceptionMono", null).block(); + }); + } + + @Test + public void activateThenInvokeWithActorImplMonoExceptionNotSubscribed() throws Exception { + ActorId actorId = newActorId(); + this.manager.activateActor(actorId).block(); + + // Nothing happens because we don't call block(). + this.manager.invokeMethod(actorId, "throwsExceptionMono", null); + } + @Test(expected = IllegalArgumentException.class) public void activateInvokeDeactivateThenInvoke() throws Exception { ActorId actorId = newActorId();