示例#1
0
        public async Task ReadStaleMax()
        {
            await WriteSampleRowsAsync();

            await Task.Delay(6);

            using (var connection = await _testFixture.GetTestDatabaseConnectionAsync())
            {
                await connection.OpenAsync();

                await Assert.ThrowsAsync <ArgumentException>(
                    async() =>
                {
                    await connection.BeginReadOnlyTransactionAsync(
                        TimestampBound.OfMaxStaleness(TimeSpan.FromSeconds(50)));
                }).ConfigureAwait(false);

                var cmd = connection.CreateSelectCommand(
                    "SELECT * FROM TX WHERE K=@k",
                    new SpannerParameterCollection {
                    { "k", SpannerDbType.String, _key }
                });
                using (var reader =
                           await cmd.ExecuteReaderAsync(
                               TimestampBound.OfMaxStaleness(TimeSpan.FromMilliseconds(5))))
                {
                    if (await reader.ReadAsync())
                    {
                        Assert.Equal(_history[2].Value, reader.GetFieldValue <string>(reader.GetOrdinal("StringValue")));
                    }
                }
            }
        }
示例#2
0
        public void ToTransactionOptions_OfMaxStaleness()
        {
            var bound = TimestampBound.OfMaxStaleness(TimeSpan.FromSeconds(5));

            AssertProtoConversion(new ReadOnly {
                MaxStaleness = new Duration {
                    Seconds = 5
                }
            }, bound);
        }
示例#3
0
        public async Task ReadStaleMax()
        {
            using (var connection = _fixture.GetConnection())
            {
                await connection.OpenAsync();

                // Can't use MaxStaleness to create a transaction
                var staleBound = TimestampBound.OfMaxStaleness(_fixture.Staleness);
                await Assert.ThrowsAsync <ArgumentException>(() => connection.BeginReadOnlyTransactionAsync(staleBound));

                var cmd         = CreateSelectAllCommandForKey(connection);
                var recentBound = TimestampBound.OfMaxStaleness(TimeSpan.FromMilliseconds(5));
                using (var reader = await cmd.ExecuteReaderAsync(recentBound))
                {
                    if (await reader.ReadAsync())
                    {
                        Assert.Equal(_newestEntry.Value, reader.GetFieldValue <string>(reader.GetOrdinal("StringValue")));
                    }
                }
            }
        }
        public void Equality()
        {
            DateTime timestamp1 = new DateTime(2000, 6, 1, 23, 1, 5, DateTimeKind.Utc);
            TimeSpan staleness1 = TimeSpan.FromSeconds(10);

            DateTime timestamp2 = new DateTime(2005, 1, 1, 1, 1, 1, DateTimeKind.Utc);
            TimeSpan staleness2 = TimeSpan.FromSeconds(30);

            var strong              = TimestampBound.Strong;
            var minRead             = TimestampBound.OfMinReadTimestamp(timestamp1);
            var read                = TimestampBound.OfReadTimestamp(timestamp1);
            var exactStaleness      = TimestampBound.OfExactStaleness(staleness1);
            var maxStaleness        = TimestampBound.OfMaxStaleness(staleness1);
            var returnReadTimestamp = TimestampBound.Strong.WithReturnReadTimestamp(true);

            EqualityTester.AssertEqual(strong,
                                       new[] { strong },
                                       new[] { minRead, read, exactStaleness, maxStaleness });

            EqualityTester.AssertEqual(minRead,
                                       new[] { TimestampBound.OfMinReadTimestamp(timestamp1) },
                                       new[] { strong, read, exactStaleness, maxStaleness, TimestampBound.OfMinReadTimestamp(timestamp2) });

            EqualityTester.AssertEqual(read,
                                       new[] { TimestampBound.OfReadTimestamp(timestamp1) },
                                       new[] { strong, minRead, exactStaleness, maxStaleness, TimestampBound.OfReadTimestamp(timestamp2) });

            EqualityTester.AssertEqual(exactStaleness,
                                       new[] { TimestampBound.OfExactStaleness(staleness1) },
                                       new[] { strong, minRead, read, maxStaleness, TimestampBound.OfExactStaleness(staleness2) });

            EqualityTester.AssertEqual(maxStaleness,
                                       new[] { TimestampBound.OfMaxStaleness(staleness1) },
                                       new[] { strong, minRead, read, exactStaleness, TimestampBound.OfMaxStaleness(staleness2) });

            EqualityTester.AssertEqual(returnReadTimestamp,
                                       new[] { returnReadTimestamp },
                                       new[] { strong, minRead, read, exactStaleness, TimestampBound.OfMaxStaleness(staleness2) });
        }