public async Task Publishes_Counter_To_Summary_On_Timer()
        {
            // using a random key allows parallel testing on the shared cluster
            var key = Guid.NewGuid().ToString();

            // get a new grain instance to test
            var grain = fixture.Cluster.GrainFactory.GetGrain <ICallingTimerGrain>(key);

            // increment the counter - this will also activate the grain and register the timer
            await grain.IncrementAsync();

            // assert the timer was registered on some silo in the cluster
            var timer = fixture.GetTimers(grain).Single();

            // tick the timer once
            await timer.TickAsync();

            // assert the summary grain got the first result
            Assert.Equal(1, await fixture.Cluster.GrainFactory.GetGrain <ISummaryGrain>(Guid.Empty).TryGetAsync(key));

            // increment the counter again
            await grain.IncrementAsync();

            // tick the timer again
            await timer.TickAsync();

            // assert the summary grain got the second result
            Assert.Equal(2, await fixture.Cluster.GrainFactory.GetGrain <ISummaryGrain>(Guid.Empty).TryGetAsync(key));
        }
Example #2
0
        public async Task Increments_Value_On_Timer()
        {
            // using a random key allows parallel testing on the shared cluster
            var key = Guid.NewGuid();

            // get a new instance of the grain
            var grain = fixture.Cluster.GrainFactory.GetGrain <ITimerGrain>(key);

            // assert the initial state is zero - this will activate the grain and register the timer
            Assert.Equal(0, await grain.GetValueAsync());

            // assert the timer was registered on some silo
            var timer = fixture.GetTimers(grain).SingleOrDefault();

            Assert.NotNull(timer);

            // tick the timer
            await timer.TickAsync();

            // assert the new value is one
            Assert.Equal(1, await grain.GetValueAsync());
        }