public void TestThatEmployeeIdentifiesModifiesRecovers()
        {
            var employeeNumber = "12345";

            var employee = _world.ActorFor <IEmployee>(() => new EmployeeEntity(employeeNumber));

            var state1 = employee.Hire(50000).Await();

            Assert.True(state1.PersistenceId > 0);
            Assert.Equal(employeeNumber, state1.Number);
            Assert.Equal(50000, state1.Salary);

            var state3 = employee.Adjust(55000).Await();

            Assert.Equal(state1.PersistenceId, state3.PersistenceId);
            Assert.Equal(employeeNumber, state3.Number);
            Assert.Equal(55000, state3.Salary);

            var employeeRecovered = _world.ActorFor <IEmployee>(typeof(EmployeeEntity), employeeNumber);
            var state4            = employeeRecovered.Current().Await();

            Assert.Equal(state3, state4);

            // TODO: test reading event entries
        }
        public void TestThatStatefulEntityPreservesRestores()
        {
            RaceConditions.Set(0);

            var entityId = $"{_idGenerator.Next(10_000)}";
            var state    = new Entity1State(entityId, "Sally", 23);

            var entity1 = _world.ActorFor <IEntity1>(() => new Entity1Actor(RaceConditions, entityId));

            Assert.Equal(state, entity1.DefineWith(state.Name, state.Age).Await());
            Assert.Equal(state, entity1.Current().Await());

            entity1.ChangeName("Sally Jane");
            var newState = entity1.Current().Await();

            Assert.Equal("Sally Jane", newState.Name);

            entity1.IncreaseAge();
            newState = entity1.Current().Await();
            Assert.Equal(24, newState.Age);

            var restoredEntity1      = _world.ActorFor <IEntity1>(() => new Entity1Actor(RaceConditions, entityId));
            var restoredEntity1State = restoredEntity1.Current().Await();

            Assert.NotNull(restoredEntity1State);

            // check whether race conditions have been reproduced
            Assert.Equal(0, RaceConditions.Get());
        }
Ejemplo n.º 3
0
        public EventSourcedTest(ITestOutputHelper output)
        {
            var converter = new Converter(output);

            Console.SetOut(converter);

            var testWorld = TestWorld.StartWithDefaults("test-es");

            _world = testWorld.World;

            _dispatcher = new MockJournalDispatcher();

            var entryAdapterProvider = EntryAdapterProvider.Instance(_world);

            entryAdapterProvider.RegisterAdapter(new Test1HappenedAdapter());
            entryAdapterProvider.RegisterAdapter(new Test2HappenedAdapter());
            entryAdapterProvider.RegisterAdapter(new Test3HappenedAdapter());

            var journal = _world.ActorFor <IJournal <string> >(() => new InMemoryJournalActor <string>(_dispatcher));

            var registry = new SourcedTypeRegistry(_world);

            registry.Register(Info.RegisterSourced <TestEventSourcedEntity>(journal));
            registry.Register(Info.RegisterSourced <ProductEntity>(journal));
            registry.Register(Info.RegisterSourced <ProductParent>(journal));
            registry.Register(Info.RegisterSourced <ProductGrandparent>(journal));

            _result = new Result();
            _entity = _world.ActorFor <IEntity>(() => new TestEventSourcedEntity(_result));
        }
