use of io.crate.testing.UseRandomizedSchema in project crate by crate.
the class TransportSQLActionTest method test_bit_string_can_be_inserted_and_queried.
@Test
@UseJdbc(0)
@UseRandomizedSchema(random = false)
public void test_bit_string_can_be_inserted_and_queried() throws Exception {
execute("create table tbl (xs bit(4))");
execute("insert into tbl (xs) values (B'0000'), (B'0001'), (B'0011'), (B'0111'), (B'1111'), (B'1001')");
assertThat(response.rowCount(), is(6L));
execute("refresh table tbl");
execute("SELECT _doc['xs'], xs, _raw, xs::bit(3) FROM tbl WHERE xs = B'1001'");
assertThat(TestingHelpers.printedTable(response.rows()), is("B'1001'| B'1001'| {\"xs\":\"CQ==\"}| B'100'\n"));
// use LIMIT 1 to hit a different execution path that should load `xs` differently
execute("SELECT _doc['xs'], xs, _raw, xs::bit(3) FROM tbl WHERE xs = B'1001' LIMIT 1");
assertThat(TestingHelpers.printedTable(response.rows()), is("B'1001'| B'1001'| {\"xs\":\"CQ==\"}| B'100'\n"));
var properties = new Properties();
properties.put("user", "crate");
properties.put("password", "");
ArrayList<String> results = new ArrayList<>();
try (var conn = DriverManager.getConnection(sqlExecutor.jdbcUrl(), properties)) {
Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("select xs from tbl order by xs");
while (result.next()) {
String string = result.getString(1);
results.add(string);
}
}
assertThat(results, Matchers.contains("B'0000'", "B'0001'", "B'0011'", "B'0111'", "B'1001'", "B'1111'"));
}
use of io.crate.testing.UseRandomizedSchema in project crate by crate.
the class TransportSQLActionTest method testUnknownTableJobGetsRemoved.
@Test
@UseRandomizedSchema(random = false)
public void testUnknownTableJobGetsRemoved() throws Exception {
String uniqueId = UUID.randomUUID().toString();
String stmtStr = "select '" + uniqueId + "' from foobar";
String stmtStrWhere = "select ''" + uniqueId + "'' from foobar";
assertThrowsMatches(() -> execute(stmtStr), isSQLError(containsString("Relation 'foobar' unknown"), UNDEFINED_TABLE, NOT_FOUND, 4041));
execute("select stmt from sys.jobs where stmt='" + stmtStrWhere + "'");
assertEquals(response.rowCount(), 0L);
}
use of io.crate.testing.UseRandomizedSchema in project crate by crate.
the class DiskDisruptionIT method testGlobalCheckpointIsSafe.
/**
* This test checks that all operations below the global checkpoint are properly persisted.
* It simulates a full power outage by preventing translog checkpoint files to be written and restart the cluster. This means that
* all un-fsynced data will be lost.
*/
@UseRandomizedSchema(random = false)
@Test
public void testGlobalCheckpointIsSafe() throws Exception {
startCluster(rarely() ? 5 : 3);
var numberOfShards = 1 + randomInt(2);
var numberOfReplicas = randomInt(2);
execute("create table test (id int primary key, data string) " + "clustered into " + numberOfShards + " shards " + "with (" + " number_of_replicas = ?, " + " \"global_checkpoint_sync.interval\" = '1s' " + ")", new Object[] { numberOfReplicas });
ensureGreen();
AtomicBoolean stopGlobalCheckpointFetcher = new AtomicBoolean();
Map<Integer, Long> shardToGcp = new ConcurrentHashMap<>();
for (int i = 0; i < numberOfShards; i++) {
shardToGcp.put(i, SequenceNumbers.NO_OPS_PERFORMED);
}
final Thread globalCheckpointSampler = new Thread(() -> {
while (stopGlobalCheckpointFetcher.get() == false) {
try {
var response = execute("select id, seq_no_stats['global_checkpoint'] " + "from sys.shards where table_name='test'");
for (var row : response.rows()) {
final int shardId = (int) row[0];
final long globalCheckpoint = (long) row[1];
shardToGcp.compute(shardId, (i, v) -> Math.max(v, globalCheckpoint));
}
} catch (Exception e) {
// ignore
logger.debug("failed to fetch shard stats", e);
}
}
});
globalCheckpointSampler.start();
int numDocsToIndex = RandomizedTest.randomIntBetween(2, 50);
try (BackgroundIndexer indexer = new BackgroundIndexer("test", "data", sqlExecutor.jdbcUrl(), -1, RandomizedTest.scaledRandomIntBetween(2, 5), false, random())) {
indexer.setRequestTimeout(TimeValue.ZERO);
indexer.setIgnoreIndexingFailures(true);
indexer.setFailureAssertion(e -> {
});
indexer.start(-1);
waitForDocs(randomIntBetween(1, numDocsToIndex), indexer, sqlExecutor);
logger.info("injecting failures");
injectTranslogFailures();
logger.info("stopping indexing");
}
logger.info("full cluster restart");
internalCluster().fullRestart(new InternalTestCluster.RestartCallback() {
@Override
public void onAllNodesStopped() {
logger.info("stopping failures");
stopTranslogFailures();
}
});
stopGlobalCheckpointFetcher.set(true);
logger.info("waiting for global checkpoint sampler");
globalCheckpointSampler.join();
logger.info("waiting for green");
ensureGreen();
execute("select distinct id, seq_no_stats['max_seq_no'] from sys.shards where table_name='test' and " + "routing_state in ('STARTED', 'RELOCATING')");
assertThat(response.rowCount(), is((long) numberOfShards));
for (var row : response.rows()) {
final int shardId = (int) row[0];
final long maxSeqNo = (long) row[1];
assertThat(maxSeqNo, greaterThanOrEqualTo(shardToGcp.get(shardId)));
}
}
use of io.crate.testing.UseRandomizedSchema in project crate by crate.
the class PartitionedTableIntegrationTest method testAlterTableAddColumnOnPartitionedTable.
@Test
@UseRandomizedSchema(random = false)
public void testAlterTableAddColumnOnPartitionedTable() throws Exception {
execute("create table t (id int primary key, date timestamp with time zone primary key) " + "partitioned by (date) " + "clustered into 1 shards " + "with (number_of_replicas=0)");
execute("insert into t (id, date) values (1, '2014-01-01')");
execute("insert into t (id, date) values (10, '2015-01-01')");
ensureYellow();
refresh();
execute("alter table t add name string");
execute("select * from t");
assertThat(Arrays.asList(response.cols()), Matchers.containsInAnyOrder("date", "id", "name"));
GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet();
IndexTemplateMetadata metadata = templatesResponse.getIndexTemplates().get(0);
String mappingSource = metadata.mappings().get(DEFAULT_MAPPING_TYPE).toString();
Map mapping = (Map) XContentFactory.xContent(mappingSource).createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource).map().get(DEFAULT_MAPPING_TYPE);
assertNotNull(((Map) mapping.get("properties")).get("name"));
// template order must not be touched
assertThat(metadata.order(), is(100));
}
use of io.crate.testing.UseRandomizedSchema in project crate by crate.
the class PartitionedTableIntegrationTest method testAlterTableAddColumnOnPartitionedTableWithoutPartitions.
@Test
@UseRandomizedSchema(random = false)
public void testAlterTableAddColumnOnPartitionedTableWithoutPartitions() throws Exception {
execute("create table t (id int primary key, date timestamp with time zone primary key) " + "partitioned by (date) " + "clustered into 1 shards " + "with (number_of_replicas=0)");
ensureYellow();
execute("alter table t add column name string");
execute("alter table t add column ft_name string index using fulltext");
ensureYellow();
execute("select * from t");
assertThat(Arrays.asList(response.cols()), Matchers.containsInAnyOrder("date", "ft_name", "id", "name"));
GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet();
IndexTemplateMetadata metadata = templatesResponse.getIndexTemplates().get(0);
String mappingSource = metadata.mappings().get(DEFAULT_MAPPING_TYPE).toString();
Map mapping = (Map) XContentFactory.xContent(mappingSource).createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource).map().get(DEFAULT_MAPPING_TYPE);
assertNotNull(((Map) mapping.get("properties")).get("name"));
assertNotNull(((Map) mapping.get("properties")).get("ft_name"));
}
Aggregations