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 exitWithFailureIfConfigSpecifiedButConfigFileDoesNotExist()
        public virtual void ExitWithFailureIfConfigSpecifiedButConfigFileDoesNotExist()
        {
            // given
            File configFile = _testDirectory.file("nonexistent_file");

            string[] args = new string[] { "-host", "localhost", "-to", "my_backup", "-config", configFile.Path };
            BackupProtocolService service    = mock(typeof(BackupProtocolService));
            PrintStream           systemOut  = mock(typeof(PrintStream));
            BackupTool            backupTool = new BackupTool(service, systemOut);

            try
            {
                // when
                backupTool.Run(args);
                fail("should exit abnormally");
            }
            catch (BackupTool.ToolFailureException e)
            {
                // then
                assertThat(e.Message, containsString("Could not read configuration file"));
                assertThat(e.InnerException, instanceOf(typeof(ConfigLoadIOException)));
            }

            verifyZeroInteractions(service);
        }
Ejemplo n.º 2
0
            internal UriTests(string host, int?port)
            {
                this.UriConflict = (port == null) ? host : host + ":" + port;
                this.Host        = host.Replace("ha://", "").Replace("single://", "");
                this.Port        = (port == null) ? BackupServer.DEFAULT_PORT : port;

                this.BackupProtocolService = mock(typeof(BackupProtocolService));
                this.SystemOut             = mock(typeof(PrintStream));
            }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMakeUseOfDebugArgument() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMakeUseOfDebugArgument()
        {
            // given
            string[] args = new string[] { "-from", "localhost", "-to", "my_backup", "-gather-forensics" };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            // when
            (new BackupTool(service, systemOut)).Run(args);

            // then
            verify(service).doIncrementalBackupOrFallbackToFull(anyString(), anyInt(), eq(DatabaseLayout.of(Paths.get("my_backup").toFile())), any(typeof(ConsistencyCheck)), any(typeof(Config)), anyLong(), eq(true));
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveNoConsistencyCheckIfVerifyFalse() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHaveNoConsistencyCheckIfVerifyFalse()
        {
            // Given
            string[] args = new string[] { "-host", "localhost", "-to", "my_backup", "-verify", "false" };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            // When
            (new BackupTool(service, systemOut)).Run(args);

            // Then
            verify(service).doIncrementalBackupOrFallbackToFull(anyString(), anyInt(), any(typeof(DatabaseLayout)), eq(ConsistencyCheck.NONE), any(typeof(Config)), anyLong(), anyBoolean());
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRespectConsistencyCheckerWithDefaultVerify() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRespectConsistencyCheckerWithDefaultVerify()
        {
            // Given
            string[] args = new string[] { "-host", "localhost", "-to", "my_backup", "-consistency-checker", "full" };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            // When
            (new BackupTool(service, systemOut)).Run(args);

            // Then
            verify(service).doIncrementalBackupOrFallbackToFull(anyString(), anyInt(), any(typeof(DatabaseLayout)), eq(ConsistencyCheck.FULL), any(typeof(Config)), anyLong(), anyBoolean());
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreFullFlag() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIgnoreFullFlag()
        {
            string[] args = new string[] { "-full", "-host", "localhost", "-to", "my_backup" };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            // when
            (new BackupTool(service, systemOut)).Run(args);

            // then
            verify(service).doIncrementalBackupOrFallbackToFull(eq("localhost"), eq(BackupServer.DEFAULT_PORT), eq(DatabaseLayout.of(Paths.get("my_backup").toFile())), eq(ConsistencyCheck.FULL), any(typeof(Config)), eq(BackupClient.BIG_READ_TIMEOUT), eq(false));
            verify(systemOut).println("Performing backup from '" + new HostnamePort("localhost", BackupServer.DEFAULT_PORT) + "'");
            verify(systemOut).println("Done");
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInvokeBackupServiceWhenArgsAreValid() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldInvokeBackupServiceWhenArgsAreValid()
        {
            // Given
            string[] args = ArgsAsString.Split(" ", true);

            BackupProtocolService backupProtocolService = mock(typeof(BackupProtocolService));
            PrintStream           printStream           = mock(typeof(PrintStream));
            BackupTool            backupTool            = new BackupTool(backupProtocolService, printStream);

            // When
            backupTool.Run(args);

            // Then
            verify(backupProtocolService).doIncrementalBackupOrFallbackToFull(eq(HOST), eq(PORT), eq(DatabaseLayout.of(_path.toFile())), ExpectedVerifyStoreValue ? eq(ConsistencyCheck.FULL) : eq(ConsistencyCheck.NONE), any(typeof(Config)), eq(BackupClient.BIG_READ_TIMEOUT), eq(false));
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void appliesDefaultTuningConfigurationForConsistencyChecker() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AppliesDefaultTuningConfigurationForConsistencyChecker()
        {
            // given
            string[] args = new string[] { "-host", "localhost", "-to", "my_backup" };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            // when
            (new BackupTool(service, systemOut)).Run(args);

            // then
            ArgumentCaptor <Config> config = ArgumentCaptor.forClass(typeof(Config));

            verify(service).doIncrementalBackupOrFallbackToFull(anyString(), anyInt(), eq(DatabaseLayout.of(Paths.get("my_backup").toFile())), any(typeof(ConsistencyCheck)), config.capture(), eq(BackupClient.BIG_READ_TIMEOUT), eq(false));
            assertFalse(config.Value.get(ConsistencyCheckSettings.consistency_check_property_owners));
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldResetTimeout() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldResetTimeout()
        {
            string newTimeout      = "3";          //seconds by default
            long   expectedTimeout = 3 * 1000;

            string[] args = new string[] { "-host", "localhost", "-to", "my_backup", "-timeout", newTimeout };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            // when
            (new BackupTool(service, systemOut)).Run(args);

            // then
            verify(service).doIncrementalBackupOrFallbackToFull(eq("localhost"), eq(BackupServer.DEFAULT_PORT), eq(DatabaseLayout.of(Paths.get("my_backup").toFile())), eq(ConsistencyCheck.FULL), any(typeof(Config)), eq(expectedTimeout), eq(false));
            verify(systemOut).println("Performing backup from '" + new HostnamePort("localhost", BackupServer.DEFAULT_PORT) + "'");
            verify(systemOut).println("Done");
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRespectVerifyFlagWithLegacyArguments() throws BackupTool.ToolFailureException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRespectVerifyFlagWithLegacyArguments()
        {
            // Given
            string host      = "localhost";
            Path   targetDir = Paths.get("/var/backup/neo4j/");

            string[] args = new string[] { "-from", host, "-to", targetDir.ToString(), "-verify", "false" };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            // When
            (new BackupTool(service, systemOut)).Run(args);

            // Then
            verify(service).doIncrementalBackupOrFallbackToFull(eq(host), eq(BackupServer.DEFAULT_PORT), eq(DatabaseLayout.of(targetDir.toFile())), eq(ConsistencyCheck.NONE), any(typeof(Config)), eq(BackupClient.BIG_READ_TIMEOUT), eq(false));
            verify(systemOut).println("Performing backup from '" + new HostnamePort(host, BackupServer.DEFAULT_PORT) + "'");
            verify(systemOut).println("Done");
        }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCrashIfInvalidConsistencyCheckerSpecified() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCrashIfInvalidConsistencyCheckerSpecified()
        {
            // Given
            string[] args = new string[] { "-host", "localhost", "-to", "my_backup", "-verify", "true", "-consistency-checker", "notarealname" };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            try
            {
                // When
                (new BackupTool(service, systemOut)).Run(args);
                fail("Should throw exception if invalid consistency checker is specified.");
            }
            catch (System.ArgumentException t)
            {
                // Then
                assertThat(t.Message, containsString("Unknown consistency check name"));
            }
        }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void passesOnConfigurationIfProvided() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void PassesOnConfigurationIfProvided()
        {
            // given
            File       configFile = _testDirectory.file(Config.DEFAULT_CONFIG_FILE_NAME);
            Properties properties = new Properties();

            properties.setProperty(ConsistencyCheckSettings.consistency_check_property_owners.name(), "true");
            properties.store(new StreamWriter(configFile), null);

            string[] args = new string[] { "-host", "localhost", "-to", "my_backup", "-config", configFile.Path };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            // when
            (new BackupTool(service, systemOut)).Run(args);

            // then
            ArgumentCaptor <Config> config = ArgumentCaptor.forClass(typeof(Config));

            verify(service).doIncrementalBackupOrFallbackToFull(anyString(), anyInt(), eq(DatabaseLayout.of(Paths.get("my_backup").toFile())), any(typeof(ConsistencyCheck)), config.capture(), anyLong(), eq(false));
            assertTrue(config.Value.get(ConsistencyCheckSettings.consistency_check_property_owners));
        }
Ejemplo n.º 13
0
        public static void Main(string[] args)
        {
            Console.Error.WriteLine("WARNING: neo4j-backup is deprecated and support for it will be removed in a future\n" + "version of Neo4j; please use neo4j-admin backup instead.\n");
            try
            {
                using (BackupProtocolService backupProtocolService = backupProtocolService())
                {
                    BackupTool    tool          = new BackupTool(backupProtocolService, System.out);
                    BackupOutcome backupOutcome = tool.Run(args);

                    if (!backupOutcome.Consistent)
                    {
                        ExitFailure("WARNING: The database is inconsistent.");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Backup failed.");
                ExitFailure(e.Message);
            }
        }
Ejemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void exitWithFailureIfInvalidSourceSpecified()
        public virtual void ExitWithFailureIfInvalidSourceSpecified()
        {
            // given
            string[] args = new string[] { "-host", "foo:localhost", "-port", "123", "-to", "my_backup" };
            BackupProtocolService service    = mock(typeof(BackupProtocolService));
            PrintStream           systemOut  = mock(typeof(PrintStream));
            BackupTool            backupTool = new BackupTool(service, systemOut);

            try
            {
                // when
                backupTool.Run(args);
                fail("should exit abnormally");
            }
            catch (BackupTool.ToolFailureException e)
            {
                // then
                assertEquals(BackupTool.WrongFromAddressSyntax, e.Message);
            }

            verifyZeroInteractions(service);
        }
Ejemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void exitWithFailureIfNoDestinationSpecified()
        public virtual void ExitWithFailureIfNoDestinationSpecified()
        {
            // given
            string[] args = new string[] { "-host", "localhost" };
            BackupProtocolService service    = mock(typeof(BackupProtocolService));
            PrintStream           systemOut  = mock(typeof(PrintStream));
            BackupTool            backupTool = new BackupTool(service, systemOut);

            try
            {
                // when
                backupTool.Run(args);
                fail("should exit abnormally");
            }
            catch (BackupTool.ToolFailureException e)
            {
                // then
                assertEquals("Specify target location with -to <target-directory>", e.Message);
            }

            verifyZeroInteractions(service);
        }
Ejemplo n.º 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void helpMessageForWrongUriShouldNotContainSchema()
        public virtual void HelpMessageForWrongUriShouldNotContainSchema()
        {
            // given
            string[] args = new string[] { "-host", ":VeryWrongURI:", "-to", "/var/backup/graph" };
            BackupProtocolService service   = mock(typeof(BackupProtocolService));
            PrintStream           systemOut = mock(typeof(PrintStream));

            try
            {
                // when
                (new BackupTool(service, systemOut)).Run(args);
                fail("should exit abnormally");
            }
            catch (BackupTool.ToolFailureException e)
            {
                // then
                assertThat(e.Message, equalTo(BackupTool.WrongFromAddressSyntax));
                assertThat(e.Message, not(containsString("<schema>")));
            }

            verifyZeroInteractions(service, systemOut);
        }
Ejemplo n.º 17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static BackupResult backup(String host, int port, java.nio.file.Path targetDirectory) throws Exception
        public static BackupResult Backup(string host, int port, Path targetDirectory)
        {
            MemoryStream outputStream     = new MemoryStream();
            bool         consistent       = true;
            bool         transientFailure = false;
            bool         failure          = false;

            try
            {
                using (BackupProtocolService backupProtocolService = backupProtocolService(outputStream))
                {
                    BackupOutcome backupOutcome = backupProtocolService.DoIncrementalBackupOrFallbackToFull(host, port, DatabaseLayout.of(targetDirectory.toFile()), ConsistencyCheck.FULL, Config.defaults(), BackupClient.BIG_READ_TIMEOUT, false);
                    consistent = backupOutcome.Consistent;
                }
            }
            catch (Exception t)
            {
                if (_isTransientError.test(t))
                {
                    transientFailure = true;
                }
                else
                {
                    failure = true;
                    throw t;
                }
            }
            finally
            {
                if (!consistent || failure)
                {
                    FlushToStandardOutput(outputStream);
                }
                IOUtils.closeAllSilently(outputStream);
            }
            return(new BackupResult(consistent, transientFailure));
        }
Ejemplo n.º 18
0
 internal BackupTool(BackupProtocolService backupProtocolService, PrintStream systemOut)
 {
     this._backupProtocolService = backupProtocolService;
     this._systemOut             = systemOut;
 }