Search in sources :

Example 6 with Transaction

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

the class VfsFileTests method testRenameFile.

@Test
public void testRenameFile() throws InterruptedException {
    testFileCreation();
    final Transaction txn = env.beginTransaction();
    File file0 = vfs.openFile(txn, "file0", false);
    txn.revert();
    Assert.assertNotNull(file0);
    final long fd = file0.getDescriptor();
    final long created = file0.getCreated();
    final long lastModified = file0.getLastModified();
    Thread.sleep(50);
    vfs.renameFile(txn, file0, "file1");
    txn.flush();
    file0 = vfs.openFile(txn, "file0", false);
    File file1 = vfs.openFile(txn, "file1", false);
    txn.abort();
    Assert.assertNull(file0);
    Assert.assertNotNull(file1);
    Assert.assertEquals(fd, file1.getDescriptor());
    Assert.assertEquals(created, file1.getCreated());
    Assert.assertTrue(file1.getLastModified() > lastModified);
}
Also used : Transaction(jetbrains.exodus.env.Transaction) Test(org.junit.Test)

Example 7 with Transaction

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

the class VfsFileTests method testDeleteFile4.

@Test
public void testDeleteFile4() throws IOException {
    final Transaction txn = env.beginTransaction();
    for (int i = 0; i < 50; ++i) {
        final File file0 = vfs.createFile(txn, "file0");
        final OutputStream outputStream = vfs.writeFile(txn, file0);
        for (int j = 0; j < i; ++j) {
            outputStream.write(new byte[vfs.getConfig().getClusteringStrategy().getFirstClusterSize()]);
        }
        outputStream.write("vain bytes to be deleted".getBytes());
        for (int j = 0; j < i + 1; ++j) {
            outputStream.write(new byte[vfs.getConfig().getClusteringStrategy().getFirstClusterSize()]);
        }
        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 8 with Transaction

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

the class VfsFileTests method testDeleteFile2.

@Test
public void testDeleteFile2() {
    Transaction txn = env.beginTransaction();
    vfs.createFile(txn, "file0");
    txn.flush();
    vfs.deleteFile(txn, "file0");
    txn.flush();
    Assert.assertNull(vfs.openFile(txn, "file0", false));
    final File file0 = vfs.openFile(txn, "file0", true);
    txn.commit();
    Assert.assertNotNull(file0);
    Assert.assertEquals("file0", file0.getPath());
}
Also used : Transaction(jetbrains.exodus.env.Transaction) Test(org.junit.Test)

Example 9 with Transaction

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

the class VfsFileTests method testOpenFile.

@Test
public void testOpenFile() {
    testFileCreation();
    final Transaction txn = env.beginTransaction();
    final File file0 = vfs.openFile(txn, "file0", false);
    txn.commit();
    Assert.assertNotNull(file0);
    Assert.assertEquals(0L, file0.getDescriptor());
    Assert.assertTrue(file0.getCreated() > 0);
    Assert.assertTrue(file0.getLastModified() > 0);
}
Also used : Transaction(jetbrains.exodus.env.Transaction) Test(org.junit.Test)

Example 10 with Transaction

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

the class VfsFileTests method testDeleteFile.

@Test
public void testDeleteFile() {
    Transaction txn = env.beginTransaction();
    vfs.createFile(txn, "file0");
    txn.commit();
    txn = env.beginTransaction();
    final File file0 = vfs.deleteFile(txn, "file0");
    txn.commit();
    Assert.assertNotNull(file0);
    Assert.assertEquals("file0", file0.getPath());
}
Also used : Transaction(jetbrains.exodus.env.Transaction) 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