コード例 #1
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();
            }
        }
コード例 #2
0
        private static PageSwapperFactory CreateAndConfigureSwapperFactory(FileSystemAbstraction fs, Config config, Log log)
        {
            PageSwapperFactory factory = GetPageSwapperFactory(config, log);

            factory.Open(fs, config);
            return(factory);
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustDisableStripingIfToldTo() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustDisableStripingIfToldTo()
        {
            // given
            int bytesPerPage = 32;
            PageSwapperFactory    factory = CreateSwapperFactory();
            FileSystemAbstraction fs      = mock(typeof(FileSystemAbstraction));
            StoreChannel          channel = mock(typeof(StoreChannel));

            when(channel.TryLock()).thenReturn(mock(typeof(FileLock)));
            when(fs.Create(any(typeof(File)))).thenReturn(channel);
            when(fs.Open(any(typeof(File)), any())).thenReturn(channel);

            // when
            factory.Open(fs, Configuration.EMPTY);
            PageSwapper swapper = CreateSwapper(factory, _file, bytesPerPage, NoCallback, true, true);

            try
            {
                // then
                verify(fs, times(1)).open(eq(_file), any(typeof(OpenMode)));
            }
            finally
            {
                swapper.Close();
            }
        }
コード例 #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}) @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void fileMustRemainLockedEvenIfChannelIsClosedByStrayInterrupt(int noChannelStriping) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void FileMustRemainLockedEvenIfChannelIsClosedByStrayInterrupt(int noChannelStriping)
        {
            PageSwapperFactory factory = CreateSwapperFactory();

            factory.Open(_fileSystem, Configuration.EMPTY);
            File file = TestDir.file("file");

            _fileSystem.create(file).close();

            PageSwapper pageSwapper = CreateSwapper(factory, file, 4, NoCallback, false, Bool(noChannelStriping));

            try
            {
                StoreChannel channel = _fileSystem.open(file, OpenMode.READ_WRITE);

                Thread.CurrentThread.Interrupt();
                pageSwapper.Force();

                assertThrows(typeof(OverlappingFileLockException), channel.tryLock);
            }
            finally
            {
                pageSwapper.Close();
            }
        }
コード例 #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();
            }
        }
コード例 #6
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();
            }
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void creatingSwapperForInternallyLockedFileMustThrow(int noChannelStriping) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void CreatingSwapperForInternallyLockedFileMustThrow(int noChannelStriping)
        {
            PageSwapperFactory factory = CreateSwapperFactory();

            factory.Open(_fileSystem, Configuration.EMPTY);
            File file = TestDir.file("file");

            StoreFileChannel channel = _fileSystem.create(file);

            using (FileLock fileLock = channel.TryLock())
            {
                assertThat(fileLock, @is(not(nullValue())));
                assertThrows(typeof(FileLockException), () => CreateSwapper(factory, file, 4, NoCallback, true, Bool(noChannelStriping)));
            }
        }
コード例 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void mustUnlockFileWhenThePageSwapperIsClosed(int noChannelStriping) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustUnlockFileWhenThePageSwapperIsClosed(int noChannelStriping)
        {
            PageSwapperFactory factory = CreateSwapperFactory();

            factory.Open(_fileSystem, Configuration.EMPTY);
            File file = TestDir.file("file");

            _fileSystem.create(file).close();

            CreateSwapper(factory, file, 4, NoCallback, false, false).close();

            using (StoreFileChannel channel = _fileSystem.open(file, OpenMode.READ_WRITE), FileLock fileLock = channel.TryLock())
            {
                assertThat(fileLock, @is(not(nullValue())));
            }
        }
コード例 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void creatingSwapperForExternallyLockedFileMustThrow(int noChannelStriping) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void CreatingSwapperForExternallyLockedFileMustThrow(int noChannelStriping)
        {
            PageSwapperFactory factory = CreateSwapperFactory();

            factory.Open(_fileSystem, Configuration.EMPTY);
            File file = TestDir.file("file");

            _fileSystem.create(file).close();

//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getCanonicalName method:
            ProcessBuilder pb = new ProcessBuilder(JavaExecutable.ToString(), "-cp", ClassPath, typeof(LockThisFileProgram).FullName, file.AbsolutePath);
            File           wd = (new File("target/test-classes")).AbsoluteFile;

            pb.directory(wd);
            Process      process = pb.start();
            StreamReader stdout  = new StreamReader(process.InputStream);
            Stream       stderr  = process.ErrorStream;

            try
            {
                assumeThat(stdout.ReadLine(), @is(LockThisFileProgram.LOCKED_OUTPUT));
            }
            catch (Exception e)
            {
                int b = stderr.Read();
                while (b != -1)
                {
                    System.err.write(b);
                    b = stderr.Read();
                }
                System.err.flush();
                int exitCode = process.waitFor();
                Console.WriteLine("exitCode = " + exitCode);
                throw e;
            }

            try
            {
                assertThrows(typeof(FileLockException), () => CreateSwapper(factory, file, 4, NoCallback, true, Bool(noChannelStriping)));
            }
            finally
            {
                process.OutputStream.write(0);
                process.OutputStream.flush();
                process.waitFor();
            }
        }
コード例 #10
0
        /// <summary>
        /// The OverlappingFileLockException is thrown when tryLock is called on the same file *in the same JVM*.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) void creatingSwapperForFileMustTakeLockOnFile(int noChannelStriping) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void CreatingSwapperForFileMustTakeLockOnFile(int noChannelStriping)
        {
            PageSwapperFactory factory = CreateSwapperFactory();

            factory.Open(_fileSystem, Configuration.EMPTY);
            File file = TestDir.file("file");

            _fileSystem.create(file).close();

            PageSwapper pageSwapper = CreateSwapper(factory, file, 4, NoCallback, false, Bool(noChannelStriping));

            try
            {
                StoreChannel channel = _fileSystem.open(file, OpenMode.READ_WRITE);
                assertThrows(typeof(OverlappingFileLockException), channel.tryLock);
            }
            finally
            {
                pageSwapper.Close();
            }
        }