Esempio n. 1
0
        public async Task DistributedReadAsync()
        {
            int numRows;

            using (var connection = await _testFixture.GetTestDatabaseConnectionAsync())
                using (var cmd = connection.CreateSelectCommand("SELECT COUNT(*) FROM Orders"))
                {
                    numRows = await cmd.ExecuteScalarAsync <int>();
                }

            using (var connection = new SpannerConnection(_testFixture.ConnectionString))
            {
                await connection.OpenAsync();

                using (var transaction = await connection.BeginReadOnlyTransactionAsync())
                    using (var cmd = connection.CreateSelectCommand("SELECT * FROM Orders"))
                    {
                        transaction.DisposeBehavior = DisposeBehavior.CloseResources;
                        cmd.Transaction             = transaction;
                        var partitions = await cmd.GetReaderPartitionsAsync(1000);

                        var transactionId = transaction.TransactionId;

                        //we simulate a serialization/deserialization step in the call to the subtask.
                        await Task.WhenAll(partitions.Select(
                                               x => DistributedReadWorkerAsync(CommandPartition.FromBase64String(x.ToBase64String()),
                                                                               TransactionId.FromBase64String(transactionId.ToBase64String()))))
                        .ConfigureAwait(false);
                    }

                Assert.Equal(numRows, _rowsRead);
            }
        }
Esempio n. 2
0
        public void TransactionIdSerializable()
        {
            var transactionId = new TransactionId(
                "ConnectionString", "Session", "Id", new TimestampBound(
                    TimestampBoundMode.MaxStaleness,
                    new TimeSpan(1, 0, 0)));

            Assert.Equal(transactionId, TransactionId.FromBase64String(transactionId.ToBase64String()));

            transactionId = new TransactionId(
                "ConnectionString2", "Session2", "Id2", new TimestampBound(
                    TimestampBoundMode.ReadTimestamp,
                    new DateTime(1999, 12, 31, 3, 33, 33, DateTimeKind.Local)));

            Assert.Equal(transactionId, TransactionId.FromBase64String(transactionId.ToBase64String()));

            transactionId = new TransactionId(
                "ConnectionString3", "Session3", "Id3", new TimestampBound(
                    TimestampBoundMode.Strong));

            Assert.Equal(transactionId, TransactionId.FromBase64String(transactionId.ToBase64String()));
        }
 public void Base64RoundTrip(TransactionId transactionId)
 {
     Assert.Equal(transactionId, TransactionId.FromBase64String(transactionId.ToBase64String()));
 }