Beispiel #1
0
        public async Task MockActorProxy_should_should_persist_state_across_multiple_proxies()
        {
            var fabricRuntime          = new MockFabricRuntime("Overlord");
            var stateActions           = new List <string>();
            var mockActorStateProvider = new MockActorStateProvider(fabricRuntime, stateActions);

            fabricRuntime.SetupActor(
                (service, actorId) => new ActorDemo(service, actorId),
                createStateProvider: () => mockActorStateProvider
                );

            await ExecutionHelper.ExecuteWithRetriesAsync((ct) =>
            {
                var actor = fabricRuntime.ActorProxyFactory.CreateActorProxy <IActorDemo>(new ActorId("testivus"));
                return(actor.SetCountAsync(5));
            }, 3, TimeSpan.FromMilliseconds(3), CancellationToken.None);


            var count = await ExecutionHelper.ExecuteWithRetriesAsync((ct) =>
            {
                var sameActor = fabricRuntime.ActorProxyFactory.CreateActorProxy <IActorDemo>(new ActorId("testivus"));
                return(sameActor.GetCountAsync());
            }, 3, TimeSpan.FromMilliseconds(3), CancellationToken.None);

            count.Should().Be(5);
        }
        public void TestAnotherCustomActorService()
        {
            //an ActorService with a NON standard constructor can be created by passing Mock arguments:

            IActorStateProvider actorStateProvider = new MockActorStateProvider();

            actorStateProvider.Initialize(ActorTypeInformation.Get(typeof(InvokeOnActor)));
            var context            = MockStatefulServiceContextFactory.Default;
            var dummy              = new object(); //this argument causes the 'non standard' ctor.
            var customActorService = new AnotherCustomActorService(dummy, context, ActorTypeInformation.Get(typeof(InvokeOnActor)));

            var actor = customActorService.Activate <InvokeOnActor>(new ActorId(123L));

            Assert.IsInstanceOfType(actor, typeof(InvokeOnActor));
            Assert.AreEqual(123L, actor.Id.GetLongId());
        }
Beispiel #3
0
        public async Task MockActorProxy_should_SaveState_after_Actor_method()
        {
            var fabricRuntime          = new MockFabricRuntime("Overlord");
            var stateActions           = new List <string>();
            var mockActorStateProvider = new MockActorStateProvider(fabricRuntime, stateActions);

            fabricRuntime.SetupActor((service, actorId) => new ActorDemo(service, actorId), createStateProvider: () => mockActorStateProvider);

            // Only to get around the kinda stupid introduced 1/20 msec 'bug'
            await ExecutionHelper.ExecuteWithRetriesAsync((ct) =>
            {
                var actor = fabricRuntime.ActorProxyFactory.CreateActorProxy <IActorDemo>(new ActorId("testivus"));
                return(actor.SetCountAsync(5));
            }, 3, TimeSpan.FromMilliseconds(3), CancellationToken.None);

            stateActions.Should().BeEquivalentTo(new[] { "ContainsStateAsync", "ActorActivatedAsync", "SaveStateAsync" });
        }