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 Dse.Policies( Dse.Policies.DefaultLoadBalancingPolicy, Dse.Policies.DefaultReconnectionPolicy, Dse.Policies.DefaultRetryPolicy, Dse.Policies.DefaultSpeculativeExecutionPolicy, new NoTimestampGenerator()); var config = new Configuration( policies, new ProtocolOptions(), PoolingOptions.GetDefault(ProtocolVersion.MaxSupported), new SocketOptions(), new ClientOptions(), NoneAuthProvider.Instance, null, new QueryOptions(), new DefaultAddressTranslator()); var request = RequestHandler <RowSet> .GetRequest(statement, Serializer, config); var stream = new MemoryStream(); request.WriteFrame(1, stream, Serializer); var headerSize = FrameHeader.GetSize(ProtocolVersion.MaxSupported); var bodyBuffer = new byte[stream.Length - headerSize]; stream.Position = headerSize; stream.Read(bodyBuffer, 0, bodyBuffer.Length); // The query request is composed by: // <query><consistency><flags><result_page_size><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 13 = flags (1) + result_page_size (4) + timestamp (8) Assert.AreEqual(13, bodyBuffer.Length - offset); var flags = (QueryFlags)bodyBuffer[offset]; Assert.True(flags.HasFlag(QueryFlags.WithDefaultTimestamp)); Assert.True(flags.HasFlag(QueryFlags.PageSize)); // Skip flags (1) + result_page_size (4) offset += 5; var timestamp = BeConverter.ToInt64(bodyBuffer, offset); Assert.AreEqual(TypeSerializer.SinceUnixEpoch(expectedTimestamp).Ticks / 10, timestamp); }
private static Configuration GetConfig(int coreConnections = 3, int maxConnections = 8, IReconnectionPolicy rp = null) { var pooling = new PoolingOptions() .SetCoreConnectionsPerHost(HostDistance.Local, coreConnections) .SetMaxSimultaneousRequestsPerConnectionTreshold(HostDistance.Local, 1500) .SetMaxConnectionsPerHost(HostDistance.Local, maxConnections); var policies = new Dse.Policies(null, rp, null, null, null); var config = new Configuration( policies, new ProtocolOptions(), pooling, new SocketOptions(), new ClientOptions(), NoneAuthProvider.Instance, null, new QueryOptions(), new DefaultAddressTranslator()); return(config); }
public void GetRequest_With_Timestamp_Generator_Empty_Value() { var statement = new SimpleStatement("QUERY"); var policies = new Dse.Policies( Dse.Policies.DefaultLoadBalancingPolicy, Dse.Policies.DefaultReconnectionPolicy, Dse.Policies.DefaultRetryPolicy, Dse.Policies.DefaultSpeculativeExecutionPolicy, new NoTimestampGenerator()); var config = new Configuration( policies, new ProtocolOptions(), PoolingOptions.GetDefault(ProtocolVersion.MaxSupported), new SocketOptions(), new ClientOptions(), NoneAuthProvider.Instance, null, new QueryOptions(), new DefaultAddressTranslator()); var request = RequestHandler <RowSet> .GetRequest(statement, Serializer.Default, config); var stream = new MemoryStream(); request.WriteFrame(1, stream, Serializer); var headerSize = FrameHeader.GetSize(ProtocolVersion.MaxSupported); var bodyBuffer = new byte[stream.Length - headerSize]; stream.Position = headerSize; stream.Read(bodyBuffer, 0, bodyBuffer.Length); // The query request is composed by: // <query><consistency><flags><result_page_size> 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 13 = flags (1) + result_page_size (4) Assert.AreEqual(5, bodyBuffer.Length - offset); var flags = (QueryFlags)bodyBuffer[offset]; Assert.False(flags.HasFlag(QueryFlags.WithDefaultTimestamp)); Assert.True(flags.HasFlag(QueryFlags.PageSize)); Assert.False(flags.HasFlag(QueryFlags.Values)); Assert.False(flags.HasFlag(QueryFlags.WithPagingState)); Assert.False(flags.HasFlag(QueryFlags.SkipMetadata)); Assert.False(flags.HasFlag(QueryFlags.WithSerialConsistency)); }