Ejemplo n.º 4
0
        private IChildCreatingStoppable[] SetUpActors(World world, TestResults results)
        {
            var stoppables = new IChildCreatingStoppable[3];

            stoppables[0] = world.ActorFor <IChildCreatingStoppable>(Definition.Has <ChildCreatingStoppableActor>(Definition.Parameters(results), "p1"));
            stoppables[1] = world.ActorFor <IChildCreatingStoppable>(Definition.Has <ChildCreatingStoppableActor>(Definition.Parameters(results), "p2"));
            stoppables[2] = world.ActorFor <IChildCreatingStoppable>(Definition.Has <ChildCreatingStoppableActor>(Definition.Parameters(results), "p3"));
            return(stoppables);
        }
        public void TestFiveStepSendingProcess()
        {
            var process = _world.ActorFor <IFiveStepProcess>(() => new FiveStepSendingSourcedProcess());

            _exchangeReceivers.SetProcess(process);

            _exchange.Send(new DoStepOne());

            Assert.Equal(5, _exchangeReceivers.Access.ReadFrom <int>("stepCount"));

            Assert.Equal(5, process.QueryStepCount().Await());
        }
        public StatefulProcessTest(ITestOutputHelper output)
        {
            var converter = new Converter(output);
            Console.SetOut(converter);
            
            _world = World.StartWithDefaults("five-step-process-test");

            var queue = new AsyncMessageQueue(null);
            _exchange = new LocalExchange(queue);
            _dispatcher = new MockTextDispatcher();
            var stateStore = _world.ActorFor<IStateStore>(() => new InMemoryStateStoreActor<TextState>(new List<IDispatcher> {_dispatcher}));

            var statefulTypeRegistry = new StatefulTypeRegistry(_world);
            
            var stepCountStateInfo = new Vlingo.Xoom.Lattice.Model.Stateful.Info(stateStore, typeof(StepCountState), stateStore.GetType().Name);
            statefulTypeRegistry.Register(stepCountStateInfo);

            _exchangeReceivers = new ExchangeReceivers();
            _exchangeSender = new LocalExchangeSender(queue);

            var processTypeRegistry = new ProcessTypeRegistry(_world);
            processTypeRegistry.Register(new StatefulProcessInfo<FiveStepEmittingStatefulProcess, StepCountState>(nameof(FiveStepEmittingStatefulProcess), _exchange, statefulTypeRegistry));

            RegisterExchangeCoveys();
        }
Ejemplo n.º 7
0
        public void TestSuspendResume()
        {
            var supervisor = World.ActorFor <IFailureControlSender>(
                Definition.Has <SuspendedSenderSupervisorActor>(Definition.NoParameters, "suspended-sender-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = World.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults),
                    SuspendedSenderSupervisorActor.Instance.Value,
                    "queueArray",
                    "failure"));
            var times = 25;

            failureControlTestResults.UntilFailNow = Until(1);
            SuspendedSenderSupervisorActor.Instance.Value.UntilInformed = Until(1);
            failureControlTestResults.UntilFailureCount = Until(times - 1);
            supervisor.SendUsing(failure, times);

            failure.FailNow();
            failureControlTestResults.UntilFailNow.Completes();
            SuspendedSenderSupervisorActor.Instance.Value.UntilInformed.Completes();
            failureControlTestResults.UntilFailureCount.Completes();

            Assert.Equal(1, SuspendedSenderSupervisorActor.Instance.Value.InformedCount.Get());
            Assert.True(failureControlTestResults.AfterFailureCount.Get() >= times - 1);
        }
