Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecisionProjectionBase on Java version #33

Open
fpellet opened this issue May 22, 2017 · 3 comments
Open

DecisionProjectionBase on Java version #33

fpellet opened this issue May 22, 2017 · 3 comments

Comments

@fpellet
Copy link
Member

fpellet commented May 22, 2017

Add test to check if event is managed by projection.
Currently, an exception of NullPointer type is raised.

@jeantil
Copy link
Member

jeantil commented Jan 31, 2018

I have looked into this, and I am not sure I want to actually change the way it is done at the moment except maybe throw a specific exception to explain what the issue is as NPE is a bit too generic.

The NPE can only happen if the event wasn't registered which is always an error :

  • either register the event
  • check whyt the aggregate received an event which it isn't concerned with.

Regarding adding a custom exception I am curious how you would go about it in the scope of the exercise. DecisionProjectionBase is an extraction of the common code in Message#DecisionProjection and Identity#DecisionProjection. This raises a couple questions for me :

  • Would you add the exception throwing and corresponding test on the aggregates or would you introduce a specific unit test for DecisionProjectionBase ?
  • Would you define a generic exception for not having registered the event or use an aggregate specific exception ?

@jeantil
Copy link
Member

jeantil commented Jan 31, 2018

Looking at the C# version a0973e2#diff-69cf78d87e13cf1a1f83cd5c2aece0f7L46

what is the behaviour of

public void Apply(IDomainEvent @event)
{
  When((dynamic)@event);
}

When passed an event for which there are no implementations ? is it silently ignored as is the case in the introduced DecisionProjectionBase or does it fail ?

A quick test using a c# repl

using System;

public interface IBar {}
public class Bar : IBar {}
public class Baz : IBar {}
public sealed class FooBar : Bar {}

// Simple helper for demonstration
public static class ConsolePrinter
{
    public static void Print(Bar item)
    {
        Console.WriteLine("Bar");
    }

    public static void Print(FooBar item)
    {
        Console.WriteLine("FooBar");
    }
}


class MainClass {
  public static void Main (string[] args) {
    var bar = new Bar();
    var baz = new Baz();
    var foo = new FooBar();
    
    IBar[] items = { bar, foo, baz };
     foreach (dynamic item in items)
    {
        ConsolePrinter.Print(item);
    }
  }
}

yields

Unhandled Exception:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for `ConsolePrinter.Print(Bar)' has some invalid arguments
at (wrapper dynamic-method) object.CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,System.Type,object) <0x0017d>
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2<System.Type, object> (System.Runtime.CompilerServices.CallSite,System.Type,object) <0x00500>
at (wrapper dynamic-method) object.CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,System.Type,object) <0x0013c>
at MainClass.Main (string[]) <0x001ce>

Therefore I argue that the refactoring in the C# branch actually changes the behaviour of the system from throwing an exception to silently ignoring unregistered events without introducing a specific test ;p

@fpellet
Copy link
Member Author

fpellet commented Feb 3, 2018

:)
This implementation change doesn't add any desired behavior, because tests check that a command works well. The internal behavior is only an implementation detail.
This issue is just for the intermediate step and help in error analyzing on tests.
The problem is just the null pointer. After, ignoring the event or sending a more telling exception, it's ok for me.
You may be able to write a test with a false implementation, just to test this creation step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants