/** {@inheritDoc} */ @Override public Map<String, ByteBuffer> getOutgoingPayload() { return st.getOutgoingPayload(); }
@BeforeMethod(groups = {"unit"}) public void setup() { MockitoAnnotations.initMocks(this); PreparedId preparedId = new PreparedId( new PreparedId.PreparedMetadata(MD5Digest.wrap(PREPARED_ID), null), new PreparedId.PreparedMetadata(MD5Digest.wrap(RESULT_METADATA_ID), null), new int[0], ProtocolVersion.V5); Mockito.when(preparedStatement.getPreparedId()).thenReturn(preparedId); ColumnDefinitions columnDefinitions = new ColumnDefinitions( new Definition[] { new Definition("ks", "table", "c1", DataType.cint()), new Definition("ks", "table", "c2", DataType.text()) }, CodecRegistry.DEFAULT_INSTANCE); Mockito.when(preparedStatement.getVariables()).thenReturn(columnDefinitions); Mockito.when(preparedStatement.getIncomingPayload()).thenReturn(null); Mockito.when(preparedStatement.getOutgoingPayload()).thenReturn(null); Mockito.when(preparedStatement.getCodecRegistry()).thenReturn(CodecRegistry.DEFAULT_INSTANCE); }
@Test(groups = "short") public void prepareStatementInheritPropertiesTest() { RegularStatement toPrepare = new SimpleStatement("SELECT * FROM test WHERE k=?"); toPrepare.setConsistencyLevel(ConsistencyLevel.QUORUM); toPrepare.setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL); toPrepare.setRetryPolicy(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) toPrepare.setOutgoingPayload(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); toPrepare.setIdempotent(true); toPrepare.enableTracing(); PreparedStatement prepared = session().prepare(toPrepare); assertThat(prepared.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM); assertThat(prepared.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); assertThat(prepared.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) assertThat(prepared.getOutgoingPayload()) .isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); assertThat(prepared.isIdempotent()).isTrue(); assertThat(prepared.isTracing()).isTrue(); BoundStatement bs = prepared.bind("someValue"); assertThat(bs.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM); assertThat(bs.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); assertThat(bs.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) assertThat(bs.getOutgoingPayload()) .isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); assertThat(bs.isIdempotent()).isTrue(); assertThat(bs.isTracing()).isTrue(); }
/** 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 payloads can still be set individually on bound statements if the prepared * statement does not have a default payload. */ @Test(groups = "short") public void should_not_set_any_payload_on_bound_statement() throws Exception { RegularStatement statement = new SimpleStatement("SELECT c2 as col3 FROM t1 where c1 = ?"); PreparedStatement ps = session().prepare(statement); assertThat(ps.getOutgoingPayload()).isNull(); assertThat(ps.getIncomingPayload()).isNull(); // bound statement should not have outgoing payload BoundStatement bs = ps.bind(1); assertThat(bs.getOutgoingPayload()).isNull(); // explicitly set a payload for this boudn statement only bs.setOutgoingPayload(payload1); ResultSet rows = session().execute(bs); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); // a second bound statement should not have any payload bs = ps.bind(); assertThat(bs.getOutgoingPayload()).isNull(); bs.setInt(0, 1); rows = session().execute(bs); actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isNull(); }
/** * Creates a new {@code BoundStatement} from the provided prepared statement. * * @param statement the prepared statement from which to create a {@code BoundStatement}. */ public BoundStatement(PreparedStatement statement) { this.statement = statement; this.wrapper = new DataWrapper(this, statement.getVariables().size()); for (int i = 0; i < wrapper.values.length; i++) { wrapper.values[i] = UNSET; } if (statement.getConsistencyLevel() != null) this.setConsistencyLevel(statement.getConsistencyLevel()); if (statement.getSerialConsistencyLevel() != null) this.setSerialConsistencyLevel(statement.getSerialConsistencyLevel()); if (statement.isTracing()) this.enableTracing(); if (statement.getRetryPolicy() != null) this.setRetryPolicy(statement.getRetryPolicy()); if (statement.getOutgoingPayload() != null) this.setOutgoingPayload(statement.getOutgoingPayload()); else // propagate incoming payload as outgoing payload, if no outgoing payload has been explicitly // set this.setOutgoingPayload(statement.getIncomingPayload()); this.codecRegistry = statement.getCodecRegistry(); if (statement.isIdempotent() != null) { this.setIdempotent(statement.isIdempotent()); } }
/** * 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); }
@BeforeMethod(groups = {"unit"}) public void setup() { MockitoAnnotations.initMocks(this); PreparedId preparedId = new PreparedId( new PreparedId.PreparedMetadata(MD5Digest.wrap(PREPARED_ID), null), new PreparedId.PreparedMetadata(MD5Digest.wrap(RESULT_METADATA_ID), null), new int[0], ProtocolVersion.V5); Mockito.when(preparedStatement.getPreparedId()).thenReturn(preparedId); ColumnDefinitions columnDefinitions = new ColumnDefinitions( new Definition[] { new Definition("ks", "table", "c1", DataType.cint()), new Definition("ks", "table", "c2", DataType.text()) }, CodecRegistry.DEFAULT_INSTANCE); Mockito.when(preparedStatement.getVariables()).thenReturn(columnDefinitions); Mockito.when(preparedStatement.getIncomingPayload()).thenReturn(null); Mockito.when(preparedStatement.getOutgoingPayload()).thenReturn(null); Mockito.when(preparedStatement.getCodecRegistry()).thenReturn(CodecRegistry.DEFAULT_INSTANCE); }
@Test(groups = "short") public void prepareStatementInheritPropertiesTest() { RegularStatement toPrepare = new SimpleStatement("SELECT * FROM test WHERE k=?"); toPrepare.setConsistencyLevel(ConsistencyLevel.QUORUM); toPrepare.setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL); toPrepare.setRetryPolicy(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) toPrepare.setOutgoingPayload(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); toPrepare.setIdempotent(true); toPrepare.enableTracing(); PreparedStatement prepared = session().prepare(toPrepare); assertThat(prepared.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM); assertThat(prepared.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); assertThat(prepared.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) assertThat(prepared.getOutgoingPayload()) .isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); assertThat(prepared.isIdempotent()).isTrue(); assertThat(prepared.isTracing()).isTrue(); BoundStatement bs = prepared.bind("someValue"); assertThat(bs.getConsistencyLevel()).isEqualTo(ConsistencyLevel.QUORUM); assertThat(bs.getSerialConsistencyLevel()).isEqualTo(ConsistencyLevel.LOCAL_SERIAL); assertThat(bs.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE); if (protocolVersion.compareTo(V4) >= 0) assertThat(bs.getOutgoingPayload()) .isEqualTo(ImmutableMap.of("foo", Bytes.fromHexString("0xcafebabe"))); assertThat(bs.isIdempotent()).isTrue(); assertThat(bs.isTracing()).isTrue(); }
/** 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 payloads can still be set individually on bound statements if the prepared * statement does not have a default payload. */ @Test(groups = "short") public void should_not_set_any_payload_on_bound_statement() throws Exception { RegularStatement statement = new SimpleStatement("SELECT c2 as col3 FROM t1 where c1 = ?"); PreparedStatement ps = session().prepare(statement); assertThat(ps.getOutgoingPayload()).isNull(); assertThat(ps.getIncomingPayload()).isNull(); // bound statement should not have outgoing payload BoundStatement bs = ps.bind(1); assertThat(bs.getOutgoingPayload()).isNull(); // explicitly set a payload for this boudn statement only bs.setOutgoingPayload(payload1); ResultSet rows = session().execute(bs); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); // a second bound statement should not have any payload bs = ps.bind(); assertThat(bs.getOutgoingPayload()).isNull(); bs.setInt(0, 1); rows = session().execute(bs); actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isNull(); }
/** * Creates a new {@code BoundStatement} from the provided prepared * statement. * * @param statement the prepared statement from which to create a {@code BoundStatement}. */ public BoundStatement(PreparedStatement statement) { this.statement = statement; this.wrapper = new DataWrapper(this, statement.getVariables().size()); for (int i = 0; i < wrapper.values.length; i++) { wrapper.values[i] = UNSET; } if (statement.getConsistencyLevel() != null) this.setConsistencyLevel(statement.getConsistencyLevel()); if (statement.getSerialConsistencyLevel() != null) this.setSerialConsistencyLevel(statement.getSerialConsistencyLevel()); if (statement.isTracing()) this.enableTracing(); if (statement.getRetryPolicy() != null) this.setRetryPolicy(statement.getRetryPolicy()); if (statement.getOutgoingPayload() != null) this.setOutgoingPayload(statement.getOutgoingPayload()); else // propagate incoming payload as outgoing payload, if no outgoing payload has been explicitly set this.setOutgoingPayload(statement.getIncomingPayload()); this.codecRegistry = statement.getCodecRegistry(); if (statement.isIdempotent() != null) { this.setIdempotent(statement.isIdempotent()); } }
/** * Creates a new {@code BoundStatement} from the provided prepared * statement. * * @param statement the prepared statement from which to create a {@code BoundStatement}. */ public BoundStatement(PreparedStatement statement) { this.statement = statement; this.wrapper = new DataWrapper(this, statement.getVariables().size()); for (int i = 0; i < wrapper.values.length; i++) { wrapper.values[i] = UNSET; } if (statement.getConsistencyLevel() != null) this.setConsistencyLevel(statement.getConsistencyLevel()); if (statement.getSerialConsistencyLevel() != null) this.setSerialConsistencyLevel(statement.getSerialConsistencyLevel()); if (statement.isTracing()) this.enableTracing(); if (statement.getRetryPolicy() != null) this.setRetryPolicy(statement.getRetryPolicy()); if (statement.getOutgoingPayload() != null) this.setOutgoingPayload(statement.getOutgoingPayload()); else // propagate incoming payload as outgoing payload, if no outgoing payload has been explicitly set this.setOutgoingPayload(statement.getIncomingPayload()); this.codecRegistry = statement.getCodecRegistry(); if (statement.isIdempotent() != null) { this.setIdempotent(statement.isIdempotent()); } }
/** * 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); }
/** * Creates a new {@code BoundStatement} from the provided prepared * statement. * * @param statement the prepared statement from which to create a {@code BoundStatement}. */ public BoundStatement(PreparedStatement statement) { this.statement = statement; this.wrapper = new DataWrapper(this, statement.getVariables().size()); for (int i = 0; i < wrapper.values.length; i++) { wrapper.values[i] = UNSET; } if (statement.getConsistencyLevel() != null) this.setConsistencyLevel(statement.getConsistencyLevel()); if (statement.getSerialConsistencyLevel() != null) this.setSerialConsistencyLevel(statement.getSerialConsistencyLevel()); if (statement.isTracing()) this.enableTracing(); if (statement.getRetryPolicy() != null) this.setRetryPolicy(statement.getRetryPolicy()); if (statement.getOutgoingPayload() != null) this.setOutgoingPayload(statement.getOutgoingPayload()); else // propagate incoming payload as outgoing payload, if no outgoing payload has been explicitly set this.setOutgoingPayload(statement.getIncomingPayload()); this.codecRegistry = statement.getCodecRegistry(); if (statement.isIdempotent() != null) { this.setIdempotent(statement.isIdempotent()); } }