Ejemplo n.º 8
0
        public void TestStopAll()
        {
            World.ActorFor <ISupervisor>(Definition.Has <StopAllSupervisorActor>(Definition.NoParameters, "stop-all"));

            var pingTestResults = new PingActor.PingTestResults();
            var ping            = World.ActorFor <IPing>(
                Definition.Has <PingActor>(
                    Definition.Parameters(pingTestResults), StopAllSupervisorActor.Instance.Value, "ping"));
            var pongTestResults = new PongActor.PongTestResults();
            var pong            = World.ActorFor <IPong>(
                Definition.Has <PongActor>(
                    Definition.Parameters(pongTestResults), StopAllSupervisorActor.Instance.Value, "pong"));

            pingTestResults.UntilStopped = Until(1);
            pongTestResults.UntilStopped = Until(1);

            Assert.False(PingActor.Instance.Value.IsStopped);
            Assert.False(PongActor.Instance.Value.IsStopped);

            ping.Ping();
            pingTestResults.UntilStopped.Completes();
            pongTestResults.UntilStopped.Completes();

            Assert.True(PingActor.Instance.Value.IsStopped);
            Assert.True(PongActor.Instance.Value.IsStopped);
        }
        public void TestThatTimeOutOccursForSideEffects()
        {
            var uc             = World.ActorFor <IUsesCompletes>(Definition.Has <UsesCompletesCausesTimeoutActor>(Definition.NoParameters));
            var helloCompletes = uc.GetHello()
                                 .AndThenConsume(2, new Hello(HelloNot), hello => SetHello(hello.greeting))
                                 .Otherwise(failedHello =>
            {
                SetHello(failedHello.greeting);
                return(failedHello);
            });

            untilHello.Completes();

            Assert.NotEqual(Hello, greeting);
            Assert.Equal(HelloNot, helloCompletes.Outcome.greeting);

            var oneCompletes = uc.GetOne()
                               .AndThenConsume(2, 0, value => SetValue(value))
                               .Otherwise(value =>
            {
                untilOne.Happened();
                return(0);
            });

            untilOne.Completes();

            Assert.NotEqual(1, value);
            Assert.Equal(0, oneCompletes.Outcome);
        }
        public void TestAfterAndThenCompletesForSideEffects()
        {
            var uc             = World.ActorFor <IUsesCompletes>(Definition.Has <UsesCompletesActor>(Definition.NoParameters));
            var helloCompletes = uc.GetHello();

            helloCompletes
            .AndThen(hello => new Hello(Prefix + helloCompletes.Outcome.greeting))
            .AndThenConsume(hello => SetHello(hello.greeting));
            untilHello.Completes();

            Assert.NotEqual(Hello, helloCompletes.Outcome.greeting);
            Assert.NotEqual(Hello, greeting);
            Assert.Equal(Prefix + Hello, helloCompletes.Outcome.greeting);
            Assert.Equal(Prefix + Hello, greeting);

            var one = uc.GetOne();

            one
            .AndThen(value => one.Outcome + 1)
            .AndThenConsume(value => SetValue(value));
            untilOne.Completes();

            Assert.NotEqual(1, one.Outcome);
            Assert.NotEqual(1, value);
            Assert.Equal(2, one.Outcome);
            Assert.Equal(2, value);
        }
Ejemplo n.º 11
0
        public InMemoryStateStoreTest(ITestOutputHelper output)
        {
            var converter = new Converter(output);

            Console.SetOut(converter);

            var testWorld = TestWorld.StartWithDefaults("test-store");

            _world = testWorld.World;

            _interest   = new MockStateStoreResultInterest();
            _dispatcher = new MockStateStoreDispatcher <TextEntry, TextState>(_interest);

            var stateAdapterProvider = new StateAdapterProvider(_world);

            new EntryAdapterProvider(_world);

            stateAdapterProvider.RegisterAdapter(new Entity1StateAdapter());
            // NOTE: No adapter registered for Entity2.class because it will use the default

            _store = _world.ActorFor <IStateStore <TextEntry> >(typeof(InMemoryStateStoreActor <TextState, TextEntry>), _dispatcher);

            StateTypeStateStoreMap.StateTypeToStoreName(_storeName1, typeof(Entity1));
            StateTypeStateStoreMap.StateTypeToStoreName(_storeName2, typeof(Entity2));
        }
        public void TestTwoArgConsumerProtocol()
        {
            var poolSize       = 4;
            var rounds         = 2;
            var messagesToSend = poolSize * rounds;
            var results        = new Results(messagesToSend);

            var router = World.ActorFor <ITwoArgSupplierProtocol>(typeof(TestRouterActor), poolSize);

            for (var i = 0; i < messagesToSend; i++)
            {
                router
                .ProductOf(i, i)
                .AndThenConsume(answer => results.Access.WriteUsing("answers", answer));
            }

            var allExpected = new List <int>();

            for (var round = 0; round < messagesToSend; round++)
            {
                int expected = round * round;
                allExpected.Add(expected);
            }

            for (var round = 0; round < messagesToSend; round++)
            {
                int actual = results.Access.ReadFrom <int, int>("answers", round);
                Assert.True(allExpected.Remove(actual));
            }

            Assert.Empty(allExpected);
        }
        public void TestSuspendResume()
        {
            var testResults = new SuspendedSenderSupervisorResults();

            var failureControlSender = World.ActorFor <IFailureControlSender>(
                Definition.Has <SuspendedSenderSupervisorActor>(Definition.Parameters(testResults), "suspended-sender-supervisor"));

            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = World.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults),
                    SuspendedSenderSupervisorActor.Instance.Value,
                    "queueArray",
                    "failure"));
            var times            = 25;
            var failureAccess    = failureControlTestResults.AfterCompleting(times);
            var supervisorAccess = testResults.AfterCompleting(1);

            failureControlSender.SendUsing(failure, times);

            failure.FailNow();

            Assert.Equal(1, supervisorAccess.ReadFromExpecting("informedCount", 1));
            Assert.Equal(times, failureAccess.ReadFromExpecting("afterFailureCountCount", times));
        }
