Search in sources :

Example 1 with FileSegmentInputStream

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());
}
Also used : FileSegmentInputStream(org.apache.cassandra.io.util.FileSegmentInputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with FileSegmentInputStream

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());
}
Also used : FileSegmentInputStream(org.apache.cassandra.io.util.FileSegmentInputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with FileSegmentInputStream

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());
}
Also used : FileSegmentInputStream(org.apache.cassandra.io.util.FileSegmentInputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with FileSegmentInputStream

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);
}
Also used : FileSegmentInputStream(org.apache.cassandra.io.util.FileSegmentInputStream) FileDataInput(org.apache.cassandra.io.util.FileDataInput) ByteBuffer(java.nio.ByteBuffer)

Example 5 with FileSegmentInputStream

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());
}
Also used : FileSegmentInputStream(org.apache.cassandra.io.util.FileSegmentInputStream) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)6 FileSegmentInputStream (org.apache.cassandra.io.util.FileSegmentInputStream)6 Test (org.junit.Test)5 FileDataInput (org.apache.cassandra.io.util.FileDataInput)1