Search in sources :

Example 6 with AdversarialFileSystemAbstraction

use of org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction in project neo4j by neo4j.

the class DurableStateStorageIT method shouldProperlyRecoveryAfterCloseOnActiveFileDuringRotation.

@Test
public void shouldProperlyRecoveryAfterCloseOnActiveFileDuringRotation() throws Exception {
    EphemeralFileSystemAbstraction normalFSA = fileSystemRule.get();
    AdversarialFileSystemAbstraction breakingFSA = new AdversarialFileSystemAbstraction(new MethodGuardedAdversary(new CountingAdversary(5, true), StoreChannel.class.getMethod("close")), normalFSA);
    SelectiveFileSystemAbstraction combinedFSA = new SelectiveFileSystemAbstraction(new File(new File(testDir.directory(), "long-state"), "long.a"), breakingFSA, normalFSA);
    long lastValue = 0;
    try (LongState persistedState = new LongState(combinedFSA, testDir.directory(), 14)) {
        while (// it will break from the Exception that AFS will throw
        true) {
            long tempValue = lastValue + 1;
            persistedState.setTheState(tempValue);
            lastValue = tempValue;
        }
    } catch (Exception expected) {
        // this stack trace should contain close()
        ensureStackTraceContainsExpectedMethod(expected.getStackTrace(), "close");
    }
    try (LongState restoredState = new LongState(normalFSA, testDir.directory(), 14)) {
        assertThat(restoredState.getTheState(), greaterThanOrEqualTo(lastValue));
    }
}
Also used : MethodGuardedAdversary(org.neo4j.adversaries.MethodGuardedAdversary) CountingAdversary(org.neo4j.adversaries.CountingAdversary) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) SelectiveFileSystemAbstraction(org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) File(java.io.File) IOException(java.io.IOException) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) Test(org.junit.Test)

Example 7 with AdversarialFileSystemAbstraction

use of org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction in project neo4j by neo4j.

the class DurableStateStorageIT method shouldProperlyRecoveryAfterCrashOnFileCreationDuringRotation.

@Test
public void shouldProperlyRecoveryAfterCrashOnFileCreationDuringRotation() throws Exception {
    EphemeralFileSystemAbstraction normalFSA = fileSystemRule.get();
    /*
         * Magic number warning. For a rotation threshold of 14, 998 operations on file A falls on truncation of the
         * file during rotation. This has been discovered via experimentation. The end result is that there is a
         * failure to create the file to rotate to. This should be recoverable.
         */
    AdversarialFileSystemAbstraction breakingFSA = new AdversarialFileSystemAbstraction(new MethodGuardedAdversary(new CountingAdversary(20, true), FileSystemAbstraction.class.getMethod("truncate", File.class, long.class)), normalFSA);
    SelectiveFileSystemAbstraction combinedFSA = new SelectiveFileSystemAbstraction(new File(new File(testDir.directory(), "long-state"), "long.a"), breakingFSA, normalFSA);
    long lastValue = 0;
    try (LongState persistedState = new LongState(combinedFSA, testDir.directory(), 14)) {
        while (// it will break from the Exception that AFS will throw
        true) {
            long tempValue = lastValue + 1;
            persistedState.setTheState(tempValue);
            lastValue = tempValue;
        }
    } catch (Exception expected) {
        // this stack trace should contain FSA.truncate()
        ensureStackTraceContainsExpectedMethod(expected.getStackTrace(), "truncate");
    }
    try (LongState restoredState = new LongState(normalFSA, testDir.directory(), 14)) {
        assertEquals(lastValue, restoredState.getTheState());
    }
}
Also used : MethodGuardedAdversary(org.neo4j.adversaries.MethodGuardedAdversary) CountingAdversary(org.neo4j.adversaries.CountingAdversary) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) SelectiveFileSystemAbstraction(org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) File(java.io.File) IOException(java.io.IOException) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) Test(org.junit.Test)

Example 8 with AdversarialFileSystemAbstraction

use of org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction in project neo4j by neo4j.

the class RotatingFileOutputStreamSupplierTest method shouldSurviveFilesystemErrors.

@Test
public void shouldSurviveFilesystemErrors() throws Exception {
    final RandomAdversary adversary = new RandomAdversary(0.1, 0.1, 0);
    adversary.setProbabilityFactor(0);
    AdversarialFileSystemAbstraction adversarialFileSystem = new SensibleAdversarialFileSystemAbstraction(adversary, fileSystem);
    RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(adversarialFileSystem, logFile, 1000, 0, 9, DIRECT_EXECUTOR);
    adversary.setProbabilityFactor(1);
    writeLines(supplier, 10000);
    // run cleanly for a while, to allow it to fill any gaps left in log archive numbers
    adversary.setProbabilityFactor(0);
    writeLines(supplier, 10000);
    assertThat(fileSystem.fileExists(logFile), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile1), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile2), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile3), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile4), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile5), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile6), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile7), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile8), is(true));
    assertThat(fileSystem.fileExists(archiveLogFile9), is(true));
}
Also used : AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) RandomAdversary(org.neo4j.adversaries.RandomAdversary) Test(org.junit.Test)

