Search in sources :

Example 31 with Transaction

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

Example 32 with Transaction

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

Example 33 with Transaction

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

Example 34 with Transaction

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

Example 35 with Transaction

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