//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: @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 WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private long flushFreeIds0(ByteBuffer writeBuffer) throws java.io.IOException private long FlushFreeIds0(ByteBuffer writeBuffer) { _channel.position(_channel.size()); writeBuffer.clear(); while (!_freeIds.Empty) { long id = _freeIds.dequeue(); if (id == NO_RESULT) { continue; } writeBuffer.putLong(id); if (writeBuffer.position() == writeBuffer.capacity()) { writeBuffer.flip(); _channel.writeAll(writeBuffer); writeBuffer.clear(); } } writeBuffer.flip(); if (writeBuffer.hasRemaining()) { _channel.writeAll(writeBuffer); } return(_channel.position()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void size() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void Size() { long size = 256; when(_actual.size()).thenReturn(size); assertEquals(256 - _offset, _channel.size()); verify(_actual).size(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private String readFailure(java.io.File failureFile) throws java.io.IOException private string ReadFailure(File failureFile) { using (StoreChannel channel = _fs.open(failureFile, OpenMode.READ)) { sbyte[] data = new sbyte[( int )channel.size()]; channel.ReadAll(ByteBuffer.wrap(data)); return(UTF8.decode(WithoutZeros(data))); } }
/// <summary> /// A keeper of freed IDs. /// </summary> /// <param name="channel"> a channel to the free ID file. </param> /// <param name="batchSize"> the number of IDs which are read/written to disk in one go. </param> /// <param name="aggressiveMode"> whether to reuse freed IDs during this lifecycle. </param> /// <exception cref="IOException"> if an I/O error occurs. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: FreeIdKeeper(org.neo4j.io.fs.StoreChannel channel, int batchSize, boolean aggressiveMode) throws java.io.IOException internal FreeIdKeeper(StoreChannel channel, int batchSize, bool aggressiveMode) { this._channel = channel; this._batchSize = batchSize; this._aggressiveMode = aggressiveMode; this._initialPosition = channel.size(); this._stackPosition = _initialPosition; this._freeIdCount = _stackPosition / _idEntrySize; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private boolean isFailed(java.io.File failureFile) throws java.io.IOException private bool IsFailed(File failureFile) { using (StoreChannel channel = _fs.open(failureFile, OpenMode.READ)) { sbyte[] data = new sbyte[( int )channel.size()]; channel.ReadAll(ByteBuffer.wrap(data)); channel.close(); return(!AllZero(data)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private ByteBuffer readFile(java.io.File file) throws java.io.IOException private ByteBuffer ReadFile(File file) { using (StoreChannel channel = FileSystemRule.get().open(file, OpenMode.READ)) { ByteBuffer buffer = ByteBuffer.allocate(( int )channel.size()); channel.ReadAll(buffer); buffer.flip(); return(buffer); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBeConsistentAfterConcurrentWritesAndForces() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldBeConsistentAfterConcurrentWritesAndForces() { ExecutorService executorService = Executors.newCachedThreadPool(); try { for (int attempt = 0; attempt < 100; attempt++) { using (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction()) { File aFile = new File("contendedFile"); ICollection <Callable <Void> > workers = new List <Callable <Void> >(); for (int i = 0; i < 100; i++) { workers.Add(() => { try { StoreChannel channel = fs.Open(aFile, OpenMode.READ_WRITE); channel.position(channel.size()); WriteLong(channel, 1); } catch (IOException e) { throw new Exception(e); } return(null); }); workers.Add(() => { StoreChannel channel = fs.Open(aFile, OpenMode.READ_WRITE); channel.force(true); return(null); }); } IList <Future <Void> > futures = executorService.invokeAll(workers); foreach (Future <Void> future in futures) { future.get(); } fs.Crash(); VerifyFileIsFullOfLongIntegerOnes(fs.Open(aFile, OpenMode.READ_WRITE)); } } } finally { executorService.shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCompactFileOnCloseInRegularMode() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCompactFileOnCloseInRegularMode() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeper(channel, batchSize); // free 4 batches for (long i = 0; i < batchSize * 4; i++) { keeper.FreeId(i); } keeper.Dispose(); assertEquals(channel.size(), 4 * batchSize * Long.BYTES); channel.close(); // after opening again the IDs should be free to reuse channel = StoreChannel; keeper = GetFreeIdKeeper(channel, batchSize); // free 4 more batches on top of the already existing 4 for (long i = 0; i < batchSize * 4; i++) { keeper.FreeId(i); } // fetch 2 batches for (int i = 0; i < batchSize * 2; i++) { keeper.Id; } keeper.Dispose(); // when assertEquals(channel.size(), 6 * batchSize * Long.BYTES); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTruncateFileInAggressiveMode() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTruncateFileInAggressiveMode() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); // free 4 batches for (long i = 0; i < batchSize * 4; i++) { keeper.FreeId(i); } assertEquals(channel.size(), 4 * batchSize * Long.BYTES); // when for (int i = 0; i < batchSize * 2; i++) { keeper.Id; } // then assertEquals(channel.size(), 2 * batchSize * Long.BYTES); }
/// <summary> /// Store failure in failure file for index with the given id /// </summary> /// <param name="failure"> message describing the failure that needs to be stored </param> /// <exception cref="IOException"> if the failure could not be stored </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public synchronized void storeIndexFailure(String failure) throws java.io.IOException public virtual void StoreIndexFailure(string failure) { lock (this) { File failureFile = failureFile(); using (StoreChannel channel = _fs.open(failureFile, OpenMode.READ_WRITE)) { sbyte[] existingData = new sbyte[( int )channel.size()]; channel.ReadAll(ByteBuffer.wrap(existingData)); channel.Position(LengthOf(existingData)); sbyte[] data = UTF8.encode(failure); channel.WriteAll(ByteBuffer.wrap(data, 0, Math.Min(data.Length, MAX_FAILURE_SIZE))); channel.Force(true); channel.close(); } } }
private static void VerifyFileIsFullOfLongIntegerOnes(StoreChannel channel) { try { long claimedSize = channel.size(); ByteBuffer buffer = allocate(( int )claimedSize); channel.ReadAll(buffer); buffer.flip(); for (int position = 0; position < claimedSize; position += 8) { long value = buffer.getLong(position); assertEquals(1, value); } } catch (IOException e) { throw new Exception(e); } }
private static void VerifyFileIsEitherEmptyOrContainsLongIntegerValueOne(StoreChannel channel) { try { long claimedSize = channel.size(); ByteBuffer buffer = allocate(8); channel.Read(buffer, 0); buffer.flip(); if (claimedSize == 8) { assertEquals(1, buffer.Long); } else { assertThrows(typeof(BufferUnderflowException), buffer.getLong, "Should have thrown an exception"); } } catch (IOException e) { throw new Exception(e); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldNotLoseDataForcedBeforeFileSystemCrashes() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldNotLoseDataForcedBeforeFileSystemCrashes() { using (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction()) { // given int numberOfBytesForced = 8; File aFile = new File("yo"); StoreChannel channel = fs.Open(aFile, OpenMode.READ_WRITE); WriteLong(channel, 1111); // when channel.Force(true); WriteLong(channel, 2222); fs.Crash(); // then StoreChannel readChannel = fs.Open(aFile, OpenMode.READ); assertEquals(numberOfBytesForced, readChannel.size()); assertEquals(1111, ReadLong(readChannel).Long); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public long size() throws java.io.IOException public override long Size() { return(@delegate.size() - _offset); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: static long countFreeIds(org.neo4j.io.fs.StoreChannel channel) throws java.io.IOException internal static long CountFreeIds(StoreChannel channel) { return(channel.size() / _idEntrySize); }