Fixing bug in exception handling from actor impl. (#246)

This commit is contained in:
Artur Souza 2020-03-09 12:36:43 -07:00 committed by GitHub
parent 9a71b8d85f
commit 1627a2c319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 5 deletions

View File

@ -285,8 +285,10 @@ class ActorManager<T extends AbstractActor> {
// 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);
}
});
}

View File

@ -7,13 +7,13 @@ package io.dapr.actors.runtime;
import io.dapr.actors.ActorId;
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;
@ -34,6 +34,12 @@ public class ActorManagerTest {
int getCount();
void incrementCount(int delta);
void throwsException();
Mono<Void> throwsExceptionHotMono();
Mono<Void> throwsExceptionMono();
}
public static class NotRemindableActor extends AbstractActor {
@ -62,6 +68,21 @@ public class ActorManagerTest {
this.timeCount = timeCount + delta;
}
@Override
public void throwsException() {
throw new IllegalArgumentException();
}
@Override
public Mono<Void> throwsExceptionHotMono() {
throw new IllegalArgumentException();
}
@Override
public Mono<Void> throwsExceptionMono() {
return Mono.error(new IllegalArgumentException());
}
public MyActorImpl(ActorRuntimeContext runtimeContext, ActorId id) {
super(runtimeContext, id);
super.registerActorTimer(
@ -106,6 +127,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();