Ejemplo n.º 14
0
        public ProjectionDispatcherTest(ITestOutputHelper output)
        {
            var converter = new Converter(output);

            Console.SetOut(converter);

            World = World.StartWithDefaults("test-store");

            var stateAdapterProvider = new StateAdapterProvider(World);

            stateAdapterProvider.RegisterAdapter(new Entity1StateAdapter());
            new EntryAdapterProvider(World);

            StateTypeStateStoreMap.StateTypeToStoreName(nameof(Entity1), typeof(Entity1));
            StateTypeStateStoreMap.StateTypeToStoreName(nameof(Entity2), typeof(Entity2));

            var dispatcherProtocols =
                World.Stage.ActorFor(
                    new[] { DispatcherInterfaceType, typeof(IProjectionDispatcher) }, ProjectionDispatcherType);

            var dispatchers = Protocols.Two <IDispatcher, IProjectionDispatcher>(dispatcherProtocols);

            Dispatcher           = dispatchers._1;
            ProjectionDispatcher = dispatchers._2;

            var storeProtocols =
                World.ActorFor(
                    new[] { StateStoreInterfaceType, typeof(IDispatcherControl) },
                    typeof(InMemoryStateStoreActor <TextState>), Dispatcher);

            var storeWithControl = Protocols.Two <IStateStore, IDispatcherControl>(storeProtocols);

            Store             = storeWithControl._1;
            DispatcherControl = storeWithControl._2;
        }
        public void TestAfterAndThenCompletesForSideEffects()
        {
            var greetingsTestResults = TestResults.AfterCompleting(1);

            var uc             = World.ActorFor <IUsesCompletes>(typeof(UsesCompletesActor), greetingsTestResults);
            var helloCompletes = uc.GetHello();

            helloCompletes
            .AndThen(hello => new Hello(Prefix + hello.Greeting))
            .AndThenConsume(hello => greetingsTestResults.SetGreeting(hello.Greeting));

            Assert.NotEqual(Hello, greetingsTestResults.GetGreeting());
            Assert.NotEqual(Hello, helloCompletes.Outcome.Greeting);
            Assert.Equal(Prefix + Hello, greetingsTestResults.GetGreeting());
            Assert.Equal(Prefix + Hello, helloCompletes.Outcome.Greeting);

            var valueTestResults = TestResults.AfterCompleting(1);
            var one = uc.GetOne();

            one
            .AndThen(value => value + 1)
            .AndThenConsume(value => valueTestResults.SetValue(value));

            Assert.NotEqual(1, valueTestResults.GetValue());
            Assert.NotEqual(1, one.Outcome);
            Assert.Equal(2, valueTestResults.GetValue());
            Assert.Equal(2, one.Outcome);
        }
        public InMemoryStateStoreRedispatchControlTest(ITestOutputHelper output)
        {
            var converter = new Converter(output);

            Console.SetOut(converter);

            _world = World.StartWithDefaults("test-store");

            _interest = new MockStateStoreResultInterest();
            _interest.AfterCompleting <string, Entity1>(0);
            _dispatcher = new MockStateStoreDispatcher <TextState>(_interest);

            var stateAdapterProvider = new StateAdapterProvider(_world);

            new EntryAdapterProvider(_world);

            stateAdapterProvider.RegisterAdapter(new Entity1StateAdapter());
            // NOTE: No adapter registered for Entity2.class because it will use the default

            StateTypeStateStoreMap.StateTypeToStoreName(typeof(Entity1).FullName, typeof(Entity1));

            _store = _world.ActorFor <IStateStore>(typeof(InMemoryStateStoreActor <TextState>), new List <IDispatcher> {
                _dispatcher
            });
        }
