在为简单关系编写基本Neo4j测试用例时,我的一个测试用例在更改CREATE语句后失败了。唯一不同的结果是最终节点id从1变为20。
为了理解我为什么要问:
如何在Neo4j中分配节点in?
我知道:(GitHub)
* A node's id is unique, but note the following: Neo4j reuses its internal ids
* when nodes and relationships are deleted, which means it's bad practice to
* refer to them this way. Instead, use application generated ids.这些语句导致关系为20的结束节点id。
CREATE (n:Person { name:'John' }) RETURN COUNT(*)
CREATE (n:Person { name:'Mary' }) RETURN COUNT(*)
MATCH (a:Person),(b:Person)
WHERE a.name = 'John'
AND b.name = 'Mary'
CREATE (a)-[r:relationship_type]->(b)
RETURN COUNT(*)此语句将导致关系为1的结束节点id。
CREATE (a:Person { name:'John' })-[r:relationship_type]->(b:Person { name:'Mary' }) RETURN COUNT(*)编辑
在从这个大小中学习回答并搜索相关的测试之后,我尝试了这个测试,我认为这个测试会将I增加2而不是1,因为有三个不同的事务,我希望每个事务都能基于record_id_batch_size启动新的一批I。
@Test
public void idBatchSize02MultipleTransactions() throws Throwable {
try (ServerControls server = TestServerBuilders.newInProcessBuilder()
.withConfig(GraphDatabaseSettings.record_id_batch_size, "2")
.newServer()) {
GraphDatabaseService graph = server.graph();
Node node_001;
Node node_002;
Node node_003;
try (Transaction tx = graph.beginTx()) {
node_001 = graph.createNode();
tx.success();
}
try (Transaction tx = graph.beginTx()) {
node_002 = graph.createNode();
tx.success();
}
try (Transaction tx = graph.beginTx()) {
node_003 = graph.createNode();
tx.success();
}
assertEquals(0L,node_001.getId());
assertEquals(2L,node_002.getId());
assertEquals(4L,node_003.getId());
}
}但是,测试失败了,因为ids实际上是0L、1L、2L,而不是0L、2L和4L。得多读点书。
发布于 2018-11-05 14:50:47
节点id取决于以前在数据库中创建的内容。它主要是一个自动增量,除了在某些情况下(例如:当我们重用ids、集群、.)
那你怎么做你的测试?您是否有一套测试,在每次测试之间启动一个新的数据库实例,还是删除数据库?
此外,对于每个事务,Neo4j都保留了一批免费id:https://github.com/neo4j/neo4j/blob/da3a460a7e4481534a8e19b73b0c2c6ede973ae8/community/kernel/src/main/java/org/neo4j/graphdb/factory/GraphDatabaseSettings.java#L794-L803。
https://stackoverflow.com/questions/53155735
复制相似问题