use of org.neo4j.graphdb.Node in project neo4j-clean-remote-db-addon by jexp.
the class DeleteDatabaseTest method createData.
private void createData(GraphDatabaseAPI db, int max) {
Transaction tx = db.beginTx();
try {
final IndexManager indexManager = db.index();
Node[] nodes = new Node[max];
for (int i = 0; i < max; i++) {
nodes[i] = db.createNode();
final Index<Node> index = indexManager.forNodes("node_index_" + String.valueOf(i % 5));
index.add(nodes[i], "ID", i);
}
Random random = new Random();
for (int i = 0; i < max * 2; i++) {
int from = random.nextInt(max);
final int to = (from + 1 + random.nextInt(max - 1)) % max;
final Relationship relationship = nodes[from].createRelationshipTo(nodes[to], DynamicRelationshipType.withName("TEST_" + i));
final Index<Relationship> index = indexManager.forRelationships("rel_index_" + String.valueOf(i % 5));
index.add(relationship, "ID", i);
}
tx.success();
} finally {
tx.finish();
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TransactionIT method shouldReadYourOwnWrites.
@Test
public void shouldReadYourOwnWrites() throws Exception {
try (Transaction tx = env.graph().beginTx()) {
Node node = env.graph().createNode(Label.label("A"));
node.setProperty("prop", "one");
tx.success();
}
BinaryLatch latch = new BinaryLatch();
long dbVersion = env.lastClosedTxId();
Thread thread = new Thread() {
@Override
public void run() {
try (BoltStateMachine machine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("<testClient>", 56789), new InetSocketAddress("<writeServer>", 7468)))) {
machine.init(USER_AGENT, emptyMap(), null);
latch.await();
machine.run("MATCH (n:A) SET n.prop = 'two'", emptyMap(), nullResponseHandler());
machine.pullAll(nullResponseHandler());
} catch (BoltConnectionFatality connectionFatality) {
throw new RuntimeException(connectionFatality);
}
}
};
thread.start();
long dbVersionAfterWrite = dbVersion + 1;
try (BoltStateMachine machine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("<testClient>", 56789), new InetSocketAddress("<readServer>", 7468)))) {
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.init(USER_AGENT, emptyMap(), null);
latch.release();
final String bookmark = "neo4j:bookmark:v1:tx" + Long.toString(dbVersionAfterWrite);
machine.run("BEGIN", singletonMap("bookmark", bookmark), nullResponseHandler());
machine.pullAll(recorder);
machine.run("MATCH (n:A) RETURN n.prop", emptyMap(), nullResponseHandler());
machine.pullAll(recorder);
machine.run("COMMIT", emptyMap(), nullResponseHandler());
machine.pullAll(recorder);
assertThat(recorder.nextResponse(), succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
assertThat(recorder.nextResponse(), succeededWithRecord("two"));
assertThat(recorder.nextResponse(), succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
}
thread.join();
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldNotTrimStringsByDefault.
@Test
public void shouldNotTrimStringsByDefault() throws Exception {
// GIVEN
String name = " This is a line with leading and trailing whitespaces ";
File data = data(":ID,name", "1,\"" + name + "\"");
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath());
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
ResourceIterator<Node> allNodes = db.getAllNodes().iterator();
Node node = Iterators.single(allNodes);
allNodes.close();
assertEquals(name, node.getProperty("name"));
tx.success();
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method import4097Labels.
@Test
public void import4097Labels() throws Exception {
// GIVEN
File header = file(fileName("4097labels-header.csv"));
try (PrintStream writer = new PrintStream(header)) {
writer.println(":LABEL");
}
File data = file(fileName("4097labels.csv"));
try (PrintStream writer = new PrintStream(data)) {
// Need to have unique names in order to get unique ids for labels. Want 4096 unique label ids present.
for (int i = 0; i < 4096; i++) {
writer.println("SIMPLE" + i);
}
// Then insert one with 3 array entries which will get ids greater than 4096. These cannot be inlined
// due 36 bits being divided into 3 parts of 12 bits each and 4097 > 2^12, thus these labels will be
// need to be dynamic records.
writer.println("FIRST 4096|SECOND 4096|");
}
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--delimiter", "TAB", "--array-delimiter", "|", "--nodes", header.getAbsolutePath() + MULTI_FILE_DELIMITER + data.getAbsolutePath());
// THEN
try (Transaction tx = dbRule.beginTx()) {
long nodeCount = Iterables.count(dbRule.getAllNodes());
assertEquals(4097, nodeCount);
tx.success();
ResourceIterator<Node> nodes = dbRule.findNodes(DynamicLabel.label("FIRST 4096"));
assertEquals(1, Iterators.asList(nodes).size());
nodes = dbRule.findNodes(DynamicLabel.label("SECOND 4096"));
assertEquals(1, Iterators.asList(nodes).size());
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ImportToolTest method shouldAcceptRawAsciiCharacterCodeAsQuoteConfiguration.
@Test
public void shouldAcceptRawAsciiCharacterCodeAsQuoteConfiguration() throws Exception {
// GIVEN
// not '1', just the character represented with code 1, which seems to be SOH
char weirdDelimiter = 1;
String name1 = weirdDelimiter + "Weird" + weirdDelimiter;
String name2 = "Start " + weirdDelimiter + "middle thing" + weirdDelimiter + " end!";
File data = data(":ID,name", "1," + name1, "2," + name2);
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath(), "--quote", String.valueOf(weirdDelimiter));
// THEN
Set<String> names = asSet("Weird", name2);
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
for (Node node : db.getAllNodes()) {
String name = (String) node.getProperty("name");
assertTrue("Didn't expect node with name '" + name + "'", names.remove(name));
}
assertTrue(names.isEmpty());
tx.success();
}
}
Aggregations