use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.
the class FulltextIndexConsistencyCheckIT method consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes.
@Test
void consistencyCheckerMustBeAbleToRunOnStoreWithFulltextIndexes() throws Exception {
GraphDatabaseService db = createDatabase();
Label[] labels = IntStream.range(1, 7).mapToObj(i -> Label.label("LABEL" + i)).toArray(Label[]::new);
RelationshipType[] relTypes = IntStream.range(1, 5).mapToObj(i -> RelationshipType.withName("REL" + i)).toArray(RelationshipType[]::new);
String[] propertyKeys = IntStream.range(1, 7).mapToObj(i -> "PROP" + i).toArray(String[]::new);
RandomValues randomValues = random.randomValues();
try (Transaction tx = db.beginTx()) {
int nodeCount = 1000;
List<Node> nodes = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
Label[] nodeLabels = random.ints(random.nextInt(labels.length), 0, labels.length).distinct().mapToObj(x -> labels[x]).toArray(Label[]::new);
Node node = tx.createNode(nodeLabels);
Stream.of(propertyKeys).forEach(p -> node.setProperty(p, random.nextBoolean() ? p : randomValues.nextValue().asObject()));
nodes.add(node);
int localRelCount = Math.min(nodes.size(), 5);
random.ints(localRelCount, 0, localRelCount).distinct().mapToObj(x -> node.createRelationshipTo(nodes.get(x), relTypes[random.nextInt(relTypes.length)])).forEach(r -> Stream.of(propertyKeys).forEach(p -> r.setProperty(p, random.nextBoolean() ? p : randomValues.nextValue().asObject())));
}
tx.commit();
}
try (Transaction tx = db.beginTx()) {
for (int i = 1; i < labels.length; i++) {
tx.execute(format(NODE_CREATE, "nodes" + i, asStrList(Arrays.stream(labels).limit(i).map(Label::name).toArray(String[]::new)), asStrList(Arrays.copyOf(propertyKeys, i)))).close();
}
for (int i = 1; i < relTypes.length; i++) {
tx.execute(format(RELATIONSHIP_CREATE, "rels" + i, asStrList(Arrays.stream(relTypes).limit(i).map(RelationshipType::name).toArray(String[]::new)), asStrList(Arrays.copyOf(propertyKeys, i)))).close();
}
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
tx.commit();
}
managementService.shutdown();
assertIsConsistent(checkConsistency());
}
use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.
the class IndexPopulationStressTest method updater.
private Runnable updater(AtomicReferenceArray<List<ValueIndexEntryUpdate<?>>> lastBatches, CountDownLatch insertersDone, ReadWriteLock updateLock, Collection<ValueIndexEntryUpdate<?>> updates) {
return throwing(() -> {
// Entity ids that have been removed, so that additions can reuse them
List<Long> removed = new ArrayList<>();
RandomValues randomValues = RandomValues.create(new Random(random.seed() + THREADS));
while (insertersDone.getCount() > 0) {
// Do updates now and then
Thread.sleep(10);
updateLock.writeLock().lock();
try (IndexUpdater updater = populator.newPopulatingUpdater(nodePropertyAccessor, NULL)) {
for (int i = 0; i < THREADS; i++) {
List<ValueIndexEntryUpdate<?>> batch = lastBatches.get(i);
if (batch != null) {
ValueIndexEntryUpdate<?> update = null;
switch(randomValues.nextInt(3)) {
case // add
0:
if (!removed.isEmpty()) {
Long id = removed.remove(randomValues.nextInt(removed.size()));
update = add(id, descriptor, valueGenerator.apply(randomValues));
}
break;
case // remove
1:
ValueIndexEntryUpdate<?> removal = batch.get(randomValues.nextInt(batch.size()));
update = remove(removal.getEntityId(), descriptor, removal.values());
removed.add(removal.getEntityId());
break;
case // change
2:
removal = batch.get(randomValues.nextInt(batch.size()));
change(removal.getEntityId(), descriptor, removal.values(), toArray(valueGenerator.apply(randomValues)));
break;
default:
throw new IllegalArgumentException();
}
if (update != null) {
updater.process(update);
updates.add(update);
}
}
}
} finally {
updateLock.writeLock().unlock();
}
}
});
}
use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.
the class ConcurrentUpdateIT method populateDbWithConcurrentUpdates.
@Test
void populateDbWithConcurrentUpdates() throws Exception {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseService database = managementService.database(DEFAULT_DATABASE_NAME);
try {
RandomValues randomValues = RandomValues.create();
int counter = 1;
for (int j = 0; j < 100; j++) {
try (Transaction transaction = database.beginTx()) {
for (int i = 0; i < 5; i++) {
Node node = transaction.createNode(Label.label("label" + counter));
node.setProperty("property", randomValues.nextValue().asObject());
}
transaction.commit();
}
counter++;
}
int populatorCount = 5;
ExecutorService executor = Executors.newFixedThreadPool(populatorCount);
CountDownLatch startSignal = new CountDownLatch(1);
AtomicBoolean endSignal = new AtomicBoolean();
for (int i = 0; i < populatorCount; i++) {
executor.submit(new Populator(database, counter, startSignal, endSignal));
}
try {
try (Transaction transaction = database.beginTx()) {
transaction.schema().indexFor(Label.label("label10")).on("property").create();
transaction.commit();
}
startSignal.countDown();
try (Transaction transaction = database.beginTx()) {
transaction.schema().awaitIndexesOnline(populatorCount, TimeUnit.MINUTES);
transaction.commit();
}
} finally {
endSignal.set(true);
executor.shutdown();
// Basically we don't care to await their completion because they've done their job
}
} finally {
managementService.shutdown();
ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
Config config = Config.defaults(GraphDatabaseSettings.pagecache_memory, "8m");
consistencyCheckService.runFullConsistencyCheck(databaseLayout, config, ProgressMonitorFactory.NONE, new Log4jLogProvider(System.out), false);
}
}
use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.
the class IndexProvidedValuesNativeBTree10Test method createTestGraph.
@Override
public void createTestGraph(GraphDatabaseService graphDb) {
try (Transaction tx = graphDb.beginTx()) {
getEntityControl().createIndex(tx, TOKEN, PROP, PROP_INDEX);
getEntityControl().createIndex(tx, TOKEN, PROP, PRIP, PROP_PRIP_INDEX);
tx.commit();
}
try (Transaction tx = graphDb.beginTx()) {
tx.schema().awaitIndexesOnline(5, MINUTES);
tx.commit();
}
try (Transaction tx = graphDb.beginTx()) {
RandomValues randomValues = randomRule.randomValues();
ValueType[] allExceptNonSortable = RandomValues.excluding(ValueType.STRING, ValueType.STRING_ARRAY);
for (int i = 0; i < N_ENTITIES; i++) {
var node = getEntityControl().createEntity(tx, TOKEN);
Value propValue = randomValues.nextValueOfTypes(allExceptNonSortable);
node.setProperty(PROP, propValue.asObject());
Value pripValue = randomValues.nextValueOfTypes(allExceptNonSortable);
node.setProperty(PRIP, pripValue.asObject());
singlePropValues.add(propValue);
doublePropValues.add(ValueTuple.of(propValue, pripValue));
}
tx.commit();
}
singlePropValues.sort(Values.COMPARATOR);
doublePropValues.sort(ValueTuple.COMPARATOR);
}
use of org.neo4j.values.storable.RandomValues in project neo4j by neo4j.
the class AbstractIndexProvidedOrderTest method createTestGraph.
@Override
public void createTestGraph(GraphDatabaseService graphDb) {
try (Transaction tx = graphDb.beginTx()) {
getEntityControl().createIndex(tx, TOKEN, PROPERTY_KEY, INDEX_NAME);
tx.commit();
}
try (Transaction tx = graphDb.beginTx()) {
tx.schema().awaitIndexesOnline(5, MINUTES);
tx.commit();
}
RandomValues randomValues = randomRule.randomValues();
ValueType[] allExceptNonOrderable = RandomValues.excluding(ValueType.STRING, ValueType.STRING_ARRAY, ValueType.GEOGRAPHIC_POINT, ValueType.GEOGRAPHIC_POINT_ARRAY, ValueType.GEOGRAPHIC_POINT_3D, ValueType.GEOGRAPHIC_POINT_3D_ARRAY, ValueType.CARTESIAN_POINT, ValueType.CARTESIAN_POINT_ARRAY, ValueType.CARTESIAN_POINT_3D, ValueType.CARTESIAN_POINT_3D_ARRAY);
targetedTypes = randomValues.selection(allExceptNonOrderable, 1, allExceptNonOrderable.length, false);
targetedTypes = ensureHighEnoughCardinality(targetedTypes);
try (Transaction tx = graphDb.beginTx()) {
for (int i = 0; i < N_ENTITIES; i++) {
var node = getEntityControl().createEntity(tx, TOKEN);
Value propValue;
EntityValueTuple singleValue;
do {
propValue = randomValues.nextValueOfTypes(targetedTypes);
singleValue = new EntityValueTuple(node.getId(), propValue);
} while (singlePropValues.contains(singleValue));
singlePropValues.add(singleValue);
node.setProperty(PROPERTY_KEY, propValue.asObject());
}
tx.commit();
}
}
Aggregations