Search in sources :

Example 6 with RandomValues

use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.

the class AbstractIndexProvidedOrderTest method shouldProvideResultInOrderIfCapable.

@Test
void shouldProvideResultInOrderIfCapable() throws KernelException {
    int prop = token.propertyKey(PROPERTY_KEY);
    RandomValues randomValues = randomRule.randomValues();
    IndexReadSession index = read.indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
    for (int i = 0; i < N_ITERATIONS; i++) {
        ValueType type = randomValues.among(targetedTypes);
        IndexOrderCapability order = index.reference().getCapability().orderCapability(type.valueGroup.category());
        if (order.supportsAsc()) {
            expectResultInOrder(randomValues, type, prop, index, IndexOrder.ASCENDING);
        }
        if (order.supportsDesc()) {
            expectResultInOrder(randomValues, type, prop, index, IndexOrder.DESCENDING);
        }
    }
}
Also used : ValueType(org.neo4j.values.storable.ValueType) RandomValues(org.neo4j.values.storable.RandomValues) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 7 with RandomValues

use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.

the class MemoryRecommendationsCommandTest method createDatabaseWithNativeIndexes.

private static void createDatabaseWithNativeIndexes(Path homeDirectory, String databaseName) {
    // Create one index for every provider that we have
    for (SchemaIndex schemaIndex : SchemaIndex.values()) {
        DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(homeDirectory).setConfig(default_schema_provider, schemaIndex.providerName()).setConfig(default_database, databaseName).build();
        GraphDatabaseService db = managementService.database(databaseName);
        String key = "key-" + schemaIndex.name();
        try {
            Label labelOne = Label.label("one");
            try (Transaction tx = db.beginTx()) {
                tx.schema().indexFor(labelOne).on(key).create();
                tx.commit();
            }
            try (Transaction tx = db.beginTx()) {
                RandomValues randomValues = RandomValues.create();
                for (int i = 0; i < 10_000; i++) {
                    tx.createNode(labelOne).setProperty(key, randomValues.nextValue().asObject());
                }
                tx.commit();
            }
        } finally {
            managementService.shutdown();
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) SchemaIndex(org.neo4j.configuration.GraphDatabaseSettings.SchemaIndex) Label(org.neo4j.graphdb.Label) RandomValues(org.neo4j.values.storable.RandomValues) MemoryRecommendationsCommand.bytesToString(org.neo4j.commandline.dbms.MemoryRecommendationsCommand.bytesToString) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 8 with RandomValues

use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.

the class IndexPopulationIT method prePopulateDatabase.

private void prePopulateDatabase(GraphDatabaseService database, Label testLabel, String propertyName) {
    final RandomValues randomValues = RandomValues.create();
    try (Transaction transaction = database.beginTx()) {
        for (int j = 0; j < 10_000; j++) {
            Node node = transaction.createNode(testLabel);
            Object property = randomValues.nextValue().asObject();
            node.setProperty(propertyName, property);
        }
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) RandomValues(org.neo4j.values.storable.RandomValues)

Example 9 with RandomValues

use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.

the class FulltextProceduresTestSupport method generateRandomValues.

List<Value> generateRandomValues(Predicate<Value> predicate) {
    int valuesToGenerate = 1000;
    RandomValues generator = RandomValues.create();
    List<Value> values = new ArrayList<>(valuesToGenerate);
    for (int i = 0; i < valuesToGenerate; i++) {
        Value value;
        do {
            value = generator.nextValue();
        } while (!predicate.test(value));
        values.add(value);
    }
    return values;
}
Also used : Value(org.neo4j.values.storable.Value) ArrayList(java.util.ArrayList) RandomValues(org.neo4j.values.storable.RandomValues)

Example 10 with RandomValues

use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.

the class ReuseStorageSpaceIT method createStuff.

/**
 * The seed will make this method create the same data every time.
 * @param db {@link GraphDatabaseService} db.
 * @param seed starting seed for the randomness.
 */
private static void createStuff(GraphDatabaseService db, long seed) {
    Race race = new Race();
    AtomicLong createdNodes = new AtomicLong();
    AtomicLong createdRelationships = new AtomicLong();
    int dataSizePerTransaction = DATA_SIZE / NUMBER_OF_TRANSACTIONS_PER_THREAD / CREATION_THREADS;
    AtomicLong nextSeed = new AtomicLong(seed);
    race.addContestants(CREATION_THREADS, throwing(() -> {
        RandomValues random = RandomValues.create(new Random(nextSeed.getAndIncrement()));
        int nodeCount = 0;
        int relationshipCount = 0;
        for (int t = 0; t < NUMBER_OF_TRANSACTIONS_PER_THREAD; t++) {
            try (Transaction tx = db.beginTx()) {
                // Nodes
                Node[] nodes = new Node[dataSizePerTransaction];
                for (int n = 0; n < nodes.length; n++) {
                    Node node = nodes[n] = tx.createNode(labels(random.selection(TOKENS, 0, TOKENS.length, false)));
                    setProperties(random, node);
                    nodeCount++;
                }
                // Relationships
                for (int r = 0; r < nodes.length; r++) {
                    Relationship relationship = random.among(nodes).createRelationshipTo(random.among(nodes), withName(random.among(TOKENS)));
                    setProperties(random, relationship);
                    relationshipCount++;
                }
                tx.commit();
            }
        }
        createdNodes.addAndGet(nodeCount);
        createdRelationships.addAndGet(relationshipCount);
    }), 1);
    race.goUnchecked();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Random(java.util.Random) Transaction(org.neo4j.graphdb.Transaction) Race(org.neo4j.test.Race) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RandomValues(org.neo4j.values.storable.RandomValues)

Aggregations

RandomValues (org.neo4j.values.storable.RandomValues)10 Transaction (org.neo4j.graphdb.Transaction)7 Node (org.neo4j.graphdb.Node)4 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)3 Value (org.neo4j.values.storable.Value)3 ValueType (org.neo4j.values.storable.ValueType)3 Random (java.util.Random)2 Config (org.neo4j.configuration.Config)2 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)2 Label (org.neo4j.graphdb.Label)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 Files (java.nio.file.Files)1 Arrays (java.util.Arrays)1