use of org.apache.cassandra.io.util.FileSegmentInputStream in project cassandra by apache.
the class CommitLogDescriptorTest method writeAndReadHeader_WithEncryptionHeader_EncryptionEnabledInYaml.
@Test
public void writeAndReadHeader_WithEncryptionHeader_EncryptionEnabledInYaml() throws IOException {
CommitLogDescriptor descriptor = new CommitLogDescriptor(CommitLogDescriptor.current_version, 1, null, enabledEncryption);
ByteBuffer buffer = ByteBuffer.allocate(16 * 1024);
CommitLogDescriptor.writeHeader(buffer, descriptor);
buffer.flip();
FileSegmentInputStream dataInput = new FileSegmentInputStream(buffer, null, 0);
CommitLogDescriptor result = CommitLogDescriptor.readHeader(dataInput, enabledEncryption);
Assert.assertNotNull(result);
Assert.assertNull(result.compression);
Assert.assertTrue(result.getEncryptionContext().isEnabled());
Assert.assertArrayEquals(iv, result.getEncryptionContext().getIV());
}
use of org.apache.cassandra.io.util.FileSegmentInputStream in project cassandra by apache.
the class CommitLogDescriptorTest method writeAndReadHeader_NoCompressionOrEncryption.
@Test
public void writeAndReadHeader_NoCompressionOrEncryption() throws IOException {
CommitLogDescriptor descriptor = new CommitLogDescriptor(CommitLogDescriptor.current_version, 1, null, neverEnabledEncryption);
ByteBuffer buffer = ByteBuffer.allocate(16 * 1024);
CommitLogDescriptor.writeHeader(buffer, descriptor);
buffer.flip();
FileSegmentInputStream dataInput = new FileSegmentInputStream(buffer, null, 0);
CommitLogDescriptor result = CommitLogDescriptor.readHeader(dataInput, neverEnabledEncryption);
Assert.assertNotNull(result);
Assert.assertNull(result.compression);
Assert.assertFalse(result.getEncryptionContext().isEnabled());
}
use of org.apache.cassandra.io.util.FileSegmentInputStream in project cassandra by apache.
the class CommitLogDescriptorTest method writeAndReadHeader_WithCompressionAndEncryption.
/**
* Shouldn't happen in the real world (should only have either compression or enabledTdeOptions), but the header
* functionality should be correct
*/
@Test
public void writeAndReadHeader_WithCompressionAndEncryption() throws IOException {
CommitLogDescriptor descriptor = new CommitLogDescriptor(CommitLogDescriptor.current_version, 1, compression, enabledEncryption);
ByteBuffer buffer = ByteBuffer.allocate(16 * 1024);
CommitLogDescriptor.writeHeader(buffer, descriptor);
buffer.flip();
FileSegmentInputStream dataInput = new FileSegmentInputStream(buffer, null, 0);
CommitLogDescriptor result = CommitLogDescriptor.readHeader(dataInput, enabledEncryption);
Assert.assertNotNull(result);
Assert.assertEquals(compression, result.compression);
Assert.assertTrue(result.getEncryptionContext().isEnabled());
Assert.assertEquals(enabledEncryption, result.getEncryptionContext());
Assert.assertArrayEquals(iv, result.getEncryptionContext().getIV());
}
use of org.apache.cassandra.io.util.FileSegmentInputStream in project cassandra by apache.
the class CommitLogDescriptorTest method testDescriptorPersistence.
// migrated from CommitLogTest
private void testDescriptorPersistence(CommitLogDescriptor desc) throws IOException {
ByteBuffer buf = ByteBuffer.allocate(1024);
CommitLogDescriptor.writeHeader(buf, desc);
long length = buf.position();
// Put some extra data in the stream.
buf.putDouble(0.1);
buf.flip();
FileDataInput input = new FileSegmentInputStream(buf, "input", 0);
CommitLogDescriptor read = CommitLogDescriptor.readHeader(input, neverEnabledEncryption);
Assert.assertEquals("Descriptor length", length, input.getFilePointer());
Assert.assertEquals("Descriptors", desc, read);
}
use of org.apache.cassandra.io.util.FileSegmentInputStream in project cassandra by apache.
the class CommitLogDescriptorTest method writeAndReadHeader_OnlyCompression.
@Test
public void writeAndReadHeader_OnlyCompression() throws IOException {
CommitLogDescriptor descriptor = new CommitLogDescriptor(CommitLogDescriptor.current_version, 1, compression, neverEnabledEncryption);
ByteBuffer buffer = ByteBuffer.allocate(16 * 1024);
CommitLogDescriptor.writeHeader(buffer, descriptor);
buffer.flip();
FileSegmentInputStream dataInput = new FileSegmentInputStream(buffer, null, 0);
CommitLogDescriptor result = CommitLogDescriptor.readHeader(dataInput, neverEnabledEncryption);
Assert.assertNotNull(result);
Assert.assertEquals(compression, result.compression);
Assert.assertFalse(result.getEncryptionContext().isEnabled());
}
Aggregations