Search in sources :

Example 6 with FileInputStreamPlus

use of org.apache.cassandra.io.util.FileInputStreamPlus 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 7 with FileInputStreamPlus

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

the class SerializationsTest method testSyncCompleteRead.

@Test
public void testSyncCompleteRead() throws IOException {
    if (EXECUTE_WRITES)
        testSyncCompleteWrite();
    InetAddressAndPort src = InetAddressAndPort.getByNameOverrideDefaults("127.0.0.2", PORT);
    InetAddressAndPort dest = InetAddressAndPort.getByNameOverrideDefaults("127.0.0.3", PORT);
    SyncNodePair nodes = new SyncNodePair(src, dest);
    try (FileInputStreamPlus in = getInput("service.SyncComplete.bin")) {
        // success
        SyncResponse message = SyncResponse.serializer.deserialize(in, getVersion());
        assert DESC.equals(message.desc);
        System.out.println(nodes);
        System.out.println(message.nodes);
        assert nodes.equals(message.nodes);
        assert message.success;
        // fail
        message = SyncResponse.serializer.deserialize(in, getVersion());
        assert DESC.equals(message.desc);
        assert nodes.equals(message.nodes);
        assert !message.success;
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) FileInputStreamPlus(org.apache.cassandra.io.util.FileInputStreamPlus) SyncNodePair(org.apache.cassandra.repair.SyncNodePair) Test(org.junit.Test)

Example 8 with FileInputStreamPlus

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

the class SerializationsTest method testBloomFilterRead1000.

@Test
public void testBloomFilterRead1000() throws IOException {
    if (EXECUTE_WRITES) {
        testBloomFilterWrite1000(false);
        testBloomFilterWrite1000(true);
    }
    try (FileInputStreamPlus in = getInput("4.0", "utils.BloomFilter1000.bin");
        IFilter filter = BloomFilterSerializer.deserialize(in, false)) {
        boolean present;
        for (int i = 0; i < 1000; i++) {
            present = filter.isPresent(Util.dk(Int32Type.instance.decompose(i)));
            Assert.assertTrue(present);
        }
        for (int i = 1000; i < 2000; i++) {
            present = filter.isPresent(Util.dk(Int32Type.instance.decompose(i)));
            Assert.assertFalse(present);
        }
    }
    try (FileInputStreamPlus in = getInput("3.0", "utils.BloomFilter1000.bin");
        IFilter filter = BloomFilterSerializer.deserialize(in, true)) {
        boolean present;
        for (int i = 0; i < 1000; i++) {
            present = filter.isPresent(Util.dk(Int32Type.instance.decompose(i)));
            Assert.assertTrue(present);
        }
        for (int i = 1000; i < 2000; i++) {
            present = filter.isPresent(Util.dk(Int32Type.instance.decompose(i)));
            Assert.assertFalse(present);
        }
    }
}
Also used : FileInputStreamPlus(org.apache.cassandra.io.util.FileInputStreamPlus) Test(org.junit.Test)

Example 9 with FileInputStreamPlus

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

the class VerifyTest method simpleFullChecksum.

protected long simpleFullChecksum(String filename) throws IOException {
    try (FileInputStreamPlus inputStream = new FileInputStreamPlus(filename)) {
        CRC32 checksum = new CRC32();
        CheckedInputStream cinStream = new CheckedInputStream(inputStream, checksum);
        byte[] b = new byte[128];
        while (cinStream.read(b) >= 0) {
        }
        return cinStream.getChecksum().getValue();
    }
}
Also used : CRC32(java.util.zip.CRC32) FileInputStreamPlus(org.apache.cassandra.io.util.FileInputStreamPlus) CheckedInputStream(java.util.zip.CheckedInputStream)

Example 10 with FileInputStreamPlus

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

the class TTLTest method copyFile.

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

Aggregations

FileInputStreamPlus (org.apache.cassandra.io.util.FileInputStreamPlus)16 Test (org.junit.Test)7 File (org.apache.cassandra.io.util.File)5 FileOutputStreamPlus (org.apache.cassandra.io.util.FileOutputStreamPlus)3 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)2 DataInputStream (java.io.DataInputStream)1 Properties (java.util.Properties)1 CRC32 (java.util.zip.CRC32)1 CheckedInputStream (java.util.zip.CheckedInputStream)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 CassandraOutgoingFile (org.apache.cassandra.db.streaming.CassandraOutgoingFile)1 Murmur3Partitioner (org.apache.cassandra.dht.Murmur3Partitioner)1 DataOutputStreamPlus (org.apache.cassandra.io.util.DataOutputStreamPlus)1 SyncNodePair (org.apache.cassandra.repair.SyncNodePair)1 TableId (org.apache.cassandra.schema.TableId)1 BloomFilter (org.apache.cassandra.utils.BloomFilter)1 BeforeClass (org.junit.BeforeClass)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1