Merge branch 'cassandra-3.0' into cassandra-3.X
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e930ffa8 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e930ffa8 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e930ffa8 Branch: refs/heads/cassandra-3.X Commit: e930ffa8a06a62a839ba817e5fe5b70ff36dc2f7 Parents: 316e1cd e9ea5e0 Author: Stefania Alborghetti <[email protected]> Authored: Mon Oct 10 09:39:18 2016 +0800 Committer: Stefania Alborghetti <[email protected]> Committed: Mon Oct 10 09:42:31 2016 +0800 ---------------------------------------------------------------------- .../CompressedRandomAccessReaderTest.java | 55 +++++++++----------- 1 file changed, 24 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/e930ffa8/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java ---------------------------------------------------------------------- diff --cc test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java index 3380e30,0c96327..0d2a9fb --- a/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java +++ b/test/unit/org/apache/cassandra/io/compress/CompressedRandomAccessReaderTest.java @@@ -21,12 -21,10 +21,13 @@@ package org.apache.cassandra.io.compres import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; + import java.util.Arrays; import java.util.Random; +import org.junit.BeforeClass; import org.junit.Test; + +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.ClusteringComparator; import org.apache.cassandra.db.marshal.BytesType; import org.apache.cassandra.exceptions.ConfigurationException; @@@ -192,69 -201,60 +196,58 @@@ public class CompressedRandomAccessRead writer.finish(); } - try(ChannelProxy channel = new ChannelProxy(file)) - { - // open compression metadata and get chunk information - CompressionMetadata meta = new CompressionMetadata(metadata.getPath(), file.length(), ChecksumType.CRC32); - CompressionMetadata.Chunk chunk = meta.chunkFor(0); - - try(RandomAccessReader reader = new CompressedRandomAccessReader.Builder(channel, meta).build()) - {// read and verify compressed data - assertEquals(CONTENT, reader.readLine()); - } + // open compression metadata and get chunk information + CompressionMetadata meta = new CompressionMetadata(metadata.getPath(), file.length(), ChecksumType.CRC32); + CompressionMetadata.Chunk chunk = meta.chunkFor(0); + try (FileHandle.Builder builder = new FileHandle.Builder(file.getPath()).withCompressionMetadata(meta); + FileHandle fh = builder.complete(); + RandomAccessReader reader = fh.createReader()) + {// read and verify compressed data + assertEquals(CONTENT, reader.readLine()); - Random random = new Random(); - RandomAccessFile checksumModifier = null; - - try + try(RandomAccessFile checksumModifier = new RandomAccessFile(file, "rw")) { - checksumModifier = new RandomAccessFile(file, "rw"); byte[] checksum = new byte[4]; // seek to the end of the compressed chunk checksumModifier.seek(chunk.length); // read checksum bytes checksumModifier.read(checksum); - // seek back to the chunk end - checksumModifier.seek(chunk.length); - // lets modify one byte of the checksum on each iteration - for (int i = 0; i < checksum.length; i++) + byte[] corruptChecksum = new byte[4]; + do { - checksumModifier.write(random.nextInt()); - SyncUtil.sync(checksumModifier); // making sure that change was synced with disk + random.nextBytes(corruptChecksum); + } while (Arrays.equals(corruptChecksum, checksum)); - try (final RandomAccessReader r = fh.createReader()) + updateChecksum(checksumModifier, chunk.length, corruptChecksum); + - try (final RandomAccessReader r = new CompressedRandomAccessReader.Builder(channel, meta).build()) ++ try (final RandomAccessReader r = fh.createReader()) + { + Throwable exception = null; + try { - Throwable exception = null; - try - { - r.readLine(); - } - catch (Throwable t) - { - exception = t; - } - assertNotNull(exception); - assertSame(exception.getClass(), CorruptSSTableException.class); - assertSame(exception.getCause().getClass(), CorruptBlockException.class); + r.readLine(); } + catch (Throwable t) + { + exception = t; + } + assertNotNull(exception); + assertSame(exception.getClass(), CorruptSSTableException.class); + assertSame(exception.getCause().getClass(), CorruptBlockException.class); } // lets write original checksum and check if we can read data updateChecksum(checksumModifier, chunk.length, checksum); + // read and verify compressed data - try (RandomAccessReader cr = new CompressedRandomAccessReader.Builder(channel, meta).build()) + try (RandomAccessReader cr = fh.createReader()) { - // read and verify compressed data assertEquals(CONTENT, cr.readLine()); - // close reader } } - finally - { - if (checksumModifier != null) - checksumModifier.close(); - } } }
