Exemple #1
0
        public async Task ReadMin()
        {
            using (var connection = _fixture.GetConnection())
            {
                await connection.OpenAsync();

                // Can't use MinReadTimestamp to create a transaction
                var bound = TimestampBound.OfMinReadTimestamp(_newestEntry.Timestamp);
                await Assert.ThrowsAsync <ArgumentException>(() => connection.BeginReadOnlyTransactionAsync(bound));

                var cmd = CreateSelectAllCommandForKey(connection);
                using (var reader = await cmd.ExecuteReaderAsync(bound))
                {
                    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) });
        }
        public async Task ReadMin()
        {
            ArgumentException caughtException = null;

            await WriteSampleRowsAsync();

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

                try
                {
                    await connection.BeginReadOnlyTransactionAsync(
                        TimestampBound.OfMinReadTimestamp(_history[2].Timestamp));
                }
                catch (ArgumentException ex)
                {
                    caughtException = ex;
                }

                var cmd = connection.CreateSelectCommand(
                    "SELECT * FROM TX WHERE K=@k",
                    new SpannerParameterCollection {
                    { "k", _key, SpannerDbType.String }
                });
                using (var reader =
                           await cmd.ExecuteReaderAsync(
                               TimestampBound.OfMinReadTimestamp(_history[2].Timestamp)))
                {
                    if (await reader.ReadAsync())
                    {
                        Assert.Equal(_history[2].Value, reader.GetFieldValue <string>(reader.GetOrdinal("StringValue")));
                    }
                }
            }
            Assert.NotNull(caughtException);
        }