Skip to content

Commit

Permalink
Cleanup exceptions. #21
Browse files Browse the repository at this point in the history
  • Loading branch information
veblush committed May 22, 2016
1 parent d19d123 commit c442e07
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Akka.Interfaced-Base\Exceptions.cs">
<Link>Exceptions.cs</Link>
</Compile>
<Compile Include="..\Akka.Interfaced-Base\IInterfacedActor.cs">
<Link>IInterfacedActor.cs</Link>
</Compile>
Expand Down
1 change: 1 addition & 0 deletions core/Akka.Interfaced-Base/Akka.Interfaced-Base.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="Exceptions.cs" />
<Compile Include="IInterfacedActor.cs" />
<Compile Include="IInterfacedPayload.cs" />
<Compile Include="IInterfacedObserver.cs" />
Expand Down
64 changes: 64 additions & 0 deletions core/Akka.Interfaced-Base/Exceptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;

namespace Akka.Interfaced
{
/// <summary>
/// This exception provides the base for all Akka.Interfaced specific exceptions within the system.
/// </summary>
public abstract class AkkaInterfacedException : Exception
{
protected AkkaInterfacedException()
{
}

protected AkkaInterfacedException(string message, Exception innerException = null)
: base(message, innerException)
{
}
}

/// <summary>
/// This exception is thrown when the actor which have a request is not found.
/// </summary>
public class RequestTargetException : AkkaInterfacedException
{
public RequestTargetException()
{
}

public RequestTargetException(string message, Exception innerException = null)
: base(message, innerException)
{
}
}

/// <summary>
/// This exception is thrown when there is an unhandled exception in processing a request.
/// </summary>
public class RequestFaultException : AkkaInterfacedException
{
public RequestFaultException()
{
}

public RequestFaultException(string message, Exception innerException = null)
: base(message, innerException)
{
}
}

/// <summary>
/// This exception is thrown when the actor is stopped in processing a request.
/// </summary>
public class RequestHaltException : AkkaInterfacedException
{
public RequestHaltException()
{
}

public RequestHaltException(string message, Exception innerException = null)
: base(message, innerException)
{
}
}
}
2 changes: 1 addition & 1 deletion core/Akka.Interfaced.Tests/ActorTaskCancellation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task TaskInRequest_WhenActorStop_Cancelled()

var exceptionTask = Record.ExceptionAsync(() => worker.Reentrant(1));
worker.Actor.Tell("E");
Assert.IsType<InterfacedRequestException>(await exceptionTask);
Assert.IsType<RequestHaltException>(await exceptionTask);

Watch(worker.Actor);
ExpectTerminated(worker.Actor);
Expand Down
18 changes: 9 additions & 9 deletions core/Akka.Interfaced.Tests/ExceptionHandle.Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task ExceptionThrown_At_Request()
var dummy = new DummyRef(ActorOf(Props.Create(() => new ExceptionActor_Request(log, 0))));

var exception = await Record.ExceptionAsync(() => dummy.Call("E"));
Assert.IsType<InterfacedRequestException>(exception);
Assert.IsType<RequestFaultException>(exception);

Watch(dummy.Actor);
ExpectTerminated(dummy.Actor);
Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task ExceptionThrown_At_RequestAsync()
var worker = new WorkerRef(ActorOf(Props.Create(() => new ExceptionActor_Request(log, 0))));

var exception = await Record.ExceptionAsync(() => worker.Atomic(1));
Assert.IsType<InterfacedRequestException>(exception);
Assert.IsType<RequestFaultException>(exception);

Watch(worker.Actor);
ExpectTerminated(worker.Actor);
Expand All @@ -135,7 +135,7 @@ public async Task ExceptionThrown_At_RequestAsyncDone()
var worker = new WorkerRef(ActorOf(Props.Create(() => new ExceptionActor_Request(log, 0))));

var exception = await Record.ExceptionAsync(() => worker.Atomic(2));
Assert.IsType<InterfacedRequestException>(exception);
Assert.IsType<RequestFaultException>(exception);

Watch(worker.Actor);
ExpectTerminated(worker.Actor);
Expand All @@ -150,7 +150,7 @@ public async Task ExceptionThrown_At_RequestReentrantAsync()
var worker = new WorkerRef(ActorOf(Props.Create(() => new ExceptionActor_Request(log, 0))));

