//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(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 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 writeIntegerIntoFile(java.io.File targetFile) throws java.io.IOException private void WriteIntegerIntoFile(File targetFile) { StoreChannel storeChannel = Fsa.create(targetFile); ByteBuffer byteBuffer = ByteBuffer.allocate((sizeof(int) * 8)).putInt(7); byteBuffer.flip(); storeChannel.WriteAll(byteBuffer); storeChannel.close(); }
//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)); } }
public IndexProviderStore(File file, FileSystemAbstraction fileSystem, long expectedVersion, bool allowUpgrade) { this._file = file; this._random = new Random(DateTimeHelper.CurrentUnixTimeMillis()); StoreChannel channel = null; bool success = false; try { // Create it if it doesn't exist if (!fileSystem.FileExists(file) || fileSystem.GetFileSize(file) == 0) { Create(file, fileSystem, expectedVersion); } // Read all the records in the file channel = fileSystem.Open(file, OpenMode.READ_WRITE); long?[] records = ReadRecordsWithNullDefaults(channel, RECORD_COUNT, allowUpgrade); _creationTime = records[0].Value; _randomIdentifier = records[1].Value; _version = records[2].Value; _lastCommittedTx = records[3].Value; long?readIndexVersion = records[4]; _fileChannel = channel; // Compare version and throw exception if there's a mismatch, also considering "allow upgrade" bool versionDiffers = CompareExpectedVersionWithStoreVersion(expectedVersion, allowUpgrade, readIndexVersion); // Here we know that either the version matches or we just upgraded to the expected version _indexVersion = expectedVersion; if (versionDiffers) { // We have upgraded the version, let's write it WriteOut(); } success = true; } catch (IOException e) { throw new Exception(e); } finally { if (!success && channel != null) { try { channel.close(); } catch (IOException) { // What to do? } } } }
private void Close(StoreChannel channel) { if (channel != null) { try { channel.close(); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } } }
//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)); }
public virtual void Close() { if (!_fileChannel.Open) { return; } WriteOut(); try { _fileChannel.close(); } 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 public void shouldNotReturnReusedIdsAfterRestart() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotReturnReusedIdsAfterRestart() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); long idGen = 0; // free 4 batches for (long i = 0; i < batchSize * 4; i++) { keeper.FreeId(idGen++); } // reuse 2 batches IList <long> reusedIds = new List <long>(); for (int i = 0; i < batchSize * 2; i++) { long id = keeper.Id; reusedIds.Add(id); } // when keeper.Dispose(); channel.close(); channel = StoreChannel; keeper = GetFreeIdKeeper(channel, batchSize); IList <long> remainingIds = new List <long>(); long id; while ((id = keeper.Id) != IdContainer.NO_RESULT) { remainingIds.Add(id); } assertEquals(2 * batchSize, remainingIds.Count); // then foreach (long?remainingId in remainingIds) { assertFalse(reusedIds.Contains(remainingId)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void allowStoreThatExceedDefaultSize() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void AllowStoreThatExceedDefaultSize() { File aFile = new File("test"); StoreChannel channel = _fs.open(aFile, OpenMode.READ_WRITE); ByteBuffer buffer = allocate(Long.BYTES); int mebiBytes = ( int )ByteUnit.mebiBytes(1); for (int position = mebiBytes + 42; position < 10_000_000; position += mebiBytes) { buffer.putLong(1); buffer.flip(); channel.WriteAll(buffer, position); buffer.clear(); } channel.close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel openForVersion(long version) throws java.io.IOException public override PhysicalLogVersionedStoreChannel OpenForVersion(long version) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.File fileToOpen = getLogFileForVersion(version); File fileToOpen = GetLogFileForVersion(version); if (!VersionExists(version)) { throw new FileNotFoundException(format("File does not exist [%s]", fileToOpen.CanonicalPath)); } StoreChannel rawChannel = null; try { rawChannel = OpenLogFileChannel(fileToOpen, OpenMode.READ); ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE); LogHeader header = readLogHeader(buffer, rawChannel, true, fileToOpen); if ((header == null) || (header.LogVersion != version)) { throw new System.InvalidOperationException(format("Unexpected log file header. Expected header version: %d, actual header: %s", version, header != null ? header.ToString() : "null header.")); } return(new PhysicalLogVersionedStoreChannel(rawChannel, version, header.LogFormatVersion)); } catch (FileNotFoundException cause) { throw ( FileNotFoundException )(new FileNotFoundException(format("File could not be opened [%s]", fileToOpen.CanonicalPath))).initCause(cause); } catch (Exception unexpectedError) { if (rawChannel != null) { // If we managed to open the file before failing, then close the channel try { rawChannel.close(); } catch (IOException e) { unexpectedError.addSuppressed(e); } } throw unexpectedError; } }
/// <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(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStoreAndRestoreIds() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStoreAndRestoreIds() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); ISet <long> freeIds = new HashSet <long>(); // stack guarantees are not maintained between restarts // when // we store enough ids to cause overflow to file for (long i = 0; i < batchSize; i++) { keeper.FreeId(i); freeIds.Add(i); } // and then some more int extraIds = 3; for (long i = batchSize; i < batchSize + extraIds; i++) { keeper.FreeId(i); freeIds.Add(i); } // and then we close the keeper keeper.Dispose(); channel.close(); // and then we open a new one over the same file channel = Fs.get().open(new File("id.file"), OpenMode.READ_WRITE); keeper = GetFreeIdKeeperAggressive(channel, batchSize); // then // the count should be returned correctly assertEquals(batchSize + extraIds, keeper.Count); assertEquals(freeIds.Count, keeper.Count); // and the ids, including the ones that did not cause a write, are still there (as a stack) for (int i = batchSize + extraIds - 1; i >= 0; i--) { long id = keeper.Id; assertTrue(freeIds.Contains(id)); } }
//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 shouldReturnNoResultIfIdsAreRestoredAndExhaustedAndThereAreFreeIdsFromThisRunWithAggressiveFalse() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReturnNoResultIfIdsAreRestoredAndExhaustedAndThereAreFreeIdsFromThisRunWithAggressiveFalse() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeper(channel, batchSize); ISet <long> freeIds = new HashSet <long>(); for (long i = 0; i < batchSize; i++) { keeper.FreeId(i); freeIds.Add(i); } keeper.Dispose(); channel.close(); // and then we open a new one over the same file channel = Fs.get().open(new File("id.file"), OpenMode.READ_WRITE); keeper = GetFreeIdKeeper(channel, batchSize); // when - then // we exhaust all ids restored for (int i = 0; i < batchSize; i++) { assertTrue(freeIds.remove(keeper.Id)); } // when // we release some ids that spill to disk for (int i = 0; i < batchSize; i++) { keeper.FreeId(i); } // then // we should have no ids to return assertEquals(NO_RESULT, keeper.Id); }
//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)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void releaseChannel() throws java.io.IOException private void ReleaseChannel() { _storeLockFileChannel.close(); _storeLockFileChannel = null; }
//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(); }
/// <summary> /// External synchronization between this method and emptyBufferIntoChannelAndClearIt is required so that they /// aren't called concurrently. Currently that's done by acquiring the PhysicalLogFile monitor. /// </summary> //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() { PrepareForFlush().flush(); _closed = true; ChannelConflict.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() { _channel.close(); }