Search in sources :

Example 1 with DatabaseState

use of org.neo4j.dbms.DatabaseState in project neo4j by neo4j.

the class CommunityDatabaseStateProcedureTest method shouldThrowWhenDatabaseNotFound.

@Test
void shouldThrowWhenDatabaseNotFound() throws ProcedureException {
    // given
    var existing = idRepository.getRaw("existing");
    var nonExisting = idRepository.getRaw("nonExisting");
    idRepository.filter(nonExisting.name());
    Map<NamedDatabaseId, DatabaseState> states = Map.of(existing, new CommunityDatabaseState(existing, true, false, null));
    var stateService = new StubDatabaseStateService(states, CommunityDatabaseState::unknown);
    var procedure = procedure(stateService);
    // when/then
    // Should not throw
    procedure.apply(mock(Context.class), new AnyValue[] { stringValue(existing.name()) }, mock(ResourceTracker.class));
    // Should throw
    assertThrows(ProcedureException.class, () -> procedure.apply(mock(Context.class), new AnyValue[] { stringValue(nonExisting.name()) }, mock(ResourceTracker.class)));
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) DatabaseState(org.neo4j.dbms.DatabaseState) CommunityDatabaseState(org.neo4j.dbms.CommunityDatabaseState) CommunityDatabaseState(org.neo4j.dbms.CommunityDatabaseState) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) StubDatabaseStateService(org.neo4j.dbms.StubDatabaseStateService) AnyValue(org.neo4j.values.AnyValue) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Test(org.junit.jupiter.api.Test)

Example 2 with DatabaseState

use of org.neo4j.dbms.DatabaseState in project neo4j by neo4j.

the class CommunityDatabaseStateProcedureTest method shouldReturnEmptyErrorForNoError.

@Test
void shouldReturnEmptyErrorForNoError() throws ProcedureException {
    // given
    var existing = idRepository.getRaw("existing");
    Map<NamedDatabaseId, DatabaseState> states = Map.of(existing, new CommunityDatabaseState(existing, true, false, null));
    var stateService = new StubDatabaseStateService(states, CommunityDatabaseState::unknown);
    var procedure = procedure(stateService);
    // when
    var result = procedure.apply(mock(Context.class), new AnyValue[] { stringValue(existing.name()) }, mock(ResourceTracker.class));
    var returned = Arrays.asList(result.next());
    // then
    assertEquals(4, returned.size(), "Procedure result should have 4 columns: role, address, state and error message");
    var roleColumn = stringValue("standalone");
    var addressColumn = stringValue("localhost:7687");
    var statusColumn = stringValue("online");
    var errorColumn = stringValue("");
    assertEquals(Arrays.asList(roleColumn, addressColumn, statusColumn, errorColumn), returned, "Error column should be empty");
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) DatabaseState(org.neo4j.dbms.DatabaseState) CommunityDatabaseState(org.neo4j.dbms.CommunityDatabaseState) CommunityDatabaseState(org.neo4j.dbms.CommunityDatabaseState) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) StubDatabaseStateService(org.neo4j.dbms.StubDatabaseStateService) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 CommunityDatabaseState (org.neo4j.dbms.CommunityDatabaseState)2 DatabaseState (org.neo4j.dbms.DatabaseState)2 StubDatabaseStateService (org.neo4j.dbms.StubDatabaseStateService)2 ResourceTracker (org.neo4j.kernel.api.ResourceTracker)2 Context (org.neo4j.kernel.api.procedure.Context)2 NamedDatabaseId (org.neo4j.kernel.database.NamedDatabaseId)2 AnyValue (org.neo4j.values.AnyValue)1