Beispiel #1
0
        public async Task TryToProcessBatchOfOperations_OperationExecutorNotAvailable_QueuesForAddressesWithNoResponseAreRemoved()
        {
            var maxDegreeOfParallelism             = 5;
            var maxAddressFailures                 = 5;
            var cleanAddressesWithFailuresTimeSpan = TimeSpan.FromDays(1);
            var pBfClient = new Mock <IPrivateBlockchainFacadeClient>();

            var pbfResponse = GetOperationsData();

            pBfClient.SetupSequence(x => x.OperationsApi.GetNewOperationsAsync())
            .ReturnsAsync(pbfResponse)
            .ReturnsAsync(new List <NewOperationResponseModel>());

            pBfClient.Setup(x => x.OperationsApi.AcceptBatchAsync(It.IsAny <Dictionary <Guid, string> >()))
            .ReturnsAsync(new OperationStatusUpdateResponseModel())
            .Verifiable();

            var executorClient = new Mock <IQuorumOperationExecutorClient>();

            executorClient.Setup(x =>
                                 x.OperationsApi.ExecuteOperationsBatchAsync(It.Is <ExecuteOperationsBatchRequest>(r => r.MasterWalletAddress != "address1")))
            .ReturnsAsync(
                new ExecuteOperationsBatchResponse
            {
                Error        = ExecuteOperationError.None,
                TxHashesDict = pbfResponse.Where(o => o.MasterWalletAddress != "address1").ToDictionary(i => i.Id, i => "hash")
            });

            executorClient.SetupSequence(x =>
                                         x.OperationsApi.ExecuteOperationsBatchAsync(It.Is <ExecuteOperationsBatchRequest>(r => r.MasterWalletAddress == "address1")))
            .ThrowsAsync(new Exception())
            .ReturnsAsync(new ExecuteOperationsBatchResponse {
                Error = ExecuteOperationError.MasterWalletNotFound
            });

            OperationOrchestratorService operationOrchestratorService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                operationOrchestratorService = new OperationOrchestratorService(
                    maxDegreeOfParallelism,
                    maxAddressFailures,
                    cleanAddressesWithFailuresTimeSpan,
                    _acceptedOperationsWarningTimeout,
                    pBfClient.Object,
                    executorClient.Object,
                    logFactory);
            }

            await operationOrchestratorService.ProcessOperationsBatchAsync();

            pBfClient.Verify(x => x.OperationsApi.AcceptBatchAsync(It.Is <Dictionary <Guid, string> >(d => d.Values.Any(v => v != "hash"))), Times.Never);

            pBfClient.Verify(x => x.OperationsApi.AcceptBatchAsync(It.Is <Dictionary <Guid, string> >(d => d.Values.Any(v => v == "hash"))), Times.Exactly(2));
        }
Beispiel #2
0
        public async Task TryToProcessBatchOfOperations_ErrorOnSomeAddressFromSeveralAttempts_OperationsForThisAddressAreNotGetForProcessing()
        {
            var maxDegreeOfParallelism             = 5;
            var maxAddressFailures                 = 3;
            var cleanAddressesWithFailuresTimeSpan = TimeSpan.FromDays(1);
            var pBfClient = new Mock <IPrivateBlockchainFacadeClient>();

            var pbfResponse = GetOperationsData();

            pBfClient.SetupSequence(x => x.OperationsApi.GetNewOperationsAsync())
            .ReturnsAsync(pbfResponse)
            .ReturnsAsync(pbfResponse)
            .ReturnsAsync(pbfResponse)
            .ReturnsAsync(pbfResponse)
            .ReturnsAsync(new List <NewOperationResponseModel>());

            pBfClient.Setup(x => x.OperationsApi.AcceptAsync(It.IsAny <Guid>(), It.IsAny <string>()))
            .ReturnsAsync(new OperationStatusUpdateResponseModel())
            .Verifiable();

            var executorClient = new Mock <IQuorumOperationExecutorClient>();

            executorClient.Setup(x =>
                                 x.OperationsApi.ExecuteOperationAsync(It.IsAny <Guid>(), It.Is <ExecuteOperationRequest>(r => r.MasterWalletAddress != "address3")))
            .ReturnsAsync(new ExecuteOperationResponse {
                Error = ExecuteOperationError.None, TxHash = "hash"
            });

            executorClient.Setup(x =>
                                 x.OperationsApi.ExecuteOperationAsync(It.IsAny <Guid>(), It.Is <ExecuteOperationRequest>(r => r.MasterWalletAddress == "address3")))
            .ReturnsAsync(new ExecuteOperationResponse {
                Error = ExecuteOperationError.MasterWalletNotFound, TxHash = "hash1"
            })
            .Verifiable();

            OperationOrchestratorService operationOrchestratorService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                operationOrchestratorService = new OperationOrchestratorService(
                    maxDegreeOfParallelism,
                    maxAddressFailures,
                    cleanAddressesWithFailuresTimeSpan,
                    _acceptedOperationsWarningTimeout,
                    pBfClient.Object,
                    executorClient.Object,
                    logFactory);
            }

            await operationOrchestratorService.ProcessOperationsBatchAsync();

            executorClient.Verify(x => x.OperationsApi.ExecuteOperationAsync
                                      (It.IsAny <Guid>(), It.Is <ExecuteOperationRequest>(r => r.MasterWalletAddress == "address3")), Times.AtMost(maxAddressFailures));
        }
Beispiel #3
0
        public async Task TryToProcessBatchOfOperations_EverythingValid_ProcessedSuccessfully()
        {
            var maxDegreeOfParallelism             = 5;
            var maxAddressFailures                 = 5;
            var cleanAddressesWithFailuresTimeSpan = TimeSpan.FromDays(1);
            var pBfClient = new Mock <IPrivateBlockchainFacadeClient>();

            var pbfResponse = GetOperationsData();

            pBfClient.SetupSequence(x => x.OperationsApi.GetNewOperationsAsync())
            .ReturnsAsync(pbfResponse)
            .ReturnsAsync(new List <NewOperationResponseModel>());

            pBfClient.Setup(x => x.OperationsApi.AcceptBatchAsync(It.IsAny <Dictionary <Guid, string> >()))
            .ReturnsAsync(new OperationStatusUpdateResponseModel())
            .Verifiable();

            var executorClient = new Mock <IQuorumOperationExecutorClient>();

            executorClient.Setup(x => x.OperationsApi.ExecuteOperationsBatchAsync(It.IsAny <ExecuteOperationsBatchRequest>()))
            .ReturnsAsync(new ExecuteOperationsBatchResponse
            {
                Error        = ExecuteOperationError.None,
                TxHashesDict = new Dictionary <Guid, string>()
            });

            OperationOrchestratorService operationOrchestratorService;

            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                operationOrchestratorService = new OperationOrchestratorService(
                    maxDegreeOfParallelism,
                    maxAddressFailures,
                    cleanAddressesWithFailuresTimeSpan,
                    _acceptedOperationsWarningTimeout,
                    pBfClient.Object,
                    executorClient.Object,
                    logFactory);
            }

            await operationOrchestratorService.ProcessOperationsBatchAsync();

            pBfClient.Verify(x => x.OperationsApi.AcceptBatchAsync(It.IsAny <Dictionary <Guid, string> >()), Times.Exactly(3));
        }