use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeRandomAccessOverwriteRead.
@Test
public void writeRandomAccessOverwriteRead() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
OutputStream outputStream = vfs.appendFile(txn, file0);
outputStream.write((HOEGAARDEN + HOEGAARDEN + HOEGAARDEN + HOEGAARDEN).getBytes(UTF_8));
outputStream.close();
txn.flush();
Assert.assertEquals(40, vfs.getFileLength(txn, file0));
outputStream = vfs.writeFile(txn, file0, 0);
outputStream.write("x".getBytes(UTF_8));
outputStream.close();
Assert.assertEquals(40, vfs.getFileLength(txn, file0));
outputStream = vfs.writeFile(txn, file0, 10);
outputStream.write("x".getBytes(UTF_8));
outputStream.close();
Assert.assertEquals(40, vfs.getFileLength(txn, file0));
outputStream = vfs.writeFile(txn, file0, 20);
outputStream.write("x".getBytes(UTF_8));
outputStream.close();
Assert.assertEquals(40, vfs.getFileLength(txn, file0));
outputStream = vfs.writeFile(txn, file0, 30);
outputStream.write("x".getBytes(UTF_8));
outputStream.close();
txn.flush();
Assert.assertEquals(40, vfs.getFileLength(txn, file0));
final InputStream inputStream = vfs.readFile(txn, file0);
Assert.assertEquals('x' + HOEGAARDEN.substring(1) + 'x' + HOEGAARDEN.substring(1) + 'x' + HOEGAARDEN.substring(1) + '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 writeRead4.
@Test
public void writeRead4() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
final OutputStream outputStream = vfs.writeFile(txn, file0);
final int count = 0x10000;
outputStream.write(new byte[count]);
outputStream.close();
final InputStream inputStream = vfs.readFile(txn, file0);
for (int i = 0; i < count; ++i) {
Assert.assertEquals(0, inputStream.read());
}
inputStream.close();
txn.commit();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method testFileLength.
@Test
public void testFileLength() throws IOException {
final Transaction txn = env.beginTransaction();
vfs.createFile(txn, "file0");
txn.flush();
for (int i = 0; i < 300; ++i) {
final File file0 = vfs.openFile(txn, "file0", false);
Assert.assertNotNull(file0);
Assert.assertEquals((long) i, vfs.getFileLength(txn, file0));
final OutputStream outputStream = vfs.appendFile(txn, file0);
outputStream.write(i);
outputStream.close();
txn.flush();
}
txn.abort();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeNegativePosition.
@Test
public void writeNegativePosition() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
TestUtil.runWithExpectedException(new Runnable() {
@Override
public void run() {
vfs.writeFile(txn, file0, -1);
}
}, IllegalArgumentException.class);
txn.commit();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeRandomAccessRead.
@Test
public void writeRandomAccessRead() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
final OutputStream outputStream = vfs.appendFile(txn, file0);
outputStream.write((HOEGAARDEN + HOEGAARDEN + HOEGAARDEN + HOEGAARDEN).getBytes(UTF_8));
outputStream.close();
txn.flush();
InputStream inputStream = vfs.readFile(txn, file0, 0);
Assert.assertEquals(HOEGAARDEN + HOEGAARDEN + HOEGAARDEN + HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
inputStream = vfs.readFile(txn, file0, 10);
Assert.assertEquals(HOEGAARDEN + HOEGAARDEN + HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
inputStream = vfs.readFile(txn, file0, 20);
Assert.assertEquals(HOEGAARDEN + HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
inputStream = vfs.readFile(txn, file0, 30);
Assert.assertEquals(HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
txn.abort();
}
Aggregations