Search in sources :

Example 1 with FileDataReader

use of jetbrains.exodus.io.FileDataReader in project xodus by JetBrains.

the class EnvironmentTest method createReaderWriter.

private Pair<DataReader, DataWriter> createReaderWriter(String subfolder) throws IOException {
    final File parent = getEnvDirectory();
    File child = subfolders.get(subfolder);
    if (child == null) {
        child = new File(parent, subfolder);
        if (child.exists())
            throw new IOException("SubDirectory already exists " + subfolder);
        if (!child.mkdirs()) {
            throw new IOException("Failed to create directory " + subfolder + " for tests.");
        }
        subfolders.put(subfolder, child);
    }
    FileDataReader reader = new FileDataReader(child);
    return new Pair<>(reader, new FileDataWriter(reader));
}
Also used : FileDataReader(jetbrains.exodus.io.FileDataReader) FileDataWriter(jetbrains.exodus.io.FileDataWriter) IOException(java.io.IOException) File(java.io.File) Pair(jetbrains.exodus.core.dataStructures.Pair)

Example 2 with FileDataReader

use of jetbrains.exodus.io.FileDataReader in project xodus by JetBrains.

the class EnvironmentLockTest method openConcurrentEnvironment.

private void openConcurrentEnvironment() {
    processor.start();
    new Job(processor) {

        @Override
        protected void execute() {
            final File dir = getEnvDirectory();
            try {
                FileDataReader reader = new FileDataReader(dir);
                env = newEnvironmentInstance(LogConfig.create(reader, new FileDataWriter(reader, LOCK_ID)), new EnvironmentConfig().setLogLockTimeout(5000));
                wasOpened[0] = true;
            } catch (ExodusException e) {
                Assert.assertTrue(e.getMessage().contains(LOCK_ID));
                wasOpened[0] = false;
            }
        }
    };
}
Also used : FileDataReader(jetbrains.exodus.io.FileDataReader) FileDataWriter(jetbrains.exodus.io.FileDataWriter) Job(jetbrains.exodus.core.execution.Job) File(java.io.File) ExodusException(jetbrains.exodus.ExodusException)

Example 3 with FileDataReader

use of jetbrains.exodus.io.FileDataReader in project xodus by JetBrains.

the class EnvironmentLockTest method testAlreadyLockedEnvironment.

@Test
public void testAlreadyLockedEnvironment() {
    boolean exOnCreate = false;
    Environment first = null;
    try {
        final File dir = getEnvDirectory();
        FileDataReader reader = new FileDataReader(dir);
        first = Environments.newInstance(LogConfig.create(reader, new FileDataWriter(reader)), EnvironmentConfig.DEFAULT);
    } catch (ExodusException ex) {
        // Environment already created on startup!
        exOnCreate = true;
    }
    if (first != null)
        first.close();
    Assert.assertTrue(exOnCreate);
}
Also used : FileDataReader(jetbrains.exodus.io.FileDataReader) FileDataWriter(jetbrains.exodus.io.FileDataWriter) File(java.io.File) ExodusException(jetbrains.exodus.ExodusException) Test(org.junit.Test)

Aggregations

File (java.io.File)3 FileDataReader (jetbrains.exodus.io.FileDataReader)3 FileDataWriter (jetbrains.exodus.io.FileDataWriter)3 ExodusException (jetbrains.exodus.ExodusException)2 IOException (java.io.IOException)1 Pair (jetbrains.exodus.core.dataStructures.Pair)1 Job (jetbrains.exodus.core.execution.Job)1 Test (org.junit.Test)1