use of org.apache.cassandra.cql3.ResultSet in project beam by apache.
the class SpannerChangeStreamErrorTest method testInvalidRecordReceived.
@Test
public void testInvalidRecordReceived() {
final Timestamp now = Timestamp.now();
final Timestamp after3Seconds = Timestamp.ofTimeSecondsAndNanos(now.getSeconds() + 3, now.getNanos());
mockTableExists();
ResultSet getPartitionResultSet = mockGetParentPartition(now, after3Seconds);
mockGetWatermark(now);
mockGetPartitionsAfter(Timestamp.ofTimeSecondsAndNanos(now.getSeconds(), now.getNanos() + 1000), getPartitionResultSet);
mockGetPartitionsAfter(Timestamp.ofTimeSecondsAndNanos(now.getSeconds(), now.getNanos() - 1000), getPartitionResultSet);
mockInvalidChangeStreamRecordReceived(now, after3Seconds);
try {
pipeline.apply(SpannerIO.readChangeStream().withSpannerConfig(getSpannerConfig()).withChangeStreamName(TEST_CHANGE_STREAM).withMetadataDatabase(TEST_DATABASE).withMetadataTable(TEST_TABLE).withInclusiveStartAt(now).withInclusiveEndAt(after3Seconds));
pipeline.run().waitUntilFinish();
} finally {
thrown.expect(PipelineExecutionException.class);
thrown.expectMessage("Field not found");
}
}
use of org.apache.cassandra.cql3.ResultSet in project beam by apache.
the class SpannerChangeStreamErrorTest method mockGetWatermark.
private void mockGetWatermark(Timestamp now) {
Statement watermarkStatement = Statement.newBuilder("SELECT Watermark FROM my-metadata-table WHERE State != @state ORDER BY Watermark ASC LIMIT 1").bind("state").to(State.FINISHED.name()).build();
ResultSetMetadata watermarkResultSetMetadata = ResultSetMetadata.newBuilder().setRowType(StructType.newBuilder().addFields(Field.newBuilder().setName("Watermark").setType(Type.newBuilder().setCode(TypeCode.TIMESTAMP).build()).build()).build()).build();
ResultSet watermarkResultSet = ResultSet.newBuilder().addRows(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue(now.toString()).build()).build()).setMetadata(watermarkResultSetMetadata).build();
mockSpannerService.putStatementResult(StatementResult.query(watermarkStatement, watermarkResultSet));
}
use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.
the class BinAuditLoggerTest method testSelectRoundTripQuery.
@Test
public void testSelectRoundTripQuery() throws Throwable {
createTable("CREATE TABLE %s (id int primary key, v1 text, v2 text)");
execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 1, "Apache", "Cassandra");
execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 2, "trace", "test");
String cql = "SELECT id, v1, v2 FROM " + KEYSPACE + '.' + currentTable() + " WHERE id = ?";
Session session = sessionNet();
PreparedStatement pstmt = session.prepare(cql);
ResultSet rs = session.execute(pstmt.bind(1));
assertEquals(1, rs.all().size());
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
ExcerptTailer tailer = queue.createTailer();
assertTrue(tailer.readDocument(wire -> {
assertEquals(0L, wire.read("version").int16());
assertEquals("audit", wire.read("type").text());
assertThat(wire.read("message").text(), containsString(AuditLogEntryType.PREPARE_STATEMENT.toString()));
}));
assertTrue(tailer.readDocument(wire -> {
assertEquals(0L, wire.read("version").int16());
assertEquals("audit", wire.read("type").text());
assertThat(wire.read("message").text(), containsString(AuditLogEntryType.SELECT.toString()));
}));
assertFalse(tailer.readDocument(wire -> {
}));
}
}
use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.
the class NativeProtocolTest method withClientRequests.
@Test
public void withClientRequests() throws Throwable {
try (ICluster ignored = init(builder().withNodes(3).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).start())) {
try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
Session session = cluster.connect()) {
session.execute("CREATE TABLE " + KEYSPACE + ".tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));");
session.execute("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v) values (1,1,1);");
Statement select = new SimpleStatement("select * from " + KEYSPACE + ".tbl;").setConsistencyLevel(ConsistencyLevel.ALL);
final ResultSet resultSet = session.execute(select);
assertRows(RowUtil.toObjects(resultSet), row(1, 1, 1));
Assert.assertEquals(3, cluster.getMetadata().getAllHosts().size());
}
}
}
use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.
the class AggregationTest method testAggregateWithWriteTimeOrTTL.
@Test
public void testAggregateWithWriteTimeOrTTL() throws Throwable {
createTable("CREATE TABLE %s (a int primary key, b int, c int)");
// Test with empty table
assertColumnNames(execute("SELECT count(writetime(b)), min(ttl(b)) as min, writetime(b), ttl(c) as first FROM %s"), "system.count(writetime(b))", "min", "writetime(b)", "first");
assertRows(execute("SELECT count(writetime(b)), min(ttl(b)) as min, writetime(b), ttl(c) as first FROM %s"), row(0L, null, null, null));
long today = System.currentTimeMillis() * 1000;
long yesterday = today - (DateUtils.MILLIS_PER_DAY * 1000);
final int secondsPerMinute = 60;
execute("INSERT INTO %s (a, b, c) VALUES (1, 2, null) USING TTL " + (20 * secondsPerMinute));
execute("INSERT INTO %s (a, b, c) VALUES (2, 4, 6) USING TTL " + (10 * secondsPerMinute));
execute("INSERT INTO %s (a, b, c) VALUES (4, 8, 12) USING TIMESTAMP " + yesterday);
assertRows(execute("SELECT count(writetime(b)), count(ttl(b)) FROM %s"), row(3L, 2L));
UntypedResultSet resultSet = execute("SELECT min(ttl(b)), ttl(b) FROM %s");
assertEquals(1, resultSet.size());
Row row = resultSet.one();
assertTrue(row.getInt("ttl(b)") > (10 * secondsPerMinute));
assertTrue(row.getInt("system.min(ttl(b))") <= (10 * secondsPerMinute));
resultSet = execute("SELECT min(writetime(b)), writetime(b) FROM %s");
assertEquals(1, resultSet.size());
row = resultSet.one();
assertTrue(row.getLong("writetime(b)") >= today);
assertTrue(row.getLong("system.min(writetime(b))") == yesterday);
}
Aggregations