コード例 #1
0
        public void GetRequest_Batch_With_64K_Queries()
        {
            var batch = new BatchStatement();

            for (var i = 0; i < ushort.MaxValue; i++)
            {
                batch.Add(new SimpleStatement("QUERY"));
            }

            var config     = RequestHandlerTests.GetConfig(new QueryOptions(), Policies.DefaultPolicies, PoolingOptions.Create());
            var request    = RequestHandler.GetRequest(batch, Serializer, config.DefaultRequestOptions);
            var bodyBuffer = GetBodyBuffer(request);

            // The batch request is composed by:
            // <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
            CollectionAssert.AreEqual(new byte[] { 0xff, 0xff }, bodyBuffer.Skip(1).Take(2));
        }
コード例 #2
0
        public void GetRequest_Batch_With_Timestamp_Generator()
        {
            var batch = new BatchStatement();

            batch.Add(new SimpleStatement("QUERY"));
            var startDate = DateTimeOffset.Now;

            // To microsecond precision
            startDate = startDate.Subtract(TimeSpan.FromTicks(startDate.Ticks % 10));

            var config     = RequestHandlerTests.GetConfig(new QueryOptions(), Policies.DefaultPolicies, PoolingOptions.Create());
            var request    = RequestHandler.GetRequest(batch, Serializer, config.DefaultRequestOptions);
            var bodyBuffer = GetBodyBuffer(request);

            // The batch request is composed by:
            // <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
            var offset = 1;

            // n = 1
            Assert.AreEqual(1, BeConverter.ToInt16(bodyBuffer, offset));
            // Query_1 <kind><string><n_params>
            offset += 2;
            // kind = 0, not prepared
            Assert.AreEqual(0, bodyBuffer[offset++]);
            var queryLength = BeConverter.ToInt32(bodyBuffer, offset);

            Assert.AreEqual(5, queryLength);
            // skip query, n_params and consistency
            offset += 4 + queryLength + 2 + 2;
            var flags = GetQueryFlags(bodyBuffer, ref offset);

            Assert.True(flags.HasFlag(QueryFlags.WithDefaultTimestamp));
            // Skip serial consistency
            offset += 2;
            var timestamp = TypeSerializer.UnixStart.AddTicks(BeConverter.ToInt64(bodyBuffer, offset) * 10);

            Assert.GreaterOrEqual(timestamp, startDate);
            Assert.LessOrEqual(timestamp, DateTimeOffset.Now.Add(TimeSpan.FromMilliseconds(100)));
        }
コード例 #3
0
        public void GetRequest_With_Timestamp_Generator_Empty_Value_With_Statement_Timestamp()
        {
            var statement         = new SimpleStatement("STATEMENT WITH TIMESTAMP");
            var expectedTimestamp = new DateTimeOffset(2010, 04, 29, 1, 2, 3, 4, TimeSpan.Zero).AddTicks(20);

            statement.SetTimestamp(expectedTimestamp);
            var policies = new Policies(
                Policies.DefaultLoadBalancingPolicy, Policies.DefaultReconnectionPolicy, Policies.DefaultRetryPolicy,
                Policies.DefaultSpeculativeExecutionPolicy, new NoTimestampGenerator());
            var config = RequestHandlerTests.GetConfig(new QueryOptions(), policies, PoolingOptions.Create());

            var request    = RequestHandler.GetRequest(statement, Serializer, config.DefaultRequestOptions);
            var bodyBuffer = GetBodyBuffer(request);

            // The query request is composed by:
            // <query><consistency><flags><result_page_size><paging_state><serial_consistency><timestamp>
            var queryBuffer = BeConverter.GetBytes(statement.QueryString.Length)
                              .Concat(Encoding.UTF8.GetBytes(statement.QueryString))
                              .ToArray();

            CollectionAssert.AreEqual(queryBuffer, bodyBuffer.Take(queryBuffer.Length));
            // Skip the query and consistency (2)
            var offset = queryBuffer.Length + 2;

            // The remaining length should be = flags (1) + result_page_size (4) + serial_consistency (2) + timestamp (8)
            Assert.AreEqual(15, bodyBuffer.Length - offset);
            var flags = GetQueryFlags(bodyBuffer, ref offset);

            Assert.True(flags.HasFlag(QueryFlags.WithDefaultTimestamp));
            Assert.True(flags.HasFlag(QueryFlags.PageSize));
            // Skip result_page_size (4) + serial_consistency (2)
            offset += 6;
            var timestamp = BeConverter.ToInt64(bodyBuffer, offset);

            Assert.AreEqual(TypeSerializer.SinceUnixEpoch(expectedTimestamp).Ticks / 10, timestamp);
        }
コード例 #4
0
 private static IRequestOptions GetRequestOptions(QueryOptions queryOptions = null, Policies policies = null)
 {
     return(RequestHandlerTests.GetConfig(queryOptions, policies).DefaultRequestOptions);
 }