You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by mc...@apache.org on 2016/10/08 13:09:06 UTC
[3/3] cassandra git commit: Merge branch 'cassandra-3.0' into trunk
Merge branch 'cassandra-3.0' into trunk
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/25380132
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/25380132
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/25380132
Branch: refs/heads/trunk
Commit: 253801323c51ae94b7f00ef80da1528cd79bff8a
Parents: a333a2f e9ea5e0
Author: mck <mc...@apache.org>
Authored: Sat Oct 8 23:49:25 2016 +1100
Committer: mck <mc...@apache.org>
Committed: Sun Oct 9 00:04:28 2016 +1100
----------------------------------------------------------------------
.../CompressedRandomAccessReaderTest.java | 55 +++++++++-----------
1 file changed, 24 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/25380132/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();
- }
}
}