Search in sources :

Example 11 with Transaction

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

the class VfsFileTests method testNumberOfFiles.

@Test
public void testNumberOfFiles() {
    final Transaction txn = env.beginTransaction();
    final HashSet<String> files = new HashSet<>();
    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);
        }
    }
    Assert.assertEquals(files.size(), vfs.getNumberOfFiles(txn));
    txn.commit();
}
Also used : Transaction(jetbrains.exodus.env.Transaction) HashSet(jetbrains.exodus.core.dataStructures.hash.HashSet) Test(org.junit.Test)

Example 12 with Transaction

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

the class VfsFileTests method testFileCreation1.

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

Example 13 with Transaction

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

the class VfsStreamsTests method writeOverwriteAppendRead.

@Test
public void writeOverwriteAppendRead() 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();
    outputStream = vfs.appendFile(txn, file0);
    outputStream.write(HOEGAARDEN.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) + 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)

Example 14 with Transaction

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

the class VfsStreamsTests method testWriteAndSeek3.

@Test
@TestFor(issues = "XD-624")
public void testWriteAndSeek3() throws IOException {
    Transaction txn = env.beginTransaction();
    vfs.getConfig().setClusteringStrategy(new ClusteringStrategy.LinearClusteringStrategy(8));
    final File file = vfs.createFile(txn, "file0");
    OutputStream outputStream = vfs.writeFile(txn, file);
    final byte[] bytes = HOEGAARDEN.getBytes(UTF_8);
    outputStream.write(bytes);
    outputStream.close();
    outputStream = vfs.appendFile(txn, file);
    outputStream.write(bytes);
    outputStream.close();
    txn.flush();
    final InputStream inputStream = vfs.readFile(txn, file);
    Assert.assertEquals(HOEGAARDEN + HOEGAARDEN, streamAsString(inputStream));
    txn.abort();
}
Also used : Transaction(jetbrains.exodus.env.Transaction) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Test(org.junit.Test) TestFor(jetbrains.exodus.TestFor)

Example 15 with Transaction

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

the class VfsStreamsTests method writeRead2.

@Test
public void writeRead2() 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();
    final InputStream inputStream = vfs.readFile(txn, file0);
    Assert.assertEquals(HOEGAARDEN, streamAsString(inputStream));
    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