Search in sources :

Example 16 with MapValueBuilder

use of org.neo4j.values.virtual.MapValueBuilder in project neo4j by neo4j.

the class SingleInstanceGetRoutingTableProcedureTest method shouldUseClientProvidedHostAndAdvertisedPortAsAdvertisedAddress.

@RoutingConfigsTest
void shouldUseClientProvidedHostAndAdvertisedPortAsAdvertisedAddress(Config config, String clientAddress) throws Exception {
    // given
    var advertisedBoldPort = 8776;
    var defaultBoltPort = 7687;
    var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
    config.set(BoltConnector.advertised_address, advertisedBoltAddress);
    var clientProvidedHost = clientAddress == null ? "mydomain.com" : clientAddress.split(":")[0];
    var ctxContents = new MapValueBuilder();
    ctxContents.add(ADDRESS_CONTEXT_KEY, Values.stringValue(clientProvidedHost));
    var ctx = ctxContents.build();
    var portRegister = mock(ConnectorPortRegister.class);
    when(portRegister.getLocalAddress(BoltConnector.NAME)).thenReturn(new HostnamePort("neo4j.com", advertisedBoldPort));
    var databaseManager = databaseManagerMock(config, true);
    var logProvider = new AssertableLogProvider();
    var procedure = newProcedure(databaseManager, portRegister, config, logProvider);
    var expectedAddress = new SocketAddress(clientProvidedHost, defaultBoltPort);
    // when
    var result = invoke(procedure, ID, ctx);
    // then
    assertEquals(singletonList(expectedAddress), result.readEndpoints());
    assertEquals(expectedWriters(expectedAddress), result.writeEndpoints());
    assertEquals(singletonList(expectedAddress), result.routeEndpoints());
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) HostnamePort(org.neo4j.internal.helpers.HostnamePort) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider)

Example 17 with MapValueBuilder

use of org.neo4j.values.virtual.MapValueBuilder in project neo4j by neo4j.

the class SingleInstanceGetRoutingTableProcedureTest method shouldThrowIfClientProvidedPortIsNegative.

@ParameterizedTest
@EnumSource(value = RoutingMode.class)
void shouldThrowIfClientProvidedPortIsNegative(RoutingMode routingMode) {
    // given
    var advertisedBoldPort = 8776;
    var clientProvidedPort = -5;
    var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
    var clientProvidedHostPortStr = String.format("%s:%d", "my.neo4j-service.com", clientProvidedPort);
    var ctxContents = new MapValueBuilder();
    ctxContents.add(ADDRESS_CONTEXT_KEY, Values.stringValue(clientProvidedHostPortStr));
    var ctx = ctxContents.build();
    var portRegister = mock(ConnectorPortRegister.class);
    when(portRegister.getLocalAddress(BoltConnector.NAME)).thenReturn(new HostnamePort("neo4j.com", advertisedBoldPort));
    var config = newConfig(Config.defaults(SERVER_DEFAULTS), Duration.ofSeconds(100), advertisedBoltAddress);
    config.set(routing_default_router, routingMode);
    var databaseManager = databaseManagerMock(config, true);
    var logProvider = new AssertableLogProvider();
    var procedure = newProcedure(databaseManager, portRegister, config, logProvider);
    var expectedMessage = "An address key is included in the query string provided to the GetRoutingTableProcedure, but its value could not be parsed.";
    // when
    assertThrows(ProcedureException.class, () -> invoke(procedure, ID, ctx), expectedMessage);
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) HostnamePort(org.neo4j.internal.helpers.HostnamePort) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with MapValueBuilder

use of org.neo4j.values.virtual.MapValueBuilder in project neo4j by neo4j.

the class SingleInstanceGetRoutingTableProcedureTest method shouldThrowWhenAddressCtxIsPresentButEmpty.

