use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class PartitionSerializationExceptionTest method testMessageWithSimplePartitionKey.
@Test
public void testMessageWithSimplePartitionKey() {
TableMetadata metadata = TableMetadata.builder("ks", "tbl").addPartitionKeyColumn("pk", UTF8Type.instance).build();
DecoratedKey key = mock(DecoratedKey.class);
when(key.getKey()).thenReturn(UTF8Type.instance.decompose("foo"));
@SuppressWarnings("unchecked") BaseRowIterator<Unfiltered> partition = mock(BaseRowIterator.class);
when(partition.metadata()).thenReturn(metadata);
when(partition.partitionKey()).thenReturn(key);
PartitionSerializationException pse = new PartitionSerializationException(partition, new RuntimeException());
assertEquals("Failed to serialize partition key 'foo' on table 'tbl' in keyspace 'ks'.", pse.getMessage());
}
use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class SSTableRewriterTest method validateKeys.
private void validateKeys(Keyspace ks) {
for (int i = 0; i < 100; i++) {
DecoratedKey key = Util.dk(Integer.toString(i));
ImmutableBTreePartition partition = Util.getOnlyPartitionUnfiltered(Util.cmd(ks.getColumnFamilyStore(CF), key).build());
assertTrue(partition != null && partition.rowCount() > 0);
}
}
use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class SSTableRewriterTest method testNumberOfFiles_abort.
private void testNumberOfFiles_abort(RewriterTest test) {
Keyspace keyspace = Keyspace.open(KEYSPACE);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
truncate(cfs);
SSTableReader s = writeFile(cfs, 1000);
cfs.addSSTable(s);
DecoratedKey origFirst = s.first;
DecoratedKey origLast = s.last;
long startSize = cfs.metric.liveDiskSpaceUsed.getCount();
Set<SSTableReader> compacting = Sets.newHashSet(s);
try (ISSTableScanner scanner = s.getScanner();
CompactionController controller = new CompactionController(cfs, compacting, 0);
LifecycleTransaction txn = cfs.getTracker().tryModify(compacting, OperationType.UNKNOWN);
SSTableRewriter rewriter = new SSTableRewriter(txn, 1000, 10000000, false, true)) {
rewriter.switchWriter(getWriter(cfs, s.descriptor.directory, txn));
test.run(scanner, controller, s, cfs, rewriter, txn);
}
LifecycleTransaction.waitForDeletions();
assertEquals(startSize, cfs.metric.liveDiskSpaceUsed.getCount());
assertEquals(1, cfs.getLiveSSTables().size());
assertFileCounts(s.descriptor.directory.tryListNames());
assertEquals(cfs.getLiveSSTables().iterator().next().first, origFirst);
assertEquals(cfs.getLiveSSTables().iterator().next().last, origLast);
validateCFS(cfs);
}
use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class BigTableZeroCopyWriterTest method defineSchema.
@BeforeClass
public static void defineSchema() throws Exception {
SchemaLoader.prepareServer();
SchemaLoader.createKeyspace(KEYSPACE1, KeyspaceParams.simple(1), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD2), SchemaLoader.compositeIndexCFMD(KEYSPACE1, CF_INDEXED, true), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARDLOWINDEXINTERVAL).minIndexInterval(8).maxIndexInterval(256).caching(CachingParams.CACHE_NOTHING));
String ks = KEYSPACE1;
String cf = "Standard1";
// clear and create just one sstable for this test
Keyspace keyspace = Keyspace.open(ks);
store = keyspace.getColumnFamilyStore(cf);
store.clearUnsafe();
store.disableAutoCompaction();
DecoratedKey firstKey = null, lastKey = null;
long timestamp = System.currentTimeMillis();
for (int i = 0; i < store.metadata().params.minIndexInterval; i++) {
DecoratedKey key = Util.dk(String.valueOf(i));
if (firstKey == null)
firstKey = key;
if (lastKey == null)
lastKey = key;
if (store.metadata().partitionKeyType.compare(lastKey.getKey(), key.getKey()) < 0)
lastKey = key;
new RowUpdateBuilder(store.metadata(), timestamp, key.getKey()).clustering("col").add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
expectedRowCount++;
}
store.forceBlockingFlush();
sstable = store.getLiveSSTables().iterator().next();
}
use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.
the class HintsTestUtil method sendHintsAndResponses.
static MockMessagingSpy sendHintsAndResponses(TableMetadata metadata, int noOfHints, int noOfResponses) {
// create spy for hint messages, but only create responses for noOfResponses hints
Message<NoPayload> message = Message.internalResponse(HINT_RSP, NoPayload.noPayload);
MockMessagingSpy spy;
if (noOfResponses != -1) {
spy = MockMessagingService.when(verb(HINT_REQ)).respondN(message, noOfResponses);
} else {
spy = MockMessagingService.when(verb(HINT_REQ)).respond(message);
}
// create and write noOfHints using service
UUID hostId = StorageService.instance.getLocalHostUUID();
for (int i = 0; i < noOfHints; i++) {
long now = Clock.Global.currentTimeMillis();
DecoratedKey dkey = dk(String.valueOf(i));
PartitionUpdate.SimpleBuilder builder = PartitionUpdate.simpleBuilder(metadata, dkey).timestamp(now);
builder.row("column0").add("val", "value0");
Hint hint = Hint.create(builder.buildAsMutation(), now);
HintsService.instance.write(hostId, hint);
}
return spy;
}
Aggregations