示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverAfterCrashUnderLoad() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverAfterCrashUnderLoad()
        {
            EphemeralFileSystemAbstraction   @delegate = _fileSystemRule.get();
            AdversarialFileSystemAbstraction fsa       = new AdversarialFileSystemAbstraction(new MethodGuardedAdversary(new CountingAdversary(100, true), typeof(StoreChannel).GetMethod("writeAll", typeof(ByteBuffer))), @delegate);

            long lastValue = 0;

            try
            {
                using (LongState persistedState = new LongState(fsa, _testDir.directory(), 14))
                {
                    while (true)                               // it will break from the Exception that AFS will throw
                    {
                        long tempValue = lastValue + 1;
                        persistedState.TheState = tempValue;
                        lastValue = tempValue;
                    }
                }
            }
            catch (Exception expected)
            {
                EnsureStackTraceContainsExpectedMethod(expected.StackTrace, "writeAll");
            }

            using (LongState restoredState = new LongState(@delegate, _testDir.directory(), 4))
            {
                assertEquals(lastValue, restoredState.TheState);
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyRecoveryAfterCloseOnActiveFileDuringRotation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProperlyRecoveryAfterCloseOnActiveFileDuringRotation()
        {
            EphemeralFileSystemAbstraction   normalFSA   = _fileSystemRule.get();
            AdversarialFileSystemAbstraction breakingFSA = new AdversarialFileSystemAbstraction(new MethodGuardedAdversary(new CountingAdversary(5, true), typeof(StoreChannel).GetMethod("close")), normalFSA);
            SelectiveFileSystemAbstraction   combinedFSA = new SelectiveFileSystemAbstraction(new File(new File(_testDir.directory(), "long-state"), "long.a"), breakingFSA, normalFSA);

            long lastValue = 0;

            try
            {
                using (LongState persistedState = new LongState(combinedFSA, _testDir.directory(), 14))
                {
                    while (true)                               // it will break from the Exception that AFS will throw
                    {
                        long tempValue = lastValue + 1;
                        persistedState.TheState = tempValue;
                        lastValue = tempValue;
                    }
                }
            }
            catch (Exception expected)
            {
                // this stack trace should contain close()
                EnsureStackTraceContainsExpectedMethod(expected.StackTrace, "close");
            }

            using (LongState restoredState = new LongState(normalFSA, _testDir.directory(), 14))
            {
                assertThat(restoredState.TheState, greaterThanOrEqualTo(lastValue));
            }
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyRecoveryAfterCrashingDuringRecovery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProperlyRecoveryAfterCrashingDuringRecovery()
        {
            EphemeralFileSystemAbstraction normalFSA = _fileSystemRule.get();

            long lastValue = 0;

            using (LongState persistedState = new LongState(normalFSA, _testDir.directory(), 14))
            {
                for (int i = 0; i < 100; i++)
                {
                    long tempValue = lastValue + 1;
                    persistedState.TheState = tempValue;
                    lastValue = tempValue;
                }
            }

            try
            {
                // We create a new state that will attempt recovery. The AFS will make it fail on open() of one of the files
                new LongState(new AdversarialFileSystemAbstraction(new MethodGuardedAdversary(new CountingAdversary(1, true), typeof(FileSystemAbstraction).GetMethod("open", typeof(File), typeof(OpenMode))), normalFSA), _testDir.directory(), 14);
                fail("Should have failed recovery");
            }
            catch (Exception expected)
            {
                // this stack trace should contain open()
                EnsureStackTraceContainsExpectedMethod(expected.InnerException.StackTrace, "open");
            }

            // Recovery over the normal filesystem after a failed recovery should proceed correctly
            using (LongState recoveredState = new LongState(normalFSA, _testDir.directory(), 14))
            {
                assertThat(recoveredState.TheState, greaterThanOrEqualTo(lastValue));
            }
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyRecoveryAfterCrashOnFileForceDuringWrite() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProperlyRecoveryAfterCrashOnFileForceDuringWrite()
        {
            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), typeof(StoreChannel).GetMethod("force", typeof(bool))), normalFSA);
            SelectiveFileSystemAbstraction   combinedFSA = new SelectiveFileSystemAbstraction(new File(new File(_testDir.directory(), "long-state"), "long.a"), breakingFSA, normalFSA);

            long lastValue = 0;

            try
            {
                using (LongState persistedState = new LongState(combinedFSA, _testDir.directory(), 14))
                {
                    while (true)                               // it will break from the Exception that AFS will throw
                    {
                        long tempValue = lastValue + 1;
                        persistedState.TheState = tempValue;
                        lastValue = tempValue;
                    }
                }
            }
            catch (Exception expected)
            {
                // this stack trace should contain force()
                EnsureStackTraceContainsExpectedMethod(expected.StackTrace, "force");
            }

            using (LongState restoredState = new LongState(normalFSA, _testDir.directory(), 14))
            {
                assertThat(restoredState.TheState, greaterThanOrEqualTo(lastValue));
            }
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyRecoveryAfterCrashOnFileCreationDuringRotation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProperlyRecoveryAfterCrashOnFileCreationDuringRotation()
        {
            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), typeof(FileSystemAbstraction).GetMethod("truncate", typeof(File), typeof(long))), normalFSA);
            SelectiveFileSystemAbstraction   combinedFSA = new SelectiveFileSystemAbstraction(new File(new File(_testDir.directory(), "long-state"), "long.a"), breakingFSA, normalFSA);

            long lastValue = 0;

            try
            {
                using (LongState persistedState = new LongState(combinedFSA, _testDir.directory(), 14))
                {
                    while (true)                               // it will break from the Exception that AFS will throw
                    {
                        long tempValue = lastValue + 1;
                        persistedState.TheState = tempValue;
                        lastValue = tempValue;
                    }
                }
            }
            catch (Exception expected)
            {
                // this stack trace should contain FSA.truncate()
                EnsureStackTraceContainsExpectedMethod(expected.StackTrace, "truncate");
            }

            using (LongState restoredState = new LongState(normalFSA, _testDir.directory(), 14))
            {
                assertEquals(lastValue, restoredState.TheState);
            }
        }
示例#6
0
 public SafeStateMarshalAnonymousInnerClass(LongState outerInstance)
 {
     this.outerInstance = outerInstance;
 }