use of io.crate.testing.SQLResponse in project crate by crate.
the class TransportSQLActionClassLifecycleTest method testCountWithGroupByNullArgs.
@Test
// NPE because of unused null parameter
@UseJdbc(0)
public void testCountWithGroupByNullArgs() throws Exception {
SQLResponse response = execute("select count(*), race from characters group by race", new Object[] { null });
assertEquals(3, response.rowCount());
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class TransportSQLActionClassLifecycleTest method testSetMultipleStatement.
@Test
// set has no rowcount
@UseJdbc(0)
public void testSetMultipleStatement() throws Exception {
SQLResponse response = execute("select settings['stats']['operations_log_size'], settings['stats']['enabled'] from sys.cluster");
assertThat(response.rowCount(), is(1L));
assertThat((Integer) response.rows()[0][0], is(CrateSettings.STATS_OPERATIONS_LOG_SIZE.defaultValue()));
assertThat((Boolean) response.rows()[0][1], is(CrateSettings.STATS_ENABLED.defaultValue()));
response = execute("set global persistent stats.operations_log_size=1024, stats.enabled=false");
assertThat(response.rowCount(), is(1L));
response = execute("select settings['stats']['operations_log_size'], settings['stats']['enabled'] from sys.cluster");
assertThat(response.rowCount(), is(1L));
assertThat((Integer) response.rows()[0][0], is(1024));
assertThat((Boolean) response.rows()[0][1], is(false));
response = execute("reset global stats.operations_log_size, stats.enabled");
assertThat(response.rowCount(), is(1L));
waitNoPendingTasksOnAll();
response = execute("select settings['stats']['operations_log_size'], settings['stats']['enabled'] from sys.cluster");
assertThat(response.rowCount(), is(1L));
assertThat((Integer) response.rows()[0][0], is(CrateSettings.STATS_OPERATIONS_LOG_SIZE.defaultValue()));
assertThat((Boolean) response.rows()[0][1], is(CrateSettings.STATS_ENABLED.defaultValue()));
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class TransportSQLActionClassLifecycleTest method testGlobalAggregateWithoutNulls.
@Test
public void testGlobalAggregateWithoutNulls() throws Exception {
SQLResponse firstResp = execute("select sum(age) from characters");
SQLResponse secondResp = execute("select sum(age) from characters where age is not null");
assertEquals(firstResp.rowCount(), secondResp.rowCount());
assertEquals(firstResp.rows()[0][0], secondResp.rows()[0][0]);
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class CopyIntegrationTest method testCopyToDirectory.
@Test
public void testCopyToDirectory() throws Exception {
this.setup.groupBySetup();
String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString();
SQLResponse response = execute("copy characters to DIRECTORY ?", new Object[] { uriTemplate });
assertThat(response.rowCount(), is(7L));
String[] list = folder.getRoot().list();
assertThat(list, is(notNullValue()));
assertThat(list.length, greaterThanOrEqualTo(1));
for (String file : list) {
assertThat(file, startsWith("characters_"));
}
List<String> lines = new ArrayList<>(7);
DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(folder.getRoot().toURI()), "*.json");
for (Path path : stream) {
lines.addAll(Files.readAllLines(path, StandardCharsets.UTF_8));
}
assertThat(lines.size(), is(7));
for (String line : lines) {
assertThat(line, startsWith("{"));
assertThat(line, endsWith("}"));
}
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class CopyIntegrationTest method testCopyToWithCompression.
@Test
public void testCopyToWithCompression() throws Exception {
execute("create table singleshard (name string) clustered into 1 shards with (number_of_replicas = 0)");
ensureYellow();
execute("insert into singleshard (name) values ('foo')");
execute("refresh table singleshard");
String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString();
SQLResponse response = execute("copy singleshard to DIRECTORY ? with (compression='gzip')", new Object[] { uriTemplate });
assertThat(response.rowCount(), is(1L));
String[] list = folder.getRoot().list();
assertThat(list, is(notNullValue()));
assertThat(list.length, is(1));
String file = list[0];
assertThat(file, both(startsWith("singleshard_")).and(endsWith(".json.gz")));
long size = Files.size(Paths.get(folder.getRoot().toURI().resolve(file)));
assertThat(size, is(35L));
}
Aggregations