Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWorkCorrectlyOnReasonableDirectoryContents()
        public virtual void ShouldWorkCorrectlyOnReasonableDirectoryContents()
        {
            // 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>();
            int          lower        = 0;
            int          upper        = 24;

            // the files are added in reverse order, so we can verify that FileNames orders based on version
            for (int i = upper; i >= lower; i--)
            {
                filesPresent.Add(fileNames.GetForVersion(i));
            }
            when(fsa.ListFiles(@base)).thenReturn(filesPresent.ToArray());

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

            // Then
            // all the things we added above should be returned
            assertEquals(upper - lower + 1, allFiles.Count);
            long currentVersion = lower;

            foreach (KeyValuePair <long, File> longFileEntry in allFiles.SetOfKeyValuePairs())
            {
                assertEquals(currentVersion, longFileEntry.Key.longValue());
                assertEquals(fileNames.GetForVersion(currentVersion), longFileEntry.Value);
                currentVersion++;
            }
        }
Example #2
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());
        }