Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotReturnReaderExperiencingErrorToPool() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotReturnReaderExperiencingErrorToPool()
        {
            // given
            StoreChannel channel    = mock(typeof(StoreChannel));
            Reader       reader     = mock(typeof(Reader));
            ReaderPool   readerPool = mock(typeof(ReaderPool));

            when(channel.read(any(typeof(ByteBuffer)))).thenThrow(new IOException());
            when(reader.Channel()).thenReturn(channel);
            when(readerPool.Acquire(anyLong(), anyLong())).thenReturn(reader);

            using (SegmentFile segment = create(FsRule.get(), _fileNames.getForVersion(0), readerPool, 0, _contentMarshal, _logProvider, _segmentHeader))
            {
                // given
                IOCursor <EntryRecord> cursor = segment.GetCursor(0);

                try
                {
                    cursor.next();
                    fail();
                }
                catch (IOException)
                {
                    // expected from mocking
                }

                // when
                cursor.close();

                // then
                verify(readerPool, never()).release(reader);
                verify(reader).close();
            }
        }
Ejemplo n.º 3
0
 private void InitializeInstanceFields()
 {
     _fileNames  = new FileNames(_bam);
     _readerPool = new ReaderPool(0, Instance, _fileNames, _fsa, Clocks.fakeClock());
     _segments   = new Segments(_fsa, _fileNames, _readerPool, emptyList(), mock(typeof(ChannelMarshal)), NullLogProvider.Instance, -1);
     _fsa.mkdir(_bam);
 }
Ejemplo n.º 4
0
 internal RecoveryProtocol(FileSystemAbstraction fileSystem, FileNames fileNames, ReaderPool readerPool, ChannelMarshal <ReplicatedContent> contentMarshal, LogProvider logProvider)
 {
     this._fileSystem     = fileSystem;
     this._fileNames      = fileNames;
     this._readerPool     = readerPool;
     this._contentMarshal = contentMarshal;
     this._logProvider    = logProvider;
     this._log            = logProvider.getLog(this.GetType());
 }
Ejemplo n.º 5
0
 private void InitializeInstanceFields()
 {
     _fileNames    = new FileNames(_baseDirectory);
     _readerPool   = new ReaderPool(0, Instance, _fileNames, _fsa, Clocks.fakeClock());
     _fileA        = spy(new SegmentFile(_fsa, _fileNames.getForVersion(0), _readerPool, 0, _contentMarshal, _logProvider, _header));
     _fileB        = spy(new SegmentFile(_fsa, _fileNames.getForVersion(1), _readerPool, 1, _contentMarshal, _logProvider, _header));
     _segmentFiles = new IList <SegmentFile> {
         _fileA, _fileB
     };
 }
Ejemplo n.º 6
0
        internal Segments(FileSystemAbstraction fileSystem, FileNames fileNames, ReaderPool readerPool, IList <SegmentFile> allSegments, ChannelMarshal <ReplicatedContent> contentMarshal, LogProvider logProvider, long currentVersion)
        {
            this._fileSystem     = fileSystem;
            this._fileNames      = fileNames;
            this._allSegments    = new List <SegmentFile>(allSegments);
            this._contentMarshal = contentMarshal;
            this._logProvider    = logProvider;
            this._log            = logProvider.getLog(this.GetType());
            this._currentVersion = currentVersion;
            this._readerPool     = readerPool;

            PopulateRangeMap();
        }
Ejemplo n.º 7
0
        internal SegmentFile(FileSystemAbstraction fileSystem, File file, ReaderPool readerPool, long version, ChannelMarshal <ReplicatedContent> contentMarshal, LogProvider logProvider, SegmentHeader header)
        {
            this._fileSystem     = fileSystem;
            this._file           = file;
            this._readerPool     = readerPool;
            this._contentMarshal = contentMarshal;
            this._header         = header;
            this._version        = version;

            this._positionCache = new PositionCache();
            this._refCount      = new ReferenceCounter();

            this._log = logProvider.getLog(this.GetType());
        }
