use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsFileTests method testFileEnumeration.
@Test
public void testFileEnumeration() {
final Transaction txn = env.beginTransaction();
final TreeSet<String> files = new TreeSet<>();
final int numberOfFiles = (int) (Math.random() * 1000 + 5000);
for (int i = 0; i < numberOfFiles; ++i) {
final String file = "file" + Math.random();
if (!files.contains(file)) {
files.add(file);
vfs.createFile(txn, file);
}
}
final Iterator<String> it = files.iterator();
for (final File file : vfs.getFiles(txn)) {
Assert.assertTrue(it.hasNext());
Assert.assertEquals(file.getPath(), it.next());
}
Assert.assertFalse(it.hasNext());
txn.commit();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsFileTests method testDeleteFile3.
@Test
public void testDeleteFile3() throws IOException {
final Transaction txn = env.beginTransaction();
for (int i = 0; i < 10; ++i) {
final File file0 = vfs.createFile(txn, "file0");
final OutputStream outputStream = vfs.writeFile(txn, file0);
outputStream.write("vain bytes to be deleted".getBytes());
outputStream.close();
txn.flush();
Assert.assertNotNull(vfs.deleteFile(txn, "file0"));
txn.flush();
}
Assert.assertEquals(0L, vfs.getContents().count(txn));
txn.commit();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsFileTests method testTouchFile.
@Test
public void testTouchFile() throws InterruptedException {
final Transaction txn = env.beginTransaction();
vfs.createFile(txn, "file0");
txn.flush();
File file0 = vfs.openFile(txn, "file0", false);
Assert.assertNotNull(file0);
Assert.assertEquals(file0.getCreated(), file0.getLastModified());
Thread.sleep(100);
vfs.touchFile(txn, file0);
txn.flush();
file0 = vfs.openFile(txn, "file0", false);
Assert.assertNotNull(file0);
Assert.assertTrue(file0.getCreated() + 50 < file0.getLastModified());
txn.commit();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeRead5.
@Test
public void writeRead5() 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);
Assert.assertEquals(count, inputStream.read(new byte[100000], 0, 100000));
Assert.assertEquals(-1, inputStream.read());
inputStream.close();
txn.commit();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeReadTrivial.
@Test
public void writeReadTrivial() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
final OutputStream outputStream = vfs.writeFile(txn, file0);
outputStream.close();
final InputStream inputStream = vfs.readFile(txn, file0);
Assert.assertEquals(-1, inputStream.read());
inputStream.close();
txn.commit();
}
Aggregations