Search in sources :

Example 1 with MapValueBuilder

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

the class AbstractCypherAdapterStreamTest method mapValues.

private MapValue mapValues(Object... values) {
    int i = 0;
    MapValueBuilder builder = new MapValueBuilder();
    while (i < values.length) {
        builder.add((String) values[i++], (AnyValue) values[i++]);
    }
    return builder.build();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder)

Example 2 with MapValueBuilder

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

the class AbstractCypherAdapterStreamTest method metadataOf.

private MapValue metadataOf(AbstractCypherAdapterStream stream) throws Throwable {
    final MapValueBuilder meta = new MapValueBuilder();
    stream.handleRecords(new BoltResult.DiscardingRecordConsumer() {

        @Override
        public void addMetadata(String key, AnyValue value) {
            meta.add(key, value);
        }
    }, STREAM_LIMIT_UNLIMITED);
    return meta.build();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) AnyValue(org.neo4j.values.AnyValue)

Example 3 with MapValueBuilder

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

the class SingleInstanceGetRoutingTableProcedureTest method shouldThrowWhenHostCtxIsInvalid.

@ParameterizedTest
@EnumSource(value = RoutingMode.class)
void shouldThrowWhenHostCtxIsInvalid(RoutingMode routingMode) {
    // given
    var ctxContents = new MapValueBuilder();
    ctxContents.add(ADDRESS_CONTEXT_KEY, Values.stringValue("not a socket address"));
    var ctx = ctxContents.build();
    var config = newConfig(Config.defaults(SERVER_DEFAULTS), Duration.ofSeconds(100), new SocketAddress("neo4j.com", 7687));
    config.set(routing_default_router, routingMode);
    var portRegister = mock(ConnectorPortRegister.class);
    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 4 with MapValueBuilder

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

the class SingleInstanceGetRoutingTableProcedureTest method shouldThrowIfClientProvidedPortIsNotANumber.

@ParameterizedTest
@EnumSource(value = RoutingMode.class)
void shouldThrowIfClientProvidedPortIsNotANumber(RoutingMode routingMode) {
    // given
    var advertisedBoldPort = 8776;
    var clientProvidedPort = "bolt";
    var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
    var clientProvidedHostPortStr = String.format("%s:%s", "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 5 with MapValueBuilder

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

the class AbstractCypherAdapterStream method queryStats.

private MapValue queryStats(QueryStatistics queryStatistics) {
    MapValueBuilder builder = new MapValueBuilder();
    addIfNonZero(builder, "nodes-created", queryStatistics.getNodesCreated());
    addIfNonZero(builder, "nodes-deleted", queryStatistics.getNodesDeleted());
    addIfNonZero(builder, "relationships-created", queryStatistics.getRelationshipsCreated());
    addIfNonZero(builder, "relationships-deleted", queryStatistics.getRelationshipsDeleted());
    addIfNonZero(builder, "properties-set", queryStatistics.getPropertiesSet());
    addIfNonZero(builder, "labels-added", queryStatistics.getLabelsAdded());
    addIfNonZero(builder, "labels-removed", queryStatistics.getLabelsRemoved());
    addIfNonZero(builder, "indexes-added", queryStatistics.getIndexesAdded());
    addIfNonZero(builder, "indexes-removed", queryStatistics.getIndexesRemoved());
    addIfNonZero(builder, "constraints-added", queryStatistics.getConstraintsAdded());
    addIfNonZero(builder, "constraints-removed", queryStatistics.getConstraintsRemoved());
    return builder.build();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder)

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