示例#1
0
        public void RunMaxConcurrentStreams()
        {
            PrepareTestData();

            var calls = new List <AsyncServerStreamingCall <ReadRowsResponse> >();

            for (int i = 0; i < numStreamCalls; i++)
            {
                var streamingCall = client.ReadRows(
                    new ReadRowsRequest
                {
                    TableName = TableName,
                    Rows      = new RowSet
                    {
                        RowKeys = { ByteString.CopyFromUtf8("large-row") }
                    }
                });
                calls.Add(streamingCall);
            }
            Console.WriteLine(String.Format("Created {0} streaming calls.", numStreamCalls));

            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       token       = tokenSource.Token;

            Console.WriteLine("Starting UnaryUnary blocking call..");
            var watch = System.Diagnostics.Stopwatch.StartNew();
            MutateRowRequest mutateRowRequest = new MutateRowRequest
            {
                TableName = TableName,
                RowKey    = ByteString.CopyFromUtf8(RowKey)
            };

            Mutation mutation = new Mutation
            {
                SetCell = new Mutation.Types.SetCell
                {
                    FamilyName      = ColumnFamily,
                    ColumnQualifier = ByteString.CopyFromUtf8(ColumnQualifier),
                    Value           = ByteString.CopyFromUtf8(TestValue),
                }
            };

            mutateRowRequest.Mutations.Add(mutation);

            // Set 5 sec time out for the blocking call.
            client.MutateRow(mutateRowRequest, null, DateTime.UtcNow.AddSeconds(5));

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Elapsed time for another call (ms): " + elapsedMs);
        }
示例#2
0
        public void ReadRows()
        {
            ReadRowsRequest readRowsRequest = new ReadRowsRequest
            {
                TableName = TableName,
                Rows      = new RowSet
                {
                    RowKeys = { ByteString.CopyFromUtf8(RowKey) }
                }
            };
            var streamingCall = client.ReadRows(readRowsRequest);
            var channelRefs   = invoker.GetChannelRefsForTest();

            Assert.AreEqual(1, channelRefs.Count);
            Assert.AreEqual(1, channelRefs[0].ActiveStreamCount);
            Assert.ThrowsException <InvalidOperationException>(() => streamingCall.GetStatus());

            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       token       = tokenSource.Token;
            var responseStream             = streamingCall.ResponseStream;
            ReadRowsResponse firstResponse = null;

            while (responseStream.MoveNext(token).Result)
            {
                if (firstResponse == null)
                {
                    firstResponse = responseStream.Current;
                }
            }
            Assert.AreEqual("test-value", firstResponse.Chunks[0].Value.ToStringUtf8());

            channelRefs = invoker.GetChannelRefsForTest();
            Assert.AreEqual(1, channelRefs.Count);
            Assert.AreEqual(0, channelRefs[0].ActiveStreamCount);
            Assert.AreEqual(StatusCode.OK, streamingCall.GetStatus().StatusCode);
        }