use of org.apache.cassandra.db.ClusteringComparator in project cassandra by apache.
the class CompressedSequentialWriterTest method resetAndTruncateTest.
@Test
@Override
public void resetAndTruncateTest() {
File tempFile = new File(Files.createTempDir(), "reset.txt");
File offsetsFile = FileUtils.createTempFile("compressedsequentialwriter.offset", "test");
final int bufferSize = 48;
final int writeSize = 64;
byte[] toWrite = new byte[writeSize];
try (SequentialWriter writer = new CompressedSequentialWriter(tempFile, offsetsFile.getPath(), null, SequentialWriterOption.DEFAULT, CompressionParams.lz4(bufferSize), new MetadataCollector(new ClusteringComparator(UTF8Type.instance)))) {
// write bytes greather than buffer
writer.write(toWrite);
long flushedOffset = writer.getLastFlushOffset();
assertEquals(writeSize, writer.position());
// mark thi position
DataPosition pos = writer.mark();
// write another
writer.write(toWrite);
// another buffer should be flushed
assertEquals(flushedOffset * 2, writer.getLastFlushOffset());
assertEquals(writeSize * 2, writer.position());
// reset writer
writer.resetAndTruncate(pos);
// current position and flushed size should be changed
assertEquals(writeSize, writer.position());
assertEquals(flushedOffset, writer.getLastFlushOffset());
// write another byte less than buffer
writer.write(new byte[] { 0 });
assertEquals(writeSize + 1, writer.position());
// flush off set should not be increase
assertEquals(flushedOffset, writer.getLastFlushOffset());
writer.finish();
} catch (IOException e) {
Assert.fail();
}
}
use of org.apache.cassandra.db.ClusteringComparator in project cassandra by apache.
the class GroupMakerTest method testIsNewGroupWithOneClusteringColumnsPrefix.
@Test
public void testIsNewGroupWithOneClusteringColumnsPrefix() {
ClusteringComparator comparator = newComparator(false, false, false);
GroupMaker groupMaker = GroupMaker.newInstance(comparator, 1);
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 1)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 2)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 3)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 2, 1)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 1)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 2)));
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 1)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 2)));
assertTrue(groupMaker.isNewGroup(partitionKey(2), clustering(2, 2, 1)));
}
use of org.apache.cassandra.db.ClusteringComparator in project cassandra by apache.
the class GroupMakerTest method testIsNewGroupWithClusteringColumns.
@Test
public void testIsNewGroupWithClusteringColumns() {
ClusteringComparator comparator = newComparator(false, false, false);
GroupMaker groupMaker = GroupMaker.newInstance(comparator, 2);
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 1)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 2)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 3)));
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 2, 1)));
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 1)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 2)));
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 1)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 2)));
assertTrue(groupMaker.isNewGroup(partitionKey(2), clustering(2, 2, 1)));
}
use of org.apache.cassandra.db.ClusteringComparator in project cassandra by apache.
the class GroupMakerTest method testIsNewGroupWithReversedClusteringColumns.
@Test
public void testIsNewGroupWithReversedClusteringColumns() {
ClusteringComparator comparator = newComparator(true, true, true);
GroupMaker groupMaker = GroupMaker.newInstance(comparator, 2);
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 2)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 3, 1)));
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 2, 1)));
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 3)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 2)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(1, 1, 1)));
assertTrue(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 2)));
assertFalse(groupMaker.isNewGroup(partitionKey(1), clustering(2, 1, 1)));
assertTrue(groupMaker.isNewGroup(partitionKey(2), clustering(2, 2, 1)));
}
use of org.apache.cassandra.db.ClusteringComparator in project cassandra by apache.
the class CompressedRandomAccessReaderTest method testResetAndTruncate.
private static void testResetAndTruncate(File f, boolean compressed, boolean usemmap, int junkSize, double minCompressRatio) throws IOException {
final String filename = f.getAbsolutePath();
MetadataCollector sstableMetadataCollector = new MetadataCollector(new ClusteringComparator(BytesType.instance));
try (SequentialWriter writer = compressed ? new CompressedSequentialWriter(f, filename + ".metadata", null, SequentialWriterOption.DEFAULT, CompressionParams.snappy(), sstableMetadataCollector) : new SequentialWriter(f)) {
writer.write("The quick ".getBytes());
DataPosition mark = writer.mark();
writer.write("blue fox jumps over the lazy dog".getBytes());
// write enough to be sure to change chunk
for (int i = 0; i < junkSize; ++i) {
writer.write((byte) 1);
}
writer.resetAndTruncate(mark);
writer.write("brown fox jumps over the lazy dog".getBytes());
writer.finish();
}
assert f.exists();
CompressionMetadata compressionMetadata = compressed ? new CompressionMetadata(filename + ".metadata", f.length(), true) : null;
try (FileHandle.Builder builder = new FileHandle.Builder(filename).mmapped(usemmap).withCompressionMetadata(compressionMetadata);
FileHandle fh = builder.complete();
RandomAccessReader reader = fh.createReader()) {
String expected = "The quick brown fox jumps over the lazy dog";
assertEquals(expected.length(), reader.length());
byte[] b = new byte[expected.length()];
reader.readFully(b);
assert new String(b).equals(expected) : "Expecting '" + expected + "', got '" + new String(b) + '\'';
} finally {
if (f.exists())
assertTrue(f.delete());
File metadata = new File(filename + ".metadata");
if (compressed && metadata.exists())
metadata.delete();
}
}
Aggregations