Search in sources :

Example 16 with Transaction

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

Example 17 with Transaction

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

Example 18 with Transaction

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

Example 19 with Transaction

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();
}
Also used : Transaction(jetbrains.exodus.env.Transaction) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream)

Example 20 with Transaction

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

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