public async Task Rem_Azure_GT_Basic() { IReminderTestGrain2 g1 = GrainClient.GrainFactory.GetGrain <IReminderTestGrain2>(Guid.NewGuid()); IReminderTestCopyGrain g2 = GrainClient.GrainFactory.GetGrain <IReminderTestCopyGrain>(Guid.NewGuid()); TimeSpan period = await g1.GetReminderPeriod(DR); // using same period await g1.StartReminder(DR); Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway await g2.StartReminder(DR); Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway long last1 = await g1.GetCounter(DR); Assert.Equal(4, last1); long last2 = await g2.GetCounter(DR); Assert.Equal(2, last2); // CopyGrain fault await g1.StopReminder(DR); Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway await g2.StopReminder(DR); long curr1 = await g1.GetCounter(DR); Assert.Equal(last1, curr1); long curr2 = await g2.GetCounter(DR); Assert.Equal(4, curr2); // CopyGrain fault }
protected async Task <bool> PerGrainFailureTest(IReminderTestGrain2 grain) { TimeSpan period = await grain.GetReminderPeriod(DR); this.log.Info("PerGrainFailureTest Period={0} Grain={1}", period, grain); await grain.StartReminder(DR); TimeSpan sleepFor = period.Multiply(failCheckAfter) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); long last = await grain.GetCounter(DR); AssertIsInRange(last, failCheckAfter - 1, failCheckAfter + 1, grain, DR, sleepFor); await grain.StopReminder(DR); sleepFor = period.Multiply(2) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); long curr = await grain.GetCounter(DR); AssertIsInRange(curr, last, last + 1, grain, DR, sleepFor); return(true); }
public async Task Rem_Azure_Basic() { log.Info(TestContext.TestName); // start up a test grain and get the period that it's programmed to use. IReminderTestGrain2 grain = GrainClient.GrainFactory.GetGrain <IReminderTestGrain2>(Guid.NewGuid()); TimeSpan period = await grain.GetReminderPeriod(DR); // start up the 'DR' reminder and wait for two ticks to pass. await grain.StartReminder(DR); Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway // retrieve the value of the counter-- it should match the sequence number which is the number of periods // we've waited. long last = await grain.GetCounter(DR); Assert.AreEqual(2, last, Time()); // stop the timer and wait for a whole period. await grain.StopReminder(DR); Thread.Sleep(period.Multiply(1) + LEEWAY); // giving some leeway // the counter should not have changed. long curr = await grain.GetCounter(DR); Assert.AreEqual(last, curr, Time()); }
public async Task Rem_Azure_Basic_Restart() { IReminderTestGrain2 grain = GrainClient.GrainFactory.GetGrain <IReminderTestGrain2>(Guid.NewGuid()); TimeSpan period = await grain.GetReminderPeriod(DR); await grain.StartReminder(DR); Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway long last = await grain.GetCounter(DR); Assert.Equal(2, last); await grain.StopReminder(DR); TimeSpan sleepFor = period.Multiply(1) + LEEWAY; Thread.Sleep(sleepFor); // giving some leeway long curr = await grain.GetCounter(DR); Assert.Equal(last, curr); AssertIsInRange(curr, last, last + 1, grain, DR, sleepFor); // start the same reminder again await grain.StartReminder(DR); sleepFor = period.Multiply(2) + LEEWAY; Thread.Sleep(sleepFor); // giving some leeway curr = await grain.GetCounter(DR); AssertIsInRange(curr, 2, 3, grain, DR, sleepFor); await grain.StopReminder(DR); // cleanup }
public async Task Rem_Azure_GT_Basic() { log.Info(TestContext.TestName); IReminderTestGrain2 g1 = GrainClient.GrainFactory.GetGrain <IReminderTestGrain2>(Guid.NewGuid()); IReminderTestCopyGrain g2 = GrainClient.GrainFactory.GetGrain <IReminderTestCopyGrain>(Guid.NewGuid()); TimeSpan period = await g1.GetReminderPeriod(DR); // using same period await g1.StartReminder(DR); Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway await g2.StartReminder(DR); Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway long last1 = await g1.GetCounter(DR); Assert.AreEqual(4, last1, string.Format("{0} Grain fault", Time())); long last2 = await g2.GetCounter(DR); Assert.AreEqual(2, last2, string.Format("{0} CopyGrain fault", Time())); await g1.StopReminder(DR); Thread.Sleep(period.Multiply(2) + LEEWAY); // giving some leeway await g2.StopReminder(DR); long curr1 = await g1.GetCounter(DR); Assert.AreEqual(last1, curr1, string.Format("{0} Grain fault", Time())); long curr2 = await g2.GetCounter(DR); Assert.AreEqual(4, curr2, string.Format("{0} CopyGrain fault", Time())); }
internal async Task <bool> PerGrainMultiReminderTestChurn(IReminderTestGrain2 g) { // for churn cases, we do execute start and stop reminders with retries as we don't have the queue-ing // functionality implemented on the LocalReminderService yet TimeSpan period = await g.GetReminderPeriod(DR); logger.Info("PerGrainMultiReminderTestChurn Period={0} Grain={1}", period, g); // Start Default Reminder //g.StartReminder(DR, file + "_" + DR).Wait(); ExecuteWithRetries(g.StartReminder, DR); TimeSpan sleepFor = period.Multiply(2); Thread.Sleep(sleepFor); // Start R1 //g.StartReminder(R1, file + "_" + R1).Wait(); ExecuteWithRetries(g.StartReminder, R1); sleepFor = period.Multiply(2); Thread.Sleep(sleepFor); // Start R2 //g.StartReminder(R2, file + "_" + R2).Wait(); ExecuteWithRetries(g.StartReminder, R2); sleepFor = period.Multiply(2); Thread.Sleep(sleepFor); sleepFor = period.Multiply(1); Thread.Sleep(sleepFor); // Stop R1 //g.StopReminder(R1).Wait(); ExecuteWithRetriesStop(g.StopReminder, R1); sleepFor = period.Multiply(2); Thread.Sleep(sleepFor); // Stop R2 //g.StopReminder(R2).Wait(); ExecuteWithRetriesStop(g.StopReminder, R2); sleepFor = period.Multiply(1); Thread.Sleep(sleepFor); // Stop Default reminder //g.StopReminder(DR).Wait(); ExecuteWithRetriesStop(g.StopReminder, DR); sleepFor = period.Multiply(1) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); long last = await g.GetCounter(R1); AssertIsInRange(last, 4, 6, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 4, 6, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 9, 10, g, DR, sleepFor); return(true); }
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)); } }
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); } }
protected async Task <bool> PerGrainMultiReminderTest(IReminderTestGrain2 g) { TimeSpan period = await g.GetReminderPeriod(DR); this.log.Info("PerGrainMultiReminderTest Period={0} Grain={1}", period, g); // Each reminder is started 2 periods after the previous reminder // once all reminders have been started, stop them every 2 periods // except the default reminder, which we stop after 3 periods instead // just to test and break the symmetry // Start Default Reminder await g.StartReminder(DR); TimeSpan sleepFor = period.Multiply(2) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); long last = await g.GetCounter(DR); AssertIsInRange(last, 1, 2, g, DR, sleepFor); // Start R1 await g.StartReminder(R1); Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 1, 2, g, R1, sleepFor); // Start R2 await g.StartReminder(R2); Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 3, 4, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 1, 2, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 5, 6, g, DR, sleepFor); // Stop R1 await g.StopReminder(R1); Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 3, 4, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 3, 4, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 7, 8, g, DR, sleepFor); // Stop R2 await g.StopReminder(R2); sleepFor = period.Multiply(3) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 3, 4, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 3, 4, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 10, 12, g, DR, sleepFor); // Stop Default reminder await g.StopReminder(DR); sleepFor = period.Multiply(1) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 3, 4, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 3, 4, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 10, 12, g, DR, sleepFor); return(true); }
protected async Task<bool> PerGrainMultiReminderTest(IReminderTestGrain2 g) { TimeSpan period = await g.GetReminderPeriod(DR); logger.Info("PerGrainMultiReminderTest Period={0} Grain={1}", period, g); // Each reminder is started 2 periods after the previous reminder // once all reminders have been started, stop them every 2 periods // except the default reminder, which we stop after 3 periods instead // just to test and break the symmetry // Start Default Reminder await g.StartReminder(DR); TimeSpan sleepFor = period.Multiply(2) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); long last = await g.GetCounter(DR); AssertIsInRange(last, 1, 2, g, DR, sleepFor); // Start R1 await g.StartReminder(R1); Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 1, 2, g, R1, sleepFor); // Start R2 await g.StartReminder(R2); Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 3, 4, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 1, 2, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 5, 6, g, DR, sleepFor); // Stop R1 await g.StopReminder(R1); Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 3, 4, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 3, 4, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 7, 8, g, DR, sleepFor); // Stop R2 await g.StopReminder(R2); sleepFor = period.Multiply(3) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 3, 4, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 3, 4, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 10, 12, g, DR, sleepFor); // Stop Default reminder await g.StopReminder(DR); sleepFor = period.Multiply(1) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); last = await g.GetCounter(R1); AssertIsInRange(last, 3, 4, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 3, 4, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 10, 12, g, DR, sleepFor); return true; }
protected async Task<bool> PerGrainFailureTest(IReminderTestGrain2 grain) { TimeSpan period = await grain.GetReminderPeriod(DR); logger.Info("PerGrainFailureTest Period={0} Grain={1}", period, grain); await grain.StartReminder(DR); TimeSpan sleepFor = period.Multiply(failCheckAfter) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); long last = await grain.GetCounter(DR); AssertIsInRange(last, failCheckAfter - 1, failCheckAfter + 1, grain, DR, sleepFor); await grain.StopReminder(DR); sleepFor = period.Multiply(2) + LEEWAY; // giving some leeway Thread.Sleep(sleepFor); long curr = await grain.GetCounter(DR); AssertIsInRange(curr, last, last + 1, grain, DR, sleepFor); return true; }
internal async Task<bool> PerGrainMultiReminderTestChurn(IReminderTestGrain2 g) { // for churn cases, we do execute start and stop reminders with retries as we don't have the queue-ing // functionality implemented on the LocalReminderService yet TimeSpan period = await g.GetReminderPeriod(DR); logger.Info("PerGrainMultiReminderTestChurn Period={0} Grain={1}", period, g); // Start Default Reminder //g.StartReminder(DR, file + "_" + DR).Wait(); await ExecuteWithRetries(g.StartReminder, DR); TimeSpan sleepFor = period.Multiply(2); await Task.Delay(sleepFor); // Start R1 //g.StartReminder(R1, file + "_" + R1).Wait(); await ExecuteWithRetries(g.StartReminder, R1); sleepFor = period.Multiply(2); await Task.Delay(sleepFor); // Start R2 //g.StartReminder(R2, file + "_" + R2).Wait(); await ExecuteWithRetries(g.StartReminder, R2); sleepFor = period.Multiply(2); await Task.Delay(sleepFor); sleepFor = period.Multiply(1); await Task.Delay(sleepFor); // Stop R1 //g.StopReminder(R1).Wait(); await ExecuteWithRetriesStop(g.StopReminder, R1); sleepFor = period.Multiply(2); await Task.Delay(sleepFor); // Stop R2 //g.StopReminder(R2).Wait(); await ExecuteWithRetriesStop(g.StopReminder, R2); sleepFor = period.Multiply(1); await Task.Delay(sleepFor); // Stop Default reminder //g.StopReminder(DR).Wait(); await ExecuteWithRetriesStop(g.StopReminder, DR); sleepFor = period.Multiply(1) + LEEWAY; // giving some leeway await Task.Delay(sleepFor); long last = await g.GetCounter(R1); AssertIsInRange(last, 4, 6, g, R1, sleepFor); last = await g.GetCounter(R2); AssertIsInRange(last, 4, 6, g, R2, sleepFor); last = await g.GetCounter(DR); AssertIsInRange(last, 9, 10, g, DR, sleepFor); return true; }