private async Task <bool> ReportLoadOnChangeRole(ReplicaRole role)
        {
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            ManualResetEvent reset = new ManualResetEvent(false);

            bool actual = false;

            MockStatefulServicePartition partition = new MockStatefulServicePartition()
            {
                OnReportLoad = (metrics) =>
                {
                    actual = true;
                    reset.Set();
                }
            };

            await((IStateProviderReplica)target).OpenAsync(ReplicaOpenMode.New, partition, CancellationToken.None);
            await((IStateProviderReplica)target).ChangeRoleAsync(role, CancellationToken.None);

            // this may yield false negatives because we're at the mercy of the task scheduler
            // to actually execute the reporting task in a timely manner, which depends on external factors.
            reset.WaitOne(TimeSpan.FromSeconds(10));

            return(actual);
        }
Exemplo n.º 2
0
        public async Task GetOrAddAsyncResultType()
        {
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            IReliableDictionary <int, string> actual = await target.GetOrAddAsync <IReliableDictionary <int, string> >("test://dictionary");

            Assert.IsTrue(actual is MetricReliableDictionary <int, string>);
        }
Exemplo n.º 3
0
        public async Task GetAsyncNoResult()
        {
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            ConditionalValue <IReliableDictionary <int, string> > actual = await target.TryGetAsync <IReliableDictionary <int, string> >("test://dictionary");

            Assert.IsFalse(actual.HasValue);
            Assert.IsNull(actual.Value);
        }
Exemplo n.º 4
0
        public async Task EnumerateEmpty()
        {
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            IAsyncEnumerator <IReliableState> enumerator = target.GetAsyncEnumerator();

            bool next = await enumerator.MoveNextAsync(CancellationToken.None);

            Assert.IsFalse(next);
            Assert.IsNull(enumerator.Current);
        }
Exemplo n.º 5
0
        public async Task GetAsyncWithResultType()
        {
            Uri name = new Uri("test://dictionary");
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            await target.GetOrAddAsync <IReliableDictionary <int, string> >(name);

            ConditionalValue <IReliableDictionary <int, string> > actual = await target.TryGetAsync <IReliableDictionary <int, string> >(name);

            Assert.IsTrue(actual.HasValue);
            Assert.IsTrue(actual.Value is MetricReliableDictionary <int, string>);
        }
Exemplo n.º 6
0
        public async Task EnumerateSingleItem()
        {
            Uri name = new Uri("test://dictionary");
            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            await target.GetOrAddAsync <IReliableDictionary <int, string> >(name);

            IAsyncEnumerator <IReliableState> enumerator = target.GetAsyncEnumerator();

            bool next = await enumerator.MoveNextAsync(CancellationToken.None);

            MetricReliableDictionary <int, string> actual = enumerator.Current as MetricReliableDictionary <int, string>;

            Assert.IsNotNull(actual);
            Assert.AreEqual <Uri>(name, actual.Name);
            Assert.IsFalse(await enumerator.MoveNextAsync(CancellationToken.None));
        }
Exemplo n.º 7
0
        public async Task EnumerateWithNonMetricCollections()
        {
            Uri dictionaryName = new Uri("test://dictionary");
            Uri queueName      = new Uri("test://queue");

            MetricReliableStateManager target = new MetricReliableStateManager(
                this.GetContext(),
                new JsonReliableStateSerializerResolver(),
                this.GetConfig(),
                new MockReliableStateManager());

            await target.GetOrAddAsync <IReliableDictionary <int, string> >(dictionaryName);

            await target.GetOrAddAsync <IReliableQueue <string> >(queueName);

            List <IReliableState> result = new List <IReliableState>();
            await target.ForeachAsync <IReliableState>(CancellationToken.None, x => result.Add(x));

            Assert.AreEqual <int>(2, result.Count);
            Assert.AreEqual <int>(1, result.Count(x => x.Name == queueName));
            Assert.AreEqual <int>(1, result.Count(x => x.Name == dictionaryName && x is MetricReliableDictionary <int, string>));
        }