Ejemplo n.º 17
0
        public void TestSupplierProtocol()
        {
            var poolSize       = 4;
            var rounds         = 2;
            var messagesToSend = poolSize * rounds;
            var results        = new Results(messagesToSend);

            var router = World.ActorFor <IOneArgSupplierProtocol>(Definition.Has <TestSupplierActor>(Definition.Parameters(poolSize)));

            for (var i = 0; i < messagesToSend; i++)
            {
                var round = i;
                router
                .CubeOf(round)
                .AndThenConsume(answer => results.Access.WriteUsing("answers", answer));
            }

            var allExpected = new List <int>();

            for (var round = 0; round < messagesToSend; round++)
            {
                int expected = round * round * round;
                allExpected.Add(expected);
            }

            for (var round = 0; round < messagesToSend; round++)
            {
                int actual = results.Access.ReadFrom <int, int>("answers", round);
                Assert.True(allExpected.Remove(actual));
            }

            Assert.Empty(allExpected);
        }
Ejemplo n.º 18
0
        public void TestThatManyScheduleOnceDeliver()
        {
            var query = World.ActorFor <IFinalCountQuery>(typeof(OnceScheduled), 10);
            var count = query.QueryCount().Await <int>();

            Assert.Equal(10, count);
        }
Ejemplo n.º 19
0
        public void TestConsumerProtocol()
        {
            var poolSize       = 4;
            var rounds         = 2;
            var messagesToSend = poolSize * rounds;
            var results        = new Results(messagesToSend);

            var router = World.ActorFor <IOneArgConsumerProtocol>(typeof(TestConsumerActor), results, poolSize);

            for (var i = 0; i < messagesToSend; i++)
            {
                router.Remember(i);
            }

            var allExpected = new List <int>();

            for (var round = 0; round < messagesToSend; round++)
            {
                allExpected.Add(round);
            }

            for (var round = 0; round < messagesToSend; round++)
            {
                Assert.True(allExpected.Remove(round));
            }

            Assert.Empty(allExpected);
        }
