// Replica does not have default constructor so need a method. private Replica CreateReplica() { Replica result; if (this.random.Next() % 2 == 0) { result = new StatefulServiceReplica( this.random.CreateRandom <ServiceReplicaStatus>(), this.random.CreateRandom <HealthState>(), ReplicaRole.IdleSecondary, this.random.CreateRandom <Uri>().ToString(), this.random.CreateRandom <string>(), this.random.CreateRandom <long>(), TimeSpan.FromSeconds(2)); } else { result = new StatelessServiceInstance( this.random.CreateRandom <ServiceReplicaStatus>(), this.random.CreateRandom <HealthState>(), this.random.CreateRandom <Uri>().ToString(), this.random.CreateRandom <string>(), this.random.CreateRandom <long>(), TimeSpan.FromSeconds(4)); } return(result); }
public async Task <Dictionary <Partition, StatelessServiceInstance[]> > QueryPartitionAndReplicaResultAsyncStateless(TimeSpan timeout, CancellationToken ct) { Dictionary <Partition, Replica[]> instancesMap = await this.QueryLocationsAsync(ct).ConfigureAwait(false); var allServiceInstances = new Dictionary <Partition, StatelessServiceInstance[]>(); foreach (var partition in instancesMap) { var statelessInstances = new List <StatelessServiceInstance>(); foreach (Replica instance in partition.Value) { StatelessServiceInstance statelessInstance = instance as StatelessServiceInstance; ReleaseAssert.AssertIf(statelessInstance == null, "Instance {0} should be of type stateless for Partition {1}", instance.Id, partition.Key.PartitionId()); statelessInstances.Add(statelessInstance); } allServiceInstances.Add(partition.Key, statelessInstances.ToArray()); } return(allServiceInstances); }