/** {@inheritDoc} */ @Override public PreparedStatement setOutgoingPayload(Map<String, ByteBuffer> payload) { return st.setOutgoingPayload(payload); }
@Test(groups = "short", expectedExceptions = NullPointerException.class) public void should_throw_npe_when_null_key_on_prepared_statement() throws Exception { Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>(); payload.put(null, ByteBuffer.wrap(new byte[] {1})); session() .prepare(new SimpleStatement("SELECT c2 FROM t1 where c1 = 1")) .setOutgoingPayload(payload); }
@Test(groups = "short", expectedExceptions = NullPointerException.class) public void should_throw_npe_when_null_value_on_prepared_statement() throws Exception { Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>(); payload.put("k1", null); session() .prepare(new SimpleStatement("SELECT c2 FROM t1 where c1 = 2")) .setOutgoingPayload(payload); }
/** Ensures that an incoming payload is propagated from prepared to bound statements. */ @Test(groups = "short") public void should_propagate_incoming_payload_to_bound_statement() throws Exception { RegularStatement statement = new SimpleStatement("SELECT c2 as col1 FROM t1 where c1 = ?"); statement.setOutgoingPayload(payload1); PreparedStatement ps = session().prepare(statement); // Prepared statement should inherit outgoing payload assertThat(ps.getOutgoingPayload()).isEqualTo(payload1); // Prepared statement should receive incoming payload assertThat(ps.getIncomingPayload()).isEqualTo(payload1); ps.setOutgoingPayload(null); // unset outgoing payload // bound statement should inherit from prepared statement's incoming payload BoundStatement bs = ps.bind(1); ResultSet rows = session().execute(bs); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); bs = ps.bind(); bs.setInt(0, 1); rows = session().execute(bs); actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); }
/** * Ensures that an incoming payload is overridden by an explicitly set outgoing payload when * propagated to bound statements. */ @Test(groups = "short") public void should_override_incoming_payload_when_outgoing_payload_explicitly_set_on_preparing_statement() throws Exception { RegularStatement statement = new SimpleStatement("SELECT c2 as col2 FROM t1 where c1 = ?"); statement.setOutgoingPayload(payload1); PreparedStatement ps = session().prepare(statement); // Prepared statement should inherit outgoing payload assertThat(ps.getOutgoingPayload()).isEqualTo(payload1); // Prepared statement should receive incoming payload assertThat(ps.getIncomingPayload()).isEqualTo(payload1); ps.setOutgoingPayload(payload2); // override outgoing payload // bound statement should inherit from prepared statement's outgoing payload BoundStatement bs = ps.bind(1); ResultSet rows = session().execute(bs); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload2); bs = ps.bind(); bs.setInt(0, 1); rows = session().execute(bs); actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload2); }
@Override public PreparedStatement apply(PreparedStatement prepared) { ProtocolVersion protocolVersion = getCluster().getConfiguration().getProtocolOptions().getProtocolVersion(); ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry); if (routingKey != null) prepared.setRoutingKey(routingKey); if (statement.getConsistencyLevel() != null) prepared.setConsistencyLevel(statement.getConsistencyLevel()); if (statement.getSerialConsistencyLevel() != null) prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel()); if (statement.isTracing()) prepared.enableTracing(); prepared.setRetryPolicy(statement.getRetryPolicy()); prepared.setOutgoingPayload(statement.getOutgoingPayload()); prepared.setIdempotent(statement.isIdempotent()); return prepared; } });
@Test(groups = "short", expectedExceptions = NullPointerException.class) public void should_throw_npe_when_null_key_on_prepared_statement() throws Exception { Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>(); payload.put(null, ByteBuffer.wrap(new byte[] {1})); session() .prepare(new SimpleStatement("SELECT c2 FROM t1 where c1 = 1")) .setOutgoingPayload(payload); }
@Test(groups = "short", expectedExceptions = NullPointerException.class) public void should_throw_npe_when_null_value_on_prepared_statement() throws Exception { Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>(); payload.put("k1", null); session() .prepare(new SimpleStatement("SELECT c2 FROM t1 where c1 = 2")) .setOutgoingPayload(payload); }
/** Ensures that an incoming payload is propagated from prepared to bound statements. */ @Test(groups = "short") public void should_propagate_incoming_payload_to_bound_statement() throws Exception { RegularStatement statement = new SimpleStatement("SELECT c2 as col1 FROM t1 where c1 = ?"); statement.setOutgoingPayload(payload1); PreparedStatement ps = session().prepare(statement); // Prepared statement should inherit outgoing payload assertThat(ps.getOutgoingPayload()).isEqualTo(payload1); // Prepared statement should receive incoming payload assertThat(ps.getIncomingPayload()).isEqualTo(payload1); ps.setOutgoingPayload(null); // unset outgoing payload // bound statement should inherit from prepared statement's incoming payload BoundStatement bs = ps.bind(1); ResultSet rows = session().execute(bs); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); bs = ps.bind(); bs.setInt(0, 1); rows = session().execute(bs); actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); }
/** * Ensures that an incoming payload is overridden by an explicitly set outgoing payload when * propagated to bound statements. */ @Test(groups = "short") public void should_override_incoming_payload_when_outgoing_payload_explicitly_set_on_preparing_statement() throws Exception { RegularStatement statement = new SimpleStatement("SELECT c2 as col2 FROM t1 where c1 = ?"); statement.setOutgoingPayload(payload1); PreparedStatement ps = session().prepare(statement); // Prepared statement should inherit outgoing payload assertThat(ps.getOutgoingPayload()).isEqualTo(payload1); // Prepared statement should receive incoming payload assertThat(ps.getIncomingPayload()).isEqualTo(payload1); ps.setOutgoingPayload(payload2); // override outgoing payload // bound statement should inherit from prepared statement's outgoing payload BoundStatement bs = ps.bind(1); ResultSet rows = session().execute(bs); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload2); bs = ps.bind(); bs.setInt(0, 1); rows = session().execute(bs); actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload2); }
@Override public PreparedStatement apply(PreparedStatement prepared) { ProtocolVersion protocolVersion = getCluster().getConfiguration().getProtocolOptions().getProtocolVersion(); ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry); if (routingKey != null) prepared.setRoutingKey(routingKey); if (statement.getConsistencyLevel() != null) prepared.setConsistencyLevel(statement.getConsistencyLevel()); if (statement.getSerialConsistencyLevel() != null) prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel()); if (statement.isTracing()) prepared.enableTracing(); prepared.setRetryPolicy(statement.getRetryPolicy()); prepared.setOutgoingPayload(statement.getOutgoingPayload()); prepared.setIdempotent(statement.isIdempotent()); return prepared; } });
@Override public PreparedStatement apply(PreparedStatement prepared) { ProtocolVersion protocolVersion = getCluster().getConfiguration().getProtocolOptions().getProtocolVersion(); ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry); if (routingKey != null) prepared.setRoutingKey(routingKey); if (statement.getConsistencyLevel() != null) prepared.setConsistencyLevel(statement.getConsistencyLevel()); if (statement.getSerialConsistencyLevel() != null) prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel()); if (statement.isTracing()) prepared.enableTracing(); prepared.setRetryPolicy(statement.getRetryPolicy()); prepared.setOutgoingPayload(statement.getOutgoingPayload()); prepared.setIdempotent(statement.isIdempotent()); return prepared; } });
@Override public PreparedStatement apply(PreparedStatement prepared) { ProtocolVersion protocolVersion = getCluster().getConfiguration().getProtocolOptions().getProtocolVersion(); ByteBuffer routingKey = statement.getRoutingKey(protocolVersion, codecRegistry); if (routingKey != null) prepared.setRoutingKey(routingKey); if (statement.getConsistencyLevel() != null) prepared.setConsistencyLevel(statement.getConsistencyLevel()); if (statement.getSerialConsistencyLevel() != null) prepared.setSerialConsistencyLevel(statement.getSerialConsistencyLevel()); if (statement.isTracing()) prepared.enableTracing(); prepared.setRetryPolicy(statement.getRetryPolicy()); prepared.setOutgoingPayload(statement.getOutgoingPayload()); prepared.setIdempotent(statement.isIdempotent()); return prepared; } });