use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.
the class CommitLogTest method testRecovery.
protected Void testRecovery(byte[] logData, int version) throws Exception {
File logFile = tmpFile(version);
try (OutputStream lout = new FileOutputStreamPlus(logFile)) {
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 CommitLogUpgradeTestMaker method makeLog.
public void makeLog() throws IOException, InterruptedException {
CommitLog commitLog = CommitLog.instance;
System.out.format("\nUsing commit log size: %dmb, compressor: %s, encryption: %s, sync: %s, %s\n", mb(DatabaseDescriptor.getCommitLogSegmentSize()), commitLog.configuration.getCompressorName(), commitLog.configuration.useEncryption(), commitLog.executor.getClass().getSimpleName(), randomSize ? "random size" : "");
final List<CommitlogExecutor> threads = new ArrayList<>();
ScheduledExecutorService scheduled = startThreads(commitLog, threads);
Thread.sleep(runTimeMs);
stop = true;
scheduled.shutdown();
Assert.assertTrue(scheduled.awaitTermination(1, TimeUnit.MINUTES));
int hash = 0;
int cells = 0;
for (CommitlogExecutor t : threads) {
t.join();
hash += t.hash;
cells += t.cells;
}
commitLog.shutdownBlocking();
File dataDir = new File(CommitLogUpgradeTest.DATA_DIR + FBUtilities.getReleaseVersionString());
System.out.format("Data will be stored in %s\n", dataDir);
if (dataDir.exists())
FileUtils.deleteRecursive(dataDir);
dataDir.tryCreateDirectories();
for (File f : new File(DatabaseDescriptor.getCommitLogLocation()).tryList()) FileUtils.createHardLink(f, new File(dataDir, f.name()));
Properties prop = new Properties();
prop.setProperty(CFID_PROPERTY, Schema.instance.getTableMetadata(KEYSPACE, TABLE).id.toString());
prop.setProperty(CELLS_PROPERTY, Integer.toString(cells));
prop.setProperty(HASH_PROPERTY, Integer.toString(hash));
prop.store(new FileOutputStreamPlus(new File(dataDir, PROPERTIES_FILE)), "CommitLog upgrade test, version " + FBUtilities.getReleaseVersionString());
System.out.println("Done");
}
use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.
the class DirectoriesTest method createFile.
private File createFile(String fileName, int size) {
File newFile = new File(fileName);
try (FileOutputStreamPlus writer = new FileOutputStreamPlus(newFile)) {
writer.write(new byte[size]);
writer.flush();
} catch (IOException ignore) {
}
return newFile;
}
use of org.apache.cassandra.io.util.FileOutputStreamPlus 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();
}
}
use of org.apache.cassandra.io.util.FileOutputStreamPlus in project cassandra by apache.
the class TableSnapshotTest method writeBatchToFile.
private Long writeBatchToFile(File file) throws IOException {
FileOutputStreamPlus out = new FileOutputStreamPlus(file);
out.write(1);
out.write(2);
out.write(3);
out.close();
return 3L;
}
Aggregations