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); }
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>); }
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); }
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); }
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>); }
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)); }
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>)); }