Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSurviveFilesystemErrors() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldSurviveFilesystemErrors()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.adversaries.RandomAdversary adversary = new org.neo4j.adversaries.RandomAdversary(0.1, 0.1, 0);
            RandomAdversary adversary = new RandomAdversary(0.1, 0.1, 0);

            adversary.ProbabilityFactor = 0;

            AdversarialFileSystemAbstraction adversarialFileSystem = new SensibleAdversarialFileSystemAbstraction(adversary, _fileSystem);
            RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(adversarialFileSystem, _logFile, 1000, 0, 9, _directExecutor);

            adversary.ProbabilityFactor = 1;
            WriteLines(supplier, 10000);

            // run cleanly for a while, to allow it to fill any gaps left in log archive numbers
            adversary.ProbabilityFactor = 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));
        }
Beispiel #2
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);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) void mustHandleMischiefInPositionedVectoredRead(int noChannelStriping) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustHandleMischiefInPositionedVectoredRead(int noChannelStriping)
        {
            int bytesTotal   = 512;
            int bytesPerPage = 32;
            int pageCount    = bytesTotal / bytesPerPage;

            sbyte[] data = new sbyte[bytesTotal];
            ThreadLocalRandom.current().NextBytes(data);

            PageSwapperFactory factory = CreateSwapperFactory();

            factory.Open(Fs, Configuration.EMPTY);
            File        file    = File;
            PageSwapper swapper = CreateSwapper(factory, file, bytesTotal, NoCallback, true, Bool(noChannelStriping));

            try
            {
                long page = CreatePage(data);
                swapper.Write(0, page);
            }
            finally
            {
                swapper.Close();
            }

            RandomAdversary adversary = new RandomAdversary(0.5, 0.0, 0.0);

            factory.Open(new AdversarialFileSystemAbstraction(adversary, Fs), Configuration.EMPTY);
            swapper = CreateSwapper(factory, file, bytesPerPage, NoCallback, false, Bool(noChannelStriping));

            long[] pages = new long[pageCount];
            for (int i = 0; i < pageCount; i++)
            {
                pages[i] = CreatePage(bytesPerPage);
            }

            sbyte[] temp = new sbyte[bytesPerPage];
            try
            {
                for (int i = 0; i < 10_000; i++)
                {
                    foreach (long page in pages)
                    {
                        Clear(page);
                    }
                    assertThat(swapper.Read(0, pages, bytesPerPage, 0, pages.Length), @is(( long )bytesTotal));
                    for (int j = 0; j < pageCount; j++)
                    {
                        Array.Copy(data, j * bytesPerPage, temp, 0, bytesPerPage);
                        assertThat(Array(pages[j]), @is(temp));
                    }
                }
            }
            finally
            {
                swapper.Close();
            }
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) void mustHandleMischiefInPositionedVectoredWrite(int noChannelStriping) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustHandleMischiefInPositionedVectoredWrite(int noChannelStriping)
        {
            int bytesTotal   = 512;
            int bytesPerPage = 32;
            int pageCount    = bytesTotal / bytesPerPage;

            sbyte[] data = new sbyte[bytesTotal];
            ThreadLocalRandom.current().NextBytes(data);
            long zeroPage = CreatePage(bytesPerPage);

            Clear(zeroPage);

            File file = File;
            PageSwapperFactory factory   = CreateSwapperFactory();
            RandomAdversary    adversary = new RandomAdversary(0.5, 0.0, 0.0);

            factory.Open(new AdversarialFileSystemAbstraction(adversary, Fs), Configuration.EMPTY);
            PageSwapper swapper = CreateSwapper(factory, file, bytesPerPage, NoCallback, true, Bool(noChannelStriping));

            long[] writePages = new long[pageCount];
            long[] readPages  = new long[pageCount];
            long[] zeroPages  = new long[pageCount];
            for (int i = 0; i < pageCount; i++)
            {
                writePages[i] = CreatePage(bytesPerPage);
                PutBytes(writePages[i], data, 0, i * bytesPerPage, bytesPerPage);
                readPages[i] = CreatePage(bytesPerPage);
                zeroPages[i] = zeroPage;
            }

            try
            {
                for (int i = 0; i < 10_000; i++)
                {
                    adversary.ProbabilityFactor = 0;
                    swapper.Write(0, zeroPages, 0, pageCount);
                    adversary.ProbabilityFactor = 1;
                    swapper.Write(0, writePages, 0, pageCount);
                    foreach (long readPage in readPages)
                    {
                        Clear(readPage);
                    }
                    adversary.ProbabilityFactor = 0;
                    assertThat(swapper.Read(0, readPages, bytesPerPage, 0, pageCount), @is(( long )bytesTotal));
                    for (int j = 0; j < pageCount; j++)
                    {
                        assertThat(Array(readPages[j]), @is(Array(writePages[j])));
                    }
                }
            }
            finally
            {
                swapper.Close();
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) void mustHandleMischiefInPositionedRead(int noChannelStriping) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustHandleMischiefInPositionedRead(int noChannelStriping)
        {
            int bytesTotal = 512;

            sbyte[] data = new sbyte[bytesTotal];
            ThreadLocalRandom.current().NextBytes(data);

            PageSwapperFactory factory = CreateSwapperFactory();

            factory.Open(Fs, Configuration.EMPTY);
            File        file    = File;
            PageSwapper swapper = CreateSwapper(factory, file, bytesTotal, NoCallback, true, Bool(noChannelStriping));

            try
            {
                long page = CreatePage(data);
                swapper.Write(0, page);
            }
            finally
            {
                swapper.Close();
            }

            RandomAdversary adversary = new RandomAdversary(0.5, 0.0, 0.0);

            factory.Open(new AdversarialFileSystemAbstraction(adversary, Fs), Configuration.EMPTY);
            swapper = CreateSwapper(factory, file, bytesTotal, NoCallback, false, Bool(noChannelStriping));

            long page = CreatePage(bytesTotal);

            try
            {
                for (int i = 0; i < 10_000; i++)
                {
                    Clear(page);
                    assertThat(swapper.Read(0, page, SizeOfAsInt(page)), @is(( long )bytesTotal));
                    assertThat(Array(page), @is(data));
                }
            }
            finally
            {
                swapper.Close();
            }
        }
Beispiel #6
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;
                }
            });
        }
 public AdversarialChannelDefaultFileSystemAbstraction(RandomAdversary adversary)
 {
     this._adversary = adversary;
 }