Helper command to fetch Cassandra tracing information
示例#1
0
        public async Task BasicFlow()
        {
            //Assume
            const string insertCql = @"insert into Test.BasicFlow (id,value) values (?,?);";
            const string retrieveCql = @"select * from Test.BasicFlow;";

            const int insertCount = 1000;

            //Act
            using (var connection = new CqlConnection(ConnectionString))
            {
                await connection.OpenAsync();

                var executions = new Task<ICqlQueryResult>[insertCount];

                var options = new ParallelOptions() { MaxDegreeOfParallelism = 1 };
                Parallel.For(0, insertCount, options, (i) =>
                {
                    var cmd = new CqlCommand(connection, insertCql, CqlConsistency.One);
                    cmd.Prepare();

                    var b = new BasicFlowData { Id = i, Data = "Hallo " + i };
                    cmd.PartitionKey.Set(b);
                    cmd.Parameters.Set(b);

                    executions[i] = cmd.ExecuteNonQueryAsync();
                });

                await Task.WhenAll(executions);

                var presence = new bool[insertCount];

                var selectCmd = new CqlCommand(connection, retrieveCql, CqlConsistency.One) { EnableTracing = true };

                CqlDataReader<BasicFlowData> reader = await selectCmd.ExecuteReaderAsync<BasicFlowData>();
                while (await reader.ReadAsync())
                {
                    BasicFlowData row = reader.Current;
                    Assert.AreEqual(row.Data, "Hallo " + row.Id);
                    presence[row.Id] = true;
                }

                Assert.IsTrue(presence.All(p => p));

                var tracer = new QueryTraceCommand(connection, reader.TracingId.Value);
                TracingSession session = await tracer.GetTraceSessionAsync();

                Assert.IsNotNull(session);
            }
        }
示例#2
0
        public async Task PrepareTracing()
        {
            //Assume
            const string insertCql = @"insert into Test.BasicFlow (id,value) values (542,'Hallo 542');";

            //Act
            using(var connection = new CqlConnection(ConnectionString))
            {
                await connection.OpenAsync();

                //insert data
                var cmd = new CqlCommand(connection, insertCql, CqlConsistency.One);
                cmd.EnableTracing = true;
                await cmd.PrepareAsync();

                Assert.IsInstanceOfType(cmd.LastQueryResult, typeof(CqlPrepared));
                Assert.IsTrue(cmd.LastQueryResult.TracingId.HasValue, "Expected a tracing id");

                var tracer = new QueryTraceCommand(connection, cmd.LastQueryResult.TracingId.Value);
                TracingSession session = await tracer.GetTraceSessionAsync(CancellationToken.None);

                Assert.IsNotNull(session);
            }
        }