use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method testWriteAndSeek.
@Test
public void testWriteAndSeek() throws IOException {
Transaction txn = env.beginTransaction();
final File file = vfs.createFile(txn, "file0");
OutputStream outputStream;
for (int i = 0; i < 4; ++i) {
outputStream = vfs.writeFile(txn, file, i);
outputStream.write(HOEGAARDEN.getBytes(UTF_8));
outputStream.close();
}
txn.flush();
final InputStream inputStream = vfs.readFile(txn, file);
Assert.assertEquals("hhh" + HOEGAARDEN, streamAsString(inputStream));
txn.abort();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method testTimeFieldsOfFiles.
@Test
public void testTimeFieldsOfFiles() throws IOException, InterruptedException {
final long start = System.currentTimeMillis();
Thread.sleep(20);
final Transaction txn = env.beginTransaction();
File file0 = vfs.createFile(txn, "file0");
txn.flush();
Thread.sleep(20);
final OutputStream outputStream = vfs.appendFile(txn, file0);
outputStream.write(RENAT_GILFANOV.getBytes(UTF_8));
outputStream.close();
txn.flush();
file0 = vfs.openFile(txn, "file0", false);
Assert.assertNotNull(file0);
Assert.assertTrue(file0.getCreated() > start);
Assert.assertTrue(file0.getCreated() < file0.getLastModified());
txn.abort();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeOverwriteRead.
@Test
public void writeOverwriteRead() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
OutputStream outputStream = vfs.appendFile(txn, file0);
outputStream.write(HOEGAARDEN.getBytes(UTF_8));
outputStream.close();
txn.flush();
outputStream = vfs.writeFile(txn, file0);
outputStream.write("x".getBytes(UTF_8));
outputStream.close();
txn.flush();
final InputStream inputStream = vfs.readFile(txn, file0);
Assert.assertEquals('x' + HOEGAARDEN.substring(1), streamAsString(inputStream));
inputStream.close();
txn.abort();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method testWriteOverwriteReadWithStrategy.
private void testWriteOverwriteReadWithStrategy(@NotNull final ClusteringStrategy strategy) throws IOException {
vfs.shutdown();
final VfsConfig config = new VfsConfig();
config.setClusteringStrategy(strategy);
vfs = new VirtualFileSystem(getEnvironment(), config);
Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
OutputStream outputStream = vfs.writeFile(txn, file0);
outputStream.write(HOEGAARDEN.getBytes(UTF_8));
outputStream.close();
InputStream inputStream = vfs.readFile(txn, file0);
String actualRead = streamAsString(inputStream);
Assert.assertEquals(HOEGAARDEN, actualRead);
inputStream.close();
txn.commit();
txn = env.beginTransaction();
outputStream = vfs.writeFile(txn, file0);
outputStream.write(RENAT_GILFANOV.getBytes(UTF_8));
outputStream.close();
inputStream = vfs.readFile(txn, file0);
actualRead = streamAsString(inputStream);
Assert.assertEquals(RENAT_GILFANOV, actualRead);
inputStream.close();
txn.commit();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeRead.
@Test
public void writeRead() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
final OutputStream outputStream = vfs.appendFile(txn, file0);
outputStream.write(HOEGAARDEN.getBytes(UTF_8));
outputStream.close();
txn.flush();
final InputStream inputStream = vfs.readFile(txn, file0);
Assert.assertEquals(HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
txn.abort();
}
Aggregations