Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
        public GatewayManager(ClientConfiguration cfg, IGatewayListProvider gatewayListProvider)
        {
            config = cfg;
            knownDead = new Dictionary<Uri, DateTime>();
            rand = new SafeRandom();
            logger = TraceLogger.GetLogger("Messaging.GatewayManager", TraceLogger.LoggerType.Runtime);
            lockable = new object();
            gatewayRefreshCallInitiated = false;

            ListProvider = gatewayListProvider;

            var knownGateways = ListProvider.GetGateways().GetResult();

            if (knownGateways.Count == 0)
            {
                string gatewayProviderType = gatewayListProvider.GetType().FullName;
                string err = String.Format("Could not find any gateway in {0}. Orleans client cannot initialize.", gatewayProviderType);
                logger.Error(ErrorCode.GatewayManager_NoGateways, err);
                throw new OrleansException(err);
            }

            logger.Info(ErrorCode.GatewayManager_FoundKnownGateways, "Found {0} knownGateways from Gateway listProvider {1}", knownGateways.Count, Utils.EnumerableToString(knownGateways));

            if (ListProvider is IGatewayListObservable)
            {
                ((IGatewayListObservable)ListProvider).SubscribeToGatewayNotificationEvents(this);
            }

            roundRobinCounter = cfg.PreferedGatewayIndex >= 0 ? cfg.PreferedGatewayIndex : rand.Next(knownGateways.Count);

            cachedLiveGateways = knownGateways;

            lastRefreshTime = DateTime.UtcNow;
            if (ListProvider.IsUpdatable)
            {
                gatewayRefreshTimer = new SafeTimer(RefreshSnapshotLiveGateways_TimerCallback, null, config.GatewayListRefreshPeriod, config.GatewayListRefreshPeriod);
            }
        }
Exemplo n.º 3
0
        internal async Task RemindersRange(int iterations=1000)
        {
            await Task.WhenAll(Enumerable.Range(1, iterations).Select(async i =>
            {
                GrainReference grainRef = MakeTestGrainReference();
                await remindersTable.UpsertRow(CreateReminder(grainRef, i.ToString()));
            }));

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

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

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

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

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

            await Task.WhenAll(Enumerable.Range(0, iterations).Select(i =>
                TestRemindersHashInterval(remindersTable, (uint)random.Next(), (uint)random.Next(),
                    remindersHashes)));
        }