예제 #1
0
        public void PollOnce()
        {
            var client = new FakeOperationsClient();

            client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                Value = "result"
            });
            var initial = Operation <StringValue, Timestamp> .PollOnceFromName("op", client);

            Assert.False(initial.IsCompleted);
            client.FakeClock.Advance(TimeSpan.FromSeconds(2));
            var polled = initial.PollOnce();

            Assert.False(polled.IsCompleted);
            client.FakeClock.Advance(TimeSpan.FromSeconds(2));
            polled = polled.PollOnce();
            Assert.True(polled.IsCompleted);
            Assert.Equal("result", polled.Result.Value);
            Assert.Equal(3, client.RequestCount);
        }
        public async Task PollUntilCompletedAsync_Success()
        {
            var client                      = new FakeOperationsClient();
            var expectedMetadata            = GenerateExpectedMetadata(client.Clock, 0, 2, 3);
            List <Timestamp> actualMetadata = new List <Timestamp>();
            await client.FakeScheduler.RunAsync(async() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                    Value = "result"
                });
                var initial  = Operation <StringValue, Timestamp> .PollOnceFromNameAsync("op", client).Result;
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                // Second request at t=0, then at t=2, then another at t=4
                var completedOperation = await initial.PollUntilCompletedAsync(settings, metadataCallback: actualMetadata.Add);
                Assert.Equal("result", completedOperation.Result.Value);
            });

            Assert.Equal(4, client.RequestCount);
            Assert.Equal(expectedMetadata, actualMetadata);
        }
예제 #3
0
        public async Task Properties_WithError()
        {
            var client    = new FakeOperationsClient();
            var operation = ForError("name", new ProtoStatus {
                Message = "Bang", Code = 123
            }, client);

            Assert.Equal("name", operation.Name);
            Assert.True(operation.IsCompleted);
            var exception = Assert.Throws <OperationFailedException>(() => operation.Result.ToString());

            Assert.Contains("Bang", exception.Message);
            Assert.Equal(123, exception.Status.Code);
            Assert.Same(operation.RpcMessage, exception.Operation);
            Assert.True(operation.IsFaulted);
            Assert.Same(exception, operation.Exception);
            Assert.Same(operation, operation.PollOnce());
            Assert.Same(operation, operation.PollUntilCompleted());
            Assert.Same(operation, await operation.PollOnceAsync());
            Assert.Same(operation, await operation.PollUntilCompletedAsync());
            Assert.Equal(0, client.RequestCount);
        }
예제 #4
0
        public void PollUntilCompleted_NullMetadata()
        {
            var client = new FakeOperationsClient {
                GenerateMetadata = false
            };
            var expectedMetadata = new List <Timestamp> {
                null, null, null
            };
            List <Timestamp> actualMetadata = new List <Timestamp>();

            client.FakeScheduler.Run(() =>
            {
                client.AddSuccessfulOperation("op", client.Clock.GetCurrentDateTimeUtc().AddSeconds(3), new StringValue {
                    Value = "result"
                });
                var initial  = Operation <StringValue, Timestamp> .PollOnceFromName("op", client);
                var settings = new PollSettings(Expiration.FromTimeout(TimeSpan.FromSeconds(5)), TimeSpan.FromSeconds(2));
                // Second request at t=2, then another at t=4
                var final = initial.PollUntilCompleted(settings, metadataCallback: actualMetadata.Add);
                Assert.Equal("result", final.Result.Value);
                Assert.Equal(4, client.RequestCount);
            });
            Assert.Equal(expectedMetadata, actualMetadata);
        }