Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreUnexpectedLogDirectoryContents()
        public virtual void ShouldIgnoreUnexpectedLogDirectoryContents()
        {
            // Given
            // a raft log directory with just the expected files, without gaps
            File                  @base     = new File("base");
            FileNames             fileNames = new FileNames(@base);
            FileSystemAbstraction fsa       = mock(typeof(FileSystemAbstraction));
            Log          log          = mock(typeof(Log));
            IList <File> filesPresent = new LinkedList <File>();

            filesPresent.Add(fileNames.GetForVersion(0));                        // should be included
            filesPresent.Add(fileNames.GetForVersion(1));                        // should be included
            filesPresent.Add(fileNames.GetForVersion(10));                       // should be included
            filesPresent.Add(fileNames.GetForVersion(11));                       // should be included
            filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "01"));  // should be ignored
            filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "001")); // should be ignored
            filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME));         // should be ignored
            filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "-1"));  // should be ignored
            filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "1a"));  // should be ignored
            filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "a1"));  // should be ignored
            filesPresent.Add(new File(@base, FileNames.BASE_FILE_NAME + "ab"));  // should be ignored

            when(fsa.ListFiles(@base)).thenReturn(filesPresent.ToArray());

            // When
            // asked for the contents of the directory
            SortedDictionary <long, File> allFiles = fileNames.GetAllFiles(fsa, log);

            // Then
            // only valid things should be returned
            assertEquals(4, allFiles.Count);
            assertEquals(allFiles[0L], fileNames.GetForVersion(0));
            assertEquals(allFiles[1L], fileNames.GetForVersion(1));
            assertEquals(allFiles[10L], fileNames.GetForVersion(10));
            assertEquals(allFiles[11L], fileNames.GetForVersion(11));

            // and the invalid ones should be logged
            verify(log, times(7)).warn(anyString());
        }
Esempio n. 2
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]);
        }
Esempio n. 3
0
        private RecoveryProtocol CreateRecoveryProtocol()
        {
            FileNames fileNames = new FileNames(_logDirectory);

            return(new RecoveryProtocol(FsRule.get(), fileNames, new ReaderPool(8, Instance, fileNames, FsRule.get(), Clocks.fakeClock()), CoreReplicatedContentMarshal.marshaller(), Instance));
        }
Esempio n. 4
0
 private void InitializeInstanceFields()
 {
     _fileNames  = new FileNames(_baseDir);
     _readerPool = spy(new ReaderPool(0, _logProvider, _fileNames, FsRule.get(), Clocks.fakeClock()));
 }
Esempio n. 5
0
 private void InitializeInstanceFields()
 {
     _fileNames = new FileNames(@base);
     _pool      = new ReaderPool(2, Instance, _fileNames, _fsa, _clock);
 }
Esempio n. 6
0
 private void InitializeInstanceFields()
 {
     _fsa        = FileSystemRule.get();
     _fileNames  = new FileNames(_root);
     _readerPool = new ReaderPool(0, Instance, _fileNames, _fsa, Clocks.fakeClock());
 }