Ejemplo n.º 20
0
        public void TestStopAll()
        {
            var stopResults = new StopAllSupervisorResult();

            World.ActorFor <ISupervisor>(Definition.Has <StopAllSupervisorActor>(Definition.Parameters(stopResults), "stop-all"));

            var pingTestResults = new PingActor.PingTestResults();
            var ping            = World.ActorFor <IPing>(
                Definition.Has <PingActor>(
                    Definition.Parameters(pingTestResults), StopAllSupervisorActor.Instance.Value, "ping"));
            var pongTestResults = new PongActor.PongTestResults();
            var pong            = World.ActorFor <IPong>(
                Definition.Has <PongActor>(
                    Definition.Parameters(pongTestResults), StopAllSupervisorActor.Instance.Value, "pong"));

            var pingAccess = pingTestResults.AfterCompleting(1);
            var pongAccess = pongTestResults.AfterCompleting(1);
            var stopAccess = stopResults.AfterCompleting(1);

            ping.Ping();

            Assert.Equal(1, stopAccess.ReadFrom <int>("informedCount"));
            Assert.Equal(1, pingAccess.ReadFrom <int>("stopCount"));
            Assert.Equal(1, pongAccess.ReadFrom <int>("stopCount"));
        }
        [Fact]//(Skip = "Need explanation of why it should timeout")]
        public void TestThatTimeOutOccursForSideEffects()
        {
            var greetingsTestResults = TestResults.AfterCompleting(1);
            var uc             = World.ActorFor <IUsesCompletes>(typeof(UsesCompletesCausesTimeoutActor), greetingsTestResults);
            var helloCompletes = uc.GetHello()
                                 .AndThenConsume(TimeSpan.FromMilliseconds(2), new Hello(HelloNot), hello => greetingsTestResults.SetGreeting(hello.greeting))
                                 .Otherwise(failedHello =>
            {
                greetingsTestResults.SetGreeting(failedHello.greeting);
                return(failedHello);
            });


            Assert.NotEqual(Hello, greetingsTestResults.GetGreeting());
            Assert.Equal(HelloNot, helloCompletes.Outcome.greeting);

            var valueTestResults = TestResults.AfterCompleting(1);

            var oneCompletes = uc.GetOne()
                               .AndThenConsume(TimeSpan.FromMilliseconds(2), 0, value => valueTestResults.SetValue(value))
                               .Otherwise(value =>
            {
                valueTestResults.SetValue(value);
                return(0);
            });

            try { Thread.Sleep(100); } catch (Exception) { }

            oneCompletes.With(1);

            Assert.NotEqual(1, valueTestResults.GetValue());
            Assert.Equal(0, oneCompletes.Outcome);
        }
        public async Task TestThatTaskLikeCompletesCanBeAwaited()
        {
            var uc  = World.ActorFor <IUsesTask>(() => new UsesTaskActor());
            var two = await uc.GetTwoAsync();

            Assert.Equal(2, two);
        }
        public async Task TestThatSchedulesLongRunningOperations()
        {
            var uc  = World.ActorFor <IUsesTask>(() => new UsesLongRunningTaskActor());
            var one = await uc.GetOne();

            Assert.Equal(1, one);
        }
Ejemplo n.º 24
0
        public void TestBeforeStart()
        {
            var testResults = TestResults.AfterCompleting(1);
            var actor       = World.ActorFor <IStoppable>(typeof(LifecycleActor), testResults);

            Assert.True(testResults.GetReceivedBeforeStart());
            Assert.False(testResults.GetReceivedAfterStop());
        }
        public void TestOutcomeInterestSuccess()
        {
            var test = World.ActorFor <ITestsOutcomeAware>(Definition.Has <DoSomethingOutcomeAwareActor>(Definition.NoParameters));

            test.DoSomething();

            Thread.Sleep(500);
        }
Ejemplo n.º 26
0
        public async Task TestThatMailboxDoesntDeliverWhileAwaiting()
        {
            var uc  = World.ActorFor <IUsesTask>(typeof(UsesTaskActor));
            var one = await uc.GetOne();

            uc.Change(10);
            Assert.Equal(1, one);
        }
        public void TestThatVoidReturnTypeThrowsException()
        {
            var testResults = TestResults.AfterCompleting(1);
            var uc          = World.ActorFor <IUsesCompletes>(typeof(UsesCompletesActor), testResults);

            uc.CompletesNotSupportedForVoidReturnType();
            Assert.True(testResults.GetExceptionThrown());
        }
Ejemplo n.º 28
0
        public void TestWorldNoDefintionActorFor()
        {
            var testResults = new TestResults(1);
            var simple      = World.ActorFor <ISimpleWorld>(typeof(SimpleActor), testResults);

            simple.SimpleSay();

            Assert.True(testResults.Invoked);
        }
Ejemplo n.º 29
0
        public void TestWorldActorForFlat()
        {
            var testResults = new TestResults(1);
            var simple      = World.ActorFor <ISimpleWorld>(Definition.Has(() => new SimpleActor(testResults)));

            simple.SimpleSay();

            Assert.True(testResults.Invoked);
        }
Ejemplo n.º 30
0
        public void TestWorldActorForDefintion()
        {
            var testResults = new TestResults(1);
            var simple      = World.ActorFor <ISimpleWorld>(Definition.Has <SimpleActor>(Definition.Parameters(testResults)));

            simple.SimpleSay();

            Assert.True(testResults.Invoked);
        }