//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(); } }
//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(); } }
//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(); } }
//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(); } }
//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(); } }
/// <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(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void close() throws java.io.IOException public override void Close() { @delegate.Close(); }