use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsFileTests method testNumberOfFiles.
@Test
public void testNumberOfFiles() {
final Transaction txn = env.beginTransaction();
final HashSet<String> files = new HashSet<>();
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);
}
}
Assert.assertEquals(files.size(), vfs.getNumberOfFiles(txn));
txn.commit();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsFileTests method testFileCreation1.
@Test
public void testFileCreation1() {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.openFile(txn, "file0", true);
txn.commit();
Assert.assertNotNull(file0);
Assert.assertEquals(0L, file0.getDescriptor());
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeOverwriteAppendRead.
@Test
public void writeOverwriteAppendRead() 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();
outputStream = vfs.writeFile(txn, file0);
outputStream.write("x".getBytes(UTF_8));
outputStream.write(HOEGAARDEN.substring(1).getBytes(UTF_8));
outputStream.write("x".getBytes(UTF_8));
outputStream.write(HOEGAARDEN.substring(1).getBytes(UTF_8));
outputStream.write("x".getBytes(UTF_8));
outputStream.write(HOEGAARDEN.substring(1).getBytes(UTF_8));
outputStream.write("x".getBytes(UTF_8));
outputStream.write(HOEGAARDEN.substring(1).getBytes(UTF_8));
outputStream.close();
txn.flush();
outputStream = vfs.appendFile(txn, file0);
outputStream.write(HOEGAARDEN.getBytes(UTF_8));
outputStream.close();
txn.flush();
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) + HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
txn.abort();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method testWriteAndSeek3.
@Test
@TestFor(issues = "XD-624")
public void testWriteAndSeek3() throws IOException {
Transaction txn = env.beginTransaction();
vfs.getConfig().setClusteringStrategy(new ClusteringStrategy.LinearClusteringStrategy(8));
final File file = vfs.createFile(txn, "file0");
OutputStream outputStream = vfs.writeFile(txn, file);
final byte[] bytes = HOEGAARDEN.getBytes(UTF_8);
outputStream.write(bytes);
outputStream.close();
outputStream = vfs.appendFile(txn, file);
outputStream.write(bytes);
outputStream.close();
txn.flush();
final InputStream inputStream = vfs.readFile(txn, file);
Assert.assertEquals(HOEGAARDEN + HOEGAARDEN, streamAsString(inputStream));
txn.abort();
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsStreamsTests method writeRead2.
@Test
public void writeRead2() 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();
final InputStream inputStream = vfs.readFile(txn, file0);
Assert.assertEquals(HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
txn.commit();
}
Aggregations