Search in sources :

Example 41 with Transaction

use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.

the class VfsStreamsTests method writeOverwriteRead2.

@Test
public void writeOverwriteRead2() 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();
    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();
}
Also used : Transaction(jetbrains.exodus.env.Transaction) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 42 with Transaction

use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.

the class VfsStreamsTests method writeRead3.

@Test
public void writeRead3() throws IOException {
    final Transaction txn = env.beginTransaction();
    final File file0 = vfs.createFile(txn, "file0");
    final OutputStream outputStream = vfs.writeFile(txn, file0);
    outputStream.write(0);
    outputStream.close();
    final InputStream inputStream = vfs.readFile(txn, file0);
    Assert.assertEquals(0, inputStream.read());
    inputStream.close();
    txn.commit();
}
Also used : Transaction(jetbrains.exodus.env.Transaction) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 43 with Transaction

use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.

the class VfsStreamsTests method testWriteReadWithStrategy.

private void testWriteReadWithStrategy(@NotNull final ClusteringStrategy strategy) throws IOException {
    vfs.shutdown();
    final VfsConfig config = new VfsConfig();
    config.setClusteringStrategy(strategy);
    vfs = new VirtualFileSystem(getEnvironment(), config);
    final Transaction txn = env.beginTransaction();
    final byte[] bytes = RENAT_GILFANOV.getBytes(UTF_8);
    final File file0 = vfs.createFile(txn, "file0");
    final OutputStream outputStream0 = vfs.appendFile(txn, file0);
    outputStream0.write(bytes);
    outputStream0.close();
    final File file1 = vfs.createFile(txn, "file1");
    final OutputStream outputStream1 = vfs.appendFile(txn, file1);
    outputStream1.write(bytes);
    outputStream1.close();
    final InputStream inputStream0 = vfs.readFile(txn, file0);
    Assert.assertEquals(RENAT_GILFANOV, streamAsString(inputStream0));
    inputStream0.close();
    final InputStream inputStream1 = vfs.readFile(txn, file1);
    Assert.assertEquals(RENAT_GILFANOV, streamAsString(inputStream1));
    inputStream1.close();
    Assert.assertEquals((long) bytes.length, vfs.getFileLength(txn, file0));
    Assert.assertEquals((long) bytes.length, vfs.getFileLength(txn, file1));
    txn.commit();
}
Also used : Transaction(jetbrains.exodus.env.Transaction) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream)

Aggregations

Transaction (jetbrains.exodus.env.Transaction)43 Test (org.junit.Test)33 OutputStream (java.io.OutputStream)22 InputStream (java.io.InputStream)18 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)4 Store (jetbrains.exodus.env.Store)4 TransactionalExecutable (jetbrains.exodus.env.TransactionalExecutable)4 File (java.io.File)3 ByteIterable (jetbrains.exodus.ByteIterable)3 Cursor (jetbrains.exodus.env.Cursor)3 TestFor (jetbrains.exodus.TestFor)2 NotNull (org.jetbrains.annotations.NotNull)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1 BlobsTable (jetbrains.exodus.entitystore.tables.BlobsTable)1 Environment (jetbrains.exodus.env.Environment)1