示例#1
0
        public async Task CreateActorsWithActorService()
        {
            _fabricRuntime = new MockFabricRuntime("Overlord");

            _fabricRuntime.SetupActor <ActorDemo, ActorDemoActorService>(
                (service, actorId) => new ActorDemo(service, actorId),
                (context, actorTypeInformation, stateProvider, stateManagerFactory) =>
                new ActorDemoActorService(context, actorTypeInformation, stateProvider: stateProvider));

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

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

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

            _proxy = _fabricRuntime.ActorProxyFactory.CreateActorServiceProxy <IActorDemoActorService>(
                _fabricRuntime.ApplicationUriBuilder.Build("ActorDemoActorService").ToUri(), new ActorId("testivus"));
        }
示例#2
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);
        }
示例#3
0
 public MockActorProxyFactory(
     MockFabricRuntime fabricRuntime,
     params IMockableActorRegistration[] actorRegistrations
     )
 {
     _fabricRuntime       = fabricRuntime;
     _actorRegistrations  = new List <IMockableActorRegistration>(actorRegistrations);
     _actorStateProviders = new Dictionary <Type, IActorStateProvider>();
     _actorProxies        = new Dictionary <object, object>();
 }
示例#4
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" });
        }
示例#5
0
        public async Task MockActorProxy_should_should_be_able_to_create_proxy_for_specific_ActorService()
        {
            var fabricRuntime = new MockFabricRuntime("Overlord");

            fabricRuntime.SetupActor <ActorDemo, ActorDemoActorService>(
                (service, actorId) => new ActorDemo(service, actorId),
                (context, actorTypeInformation, stateProvider, stateManagerFactory) => new ActorDemoActorService(context, actorTypeInformation));

            IActorDemoActorService proxy = null;
            await ExecutionHelper.ExecuteWithRetriesAsync((ct) =>
            {
                proxy = fabricRuntime.ActorProxyFactory.CreateActorServiceProxy <IActorDemoActorService>(
                    fabricRuntime.ApplicationUriBuilder.Build("ActorDemoActorService").ToUri(), new ActorId("testivus"));
                return(Task.FromResult(true));
            }, 3, TimeSpan.FromMilliseconds(3), CancellationToken.None);

            proxy.Should().NotBeNull();
        }
示例#6
0
        public async Task MockActorProxy_should_should_be_able_to_create_proxy_for_Actor_with_specific_ActorService()
        {
            var fabricRuntime = new MockFabricRuntime("Overlord");

            fabricRuntime.SetupActor <ActorDemo, ActorDemoActorService>(
                (service, actorId) => new ActorDemo(service, actorId),
                (context, actorTypeInformation, stateProvider, stateManagerFactory) => new ActorDemoActorService(context, actorTypeInformation,
                                                                                                                 stateProvider: stateProvider, stateManagerFactory: stateManagerFactory));

            IActorDemo proxy = null;

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

            proxy.Should().NotBeNull();
        }
 public MockActorStateProvider(MockFabricRuntime fabricRuntime, IList <string> actionsPerformed = null)
 {
     ActionsPerformed = actionsPerformed ?? new List <string>();
     _fabricRuntime   = fabricRuntime;
 }
示例#8
0
 public MockServiceProxyFactory(MockFabricRuntime fabricRuntime)
 {
     _fabricRuntime = fabricRuntime;
 }