Search in sources :

Example 1 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class CommitLogTest method testRecovery.

protected Void testRecovery(CommitLogDescriptor desc, byte[] logData) throws Exception {
    File logFile = tmpFile(desc.version);
    CommitLogDescriptor fromFile = CommitLogDescriptor.fromFileName(logFile.name());
    // Change id to match file.
    desc = new CommitLogDescriptor(desc.version, fromFile.id, desc.compression, desc.getEncryptionContext());
    ByteBuffer buf = ByteBuffer.allocate(1024);
    CommitLogDescriptor.writeHeader(buf, desc, getAdditionalHeaders(desc.getEncryptionContext()));
    try (OutputStream lout = new FileOutputStreamPlus(logFile)) {
        lout.write(buf.array(), 0, buf.position());
        lout.write(logData);
        // statics make it annoying to test things correctly
        // CASSANDRA-1119 / CASSANDRA-1179 throw on failure*/
        CommitLog.instance.recover(logFile.path());
    }
    return null;
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) File(org.apache.cassandra.io.util.File) ByteBuffer(java.nio.ByteBuffer) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus)

Example 2 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class BloomFilterSerializerBench method serializationTest.

@Benchmark
public void serializationTest() throws IOException {
    File file = FileUtils.createTempFile("bloomFilterTest-", ".dat");
    try {
        BloomFilter filter = (BloomFilter) FilterFactory.getFilter(numElemsInK * 1024, 0.01d);
        filter.add(wrap(testVal));
        DataOutputStreamPlus out = new FileOutputStreamPlus(file);
        if (oldBfFormat)
            SerializationsTest.serializeOldBfFormat(filter, out);
        else
            BloomFilterSerializer.serialize(filter, out);
        out.close();
        filter.close();
        FileInputStreamPlus in = new FileInputStreamPlus(file);
        BloomFilter filter2 = BloomFilterSerializer.deserialize(in, oldBfFormat);
        FileUtils.closeQuietly(in);
        filter2.close();
    } finally {
        file.tryDelete();
    }
}
Also used : FileInputStreamPlus(org.apache.cassandra.io.util.FileInputStreamPlus) File(org.apache.cassandra.io.util.File) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus) BloomFilter(org.apache.cassandra.utils.BloomFilter) DataOutputStreamPlus(org.apache.cassandra.io.util.DataOutputStreamPlus) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 3 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class LegacySSTableTest method copyFile.

private static void copyFile(File cfDir, File file) throws IOException {
    byte[] buf = new byte[65536];
    if (file.isFile()) {
        File target = new File(cfDir, file.name());
        int rd;
        try (FileInputStreamPlus is = new FileInputStreamPlus(file);
            FileOutputStreamPlus os = new FileOutputStreamPlus(target)) {
            while ((rd = is.read(buf)) >= 0) os.write(buf, 0, rd);
        }
    }
}
Also used : FileInputStreamPlus(org.apache.cassandra.io.util.FileInputStreamPlus) File(org.apache.cassandra.io.util.File) CassandraOutgoingFile(org.apache.cassandra.db.streaming.CassandraOutgoingFile) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus)

Example 4 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class SnapshotManifestTest method testIngoredFields.

@Test
public void testIngoredFields() throws IOException {
    Map<String, Object> map = new HashMap<>();
    map.put("files", Arrays.asList("db1", "db2", "db3"));
    map.put("dummy", "dummy");
    ObjectMapper mapper = new ObjectMapper();
    File manifestFile = new File(tempFolder.newFile("manifest.json"));
    mapper.writeValue((OutputStream) new FileOutputStreamPlus(manifestFile), map);
    SnapshotManifest manifest = SnapshotManifest.deserializeFromJsonFile(manifestFile);
    assertThat(manifest.getFiles()).contains("db1").contains("db2").contains("db3").hasSize(3);
}
Also used : HashMap(java.util.HashMap) File(org.apache.cassandra.io.util.File) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with FileOutputStreamPlus

use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.

the class SnapshotManifestTest method testDeserializeFromInvalidFile.

@Test
public void testDeserializeFromInvalidFile() throws IOException {
    File manifestFile = new File(tempFolder.newFile("invalid"));
    assertThatIOException().isThrownBy(() -> {
        SnapshotManifest.deserializeFromJsonFile(manifestFile);
    });
    FileOutputStreamPlus out = new FileOutputStreamPlus(manifestFile);
    out.write(1);
    out.write(2);
    out.write(3);
    out.close();
    assertThatIOException().isThrownBy(() -> SnapshotManifest.deserializeFromJsonFile(manifestFile));
}
Also used : File(org.apache.cassandra.io.util.File) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus) Test(org.junit.Test)

Aggregations

FileOutputStreamPlus (org.apache.cassandra.io.util.FileOutputStreamPlus)16 File (org.apache.cassandra.io.util.File)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataOutputStream (java.io.DataOutputStream)6 OutputStream (java.io.OutputStream)6 ByteBuffer (java.nio.ByteBuffer)5 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 FileInputStreamPlus (org.apache.cassandra.io.util.FileInputStreamPlus)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 CassandraOutgoingFile (org.apache.cassandra.db.streaming.CassandraOutgoingFile)1 DataOutputStreamPlus (org.apache.cassandra.io.util.DataOutputStreamPlus)1 RandomAccessReader (org.apache.cassandra.io.util.RandomAccessReader)1 EncryptionContext (org.apache.cassandra.security.EncryptionContext)1 BloomFilter (org.apache.cassandra.utils.BloomFilter)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1