@ParameterizedTest
@EnumSource(value = RoutingMode.class)
void shouldThrowWhenAddressCtxIsPresentButEmpty(RoutingMode routingMode) {
    // given
    var ctxContents = new MapValueBuilder();
    ctxContents.add(ADDRESS_CONTEXT_KEY, Values.EMPTY_STRING);
    var ctx = ctxContents.build();
    var portRegister = mock(ConnectorPortRegister.class);
    var config = newConfig(Config.defaults(SERVER_DEFAULTS), Duration.ofSeconds(100), new SocketAddress("neo4j.com", 7687));
    config.set(routing_default_router, routingMode);
    var databaseManager = databaseManagerMock(config, true);
    var logProvider = new AssertableLogProvider();
    var procedure = newProcedure(databaseManager, portRegister, config, logProvider);
    var expectedMessage = "An address key is included in the query string provided to the GetRoutingTableProcedure, but its value could not be parsed.";
    // when/then
    assertThrows(ProcedureException.class, () -> invoke(procedure, ID, ctx), expectedMessage);
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with MapValueBuilder

use of org.neo4j.values.virtual.MapValueBuilder in project neo4j by neo4j.

the class JmxQueryProcedure method toNeo4jValue.

private MapValue toNeo4jValue(CompositeData composite) {
    MapValueBuilder properties = new MapValueBuilder();
    for (String key : composite.getCompositeType().keySet()) {
        properties.add(key, toNeo4jValue(composite.get(key)));
    }
    MapValueBuilder out = new MapValueBuilder();
    out.add("description", stringValue(composite.getCompositeType().getDescription()));
    out.add("properties", properties.build());
    return out.build();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder)

Example 20 with MapValueBuilder

use of org.neo4j.values.virtual.MapValueBuilder in project neo4j by neo4j.

the class RoutingResultFormat method build.

public static AnyValue[] build(RoutingResult result) {
    ListValue routers = asValues(result.routeEndpoints());
    ListValue readers = asValues(result.readEndpoints());
    ListValue writers = asValues(result.writeEndpoints());
    ListValueBuilder servers = ListValueBuilder.newListBuilder();
    if (writers.size() > 0) {
        MapValueBuilder builder = new MapValueBuilder();
        builder.add(ROLE_KEY, WRTE_NAME);
        builder.add(ADDRESSES_KEY, writers);
        servers.add(builder.build());
    }
    if (readers.size() > 0) {
        MapValueBuilder builder = new MapValueBuilder();
        builder.add(ROLE_KEY, READ_NAME);
        builder.add(ADDRESSES_KEY, readers);
        servers.add(builder.build());
    }
    if (routers.size() > 0) {
        MapValueBuilder builder = new MapValueBuilder();
        builder.add(ROLE_KEY, ROUTE_NAME);
        builder.add(ADDRESSES_KEY, routers);
        servers.add(builder.build());
    }
    LongValue timeToLiveSeconds = longValue(MILLISECONDS.toSeconds(result.ttlMillis()));
    return new AnyValue[] { timeToLiveSeconds, servers.build() };
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) ListValue(org.neo4j.values.virtual.ListValue) LongValue(org.neo4j.values.storable.LongValue) AnyValue(org.neo4j.values.AnyValue) ListValueBuilder(org.neo4j.values.virtual.ListValueBuilder)

Aggregations

MapValueBuilder (org.neo4j.values.virtual.MapValueBuilder)22 AnyValue (org.neo4j.values.AnyValue)6 SocketAddress (org.neo4j.configuration.helpers.SocketAddress)5 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)5 Map (java.util.Map)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 Point (org.neo4j.graphdb.spatial.Point)3 HostnamePort (org.neo4j.internal.helpers.HostnamePort)3 LongValue (org.neo4j.values.storable.LongValue)3 Value (org.neo4j.values.storable.Value)3 Values.doubleValue (org.neo4j.values.storable.Values.doubleValue)3 Values.longValue (org.neo4j.values.storable.Values.longValue)3 Values.stringValue (org.neo4j.values.storable.Values.stringValue)3 NodeValue (org.neo4j.values.virtual.NodeValue)3 PathValue (org.neo4j.values.virtual.PathValue)3 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)3 VirtualNodeValue (org.neo4j.values.virtual.VirtualNodeValue)3 VirtualRelationshipValue (org.neo4j.values.virtual.VirtualRelationshipValue)3 SequenceValue (org.neo4j.values.SequenceValue)2