Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void sendLargeFileWithUnreliableReadBufferSize() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SendLargeFileWithUnreliableReadBufferSize()
        {
            // given
            sbyte[] bytes = new sbyte[MAX_SIZE * 3];
            _random.NextBytes(bytes);

            File smallFile = TestDirectory.file("smallFile");

            using (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(new StoreResource(smallFile, null, 16, afs));

            // when + then
            assertFalse(fileSender.EndOfInput);
            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.EndOfInput);
        }
Example #2
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);
            }
        }
Example #3
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));
            }
        }
        /*
         * There was an issue where if multiple concurrent appending threads did append and they moved on
         * to await a force, where the force would fail and the one doing the force would raise a panic...
         * the other threads may not notice the panic and move on to mark those transactions as committed
         * and notice the panic later (which would be too late).
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveAllConcurrentAppendersSeePanic() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHaveAllConcurrentAppendersSeePanic()
        {
            // GIVEN
            Adversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, true), FailMethod(typeof(BatchingTransactionAppender), "force"));
            EphemeralFileSystemAbstraction efs = new EphemeralFileSystemAbstraction();
            FileSystemAbstraction          fs  = new AdversarialFileSystemAbstraction(adversary, efs);

            _life.add(new FileSystemLifecycleAdapter(fs));
            DatabaseHealth databaseHealth = new DatabaseHealth(mock(typeof(DatabasePanicEventGenerator)), NullLog.Instance);
            LogFiles       logFiles       = LogFilesBuilder.builder(_testDirectory.databaseLayout(), fs).withLogVersionRepository(_logVersionRepository).withTransactionIdStore(_transactionIdStore).build();

            _life.add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final BatchingTransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, explicitIndexTransactionOrdering, databaseHealth));
            BatchingTransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, _logRotation, _transactionMetadataCache, _transactionIdStore, _explicitIndexTransactionOrdering, databaseHealth));

            _life.start();

            // WHEN
            int numberOfAppenders = 10;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch trap = new java.util.concurrent.CountDownLatch(numberOfAppenders);
            System.Threading.CountdownEvent trap = new System.Threading.CountdownEvent(numberOfAppenders);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent beforeForceTrappingEvent = new org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent_Empty()
            LogAppendEvent beforeForceTrappingEvent = new LogAppendEvent_EmptyAnonymousInnerClass(this, trap);
            Race           race = new Race();

            for (int i = 0; i < numberOfAppenders; i++)
            {
                race.AddContestant(() =>
                {
                    try
                    {
                        // Append to the log, the LogAppenderEvent will have all of the appending threads
                        // do wait for all of the other threads to start the force thing
                        appender.Append(Tx(), beforeForceTrappingEvent);
                        fail("No transaction should be considered appended");
                    }
                    catch (IOException)
                    {
                        // Good, we know that this test uses an adversarial file system which will throw
                        // an exception in BatchingTransactionAppender#force, and since all these transactions
                        // will append and be forced in the same batch, where the force will fail then
                        // all these transactions should fail. If there's any transaction not failing then
                        // it just didn't notice the panic, which would be potentially hazardous.
                    }
                });
            }

            // THEN perform the race. The relevant assertions are made inside the contestants.
            race.Go();
        }
Example #5
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));
            }
        }
Example #6
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);
            }
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @RepeatedTest(20) void pageCacheMustRemainInternallyConsistentWhenGettingRandomFailures()
        internal virtual void PageCacheMustRemainInternallyConsistentWhenGettingRandomFailures()
        {
            assertTimeout(ofMillis(LONG_TIMEOUT_MILLIS), () =>
            {
                // NOTE: This test is inherently non-deterministic. This means that every failure must be
                // thoroughly investigated, since they have a good chance of being a real issue.
                // This is effectively a targeted robustness test.

                RandomAdversary adversary   = new RandomAdversary(0.5, 0.2, 0.2);
                adversary.ProbabilityFactor = 0.0;
                FileSystemAbstraction fs    = new AdversarialFileSystemAbstraction(adversary, this.fs);
                ThreadLocalRandom rng       = ThreadLocalRandom.current();

                // Because our test failures are non-deterministic, we use this tracer to capture a full history of the
                // events leading up to any given failure.
                LinearTracers linearTracers = LinearHistoryTracerFactory.pageCacheTracer();
                getPageCache(fs, maxPages, linearTracers.PageCacheTracer, linearTracers.CursorTracerSupplier);

                PagedFile pfA = pageCache.map(existingFile("a"), filePageSize);
                PagedFile pfB = pageCache.map(existingFile("b"), filePageSize / 2 + 1);
                adversary.ProbabilityFactor = 1.0;

                for (int i = 0; i < 1000; i++)
                {
                    PagedFile pagedFile = rng.nextBoolean() ? pfA : pfB;
                    long maxPageId      = pagedFile.LastPageId;
                    bool performingRead = rng.nextBoolean() && maxPageId != -1;
                    long startingPage   = maxPageId < 0 ? 0 : rng.nextLong(maxPageId + 1);
                    int pfFlags         = performingRead ? PF_SHARED_READ_LOCK : PF_SHARED_WRITE_LOCK;
                    int pageSize        = pagedFile.PageSize();

                    try
                    {
                        using (PageCursor cursor = pagedFile.Io(startingPage, pfFlags))
                        {
                            if (performingRead)
                            {
                                PerformConsistentAdversarialRead(cursor, maxPageId, startingPage, pageSize);
                            }
                            else
                            {
                                PerformConsistentAdversarialWrite(cursor, rng, pageSize);
                            }
                        }
                    }
                    catch (AssertionError error)
                    {
                        // Capture any exception that might have hit the eviction thread.
                        adversary.ProbabilityFactor = 0.0;
                        try
                        {
                            using (PageCursor cursor = pagedFile.Io(0, PF_SHARED_WRITE_LOCK))
                            {
                                for (int j = 0; j < 100; j++)
                                {
                                    cursor.Next(rng.nextLong(maxPageId + 1));
                                }
                            }
                        }
                        catch (Exception throwable)
                        {
                            error.addSuppressed(throwable);
                        }

                        throw error;
                    }
                    catch (Exception)
                    {
                        // Don't worry about it... it's fine!
//                throwable.printStackTrace(); // only enable this when debugging test failures.
                    }
                }

                // Unmapping will cause pages to be flushed.
                // We don't want that to fail, since it will upset the test tear-down.
                adversary.ProbabilityFactor = 0.0;
                try
                {
                    // Flushing all pages, if successful, should clear any internal
                    // exception.
                    pageCache.flushAndForce();

                    // Do some post-chaos verification of what has been written.
                    VerifyAdversarialPagedContent(pfA);
                    VerifyAdversarialPagedContent(pfB);

                    pfA.Close();
                    pfB.Close();
                }
                catch (Exception e)
                {
                    linearTracers.printHistory(System.err);
                    throw e;
                }
            });
        }