Search in sources :

Example 36 with Transaction

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

Example 37 with Transaction

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

Example 38 with Transaction

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

Example 39 with Transaction

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

Example 40 with Transaction

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();
}
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