Search in sources :

Example 6 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class NeoStoresRule method open.

public NeoStores open(RecordFormats format, String... config) throws IOException {
    efs = new EphemeralFileSystemAbstraction();
    Config conf = Config.embeddedDefaults(stringMap(config));
    pageCache = getOrCreatePageCache(conf, efs);
    return open(efs, pageCache, format, config);
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config)

Example 7 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class BatchInsertersTest method providedFileSystemNotClosedAfterShutdown.

@Test
public void providedFileSystemNotClosedAfterShutdown() throws IOException {
    EphemeralFileSystemAbstraction fs = fileSystemRule.get();
    vefiryProvidedFileSystemOpenAfterShutdown(inserter(getStoreDir(), fs), fs);
    vefiryProvidedFileSystemOpenAfterShutdown(inserter(getStoreDir(), fs, getConfig()), fs);
    vefiryProvidedFileSystemOpenAfterShutdown(inserter(getStoreDir(), fs, getConfig(), getKernelExtensions()), fs);
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Test(org.junit.Test)

Example 8 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class TestEphemeralFileChannel method smoke.

@Test
public void smoke() throws Exception {
    EphemeralFileSystemAbstraction fs = fileSystemRule.get();
    StoreChannel channel = fs.open(new File("yo"), "rw");
    // Clear it because we depend on it to be zeros where we haven't written
    ByteBuffer buffer = allocateDirect(23);
    // zeros
    buffer.put(new byte[23]);
    buffer.flip();
    channel.write(buffer);
    channel = fs.open(new File("yo"), "rw");
    long longValue = 1234567890L;
    // [1].....[2]........[1234567890L]...
    buffer.clear();
    buffer.limit(1);
    buffer.put((byte) 1);
    buffer.flip();
    channel.write(buffer);
    buffer.clear();
    buffer.limit(1);
    buffer.put((byte) 2);
    buffer.flip();
    channel.position(6);
    channel.write(buffer);
    buffer.clear();
    buffer.limit(8);
    buffer.putLong(longValue);
    buffer.flip();
    channel.position(15);
    channel.write(buffer);
    assertEquals(23, channel.size());
    // Read with position
    // byte 0
    buffer.clear();
    buffer.limit(1);
    channel.read(buffer, 0);
    buffer.flip();
    assertEquals((byte) 1, buffer.get());
    // bytes 5-7
    buffer.clear();
    buffer.limit(3);
    channel.read(buffer, 5);
    buffer.flip();
    assertEquals((byte) 0, buffer.get());
    assertEquals((byte) 2, buffer.get());
    assertEquals((byte) 0, buffer.get());
    // bytes 15-23
    buffer.clear();
    buffer.limit(8);
    channel.read(buffer, 15);
    buffer.flip();
    assertEquals(longValue, buffer.getLong());
    fs.close();
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 9 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class TestEphemeralFileChannel method listFiles.

@Test
public void listFiles() throws Exception {
    /* GIVEN
         *                        root
         *                       /    \
         *         ----------- dir1   dir2
         *        /       /     |       \
         *    subdir1  file  file2      file
         *       |
         *     file
         */
    EphemeralFileSystemAbstraction fs = fileSystemRule.get();
    File root = new File("/root").getCanonicalFile();
    File dir1 = new File(root, "dir1");
    File dir2 = new File(root, "dir2");
    File subdir1 = new File(dir1, "sub");
    File file1 = new File(dir1, "file");
    File file2 = new File(dir1, "file2");
    File file3 = new File(dir2, "file");
    File file4 = new File(subdir1, "file");
    fs.mkdirs(dir2);
    fs.mkdirs(dir1);
    fs.mkdirs(subdir1);
    fs.create(file1);
    fs.create(file2);
    fs.create(file3);
    fs.create(file4);
    // THEN
    assertEquals(asSet(dir1, dir2), asSet(fs.listFiles(root)));
    assertEquals(asSet(subdir1, file1, file2), asSet(fs.listFiles(dir1)));
    assertEquals(asSet(file3), asSet(fs.listFiles(dir2)));
    assertEquals(asSet(file4), asSet(fs.listFiles(subdir1)));
    fs.close();
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) File(java.io.File) Test(org.junit.Test)

Example 10 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class TestGraphProperties method produceUncleanStore.

private EphemeralFileSystemAbstraction produceUncleanStore(EphemeralFileSystemAbstraction fileSystem, File storeDir) {
    GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem(fileSystem).newImpermanentDatabase(storeDir);
    Transaction tx = db.beginTx();
    Node node = db.createNode();
    node.setProperty("name", "Something");
    properties((GraphDatabaseAPI) db).setProperty("prop", "Some value");
    tx.success();
    tx.close();
    EphemeralFileSystemAbstraction snapshot = fileSystem.snapshot();
    db.shutdown();
    return snapshot;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)

Aggregations

EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)54 Test (org.junit.Test)37 File (java.io.File)27 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)10 StoreChannel (org.neo4j.io.fs.StoreChannel)8 IOException (java.io.IOException)7 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)7 Before (org.junit.Before)6 CountingAdversary (org.neo4j.adversaries.CountingAdversary)6 Transaction (org.neo4j.graphdb.Transaction)6 ByteBuffer (java.nio.ByteBuffer)5 MethodGuardedAdversary (org.neo4j.adversaries.MethodGuardedAdversary)5 StateRecoveryManager (org.neo4j.causalclustering.core.state.StateRecoveryManager)5 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Node (org.neo4j.graphdb.Node)4 SelectiveFileSystemAbstraction (org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4