Ejemplo n.º 1
0
        public static void Initialize(Silo silo, IGrainFactory grainFactory, string reminderTableAssembly = null)
        {
            var config = silo.GlobalConfig;
            var serviceType = config.ReminderServiceType;
            var logger = TraceLogger.GetLogger("ReminderTable");

            switch (serviceType)
            {
                default:
                    throw new NotSupportedException(
                        String.Format(
                            "The reminder table does not currently support service provider {0}.",
                            serviceType));

                case GlobalConfiguration.ReminderServiceProviderType.SqlServer:
                    Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(Constants.ORLEANS_SQL_UTILS_DLL, logger);
                    return;

                case GlobalConfiguration.ReminderServiceProviderType.AzureTable:
                    Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(Constants.ORLEANS_AZURE_UTILS_DLL, logger);
                    return;

                case GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain:
                    Singleton = grainFactory.GetGrain<IReminderTableGrain>(Constants.ReminderTableGrainId);
                    return;

                case GlobalConfiguration.ReminderServiceProviderType.MockTable:
                    Singleton = new MockReminderTable(config.MockReminderTableTimeout);
                    return;

                case GlobalConfiguration.ReminderServiceProviderType.Custom:
                    Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(reminderTableAssembly, logger);
                    return;
            }
        }
Ejemplo n.º 2
0
 public void TestCleanup()
 {
     if (remindersTable != null && SiloInstanceTableTestConstants.DeleteEntriesAfterTest)
     {
         remindersTable.TestOnlyClearTable().Wait();
         remindersTable = null;
     }
     logger.Info("Test {0} completed - Outcome = {1}", TestContext.TestName, TestContext.CurrentTestOutcome);
 }
Ejemplo n.º 3
0
        internal static async Task ReminderTableUpsertParallel(IReminderTable reminder)
        {
            var grainRef = MakeTestGrainReference();
            var period = TimeSpan.FromMinutes(1);
            var reminderName = "testReminderName";
            var startAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(1));
            var results = await Task.WhenAll(Enumerable.Range(0, 10).Select(x => UpsertReminder(reminder, grainRef, reminderName, startAt, period)));

            Assert.IsTrue(results.Distinct().Count() == results.Length);
        }
 internal static async Task ReminderTableUpsertTwice(IReminderTable reminder)
 {
     var grainRef = MakeTestGrainReference();
     var period = TimeSpan.FromMinutes(1);
     var reminderName = "testReminderName";
     var startAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(1));
     var etag1 = await UpsertReminder(reminder, grainRef, reminderName, startAt, period);
     var etag2 = await UpsertReminder(reminder, grainRef, reminderName, startAt, period);
     Assert.AreNotEqual(etag1, etag2);
 }
Ejemplo n.º 5
0
 private static async Task<string> UpsertReminder(IReminderTable reminder, GrainReference grainRef, string reminderName, DateTime startAt, TimeSpan period)
 {
     var reminderRow = new ReminderEntry
                       {
                           GrainRef = grainRef,
                           Period = period,
                           StartAt = startAt,
                           ReminderName = reminderName
                       };
     return await reminder.UpsertRow(reminderRow);
 }
Ejemplo n.º 6
0
        private static async Task TestRemindersHashInterval(IReminderTable reminderTable, uint beginHash, uint endHash,
            uint[] remindersHashes)
        {
            var rowsTask = reminderTable.ReadRows(beginHash, endHash);
            var expectedHashes = beginHash < endHash
                ? remindersHashes.Where(r => r > beginHash && r <= endHash)
                : remindersHashes.Where(r => r > beginHash || r <= endHash);

            HashSet<uint> expectedSet = new HashSet<uint>(expectedHashes);
            var returnedHashes = (await rowsTask).Reminders.Select(r => r.GrainRef.GetUniformHashCode());
            var returnedSet = new HashSet<uint>(returnedHashes);

            Assert.IsTrue(returnedSet.SetEquals(expectedSet));
        }