Ejemplo n.º 8
0
        public SegmentedRaftLog(FileSystemAbstraction fileSystem, File directory, long rotateAtSize, ChannelMarshal <ReplicatedContent> contentMarshal, LogProvider logProvider, int readerPoolSize, Clock clock, JobScheduler scheduler, CoreLogPruningStrategy pruningStrategy)
        {
            this._fileSystem     = fileSystem;
            this._directory      = directory;
            this._rotateAtSize   = rotateAtSize;
            this._contentMarshal = contentMarshal;
            this._logProvider    = logProvider;
            this._scheduler      = scheduler;

            this._fileNames  = new FileNames(directory);
            this._readerPool = new ReaderPool(readerPoolSize, logProvider, _fileNames, fileSystem, clock);
            this._pruner     = new SegmentedRaftLogPruner(pruningStrategy);
            this._log        = logProvider.getLog(this.GetType());
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private int dump(String filenameOrDirectory, java.io.PrintStream out) throws java.io.IOException, DamagedLogStorageException, DisposedException
        private int Dump(string filenameOrDirectory, PrintStream @out)
        {
            LogProvider logProvider = NullLogProvider.Instance;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int[] logsFound = {0};
            int[]            logsFound        = new int[] { 0 };
            FileNames        fileNames        = new FileNames(new File(filenameOrDirectory));
            ReaderPool       readerPool       = new ReaderPool(0, logProvider, fileNames, _fileSystem, Clocks.systemClock());
            RecoveryProtocol recoveryProtocol = new RecoveryProtocol(_fileSystem, fileNames, readerPool, _marshal, logProvider);
            Segments         segments         = recoveryProtocol.Run().Segments;

            segments.Visit(segment =>
            {
                logsFound[0]++;
                @out.println("=== " + segment.Filename + " ===");
                SegmentHeader header = segment.header();
                @out.println(header.ToString());
                try
                {
                    using (IOCursor <EntryRecord> cursor = segment.getCursor(header.PrevIndex() + 1))
                    {
                        while (cursor.next())
                        {
                            @out.println(cursor.get().ToString());
                        }
                    }
                }
                catch (Exception e) when(e is DisposedException || e is IOException)
                {
                    e.printStackTrace();
                    Environment.Exit(-1);
                    return(true);
                }
                return(false);
            });

            return(logsFound[0]);
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static SegmentFile create(org.neo4j.io.fs.FileSystemAbstraction fileSystem, java.io.File file, ReaderPool readerPool, long version, org.neo4j.causalclustering.messaging.marshalling.ChannelMarshal<org.neo4j.causalclustering.core.replication.ReplicatedContent> contentMarshal, org.neo4j.logging.LogProvider logProvider, SegmentHeader header) throws java.io.IOException
        internal static SegmentFile Create(FileSystemAbstraction fileSystem, File file, ReaderPool readerPool, long version, ChannelMarshal <ReplicatedContent> contentMarshal, LogProvider logProvider, SegmentHeader header)
        {
            if (fileSystem.FileExists(file))
            {
                throw new System.InvalidOperationException("File was not expected to exist");
            }

            SegmentFile segment = new SegmentFile(fileSystem, file, readerPool, version, contentMarshal, logProvider, header);

            _headerMarshal.marshal(header, segment.OrCreateWriter);
            segment.Flush();

            return(segment);
        }
Ejemplo n.º 11
0
 private void InitializeInstanceFields()
 {
     _fileNames = new FileNames(@base);
     _pool      = new ReaderPool(2, Instance, _fileNames, _fsa, _clock);
 }
Ejemplo n.º 12
0
 private void InitializeInstanceFields()
 {
     _fsa        = FileSystemRule.get();
     _fileNames  = new FileNames(_root);
     _readerPool = new ReaderPool(0, Instance, _fileNames, _fsa, Clocks.fakeClock());
 }