use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class SSTableLoaderTest method testLoadingSSTable.
@Test
public void testLoadingSSTable() throws Exception {
File dataDir = new File(tmpdir.getAbsolutePath() + File.separator + KEYSPACE1 + File.separator + CF_STANDARD1);
assert dataDir.mkdirs();
TableMetadata metadata = Schema.instance.getTableMetadata(KEYSPACE1, CF_STANDARD1);
String schema = "CREATE TABLE %s.%s (key ascii, name ascii, val ascii, val1 ascii, PRIMARY KEY (key, name))";
String query = "INSERT INTO %s.%s (key, name, val) VALUES (?, ?, ?)";
try (CQLSSTableWriter writer = CQLSSTableWriter.builder().inDirectory(dataDir).forTable(String.format(schema, KEYSPACE1, CF_STANDARD1)).using(String.format(query, KEYSPACE1, CF_STANDARD1)).build()) {
writer.addRow("key1", "col1", "100");
}
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD1);
// wait for sstables to be on disk else we won't be able to stream them
cfs.forceBlockingFlush();
final CountDownLatch latch = new CountDownLatch(1);
SSTableLoader loader = new SSTableLoader(dataDir, new TestClient(), new OutputHandler.SystemOutput(false, false));
loader.stream(Collections.emptySet(), completionStreamListener(latch)).get();
List<FilteredPartition> partitions = Util.getAll(Util.cmd(cfs).build());
assertEquals(1, partitions.size());
assertEquals("key1", AsciiType.instance.getString(partitions.get(0).partitionKey().getKey()));
assertEquals(ByteBufferUtil.bytes("100"), partitions.get(0).getRow(Clustering.make(ByteBufferUtil.bytes("col1"))).getCell(metadata.getColumn(ByteBufferUtil.bytes("val"))).value());
// The stream future is signalled when the work is complete but before releasing references. Wait for release
// before cleanup (CASSANDRA-10118).
latch.await();
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class MockSchema method newCFS.
public static ColumnFamilyStore newCFS(String ksname) {
String cfname = "mockcf" + (id.incrementAndGet());
TableMetadata metadata = newTableMetadata(ksname, cfname);
return new ColumnFamilyStore(ks, cfname, 0, new TableMetadataRef(metadata), new Directories(metadata), false, false, false);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class QueryPagerTest method sliceQuery.
private static SinglePartitionReadCommand sliceQuery(String key, String start, String end, boolean reversed, int count) {
ClusteringComparator cmp = cfs().getComparator();
TableMetadata metadata = cfs().metadata();
Slice slice = Slice.make(cmp.make(start), cmp.make(end));
ClusteringIndexSliceFilter filter = new ClusteringIndexSliceFilter(Slices.with(cmp, slice), reversed);
return SinglePartitionReadCommand.create(metadata, nowInSec, ColumnFilter.all(metadata), RowFilter.NONE, DataLimits.NONE, Util.dk(key), filter);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class TriggerExecutorTest method differentKeyColumnFamilies.
@Test(expected = InvalidRequestException.class)
public void differentKeyColumnFamilies() throws ConfigurationException, InvalidRequestException {
TableMetadata metadata = makeTableMetadata("ks1", "cf1", TriggerMetadata.create("test", DifferentKeyTrigger.class.getName()));
TriggerExecutor.instance.execute(makeCf(metadata, "k1", "v1", null));
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class TriggersSchemaTest method addNewCfWithTriggerToKs.
@Test
public void addNewCfWithTriggerToKs() throws Exception {
KeyspaceMetadata ksm = KeyspaceMetadata.create(ksName, KeyspaceParams.simple(1));
MigrationManager.announceNewKeyspace(ksm);
TableMetadata metadata = CreateTableStatement.parse(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName).triggers(Triggers.of(TriggerMetadata.create(triggerName, triggerClass))).build();
MigrationManager.announceNewTable(metadata);
metadata = Schema.instance.getTableMetadata(ksName, cfName);
assertFalse(metadata.triggers.isEmpty());
assertEquals(1, metadata.triggers.size());
assertEquals(TriggerMetadata.create(triggerName, triggerClass), metadata.triggers.get(triggerName).get());
}
Aggregations