Ejemplo n.º 1
0
        public async Task AsyncTimerTest_GrainCall()
        {
            const string testName = "AsyncTimerTest_GrainCall";
            TimeSpan     delay    = TimeSpan.FromSeconds(5);
            TimeSpan     wait     = delay.Multiply(2);

            ITimerCallGrain grain = null;

            Exception error = null;

            try
            {
                grain = GrainClient.GrainFactory.GetGrain <ITimerCallGrain>(GetRandomGrainId());

                await grain.StartTimer(testName, delay);

                await Task.Delay(wait);

                int tickCount = await grain.GetTickCount();

                Assert.AreEqual(1, tickCount, "Should be {0} timer callback", tickCount);

                Exception err = await grain.GetException();

                Assert.IsNull(err, "Should be no exceptions during timer callback");
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
                error = exc;
            }

            try
            {
                if (grain != null)
                {
                    await grain.StopTimer(testName);
                }
            }
            catch (Exception exc)
            {
                // Ignore
                Console.WriteLine("Ignoring exception from StopTimer : {0}", exc);
                TestingSiloHost.StopAllSilosIfRunning();
            }

            if (error != null)
            {
                Assert.Fail("Test {0} failed with error {1}", testName, error);
            }
        }
Ejemplo n.º 2
0
        public async Task AsyncTimerTest_GrainCall()
        {
            const string testName = "AsyncTimerTest_GrainCall";
            TimeSpan     delay    = TimeSpan.FromSeconds(5);
            TimeSpan     wait     = delay.Multiply(2);

            ITimerCallGrain grain = null;

            Exception error = null;

            try
            {
                grain = GrainFactory.GetGrain <ITimerCallGrain>(GetRandomGrainId());

                await grain.StartTimer(testName, delay);

                await Task.Delay(wait);

                int tickCount = await grain.GetTickCount();

                Assert.Equal(1, tickCount);

                Exception err = await grain.GetException();

                Assert.Null(err); // Should be no exceptions during timer callback
            }
            catch (Exception exc)
            {
                output.WriteLine(exc);
                error = exc;
            }

            try
            {
                if (grain != null)
                {
                    await grain.StopTimer(testName);
                }
            }
            catch (Exception exc)
            {
                // Ignore
                output.WriteLine("Ignoring exception from StopTimer : {0}", exc);
            }

            if (error != null)
            {
                Assert.True(false, $"Test {testName} failed with error {error}");
            }
        }