Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPruneReadersOfVersion() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPruneReadersOfVersion()
        {
            // given
            _pool = new ReaderPool(8, Instance, _fileNames, _fsa, _clock);

            Reader readerA = spy(_pool.acquire(0, 0));
            Reader readerB = spy(_pool.acquire(1, 0));
            Reader readerC = spy(_pool.acquire(1, 0));
            Reader readerD = spy(_pool.acquire(2, 0));

            _pool.release(readerA);
            _pool.release(readerB);
            _pool.release(readerC);
            _pool.release(readerD);

            // when
            _pool.prune(1);

            // then
            verify(readerA, never()).close();
            verify(readerB).close();
            verify(readerC).close();
            verify(readerD, never()).close();

            // when
            _pool.prune(0);
            // then
            verify(readerA).close();
            verify(readerD, never()).close();

            // when
            _pool.prune(2);
            // then
            verify(readerD).close();
        }
Example #2
0
        /// <summary>
        /// Channels must be closed when no longer used, so that they are released back to the pool of readers.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: org.neo4j.cursor.IOCursor<org.neo4j.causalclustering.core.consensus.log.EntryRecord> getCursor(long logIndex) throws java.io.IOException, DisposedException
        internal virtual IOCursor <EntryRecord> GetCursor(long logIndex)
        {
            Debug.Assert(logIndex > _header.prevIndex());

            if (!_refCount.increase())
            {
                throw new DisposedException();
            }

            /* This is the relative index within the file, starting from zero. */
            long offsetIndex = logIndex - (_header.prevIndex() + 1);

            LogPosition position = _positionCache.lookup(offsetIndex);
            Reader      reader   = _readerPool.acquire(_version, position.ByteOffset);

            try
            {
                long currentIndex = position.LogIndex;
                return(new EntryRecordCursor(reader, _contentMarshal, currentIndex, offsetIndex, this));
            }
            catch (EndOfStreamException)
            {
                _readerPool.release(reader);
                _refCount.decrease();
                return(IOCursor.Empty);
            }
            catch (IOException e)
            {
                reader.Dispose();
                _refCount.decrease();
                throw e;
            }
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReacquireReaderFromPool() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReacquireReaderFromPool()
        {
            // given
            Reader reader = _pool.acquire(0, 0);

            _pool.release(reader);

            // when
            Reader newReader = _pool.acquire(0, 0);

            // then
            verify(_fsa, times(1)).open(any(), any());
            assertThat(reader, @is(newReader));
        }