//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOpenTheNextChannelWhenItExists() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldOpenTheNextChannelWhenItExists()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.fs.StoreChannel newStoreChannel = mock(org.neo4j.io.fs.StoreChannel.class);
            StoreChannel newStoreChannel = mock(typeof(StoreChannel));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge bridge = new org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge(logFiles);
            ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(_logFiles);

            when(_channel.Version).thenReturn(_version);
            when(_channel.LogFormatVersion).thenReturn(CURRENT_LOG_VERSION);
            when(_fs.fileExists(any(typeof(File)))).thenReturn(true);
            when(_fs.open(any(typeof(File)), eq(OpenMode.READ))).thenReturn(newStoreChannel);
            when(newStoreChannel.read(ArgumentMatchers.any <ByteBuffer>())).then(invocationOnMock =>
            {
                ByteBuffer buffer = invocationOnMock.getArgument(0);
                buffer.putLong(encodeLogVersion(_version + 1));
                buffer.putLong(42);
                return(LOG_HEADER_SIZE);
            });

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel result = bridge.next(channel);
            LogVersionedStoreChannel result = bridge.Next(_channel);

            // then
            PhysicalLogVersionedStoreChannel expected = new PhysicalLogVersionedStoreChannel(newStoreChannel, _version + 1, CURRENT_LOG_VERSION);

            assertEquals(expected, result);
            verify(_channel, times(1)).close();
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the id generator and performs a simple validation. Returns true if the initialization restored
        /// properly on disk state, false otherwise (such as creating an id file from scratch).
        /// Will throw <seealso cref="InvalidIdGeneratorException"/> if the id file is found to be damaged or unclean.
        /// </summary>
        public virtual bool Init()
        {
            bool result = true;

            try
            {
                if (!_fs.fileExists(_file))
                {
                    CreateEmptyIdFile(_fs, _file, 0, false);
                    result = false;
                }

                _fileChannel   = _fs.open(_file, OpenMode.READ_WRITE);
                _initialHighId = ReadAndValidateHeader();
                MarkAsSticky();

                this._freeIdKeeper = new FreeIdKeeper(new OffsetChannel(_fileChannel, HeaderSize), _grabSize, _aggressiveReuse);
                _closed            = false;
            }
            catch (IOException e)
            {
                throw new UnderlyingStorageException("Unable to init id file " + _file, e);
            }
            return(result);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseChannelOnClose() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseChannelOnClose()
        {
            // given
            when(_fsa.open(_file, OpenMode.READ)).thenReturn(_channel);
            Reader reader = new Reader(_fsa, _file, 0);

            // when
            reader.Dispose();

            // then
            verify(_channel).close();
        }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private ByteBuffer readFileContent(java.io.File nativeLabelIndex, int length) throws java.io.IOException
        private ByteBuffer ReadFileContent(File nativeLabelIndex, int length)
        {
            using (StoreChannel storeChannel = _fileSystem.open(nativeLabelIndex, OpenMode.READ))
            {
                ByteBuffer readBuffer = ByteBuffer.allocate(length);
                //noinspection StatementWithEmptyBody
                while (readBuffer.hasRemaining() && storeChannel.read(readBuffer) > 0)
                {
                    // read till the end of store channel
                }
                readBuffer.flip();
                return(readBuffer);
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public T readState() throws java.io.IOException
        public override T ReadState()
        {
            try
            {
                using (ReadableClosableChannel channel = new ReadAheadChannel <>(_fileSystem.open(_file, OpenMode.READ)))
                {
                    return(_marshal.unmarshal(channel));
                }
            }
            catch (EndOfStreamException e)
            {
                _log.error("End of stream reached: " + _file);
                throw new IOException(e);
            }
        }
Beispiel #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: BlockEntryReader<KEY,VALUE> nextBlock(ByteBuffer blockBuffer) throws java.io.IOException
        internal virtual BlockEntryReader <KEY, VALUE> NextBlock(ByteBuffer blockBuffer)
        {
            long position = _channel.position();

            if (position >= _channel.size())
            {
                return(null);
            }
            StoreChannel blockChannel = _fs.open(_file, OpenMode.READ);

            blockChannel.Position(position);
            PageCursor pageCursor = new ReadableChannelPageCursor(new ReadAheadChannel <>(blockChannel, blockBuffer));
            BlockEntryReader <KEY, VALUE> blockEntryReader = new BlockEntryReader <KEY, VALUE>(pageCursor, _layout);
            long blockSize = blockEntryReader.BlockSize();

            _channel.position(position + blockSize);
            return(blockEntryReader);
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldForceChannelAfterWritingMetadata() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldForceChannelAfterWritingMetadata()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.fs.StoreChannel[] channelUsedToCreateFile = {null};
            StoreChannel[] channelUsedToCreateFile = new StoreChannel[] { null };

            FileSystemAbstraction fs = spy(_fileSystem);
            StoreChannel          tempChannel;

            when(tempChannel = fs.Open(_file, OpenMode.READ_WRITE)).then(ignored =>
            {
                StoreChannel channel = _fileSystem.open(_file, OpenMode.READ_WRITE);
                if (channelUsedToCreateFile[0] == null)
                {
                    StoreChannel channelSpy    = spy(channel);
                    channelUsedToCreateFile[0] = channelSpy;
                    channel = channelSpy;
                }
                return(channel);
            });

            // Doing the FSA spying above, calling fs.open, actually invokes that method and so a channel
            // is opened. We put that in tempChannel and close it before deleting the file below.
            tempChannel.close();
            fs.DeleteFile(_file);

            // When
            IndexProviderStore store = new IndexProviderStore(_file, fs, MetaDataStore.versionStringToLong("3.5"), false);

            // Then
            StoreChannel channel = channelUsedToCreateFile[0];

            verify(channel).writeAll(any(typeof(ByteBuffer)), eq(0L));
            verify(channel).force(true);
            verify(channel).close();
            verifyNoMoreInteractions(channel);
            store.Close();
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void copyTransactionLogContent(long logFileIndex, long logOffset, java.util.zip.ZipOutputStream destination, ByteBuffer byteBuffer) throws java.io.IOException
        private void CopyTransactionLogContent(long logFileIndex, long logOffset, ZipOutputStream destination, ByteBuffer byteBuffer)
        {
            File logFile = _logFiles.getLogFileForVersion(logFileIndex);

            if (_fs.getFileSize(logFile) == logOffset)
            {
                // file was recovered fully, nothing to backup
                return;
            }
            ZipEntry zipEntry = new ZipEntry(logFile.Name);

            destination.putNextEntry(zipEntry);
            using (StoreChannel transactionLogChannel = _fs.open(logFile, OpenMode.READ))
            {
                transactionLogChannel.Position(logOffset);
                while (transactionLogChannel.read(byteBuffer) >= 0)
                {
                    byteBuffer.flip();
                    destination.write(byteBuffer.array(), byteBuffer.position(), byteBuffer.remaining());
                    byteBuffer.clear();
                }
            }
            destination.closeEntry();
        }
Beispiel #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: java.nio.channels.ReadableByteChannel open() throws java.io.IOException
        internal virtual ReadableByteChannel Open()
        {
            return(_fs.open(_file, OpenMode.READ));
        }
Beispiel #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: CURSOR reader() throws java.io.IOException
        internal virtual CURSOR Reader()
        {
            if (!_allocated)
            {
                return(Reader(new ByteArrayPageCursor(_noEntries)));
            }

            // Reuse the existing buffer because we're not writing while reading anyway
            _buffer.clear();
            ReadAheadChannel <StoreChannel> channel = new ReadAheadChannel <StoreChannel>(_fs.open(_file, OpenMode.READ), _buffer);
            PageCursor pageCursor = new ReadableChannelPageCursor(channel);

            return(Reader(pageCursor));
        }