@Test(groups = "short") public void should_encode_null_values() throws Exception { Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>(); payload.put("k1", Statement.NULL_PAYLOAD_VALUE); Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1); statement.setOutgoingPayload(payload); ResultSet rows = session().execute(statement); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload); }
@Test(groups = "short") public void should_echo_custom_payload_when_executing_statement() throws Exception { Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1); statement.setOutgoingPayload(payload1); ResultSet rows = session().execute(statement); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); }
@Test(groups = "short") public void should_echo_custom_payload_when_executing_batch_statement() throws Exception { Statement statement = new BatchStatement().add(new SimpleStatement("INSERT INTO t1 (c1, c2) values (1, 'foo')")); statement.setOutgoingPayload(payload1); ResultSet rows = session().execute(statement); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); }
private void assertRow(Row row) { assertThat(row.getInt(0)).isEqualTo(n_int); assertThat(row.getList(1, Integer.class)).isEqualTo(l_int); assertThat(row.getList(2, Long.class)).isEqualTo(l_bigint); assertThat(row.getSet(3, Float.class)).isEqualTo(s_float); assertThat(row.getSet(4, Double.class)).isEqualTo(s_double); assertThat(row.getMap(5, Integer.class, BigInteger.class)).isEqualTo(m_varint); assertThat(row.getMap(6, Integer.class, BigDecimal.class)).isEqualTo(m_decimal); // with get + type assertThat(row.get(1, TypeTokens.listOf(Integer.class))).isEqualTo(l_int); assertThat(row.get(2, TypeTokens.listOf(Long.class))).isEqualTo(l_bigint); assertThat(row.get(3, TypeTokens.setOf(Float.class))).isEqualTo(s_float); assertThat(row.get(4, TypeTokens.setOf(Double.class))).isEqualTo(s_double); assertThat(row.get(5, TypeTokens.mapOf(Integer.class, BigInteger.class))).isEqualTo(m_varint); assertThat(row.get(6, TypeTokens.mapOf(Integer.class, BigDecimal.class))).isEqualTo(m_decimal); // with getObject assertThat(row.getObject(1)).isEqualTo(l_int); assertThat(row.getObject(2)).isEqualTo(l_bigint); assertThat(row.getObject(3)).isEqualTo(s_float); assertThat(row.getObject(4)).isEqualTo(s_double); assertThat(row.getObject(5)).isEqualTo(m_varint); assertThat(row.getObject(6)).isEqualTo(m_decimal); } }
/** 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); }
@Test(groups = "short") public void should_echo_custom_payload_when_building_statement() throws Exception { Statement statement = select("c2").from("t1").where(eq("c1", 1)).setOutgoingPayload(payload1); ResultSet rows = session().execute(statement); Map<String, ByteBuffer> 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); }
@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(); }
@Test(groups = "short") public void should_handle_collections_of_UDT() throws Exception { UserType udtType = cluster().getMetadata().getKeyspace(keyspace).getUserType("udt"); UDTValue udtValue = udtType.newValue().setInt("i", 2).setInet("a", InetAddress.getByName("localhost")); UDTValue udtValue2 = udtType.newValue().setInt("i", 3).setInet("a", InetAddress.getByName("localhost")); Statement insert = insertInto("udtTest").value("k", 1).value("l", ImmutableList.of(udtValue)); assertThat(insert.toString()) .isEqualTo("INSERT INTO udtTest (k,l) VALUES (1,[{i:2,a:'127.0.0.1'}]);"); session().execute(insert); List<Row> rows = session().execute(select().from("udtTest").where(eq("k", 1))).all(); assertThat(rows.size()).isEqualTo(1); Row r1 = rows.get(0); assertThat(r1.getList("l", UDTValue.class).get(0).getInet("a").getHostAddress()) .isEqualTo("127.0.0.1"); Map<Integer, UDTValue> map = Maps.newHashMap(); map.put(0, udtValue); map.put(2, udtValue2); Statement updateMap = update("udtTest").with(putAll("m", map)).where(eq("k", 1)); assertThat(updateMap.toString()) .isEqualTo( "UPDATE udtTest SET m=m+{0:{i:2,a:'127.0.0.1'},2:{i:3,a:'127.0.0.1'}} WHERE k=1;"); session().execute(updateMap); rows = session().execute(select().from("udtTest").where(eq("k", 1))).all(); r1 = rows.get(0); assertThat(r1.getMap("m", Integer.class, UDTValue.class)).isEqualTo(map); }
cluster().getMetadata().getKeyspace(keyspace).getTable("table_with_extensions"); assertThat(table.getOptions().getExtensions()).isEqualTo(extensions);
/** * 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(); }
assertThat(row.getList("l", mapping.codec.getJavaType())).isEqualTo(list); assertThat(row.getMap("m", mapping.codec.getJavaType(), mapping.codec.getJavaType())) .isEqualTo(map); assertThat(row.getList(1, mapping.codec.getJavaType())).isEqualTo(list); assertThat(row.getMap(2, mapping.codec.getJavaType(), mapping.codec.getJavaType())) .isEqualTo(map);
@Test(groups = "short") public void should_encode_null_values() throws Exception { Map<String, ByteBuffer> payload = new HashMap<String, ByteBuffer>(); payload.put("k1", Statement.NULL_PAYLOAD_VALUE); Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1); statement.setOutgoingPayload(payload); ResultSet rows = session().execute(statement); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload); }
@Test public void traits() { GroupPayload payload = builder.groupId("group_id").traits(ImmutableMap.of("foo", "bar")).build(); assertThat(payload.traits()).isEqualTo(ImmutableMap.of("foo", "bar")); assertThat(payload).containsEntry(GroupPayload.TRAITS_KEY, ImmutableMap.of("foo", "bar")); } }
@Test public void properties() { TrackPayload payload = builder.event("event").properties(ImmutableMap.of("foo", "bar")).build(); assertThat(payload.properties()).isEqualTo(ImmutableMap.of("foo", "bar")); assertThat(payload).containsEntry(TrackPayload.PROPERTIES_KEY, ImmutableMap.of("foo", "bar")); } }
@Test public void properties() { ScreenPayload payload = builder.name("name").properties(ImmutableMap.of("foo", "bar")).build(); assertThat(payload.properties()).isEqualTo(ImmutableMap.of("foo", "bar")); assertThat(payload).containsEntry(ScreenPayload.PROPERTIES_KEY, ImmutableMap.of("foo", "bar")); }
@Test(groups = "short") public void should_echo_custom_payload_when_executing_statement() throws Exception { Statement statement = new SimpleStatement("SELECT c2 FROM t1 where c1 = ?", 1); statement.setOutgoingPayload(payload1); ResultSet rows = session().execute(statement); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); }
@Test public void copyReturnsSameMappings() { AnalyticsContext copy = context.unmodifiableCopy(); assertThat(copy).hasSameSizeAs(context).isNotSameAs(context).isEqualTo(context); for (Map.Entry<String, Object> entry : context.entrySet()) { assertThat(copy).contains(MapEntry.entry(entry.getKey(), entry.getValue())); } }
@Test public void copyReturnsSameMappings() { Traits copy = traits.unmodifiableCopy(); assertThat(copy).hasSameSizeAs(traits).isNotSameAs(traits).isEqualTo(traits); for (Map.Entry<String, Object> entry : traits.entrySet()) { assertThat(copy).contains(MapEntry.entry(entry.getKey(), entry.getValue())); } }
@Test(groups = "short") public void should_echo_custom_payload_when_building_statement() throws Exception { Statement statement = select("c2").from("t1").where(eq("c1", 1)).setOutgoingPayload(payload1); ResultSet rows = session().execute(statement); Map<String, ByteBuffer> actual = rows.getExecutionInfo().getIncomingPayload(); assertThat(actual).isEqualTo(payload1); }