Ping pong Bruce Lee test

Posted by scooletz on April 08, 2016 · 2 mins read

There is a famous Bruce Lee clip showing him as a very good ping pong player using unusual tooling to get the job done. It thought that this ping pong match would be a great story for writing a test for my RampUp library, especially when I provided the first, most likely not final, version of the actor system.

To have more fun I split Bruce Lee into Bruce & Lee. Each part of Bruce Lee either pings or pongs.

[code language=”csharp”]

public class Bruce : IHandle {    public IBus Bus;

   public void Handle(ref Envelope envelope, ref Ping msg)    {       var p = new Pong();       Bus.Publish(ref p);    } }

public class Lee : IHandle {    public IBus Bus;

   public void Handle(ref Envelope envelope, ref Pong msg)    {       var p = ne w Ping();       Bus.Publish(ref p);    } }


The ping/pong messages are only markups:

[code language="csharp"]

public struct Pong : IMessage {}

public struct Ping : IMessage {}

And the final execution of this setup can be summarized in:

[code language=”csharp”]

public class Program {    public static void Main()    {       var system = new ActorSystem();       IBus bus = null;

      system.Add(new Bruce(), ctx => { bus = ctx.Actor.Bus = ctx.Bus; });       system.Add(new Lee(), ctx => { ctx.Actor.Bus = ctx.Bus; });

      system.Start();

      var p = new Pong();       bus.Publish(ref p); // pong as Bruce       // … later       system.Stop();    } } ```

I hope you like the example. I’m aware that ActorSystem API isn’t the best possible API ever, but even in this shape enables me to push RampUp forward.


Comments

I see that all those IHandle/IBus/Publish concepts has evolved into something sweet. The one thing I can't get is this IBus assignment - why are you getting an instance from Bruce instead of Lee? Can't you get it from ActorSystem?

by Kamil Mrzygłód (@Kamil_Mrzyglod) at 2016-04-08 20:39:36 +0000

I'm glad you like the higher level API. For now there's no bus that can be obtained from the system itself, but I'll add it for sure. I desperately needed to provide any kind of API to enable me and potential community members to shape the rest of RampUp.

by Szymon Kulec 'Scooletz' at 2016-04-08 20:49:06 +0000

My tools



[PL] Master of Aggregates
[PL] Master of Aggregates
[ENG] My free e-book
[ENG] My free e-book