Example #1
0
        public async Task SimpleRetry()
        {
            var request = new MutateRowsRequest
            {
                Entries =
                {
                    Mutations.CreateEntry("a", Mutations.DeleteFromRow()),
                    Mutations.CreateEntry("b", Mutations.DeleteFromRow()),
                    Mutations.CreateEntry("c", Mutations.DeleteFromRow())
                }
            };
            var client = MutateRowsStreamUtilities.CreateClientForMutateRowsRetries(
                request,
                entriesForInitialResponse: new[]
            {
                MutateRowsStreamUtilities.CreateEntry(0, Code.Ok),
                MutateRowsStreamUtilities.CreateEntry(1, Code.DeadlineExceeded),
                MutateRowsStreamUtilities.CreateEntry(2, Code.Ok)
            },
                entriesForRetryResponses: new[]
            {
                // 1st retry response entries
                new[] { MutateRowsStreamUtilities.CreateEntry(0, Code.Ok) }
            });

            var entries = (await client.MutateRowsAsync(request)).Entries.OrderBy(e => e.Index).ToList();

            Assert.Equal(3, entries.Count);

            var entry = entries[0];

            Assert.Equal(0, entry.Index);
            Assert.Equal((int)Code.Ok, entry.Status.Code);

            entry = entries[1];
            Assert.Equal(1, entry.Index);
            Assert.Equal((int)Code.Ok, entry.Status.Code);

            entry = entries[2];
            Assert.Equal(2, entry.Index);
            Assert.Equal((int)Code.Ok, entry.Status.Code);
        }
Example #2
0
        public async Task NonRetryableErrorCodePreventsRetry()
        {
            var request = new MutateRowsRequest
            {
                Entries =
                {
                    Mutations.CreateEntry("a", Mutations.DeleteFromRow()),
                    Mutations.CreateEntry("b", Mutations.DeleteFromRow()),
                    Mutations.CreateEntry("c", Mutations.DeleteFromRow())
                }
            };
            var client = MutateRowsStreamUtilities.CreateClientForMutateRowsRetries(
                request,
                entriesForInitialResponse: new[]
            {
                MutateRowsStreamUtilities.CreateEntry(0, Code.Ok),
                MutateRowsStreamUtilities.CreateEntry(1, Code.FailedPrecondition),
                MutateRowsStreamUtilities.CreateEntry(2, Code.DeadlineExceeded)
            },
                entriesForRetryResponses: null // No retries should be made
                );

            var entries = (await client.MutateRowsAsync(request)).Entries.OrderBy(e => e.Index).ToList();

            Assert.Equal(3, entries.Count);

            var entry = entries[0];

            Assert.Equal(0, entry.Index);
            Assert.Equal((int)Code.Ok, entry.Status.Code);

            entry = entries[1];
            Assert.Equal(1, entry.Index);
            Assert.Equal((int)Code.FailedPrecondition, entry.Status.Code);

            entry = entries[2];
            Assert.Equal(2, entry.Index);
            Assert.Equal((int)Code.DeadlineExceeded, entry.Status.Code);
        }
        public async Task MultipleRetries()
        {
            var request = new MutateRowsRequest
            {
                Entries =
                {
                    Mutations.CreateEntry("a", Mutations.DeleteFromRow()),
                    Mutations.CreateEntry("b", Mutations.DeleteFromRow()),
                    Mutations.CreateEntry("c", Mutations.DeleteFromRow()),
                    Mutations.CreateEntry("d", Mutations.DeleteFromRow()),
                    Mutations.CreateEntry("e", Mutations.DeleteFromRow())
                }
            };
            var client = MutateRowsStreamUtilities.CreateClientForMutateRowsRetries(
                entriesForInitialResponse: new[]
            {
                MutateRowsStreamUtilities.CreateEntry(0, Code.Ok),
                MutateRowsStreamUtilities.CreateEntry(1, Code.DeadlineExceeded),
                MutateRowsStreamUtilities.CreateEntry(2, Code.Ok),
                MutateRowsStreamUtilities.CreateEntry(3, Code.DeadlineExceeded),
                MutateRowsStreamUtilities.CreateEntry(4, Code.DeadlineExceeded)
            },
                entriesForRetryResponses: new[]
            {
                // 1st retry response entries
                new[]
                {
                    // Original entry 1
                    MutateRowsStreamUtilities.CreateEntry(0, Code.Ok),
                    // Original entry 3
                    MutateRowsStreamUtilities.CreateEntry(1, Code.DeadlineExceeded),
                    // Original entry 4
                    MutateRowsStreamUtilities.CreateEntry(2, Code.Ok)
                },
                // 2nd retry response entries
                new[]
                {
                    // Original entry 3
                    MutateRowsStreamUtilities.CreateEntry(0, Code.FailedPrecondition)
                }
            });

            var entries = (await client.MutateRowsAsync(request)).Entries.OrderBy(e => e.Index).ToList();

            Assert.Equal(5, entries.Count);

            var entry = entries[0];

            Assert.Equal(0, entry.Index);
            Assert.Equal((int)Code.Ok, entry.Status.Code);

            entry = entries[1];
            Assert.Equal(1, entry.Index);
            Assert.Equal((int)Code.Ok, entry.Status.Code);

            entry = entries[2];
            Assert.Equal(2, entry.Index);
            Assert.Equal((int)Code.Ok, entry.Status.Code);

            entry = entries[3];
            Assert.Equal(3, entry.Index);
            Assert.Equal((int)Code.FailedPrecondition, entry.Status.Code);

            entry = entries[4];
            Assert.Equal(4, entry.Index);
            Assert.Equal((int)Code.Ok, entry.Status.Code);
        }