//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)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadBackManyPersistedIdBatchesWhenAggressiveModeIsSet() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReadBackManyPersistedIdBatchesWhenAggressiveModeIsSet() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); ISet <long> freeIds = new HashSet <long>(); // when // we store enough ids to cause overflow to file, in two batches for (long i = 0; i < batchSize * 2; i++) { keeper.FreeId(i); freeIds.Add(i); } // then // they should be returned assertEquals(freeIds.Count, keeper.Count); for (int i = batchSize * 2 - 1; i >= 0; i--) { assertTrue(freeIds.remove(keeper.Id)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void persistedIdsShouldStillBeCounted() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void PersistedIdsShouldStillBeCounted() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = new FreeIdKeeper(channel, batchSize, true); // when // we store enough ids to cause overflow to file for (int i = 0; i < batchSize; i++) { keeper.FreeId(i); } // and then some more int extraIds = 3; for (int i = batchSize; i < batchSize + extraIds; i++) { keeper.FreeId(i); } // then // the count should be returned correctly assertEquals(batchSize + extraIds, keeper.Count); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private int swapIn(org.neo4j.io.fs.StoreChannel channel, long bufferAddress, int bufferSize, long fileOffset, int filePageSize) throws java.io.IOException private int SwapIn(StoreChannel channel, long bufferAddress, int bufferSize, long fileOffset, int filePageSize) { int readTotal = 0; try { ByteBuffer bufferProxy = Proxy(bufferAddress, filePageSize); int read; do { read = channel.Read(bufferProxy, fileOffset + readTotal); } while (read != -1 && (readTotal += read) < filePageSize); // Zero-fill the rest. Debug.Assert(readTotal >= 0 && filePageSize <= bufferSize && readTotal <= filePageSize, format("pointer = %h, readTotal = %s, length = %s, page size = %s", bufferAddress, readTotal, filePageSize, bufferSize)); UnsafeUtil.setMemory(bufferAddress + readTotal, filePageSize - readTotal, MuninnPageCache.ZERO_BYTE); return(readTotal); } catch (IOException e) { throw e; } catch (Exception e) { string msg = format("Read failed after %s of %s bytes from fileOffset %s", readTotal, filePageSize, fileOffset); throw new IOException(msg, e); } }
/// <summary> /// Reopens the channel if it has been closed and the close() method on /// this swapper has not been called. In other words, if the channel has /// been "accidentally" closed by an interrupt or the like. /// /// If the channel has been explicitly closed with the PageSwapper#close() /// method, then this method will re-throw the passed-in exception. /// /// If the reopening of the file fails with an exception for some reason, /// then that exception is added as a suppressed exception to the passed in /// ClosedChannelException, and the CCE is then rethrown. /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private synchronized void tryReopen(long filePageId, java.nio.channels.ClosedChannelException closedException) throws java.nio.channels.ClosedChannelException private void TryReopen(long filePageId, ClosedChannelException closedException) { lock (this) { int stripe = stripe(filePageId); StoreChannel channel = _channels[stripe]; if (channel.Open) { // Someone got ahead of us, presumably. Nothing to do. return; } if (_closed) { // We've been explicitly closed, so we shouldn't reopen the // channel. throw closedException; } try { _channels[stripe] = _fs.open(_file, OpenMode.READ_WRITE); if (stripe == TOKEN_CHANNEL_STRIPE) { // The closing of a FileChannel also releases all associated file locks. AcquireLock(); } } catch (IOException e) { closedException.addSuppressed(e); throw closedException; } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void readAndWriteMustTakeBufferPositionIntoAccount() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ReadAndWriteMustTakeBufferPositionIntoAccount() { sbyte[] bytes = new sbyte[] { 1, 2, 3, 4, 5 }; ByteBuffer buf = ByteBuffer.wrap(bytes); buf.position(1); Fsa.mkdirs(Path); File file = new File(Path, "file"); using (StoreChannel channel = Fsa.open(file, OpenMode.ReadWrite)) { assertThat(channel.write(buf), @is(4)); } using (Stream stream = Fsa.openAsInputStream(file)) { assertThat(stream.Read(), @is(2)); assertThat(stream.Read(), @is(3)); assertThat(stream.Read(), @is(4)); assertThat(stream.Read(), @is(5)); assertThat(stream.Read(), @is(-1)); } Arrays.fill(bytes, ( sbyte )0); buf.position(1); using (StoreChannel channel = Fsa.open(file, OpenMode.ReadWrite)) { assertThat(channel.read(buf), @is(4)); buf.clear(); assertThat(buf.get(), @is((sbyte)0)); assertThat(buf.get(), @is((sbyte)2)); assertThat(buf.get(), @is((sbyte)3)); assertThat(buf.get(), @is((sbyte)4)); assertThat(buf.get(), @is((sbyte)5)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static SegmentHeader loadHeader(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File file) throws java.io.IOException, org.neo4j.causalclustering.messaging.EndOfStreamException private static SegmentHeader LoadHeader(FileSystemAbstraction fileSystem, File file) { using (StoreChannel channel = fileSystem.Open(file, OpenMode.READ)) { return(_headerMarshal.unmarshal(new ReadAheadChannel <>(channel, SegmentHeader.Size))); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expected = IllegalStateException.class) public void createIdGeneratorMustRefuseOverwritingExistingFile() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CreateIdGeneratorMustRefuseOverwritingExistingFile() { IdGeneratorImpl.createGenerator(_fs, IdGeneratorFile(), 0, false); IdGenerator idGenerator = new IdGeneratorImpl(_fs, IdGeneratorFile(), 1008, 1000, false, IdType.NODE, () => 0L); try { IdGeneratorImpl.createGenerator(_fs, IdGeneratorFile(), 0, true); } finally { CloseIdGenerator(idGenerator); // verify that id generator is ok StoreChannel fileChannel = _fs.open(IdGeneratorFile(), OpenMode.READ_WRITE); ByteBuffer buffer = ByteBuffer.allocate(9); fileChannel.ReadAll(buffer); buffer.flip(); assertEquals(( sbyte )0, buffer.get()); assertEquals(0L, buffer.Long); buffer.flip(); int readCount = fileChannel.read(buffer); if (readCount != -1 && readCount != 0) { fail("Id generator header not ok read 9 + " + readCount + " bytes from file"); } fileChannel.close(); File file = IdGeneratorFile(); if (file.exists()) { assertTrue(file.delete()); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void writeBlock(org.neo4j.io.fs.StoreChannel targetChannel, BlockEntryCursor<KEY,VALUE> blockEntryCursor, long blockSize, long entryCount, Cancellation cancellation, System.Action<int> entryCountReporter, ByteBuffer byteBuffer) throws java.io.IOException private void WriteBlock(StoreChannel targetChannel, BlockEntryCursor <KEY, VALUE> blockEntryCursor, long blockSize, long entryCount, Cancellation cancellation, System.Action <int> entryCountReporter, ByteBuffer byteBuffer) { WriteHeader(byteBuffer, blockSize, entryCount); long actualDataSize = WriteEntries(targetChannel, byteBuffer, _layout, blockEntryCursor, cancellation, entryCountReporter); WriteLastEntriesWithPadding(targetChannel, byteBuffer, blockSize - actualDataSize); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowClosedChannelExceptionWhenChannelUnexpectedlyClosed() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowClosedChannelExceptionWhenChannelUnexpectedlyClosed() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.File file = new java.io.File(directory.directory(), "file"); File file = new File(Directory.directory(), "file"); StoreChannel storeChannel = FileSystemRule.get().open(file, OpenMode.READ_WRITE); PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, ( sbyte )-1); PhysicalFlushableChannel channel = new PhysicalFlushableChannel(versionedStoreChannel); // just close the underlying channel storeChannel.close(); // WHEN just appending something to the buffer channel.Put(( sbyte )0); // and wanting to empty that into the channel try { channel.PrepareForFlush(); fail("Should have thrown exception"); } catch (ClosedChannelException) { // THEN we should get a ClosedChannelException } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUseAlreadyOpenedFileChannel() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldUseAlreadyOpenedFileChannel() { StoreChannel channel = Mockito.mock(typeof(StoreChannel)); CustomChannelFileSystemAbstraction fileSystemAbstraction = new CustomChannelFileSystemAbstraction(this, FileSystemRule.get(), channel); int numberOfCallesToOpen = 0; try { using (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction, Target.storeLayout())) { try { storeLocker.CheckLock(); fail(); } catch (StoreLockException) { numberOfCallesToOpen = fileSystemAbstraction.NumberOfCallsToOpen; // Try to grab lock a second time storeLocker.CheckLock(); } } } catch (StoreLockException) { // expected } assertEquals("Expect that number of open channels will remain the same for ", numberOfCallesToOpen, fileSystemAbstraction.NumberOfCallsToOpen); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowIllegalStateExceptionAfterClosed() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldThrowIllegalStateExceptionAfterClosed() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.File file = new java.io.File(directory.directory(), "file"); File file = new File(Directory.directory(), "file"); StoreChannel storeChannel = FileSystemRule.get().open(file, OpenMode.READ_WRITE); PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, ( sbyte )-1); PhysicalFlushableChannel channel = new PhysicalFlushableChannel(versionedStoreChannel); // closing the WritableLogChannel, then the underlying channel is what PhysicalLogFile does channel.Dispose(); storeChannel.close(); // WHEN just appending something to the buffer channel.Put(( sbyte )0); // and wanting to empty that into the channel try { channel.PrepareForFlush(); fail("Should have thrown exception"); } catch (System.InvalidOperationException) { // THEN we should get an IllegalStateException, not a ClosedChannelException } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void readMap(org.neo4j.io.fs.StoreChannel channel, java.util.Map<String,java.util.Map<String,String>> map, System.Nullable<int> sizeOrTillEof) throws java.io.IOException private void ReadMap(StoreChannel channel, IDictionary <string, IDictionary <string, string> > map, int?sizeOrTillEof) { for (int i = 0; sizeOrTillEof == null || i < sizeOrTillEof.Value; i++) { string indexName = ReadNextString(channel); if (string.ReferenceEquals(indexName, null)) { break; } int?propertyCount = ReadNextInt(channel); if (propertyCount == null) { break; } IDictionary <string, string> properties = new Dictionary <string, string>(); for (int p = 0; p < propertyCount.Value; p++) { string key = ReadNextString(channel); if (string.ReferenceEquals(key, null)) { break; } string value = ReadNextString(channel); if (string.ReferenceEquals(value, null)) { break; } properties[key] = value; } map[indexName] = properties; } }
//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 WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void generateFileWithRecords(java.io.File file, int recordCount, int recordSize) throws java.io.IOException protected internal virtual void GenerateFileWithRecords(File file, int recordCount, int recordSize) { using (StoreChannel channel = Fs.open(file, OpenMode.READ_WRITE)) { GenerateFileWithRecords(channel, recordCount, recordSize); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void removeLastCheckpointRecordFromLastLogFile() throws java.io.IOException private void RemoveLastCheckpointRecordFromLastLogFile() { LogPosition checkpointPosition = null; LogFile transactionLogFile = _logFiles.LogFile; VersionAwareLogEntryReader <ReadableLogChannel> entryReader = new VersionAwareLogEntryReader <ReadableLogChannel>(); LogPosition startPosition = LogPosition.start(_logFiles.HighestLogVersion); using (ReadableLogChannel reader = transactionLogFile.GetReader(startPosition)) { LogEntry logEntry; do { logEntry = entryReader.ReadLogEntry(reader); if (logEntry is CheckPoint) { checkpointPosition = (( CheckPoint )logEntry).LogPosition; } } while (logEntry != null); } if (checkpointPosition != null) { using (StoreChannel storeChannel = _fileSystemRule.open(_logFiles.HighestLogFile, OpenMode.READ_WRITE)) { storeChannel.Truncate(checkpointPosition.ByteOffset); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void verifyRecordsInFile(java.io.File file, int recordCount) throws java.io.IOException protected internal virtual void VerifyRecordsInFile(File file, int recordCount) { using (StoreChannel channel = Fs.open(file, OpenMode.READ)) { VerifyRecordsInFile(channel, recordCount); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void sendLargerFileWhichGrows() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SendLargerFileWhichGrows() { // given File file = TestDirectory.file("file"); StoreChannel writer = _fs.create(file); FileSender fileSender = new FileSender(new StoreResource(file, null, 16, _fs)); // when sbyte[] chunkA = WriteRandomBytes(writer, MAX_SIZE); sbyte[] chunkB = WriteRandomBytes(writer, MAX_SIZE); FileChunk readChunkA = fileSender.ReadChunk(_allocator); // then assertEquals(FileChunk.Create(chunkA, false), readChunkA); assertFalse(fileSender.EndOfInput); // when sbyte[] chunkC = WriteRandomBytes(writer, MAX_SIZE); FileChunk readChunkB = fileSender.ReadChunk(_allocator); // then assertEquals(FileChunk.Create(chunkB, false), readChunkB); assertFalse(fileSender.EndOfInput); // when FileChunk readChunkC = fileSender.ReadChunk(_allocator); assertEquals(FileChunk.Create(chunkC, true), readChunkC); // then assertTrue(fileSender.EndOfInput); assertNull(fileSender.ReadChunk(_allocator)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void streamFilesRecursiveRenameMustNotChangeSourceFileContentsWithReplaceExisting() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void StreamFilesRecursiveRenameMustNotChangeSourceFileContentsWithReplaceExisting() { File a = ExistingFile("a"); File b = ExistingFile("b"); GenerateFileWithRecords(a, _recordCount); GenerateFileWithRecords(b, _recordCount + _recordsPerFilePage); // Fill 'b' with random data using (StoreChannel channel = Fsa.open(b, OpenMode.ReadWrite)) { ThreadLocalRandom rng = ThreadLocalRandom.current(); int fileSize = ( int )channel.size(); ByteBuffer buffer = ByteBuffer.allocate(fileSize); for (int i = 0; i < fileSize; i++) { buffer.put(i, ( sbyte )rng.Next()); } buffer.rewind(); channel.WriteAll(buffer); } // Do the rename FileHandle handle = Fsa.streamFilesRecursive(a).findAny().get(); handle.Rename(b, REPLACE_EXISTING); // Then verify that the old random data we put in 'b' has been replaced with the contents of 'a' VerifyRecordsInFile(b, _recordCount); }
//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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private long writeDataThroughFileSystem(java.io.File file, java.nio.channels.ReadableByteChannel data, ByteBuffer temporaryBuffer, boolean hasData) throws java.io.IOException private long WriteDataThroughFileSystem(File file, ReadableByteChannel data, ByteBuffer temporaryBuffer, bool hasData) { using (StoreChannel channel = _fs.create(file)) { return(WriteData(data, temporaryBuffer, hasData, channel)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private byte[] writeRandomBytes(org.neo4j.io.fs.StoreChannel writer, int size) throws java.io.IOException private sbyte[] WriteRandomBytes(StoreChannel writer, int size) { sbyte[] bytes = new sbyte[size]; _random.NextBytes(bytes); writer.WriteAll(ByteBuffer.wrap(bytes)); return(bytes); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private long writeAndRetryIfInterrupted(long filePageId, long bufferAddress, int attemptsLeft) throws java.io.IOException private long WriteAndRetryIfInterrupted(long filePageId, long bufferAddress, int attemptsLeft) { long fileOffset = PageIdToPosition(filePageId); IncreaseFileSizeTo(fileOffset + _filePageSize); try { StoreChannel channel = channel(filePageId); return(SwapOut(bufferAddress, fileOffset, channel)); } catch (ClosedChannelException e) { TryReopen(filePageId, e); if (attemptsLeft < 1) { throw new IOException("IO failed due to interruption", e); } bool interrupted = Thread.interrupted(); long bytesWritten = WriteAndRetryIfInterrupted(filePageId, bufferAddress, attemptsLeft - 1); if (interrupted) { Thread.CurrentThread.Interrupt(); } return(bytesWritten); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void writeChars(org.neo4j.io.fs.StoreChannel channel, ByteBuffer buffer, char[] chars) throws java.io.IOException private static void WriteChars(StoreChannel channel, ByteBuffer buffer, char[] chars) { int position = 0; do { buffer.clear(); int leftToWrite = chars.Length - position; if (leftToWrite * 2 < buffer.capacity()) { buffer.asCharBuffer().put(chars, position, leftToWrite); buffer.limit(leftToWrite * 2); channel.write(buffer); position += leftToWrite; } else { int length = buffer.capacity() / 2; buffer.asCharBuffer().put(chars, position, length); buffer.limit(length * 2); channel.write(buffer); position += length; } } while (position < chars.Length); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldOnlyOverflowWhenThresholdIsReached() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldOnlyOverflowWhenThresholdIsReached() { // Given StoreChannel channel = spy(Fs.get().open(new File("id.file"), OpenMode.READ_WRITE)); int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); reset(channel); // because we get the position in the constructor, we need to reset all calls on the spy // when // we free 9 ids for (int i = 0; i < batchSize - 1; i++) { keeper.FreeId(i); } // then verifyZeroInteractions(channel); // when we free one more keeper.FreeId(10); // then verify(channel).writeAll(any(typeof(ByteBuffer))); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void writeInt(org.neo4j.io.fs.StoreChannel channel, ByteBuffer buffer, int value) throws java.io.IOException public static void WriteInt(StoreChannel channel, ByteBuffer buffer, int value) { buffer.clear(); buffer.putInt(value); buffer.flip(); channel.write(buffer); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFirstReturnNonPersistedIdsAndThenPersistedOnesWhenAggressiveMode() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldFirstReturnNonPersistedIdsAndThenPersistedOnesWhenAggressiveMode() { // this is testing the stack property, but from the viewpoint of avoiding unnecessary disk reads // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); // when // we store enough ids to cause overflow to file for (int i = 0; i < batchSize; i++) { keeper.FreeId(i); } // and then some more int extraIds = 3; for (int i = batchSize; i < batchSize + extraIds; i++) { keeper.FreeId(i); } // then // the first returned should be the newly freed ones for (int i = batchSize; i < batchSize + extraIds; i++) { assertEquals(i, keeper.Id); } // and then there should be the persisted ones for (int i = 0; i < batchSize; i++) { assertEquals(i, keeper.Id); } }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private org.neo4j.io.pagecache.randomharness.Phase filesAreCorrectlyWrittenVerification(final org.neo4j.io.pagecache.randomharness.RecordFormat recordFormat, final int filePageCount) private Phase FilesAreCorrectlyWrittenVerification(RecordFormat recordFormat, int filePageCount) { return((cache, fs1, filesTouched) => { foreach (File file in filesTouched) { using (PagedFile pf = cache.map(file, cache.pageSize()), PageCursor cursor = pf.Io(0, PF_SHARED_READ_LOCK)) { for (int pageId = 0; pageId < filePageCount && cursor.Next(); pageId++) { try { recordFormat.AssertRecordsWrittenCorrectly(cursor); } catch (Exception th) { th.addSuppressed(new Exception("pageId = " + pageId)); throw th; } } } using (StoreChannel channel = fs1.open(file, OpenMode.READ)) { recordFormat.AssertRecordsWrittenCorrectly(file, channel); } } }); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private int scrambleIndexFiles(org.neo4j.io.fs.FileSystemAbstraction fs, java.io.File fileOrDir) throws java.io.IOException private int ScrambleIndexFiles(FileSystemAbstraction fs, File fileOrDir) { if (fs.IsDirectory(fileOrDir)) { int count = 0; File[] children = fs.ListFiles(fileOrDir); if (children != null) { foreach (File child in children) { count += ScrambleIndexFiles(fs, child); } } return(count); } else { // Completely scramble file, assuming small files using (StoreChannel channel = fs.Open(fileOrDir, OpenMode.READ_WRITE)) { if (channel.size() > mebiBytes(10)) { throw new System.ArgumentException("Was expecting small files here"); } sbyte[] bytes = new sbyte[( int )channel.size()]; _random.NextBytes(bytes); channel.WriteAll(ByteBuffer.wrap(bytes)); } return(1); } }
//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(); } }