Skip to content

Instantly share code, notes, and snippets.

@ikwattro
Created December 5, 2015 17:22
Show Gist options
  • Save ikwattro/187c07d077f411079bda to your computer and use it in GitHub Desktop.
Save ikwattro/187c07d077f411079bda to your computer and use it in GitHub Desktop.
test
package com.graphaware.test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.*;
import org.neo4j.test.TestGraphDatabaseFactory;
import static org.junit.Assert.assertEquals;
public class LabelsBatchTest {
protected GraphDatabaseService db;
@Before
public void prepareDatabase() {
db = new TestGraphDatabaseFactory().newImpermanentDatabase();
}
@After
public void destroyDb() {
db.shutdown();
}
@Test
public void addLabelsInBatch() throws InterruptedException {
for (int i = 0; i < 1000; ++i) {
try (Transaction tx = db.beginTx()) {
//System.out.println(i);
db.execute("FOREACH (x in range(1, 1000) | CREATE (:Node {value:x}))");
tx.success();
}
}
int c = 0;
try (Transaction tx = db.beginTx()) {
ResourceIterator<Node> it = db.findNodes(DynamicLabel.label("Node"));
while (it.hasNext()) {
it.next();
++c;
}
tx.success();
}
assertEquals(1000000, c);
for (int i = 0; i < 1000; ++i) {
try (Transaction tx = db.beginTx()) {
db.execute("MATCH (n:Node) WITH n LIMIT 1000 SET n:SecondLabel");
tx.success();
}
}
int c2 = 0;
try (Transaction tx = db.beginTx()) {
ResourceIterator<Node> it = db.findNodes(DynamicLabel.label("SecondLabel"));
while (it.hasNext()) {
it.next();
++c2;
}
tx.success();
}
assertEquals(1000000, c2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment