Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverSeveralSkips() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverSeveralSkips()
        {
            // given
            CreateLogFile(_fsa, 10, 1, 1, 20, 9);
            CreateLogFile(_fsa, 100, 2, 2, 200, 99);
            CreateLogFile(_fsa, 1000, 3, 3, 2000, 999);

            RecoveryProtocol protocol = new RecoveryProtocol(_fsa, _fileNames, _readerPool, _contentMarshal, NullLogProvider.Instance);

            // when
            State state = protocol.Run();

            // then
            assertEquals(2000, state.PrevIndex);
            assertEquals(999, state.PrevTerm);

            assertEquals(-1, state.Terms.get(20));
            assertEquals(-1, state.Terms.get(200));
            assertEquals(-1, state.Terms.get(1999));

            assertEquals(999, state.Terms.get(2000));
            assertEquals(-1, state.Terms.get(2001));

            assertEquals(999, state.Terms.latest());
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverEvenIfLastHeaderIsMissing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverEvenIfLastHeaderIsMissing()
        {
            // given
            CreateLogFile(_fsa, -1, 0, 0, -1, -1);
            CreateEmptyLogFile(_fsa, 1);

            RecoveryProtocol protocol = new RecoveryProtocol(_fsa, _fileNames, _readerPool, _contentMarshal, NullLogProvider.Instance);

            // when
            protocol.Run();

            // then
            assertNotEquals(0, _fsa.getFileSize(_fileNames.getForVersion(1)));
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnEmptyStateOnEmptyDirectory() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnEmptyStateOnEmptyDirectory()
        {
            // given
            RecoveryProtocol protocol = new RecoveryProtocol(_fsa, _fileNames, _readerPool, _contentMarshal, NullLogProvider.Instance);

            // when
            State state = protocol.Run();

            // then
            assertEquals(-1, state.AppendIndex);
            assertEquals(-1, state.Terms.latest());
            assertEquals(-1, state.PrevIndex);
            assertEquals(-1, state.PrevTerm);
            assertEquals(0, state.Segments.last().header().version());
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailIfTheVersionNumberInTheHeaderAndFileNameDiffer() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailIfTheVersionNumberInTheHeaderAndFileNameDiffer()
        {
            // given
            CreateLogFile(_fsa, -1, 0, 1, -1, -1);

            RecoveryProtocol protocol = new RecoveryProtocol(_fsa, _fileNames, _readerPool, _contentMarshal, NullLogProvider.Instance);

            try
            {
                // when
                protocol.Run();
                fail("Expected an exception");
            }
            catch (DamagedLogStorageException)
            {
                // expected
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverAndBeAbleToSkip() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverAndBeAbleToSkip()
        {
            // given
            CreateLogFile(_fsa, -1, 0, 0, -1, -1);
            CreateLogFile(_fsa, 10, 1, 1, 10, 0);
            CreateLogFile(_fsa, 20, 2, 2, 20, 1);

            RecoveryProtocol protocol = new RecoveryProtocol(_fsa, _fileNames, _readerPool, _contentMarshal, NullLogProvider.Instance);

            // when
            State       state   = protocol.Run();
            SegmentFile newFile = state.Segments.skip(20, 40, 2);

            // then
            assertEquals(20, newFile.Header().prevFileLastIndex());
            assertEquals(3, newFile.Header().version());
            assertEquals(40, newFile.Header().prevIndex());
            assertEquals(2, newFile.Header().prevTerm());
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailIfANonLastFileIsMissingHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailIfANonLastFileIsMissingHeader()
        {
            // given
            CreateLogFile(_fsa, -1, 0, 0, -1, -1);
            CreateEmptyLogFile(_fsa, 1);
            CreateLogFile(_fsa, -1, 2, 2, -1, -1);

            RecoveryProtocol protocol = new RecoveryProtocol(_fsa, _fileNames, _readerPool, _contentMarshal, NullLogProvider.Instance);

            try
            {
                // when
                protocol.Run();
                fail("Expected an exception");
            }
            catch (DamagedLogStorageException)
            {
                // expected
            }
        }
Beispiel #7
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]);
        }
Beispiel #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void testRecoveryOfBootstrappedEntry(long bootstrapIndex, long bootstrapTerm) throws java.io.IOException, DamagedLogStorageException, DisposedException
        private void TestRecoveryOfBootstrappedEntry(long bootstrapIndex, long bootstrapTerm)
        {
            // given
            CreateLogFile(_fsa, -1, 0, 0, -1, -1);
            CreateLogFile(_fsa, -1, 1, 1, bootstrapIndex, bootstrapTerm);

            RecoveryProtocol protocol = new RecoveryProtocol(_fsa, _fileNames, _readerPool, _contentMarshal, NullLogProvider.Instance);

            // when
            State state = protocol.Run();

            // then
            assertEquals(bootstrapIndex, state.PrevIndex);
            assertEquals(bootstrapTerm, state.PrevTerm);

            assertEquals(-1, state.Terms.get(-1));
            assertEquals(-1, state.Terms.get(bootstrapIndex - 1));
            assertEquals(bootstrapTerm, state.Terms.get(bootstrapIndex));
            assertEquals(-1, state.Terms.get(bootstrapIndex + 1));

            assertEquals(bootstrapTerm, state.Terms.latest());
        }