var exception = await Record.ExceptionAsync(() => worker.Reentrant(1));
Assert.IsType<InterfacedRequestException>(exception);
Assert.IsType<RequestFaultException>(exception);

Watch(worker.Actor);
ExpectTerminated(worker.Actor);
Expand All @@ -165,7 +165,7 @@ public async Task ExceptionThrown_At_RequestReentrantAsyncDone()
var worker = new WorkerRef(ActorOf(Props.Create(() => new ExceptionActor_Request(log, 0))));

var exception = await Record.ExceptionAsync(() => worker.Reentrant(2));
Assert.IsType<InterfacedRequestException>(exception);
Assert.IsType<RequestFaultException>(exception);

Watch(worker.Actor);
ExpectTerminated(worker.Actor);
Expand All @@ -181,7 +181,7 @@ public async Task ExceptionThrown_At_OngoingAtomicAsync_ThrownByActorStop()

var exceptionTask = Record.ExceptionAsync(() => worker.Atomic(10));
worker.Actor.Tell(PoisonPill.Instance); // dangerous but for test
Assert.IsType<InterfacedRequestException>(await exceptionTask);
Assert.IsType<RequestHaltException>(await exceptionTask);

Watch(worker.Actor);
ExpectTerminated(worker.Actor);
Expand All @@ -198,9 +198,9 @@ public async Task ExceptionThrown_At_RequestReentrantAsync_ThrownByActorStop()
var exceptionTask1 = Record.ExceptionAsync(() => worker.Reentrant(10));
var exceptionTask2 = Record.ExceptionAsync(() => worker.Reentrant(11));
var exception = await Record.ExceptionAsync(() => worker.Atomic(1));
Assert.IsType<InterfacedRequestException>(exception);
Assert.IsType<InterfacedRequestException>(await exceptionTask1);
Assert.IsType<InterfacedRequestException>(await exceptionTask2);
Assert.IsType<RequestFaultException>(exception);
Assert.IsType<RequestHaltException>(await exceptionTask1);
Assert.IsType<RequestHaltException>(await exceptionTask2);

Watch(worker.Actor);
ExpectTerminated(worker.Actor);
Expand Down
1 change: 0 additions & 1 deletion core/Akka.Interfaced/Akka.Interfaced.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<Compile Include="InterfacedObserver.cs" />
<Compile Include="InterfacedActor.cs" />
<Compile Include="InterfacedActorRef.cs" />
<Compile Include="InterfacedRequestException.cs" />
<Compile Include="IRequestWaiter.cs" />
<Compile Include="MessageHandler.cs" />
<Compile Include="MessageHandlerAttribute.cs" />
Expand Down
2 changes: 1 addition & 1 deletion core/Akka.Interfaced/DeadRequestProcessingActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override void OnReceive(object message)
var response = new ResponseMessage
{
RequestId = request.RequestId,
Exception = new InvalidOperationException("Actor not found")
Exception = new RequestTargetException()
};
deadLetter.Sender.Tell(response);
}
Expand Down
4 changes: 2 additions & 2 deletions core/Akka.Interfaced/InterfacedActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void CancelAllTasks()
i.Sender.Tell(new ResponseMessage
{
RequestId = i.RequestId,
Exception = new InterfacedRequestException()
Exception = new RequestHaltException()
});
}
}
Expand All @@ -139,7 +139,7 @@ private void CancelAllTasks()
_currentAtomicContext.Sender.Tell(new ResponseMessage
{
RequestId = _currentAtomicContext.RequestId,
Exception = new InterfacedRequestException()
Exception = new RequestHaltException()
});
}
}
Expand Down
8 changes: 0 additions & 8 deletions core/Akka.Interfaced/InterfacedRequestException.cs

This file was deleted.

4 changes: 2 additions & 2 deletions core/Akka.Interfaced/RequestHandlerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private static RequestHandler BuildHandler(
response = new ResponseMessage
{
RequestId = request.RequestId,
Exception = new InterfacedRequestException()
Exception = new RequestFaultException("", exception)
};
}

Expand Down Expand Up @@ -379,7 +379,7 @@ private static RequestAsyncHandler BuildAsyncHandler(
response = new ResponseMessage
{
RequestId = request.RequestId,
Exception = new InterfacedRequestException()
Exception = new RequestFaultException("", exception)
};
}

Expand Down

0 comments on commit c442e07

Please sign in to comment.