Example 9 with AdversarialFileSystemAbstraction

use of org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction in project neo4j by neo4j.

the class FileSenderTest method sendLargeFileWithUnreliableReadBufferSize.

@Test
public void sendLargeFileWithUnreliableReadBufferSize() throws Exception {
    // given
    byte[] bytes = new byte[MAX_SIZE * 3];
    random.nextBytes(bytes);
    File smallFile = testDirectory.file("smallFile");
    try (StoreChannel storeChannel = fs.create(smallFile)) {
        storeChannel.write(ByteBuffer.wrap(bytes));
    }
    Adversary adversary = new RandomAdversary(0.9, 0.0, 0.0);
    AdversarialFileSystemAbstraction afs = new AdversarialFileSystemAbstraction(adversary, fs);
    FileSender fileSender = new FileSender(afs.open(smallFile, "r"));
    // when + then
    assertFalse(fileSender.isEndOfInput());
    assertEquals(FileChunk.create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.readChunk(allocator));
    assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE, MAX_SIZE * 2), false), fileSender.readChunk(allocator));
    assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE * 2, bytes.length), true), fileSender.readChunk(allocator));
    assertNull(fileSender.readChunk(allocator));
    assertTrue(fileSender.isEndOfInput());
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) RandomAdversary(org.neo4j.adversaries.RandomAdversary) Adversary(org.neo4j.adversaries.Adversary) RandomAdversary(org.neo4j.adversaries.RandomAdversary) Test(org.junit.Test)

Example 10 with AdversarialFileSystemAbstraction

use of org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction in project neo4j by neo4j.

the class DurableStateStorageIT method shouldProperlyRecoveryAfterCrashOnFileForceDuringWrite.

@Test
public void shouldProperlyRecoveryAfterCrashOnFileForceDuringWrite() throws Exception {
    EphemeralFileSystemAbstraction normalFSA = fileSystemRule.get();
    /*
         * Magic number warning. For a rotation threshold of 14, 990 operations on file A falls on a force() of the
         * current active file. This has been discovered via experimentation. The end result is that there is a
         * flush (but not write) a value. This should be recoverable. Interestingly, the failure semantics are a bit
         * unclear on what should happen to that value. We assume that exception during persistence requires recovery
         * to discover if the last argument made it to disk or not. Since we use an EFSA, force is not necessary and
         * the value that caused the failure is actually "persisted" and recovered.
         */
    AdversarialFileSystemAbstraction breakingFSA = new AdversarialFileSystemAbstraction(new MethodGuardedAdversary(new CountingAdversary(40, true), StoreChannel.class.getMethod("force", boolean.class)), normalFSA);
    SelectiveFileSystemAbstraction combinedFSA = new SelectiveFileSystemAbstraction(new File(new File(testDir.directory(), "long-state"), "long.a"), breakingFSA, normalFSA);
    long lastValue = 0;
    try (LongState persistedState = new LongState(combinedFSA, testDir.directory(), 14)) {
        while (// it will break from the Exception that AFS will throw
        true) {
            long tempValue = lastValue + 1;
            persistedState.setTheState(tempValue);
            lastValue = tempValue;
        }
    } catch (Exception expected) {
        // this stack trace should contain force()
        ensureStackTraceContainsExpectedMethod(expected.getStackTrace(), "force");
    }
    try (LongState restoredState = new LongState(normalFSA, testDir.directory(), 14)) {
        assertThat(restoredState.getTheState(), greaterThanOrEqualTo(lastValue));
    }
}
Also used : MethodGuardedAdversary(org.neo4j.adversaries.MethodGuardedAdversary) CountingAdversary(org.neo4j.adversaries.CountingAdversary) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) SelectiveFileSystemAbstraction(org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) File(java.io.File) IOException(java.io.IOException) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) Test(org.junit.Test)

Aggregations

AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)15 Test (org.junit.Test)14 File (java.io.File)12 RandomAdversary (org.neo4j.adversaries.RandomAdversary)8 CountingAdversary (org.neo4j.adversaries.CountingAdversary)7 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)7 IOException (java.io.IOException)6 MethodGuardedAdversary (org.neo4j.adversaries.MethodGuardedAdversary)5 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)5 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)5 SelectiveFileSystemAbstraction (org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction)4 PageSwapper (org.neo4j.io.pagecache.PageSwapper)4 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 Adversary (org.neo4j.adversaries.Adversary)2 ClassGuardedAdversary (org.neo4j.adversaries.ClassGuardedAdversary)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1