//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: @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(); } }
public MuninnPageCache(PageSwapperFactory swapperFactory, MemoryAllocator memoryAllocator, int cachePageSize, PageCacheTracer pageCacheTracer, PageCursorTracerSupplier pageCursorTracerSupplier, VersionContextSupplier versionContextSupplier, JobScheduler jobScheduler) { VerifyHacks(); VerifyCachePageSizeIsPowerOfTwo(cachePageSize); int maxPages = CalculatePageCount(memoryAllocator, cachePageSize); // Expose the total number of pages pageCacheTracer.MaxPages(maxPages); MemoryAllocationTracker memoryTracker = GlobalMemoryTracker.INSTANCE; this._pageCacheId = _pageCacheIdCounter.incrementAndGet(); this._swapperFactory = swapperFactory; this._cachePageSize = cachePageSize; this._keepFree = Math.Min(_pagesToKeepFree, maxPages / 2); this._pageCacheTracer = pageCacheTracer; this._pageCursorTracerSupplier = pageCursorTracerSupplier; this._versionContextSupplier = versionContextSupplier; this._printExceptionsOnClose = true; long alignment = swapperFactory.RequiredBufferAlignment; this.VictimPage = VictimPageReference.GetVictimPage(cachePageSize, memoryTracker); this.Pages = new PageList(maxPages, cachePageSize, memoryAllocator, new SwapperSet(), VictimPage, alignment); this._scheduler = jobScheduler; FreelistHead = new AtomicInteger(); }
public override MuninnPageCache CreatePageCache(PageSwapperFactory swapperFactory, int maxPages, PageCacheTracer tracer, PageCursorTracerSupplier cursorTracerSupplier, VersionContextSupplier contextSupplier, JobScheduler jobScheduler) { long memory = MuninnPageCache.MemoryRequiredForPages(maxPages); _allocator = MemoryAllocator.createAllocator(memory.ToString(), new LocalMemoryTracker()); return(new MuninnPageCache(swapperFactory, _allocator, tracer, cursorTracerSupplier, contextSupplier, jobScheduler)); }
//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 mustCloseFilesIfTakingFileLockThrows(int noChannelStriping) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void MustCloseFilesIfTakingFileLockThrows(int noChannelStriping) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger openFilesCounter = new java.util.concurrent.atomic.AtomicInteger(); AtomicInteger openFilesCounter = new AtomicInteger(); PageSwapperFactory factory = CreateSwapperFactory(); factory.open(new DelegatingFileSystemAbstractionAnonymousInnerClass(this, _fileSystem, openFilesCounter) , Configuration.EMPTY); File file = TestDir.file("file"); try { using (StoreChannel ch = _fileSystem.create(file), FileLock ignore = ch.TryLock()) { CreateSwapper(factory, file, 4, NoCallback, false, Bool(noChannelStriping)).close(); fail("Creating a page swapper for a locked channel should have thrown"); } } catch (FileLockException) { // As expected. } assertThat(openFilesCounter.get(), @is(0)); }
private static PageSwapperFactory CreateAndConfigureSwapperFactory(FileSystemAbstraction fs, Config config, Log log) { PageSwapperFactory factory = GetPageSwapperFactory(config, log); factory.Open(fs, config); return(factory); }
//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: @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(); } }
protected internal T CreatePageCache(PageSwapperFactory swapperFactory, int maxPages, PageCacheTracer tracer, PageCursorTracerSupplier cursorTracerSupplier, VersionContextSupplier versionContextSupplier) { T pageCache = _fixture.createPageCache(swapperFactory, maxPages, tracer, cursorTracerSupplier, versionContextSupplier, JobScheduler); PageCachePageSize = pageCache.PageSize(); RecordsPerFilePage = PageCachePageSize / RecordSize; RecordCount = 5 * maxPages * RecordsPerFilePage; FilePageSize = RecordsPerFilePage * RecordSize; BufA = ByteBuffer.allocate(RecordSize); return(pageCache); }
//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))); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) void mustZeroFillPageBeyondEndOfFile(int noChannelStriping) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void MustZeroFillPageBeyondEndOfFile(int noChannelStriping) { sbyte[] bytes = new sbyte[] { 1, 2, 3, 4, 5, 6 }; StoreChannel channel = Fs.create(File); channel.WriteAll(Wrap(bytes)); channel.close(); PageSwapperFactory factory = CreateSwapperFactory(); PageSwapper swapper = CreateSwapper(factory, File, 4, null, false, Bool(noChannelStriping)); long target = CreatePage(4); swapper.Read(1, target, SizeOfAsInt(target)); assertThat(Array(target), byteArray(new sbyte[] { 5, 6, 0, 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 swappingInMustFillPageWithData(int noChannelStriping) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void SwappingInMustFillPageWithData(int noChannelStriping) { sbyte[] bytes = new sbyte[] { 1, 2, 3, 4 }; StoreChannel channel = Fs.create(File); channel.WriteAll(Wrap(bytes)); channel.close(); PageSwapperFactory factory = CreateSwapperFactory(); PageSwapper swapper = CreateSwapper(factory, File, 4, null, false, Bool(noChannelStriping)); long target = CreatePage(4); swapper.Read(0, target, SizeOfAsInt(target)); assertThat(Array(target), byteArray(bytes)); }
//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()))); } }
//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(); } }
//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 swappingOutMustWritePageToFile(int noChannelStriping) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void SwappingOutMustWritePageToFile(int noChannelStriping) { Fs.create(File).close(); sbyte[] expected = new sbyte[] { 1, 2, 3, 4 }; long page = CreatePage(expected); PageSwapperFactory factory = CreateSwapperFactory(); PageSwapper swapper = CreateSwapper(factory, File, 4, null, false, Bool(noChannelStriping)); swapper.Write(0, page); Stream stream = Fs.openAsInputStream(File); sbyte[] actual = new sbyte[expected.Length]; assertThat(stream.Read(actual, 0, actual.Length), @is(actual.Length)); assertThat(actual, byteArray(expected)); }
/// <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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ParameterizedTest @ValueSource(ints = {0, 1}) void swappingOutMustNotOverwriteDataBeyondPage(int noChannelStriping) throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void SwappingOutMustNotOverwriteDataBeyondPage(int noChannelStriping) { sbyte[] initialData = new sbyte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; sbyte[] finalData = new sbyte[] { 1, 2, 3, 4, 8, 7, 6, 5, 9, 10 }; StoreChannel channel = Fs.create(File); channel.WriteAll(Wrap(initialData)); channel.close(); sbyte[] change = new sbyte[] { 8, 7, 6, 5 }; long page = CreatePage(change); PageSwapperFactory factory = CreateSwapperFactory(); PageSwapper swapper = CreateSwapper(factory, File, 4, null, false, Bool(noChannelStriping)); swapper.Write(1, page); Stream stream = Fs.openAsInputStream(File); sbyte[] actual = new sbyte[( int )Fs.getFileSize(File)]; assertThat(stream.Read(actual, 0, actual.Length), @is(actual.Length)); assertThat(actual, byteArray(finalData)); }
/// <summary> /// Create page cache. </summary> /// <param name="swapperFactory"> page cache swapper factory </param> /// <param name="maxPages"> maximum number of pages </param> /// <param name="pageCacheTracer"> global page cache tracer </param> /// <param name="pageCursorTracerSupplier"> supplier of thread local (transaction local) page cursor tracer that will provide /// thread local page cache statistics </param> /// <param name="versionContextSupplier"> supplier of thread local (transaction local) version context that will provide /// access to thread local version context </param> public MuninnPageCache(PageSwapperFactory swapperFactory, int maxPages, PageCacheTracer pageCacheTracer, PageCursorTracerSupplier pageCursorTracerSupplier, VersionContextSupplier versionContextSupplier, JobScheduler jobScheduler) : this(swapperFactory, MemoryAllocator.createAllocator("" + MemoryRequiredForPages(maxPages), GlobalMemoryTracker.INSTANCE), org.neo4j.io.pagecache.PageCache_Fields.PAGE_SIZE, pageCacheTracer, pageCursorTracerSupplier, versionContextSupplier, jobScheduler) { }
public abstract T CreatePageCache(PageSwapperFactory swapperFactory, int maxPages, PageCacheTracer tracer, PageCursorTracerSupplier cursorTracerSupplier, VersionContextSupplier contextSupplier, JobScheduler jobScheduler);
/// <summary> /// Create page cache. </summary> /// <param name="swapperFactory"> page cache swapper factory </param> /// <param name="memoryAllocator"> the source of native memory the page cache should use </param> /// <param name="pageCacheTracer"> global page cache tracer </param> /// <param name="pageCursorTracerSupplier"> supplier of thread local (transaction local) page cursor tracer that will provide /// thread local page cache statistics </param> /// <param name="versionContextSupplier"> supplier of thread local (transaction local) version context that will provide /// access to thread local version context </param> public MuninnPageCache(PageSwapperFactory swapperFactory, MemoryAllocator memoryAllocator, PageCacheTracer pageCacheTracer, PageCursorTracerSupplier pageCursorTracerSupplier, VersionContextSupplier versionContextSupplier, JobScheduler jobScheduler) : this(swapperFactory, memoryAllocator, org.neo4j.io.pagecache.PageCache_Fields.PAGE_SIZE, pageCacheTracer, pageCursorTracerSupplier, versionContextSupplier, jobScheduler) { }