Пример #1
0
        public async Task Test_Reminders_Basic_ListOps()
        {
            Guid id = Guid.NewGuid();

            if (this.log != null)
            {
                log.Info("Start Grain Id = {0}", id);
            }

            IReminderTestGrain2 grain = GrainClient.GrainFactory.GetGrain <IReminderTestGrain2>(id);
            const int           count = 5;

            Task <IGrainReminder>[] startReminderTasks = new Task <IGrainReminder> [count];
            for (int i = 0; i < count; i++)
            {
                startReminderTasks[i] = grain.StartReminder(DR + "_" + i);
            }

            await Task.WhenAll(startReminderTasks);

            // do comparison on strings
            List <string> registered = (from reminder in startReminderTasks select reminder.Result.ReminderName).ToList();

            List <IGrainReminder> remindersList = await grain.GetRemindersList();

            List <string> fetched = (from reminder in remindersList select reminder.ReminderName).ToList();

            foreach (var remRegistered in registered)
            {
                Assert.IsTrue(fetched.Remove(remRegistered), $"Couldn't get reminder {remRegistered}. " +
                              $"Registered list: {Utils.EnumerableToString(registered)}, " +
                              $"fetched list: {Utils.EnumerableToString(remindersList, r => r.ReminderName)}");
            }
            Assert.IsTrue(fetched.Count == 0, $"More than registered reminders. Extra: {Utils.EnumerableToString(fetched)}");

            // do some time tests as well
            if (this.log != null)
            {
                log.Info("Time tests");
            }

            TimeSpan period = await grain.GetReminderPeriod(DR);

            Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway
            for (int i = 0; i < count; i++)
            {
                long curr = await grain.GetCounter(DR + "_" + i);

                Assert.AreEqual(2, curr); // string.Format("Incorrect ticks for {0}_{1}", DR, i));
            }
        }
Пример #2
0
        public async Task Test_Reminders_Basic_ListOps()
        {
            Guid id = Guid.NewGuid();

            log.LogInformation("Start Grain Id = {GrainId}", id);
            IReminderTestGrain2 grain = this.GrainFactory.GetGrain <IReminderTestGrain2>(id);
            const int           count = 5;

            Task <IGrainReminder>[] startReminderTasks = new Task <IGrainReminder> [count];
            for (int i = 0; i < count; i++)
            {
                startReminderTasks[i] = grain.StartReminder(DR + "_" + i);
                log.LogInformation("Started {ReminderName}_{ReminderNumber}", DR, i);
            }

            await Task.WhenAll(startReminderTasks);

            // do comparison on strings
            List <string> registered = (from reminder in startReminderTasks select reminder.Result.ReminderName).ToList();

            log.LogInformation("Waited");

            List <IGrainReminder> remindersList = await grain.GetRemindersList();

            List <string> fetched = (from reminder in remindersList select reminder.ReminderName).ToList();

            foreach (var remRegistered in registered)
            {
                Assert.True(fetched.Remove(remRegistered), $"Couldn't get reminder {remRegistered}. " +
                            $"Registered list: {Utils.EnumerableToString(registered)}, " +
                            $"fetched list: {Utils.EnumerableToString(remindersList, r => r.ReminderName)}");
            }
            Assert.True(fetched.Count == 0, $"More than registered reminders. Extra: {Utils.EnumerableToString(fetched)}");

            // do some time tests as well
            log.LogInformation("Time tests");
            TimeSpan period = await grain.GetReminderPeriod(DR);

            await Task.Delay(period.Multiply(2) + LEEWAY); // giving some leeway

            for (int i = 0; i < count; i++)
            {
                long curr = await grain.GetCounter(DR + "_" + i);

                Assert.Equal(2, curr);
            }
        }