Skip to content

Commit

Permalink
Test the chunk ending position does not fail
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-miezal committed Feb 25, 2025
1 parent ab0c832 commit d38abd1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -418,6 +419,35 @@ public void testAssertionsOnDiskSizeForPartitionPositions()
.isInstanceOf(AssertionError.class);
}

@Test
public void testDoNotFailOnChunkEndingPosition()
{
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_COMPRESSED);
int count = 530;
// insert data and compact to a single sstable
for (int j = 0; j < count; j++)
{
new RowUpdateBuilder(cfs.metadata(), 15000, k0(j))
.clustering("0")
.add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER)
.build()
.applyUnsafe();
}
cfs.forceBlockingFlush(UNIT_TESTS);
cfs.forceMajorCompaction();
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();

partitioner = sstable.getPartitioner();
int chunkLength = sstable.getCompressionMetadata().parameters.chunkLength();
long chunkCount = (long) Math.ceil((double) sstable.uncompressedLength() / chunkLength);
assertEquals(2, chunkCount);
long endPosition = chunkLength * chunkCount;

long size = sstable.onDiskSizeForPartitionPositions(Collections.singleton(new PartitionPositionBounds(0, endPosition)));
assertNotEquals(0, size);
}

long onDiskSizeForRanges(SSTableReader sstable, Collection<Range<Token>> ranges)
{
return sstable.onDiskSizeForPartitionPositions(sstable.getPositionsForRanges(ranges));
Expand Down

0 comments on commit d38abd1

Please sign in to comment.