Exemplo n.º 1
0
    public async void GetPartitionListAsync_ServiceFabricFails_ResultIsCached()
    {
        var caller = Create <CachedServiceFabricCaller>();
        var originalPartitionInfoList = new List <PartitionWrapper> {
            SFTestHelpers.FakePartition()
        };

        Mock <IQueryClientWrapper>()
        .SetupSequence(m => m.GetPartitionListAsync(
                           new Uri("http://localhost/app1/sv1"),
                           It.IsAny <TimeSpan>(),
                           It.IsAny <CancellationToken>()))
        .ReturnsAsync(originalPartitionInfoList)
        .ThrowsAsync(new Exception("the cake is a lie"))
        .ThrowsAsync(new Exception("the cake is still a lie"));

        await CallThreeTimesAndAssertAsync(() => caller.GetPartitionListAsync(new Uri("http://localhost/app1/sv1"), CancellationToken.None));
    }
Exemplo n.º 2
0
    private ServiceWrapper CreateService(string appName, string serviceName, int numPartitions, int numReplicasPerPartition, out List <ReplicaWrapper> replicas, out List <PartitionWrapper> partitions, ServiceKind serviceKind = ServiceKind.Stateless)
    {
        var svcName = new Uri($"fabric:/{appName}/{serviceName}");
        var service = SFTestHelpers.FakeService(svcName, $"{appName}_{serviceName}_Type", serviceKind: serviceKind);

        replicas   = new List <ReplicaWrapper>();
        partitions = new List <PartitionWrapper>();

        for (var i = 0; i < numPartitions; i++)
        {
            var partitionReplicas = Enumerable.Range(i * numReplicasPerPartition, numReplicasPerPartition).Select(replicaId => SFTestHelpers.FakeReplica(svcName, replicaId)).ToList();
            replicas.AddRange(partitionReplicas);
            var partition = SFTestHelpers.FakePartition();
            partitions.Add(partition);
            Mock_ReplicasResponse(partition.Id, partitionReplicas.ToArray());
        }
        Mock_PartitionsResponse(svcName, partitions.ToArray());
        return(service);
    }