Ejemplo n.º 7
0
        internal static async Task ReminderTableTest(IReminderTable reminderTable)
        {
            Guid guid = Guid.NewGuid();
            var results = await Task.WhenAll(Enumerable.Range(0, 10).
                Select(x => reminderTable.UpsertRow(CreateReminder(MakeTestGrainReference(guid), "0"))));

            Assert.AreEqual(results.Distinct().Count(), results.Length);

            await Task.WhenAll(Enumerable.Range(1, 999).Select(async i =>
            {
                GrainReference grainRef = MakeTestGrainReference(Guid.NewGuid());
                await reminderTable.UpsertRow(CreateReminder(grainRef, i.ToString()));
            }));

            var rows = await reminderTable.ReadRows(0, uint.MaxValue);

            Assert.AreEqual(rows.Reminders.Count, 1000);

            rows = await reminderTable.ReadRows(0, 0);

            Assert.AreEqual(rows.Reminders.Count, 1000);

            var remindersHashes = rows.Reminders.Select(r => r.GrainRef.GetUniformHashCode()).ToArray();
            
            SafeRandom random = new SafeRandom();

            await Task.WhenAll(Enumerable.Repeat(
                        TestRemindersHashInterval(reminderTable, (uint) random.Next(), (uint) random.Next(),
                            remindersHashes), 1000));

            var reminder = rows.Reminders.First();

            var shouldExist = await reminderTable.ReadRow(reminder.GrainRef, reminder.ReminderName);

            Assert.IsNotNull(shouldExist);

            string etagTemp = reminder.ETag;

            reminder.ETag = await reminderTable.UpsertRow(reminder);

            var removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, etagTemp);
            Assert.IsFalse(removeRowRes, "should have failed. Etag is wrong");
            removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, "bla", reminder.ETag);
            Assert.IsFalse(removeRowRes, "should have failed. reminder name is wrong");
            removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, reminder.ETag);
            Assert.IsTrue(removeRowRes, "should have succeeded. Etag is right");
            removeRowRes = await reminderTable.RemoveRow(reminder.GrainRef, reminder.ReminderName, reminder.ETag);
            Assert.IsFalse(removeRowRes, "should have failed. reminder shouldn't exist");
        }
Ejemplo n.º 8
0
        public void TestInitialize()
        {
            logger = TraceLogger.GetLogger(GetType().Name, TraceLogger.LoggerType.Application);
            var serviceId = Guid.NewGuid();
            var deploymentId = "test-" + serviceId;

            logger.Info("DeploymentId={0}", deploymentId);

            var globalConfiguration = new GlobalConfiguration
            {
                ServiceId = serviceId,
                DeploymentId = deploymentId,
                AdoInvariantForReminders = GetAdoInvariant(),
                DataConnectionStringForReminders = GetConnectionString()
            };

            var rmndr = CreateRemindersTable();
            rmndr.Init(globalConfiguration, logger).WithTimeout(TimeSpan.FromMinutes(1)).Wait();
            remindersTable = rmndr;
        }
        private async Task TestTableInsertRate(IReminderTable reminderTable, double numOfInserts)
        {
            DateTime startedAt = DateTime.UtcNow;

            try
            {
                List<Task<bool>> promises = new List<Task<bool>>();
                for (int i = 0; i < numOfInserts; i++)
                {
                    //"177BF46E-D06D-44C0-943B-C12F26DF5373"
                    string s = string.Format("177BF46E-D06D-44C0-943B-C12F26D{0:d5}", i);

                    var e = new ReminderEntry
                    {
                        //GrainId = GrainId.GetGrainId(new Guid(s)),
                        GrainRef = GrainReference.FromGrainId(GrainId.NewId()),
                        ReminderName = "MY_REMINDER_" + i,
                        Period = TimeSpan.FromSeconds(5),
                        StartAt = DateTime.UtcNow
                    };

                    int capture = i;
                    Task<bool> promise = Task.Run(async () =>
                    {
                        await reminderTable.UpsertRow(e);
                        output.WriteLine("Done " + capture);
                        return true;
                    });
                    promises.Add(promise);
                    log.Info("Started " + capture);
                }
                log.Info("Started all, now waiting...");
                await Task.WhenAll(promises).WithTimeout(TimeSpan.FromSeconds(500));
            }
            catch (Exception exc)
            {
                log.Info("Exception caught {0}", exc);
            }
            TimeSpan dur = DateTime.UtcNow - startedAt;
            log.Info("Inserted {0} rows in {1}, i.e., {2:f2} upserts/sec", numOfInserts, dur, (numOfInserts / dur.TotalSeconds));
        }
 private async Task<IEnumerable<ReminderEntry>> GetAllRows(IReminderTable table)
 {
     ReminderTableData data = await table.ReadRows(0, 0xffffffff);
     return data.Reminders;
 }