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;
}
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();
}
}
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);
}
}
}
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);
}
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));
}
Aggregations