Search in sources :

Example 6 with ServiceUnavailableException

use of org.neo4j.driver.exceptions.ServiceUnavailableException in project neo4j by neo4j.

the class InteractiveShellRunnerTest method testSwitchToUnavailableDatabase2.

@Test
public void testSwitchToUnavailableDatabase2() throws Exception {
    // given
    String input = ":use foo;\n";
    TestInteractiveShellRunner sr = setupInteractiveTestShellRunner(input);
    // when
    when(sr.mockedBoltStateHandler.getActualDatabaseAsReportedByServer()).thenReturn("foo");
    doThrow(new ServiceUnavailableException("Not available")).when(sr.mockedBoltStateHandler).setActiveDatabase("foo");
    sr.runner.runUntilEnd();
    // then
    assertThat(sr.output.toString(), containsString(format("myusername@foo%s> ", DATABASE_UNAVAILABLE_ERROR_PROMPT_TEXT)));
    assertThat(sr.error.toString(), containsString("Not available"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) Test(org.junit.Test)

Example 7 with ServiceUnavailableException

use of org.neo4j.driver.exceptions.ServiceUnavailableException in project neo4j by neo4j.

the class MainIntegrationTest method switchingToUnavailableDefaultDatabaseIfInteractive.

@Test
public void switchingToUnavailableDefaultDatabaseIfInteractive() throws Exception {
    shell.setCommandHelper(new CommandHelper(mock(Logger.class), Historian.empty, shell));
    inputBuffer.put(String.format("neo4j%nneo%n").getBytes());
    assertEquals("", connectionConfig.username());
    assertEquals("", connectionConfig.password());
    // when
    main.connectMaybeInteractively(shell, connectionConfig, true, true, true);
    // Multiple databases are only available from 4.0
    assumeTrue(majorVersion(shell.getServerVersion()) >= 4);
    // then
    // should be connected
    assertTrue(shell.isConnected());
    // should have prompted and set the username and password
    String expectedLoginOutput = format("username: neo4j%npassword: ***%n");
    assertEquals(expectedLoginOutput, baos.toString());
    assertEquals("neo4j", connectionConfig.username());
    assertEquals("neo", connectionConfig.password());
    // Stop the default database
    shell.execute(":use " + SYSTEM_DB_NAME);
    shell.execute("STOP DATABASE " + DatabaseManager.DEFAULT_DEFAULT_DB_NAME);
    try {
        // Should get exception that database is unavailable when trying to connect
        shell.execute(":use");
        fail("No exception thrown");
    } catch (TransientException | ServiceUnavailableException e) {
        expectDatabaseUnavailable(e, "neo4j");
    } finally {
        // Start the default database again
        ensureDefaultDatabaseStarted();
    }
}
Also used : TransientException(org.neo4j.driver.exceptions.TransientException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) CommandHelper(org.neo4j.shell.commands.CommandHelper) Test(org.junit.Test)

Aggregations

ServiceUnavailableException (org.neo4j.driver.exceptions.ServiceUnavailableException)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Test (org.junit.Test)4 TransientException (org.neo4j.driver.exceptions.TransientException)3 CommandHelper (org.neo4j.shell.commands.CommandHelper)3 ClientException (org.neo4j.driver.exceptions.ClientException)2 DiscoveryException (org.neo4j.driver.exceptions.DiscoveryException)2 Neo4jException (org.neo4j.driver.exceptions.Neo4jException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Nonnull (javax.annotation.Nonnull)1 AuthToken (org.neo4j.driver.AuthToken)1 SessionExpiredException (org.neo4j.driver.exceptions.SessionExpiredException)1 ConnectionConfig (org.neo4j.shell.ConnectionConfig)1 AnsiFormattedException (org.neo4j.shell.exception.AnsiFormattedException)1 CommandException (org.neo4j.shell.exception.CommandException)1 Versions.isPasswordChangeRequiredException (org.neo4j.shell.util.Versions.isPasswordChangeRequiredException)1