@Test public void shouldRetrieveMultipleNodesWithSameValueFromIndex() throws Exception { // this test was included here for now as a precondition for the following test // given GraphDatabaseService graph = dbRule.getGraphDatabaseService(); createIndex(graph, LABEL1, "name"); Node node1, node2; try (Transaction tx = graph.beginTx()) { node1 = graph.createNode(LABEL1); node1.setProperty("name", "Stefan"); node2 = graph.createNode(LABEL1); node2.setProperty("name", "Stefan"); tx.success(); } try (Transaction tx = graph.beginTx()) { ResourceIterator<Node> result = graph.findNodes(LABEL1, "name", "Stefan"); assertEquals(asSet(node1, node2), asSet(result)); tx.success(); } }
public void rn() throws IOException { List<RoadLink> links = loadToDatabase("/Users/duduba/gj.mif", "/Users/duduba/gj.mid", false); GraphDatabaseService graphDb = neo.getDb(); Index<Node> nodeIndex = neo.getNodeIndex(); for (RoadLink link : links) { Transaction tx = graphDb.beginTx(); try { Node fromNode = nodeIndex.get("id", link.fromNode).getSingle(); if (fromNode == null) { fromNode = graphDb.createNode(); fromNode.setProperty("id", link.fromNode); nodeIndex.add(fromNode, "id", link.fromNode); } Node toNode = nodeIndex.get("id", link.toNode).getSingle(); if (toNode == null) { toNode = graphDb.createNode(); toNode.setProperty("id", link.toNode); nodeIndex.add(toNode, "id", link.toNode); } Relationship r = fromNode.createRelationshipTo(toNode, Neo.RelTypes.TO); r.setProperty("no", link.no); r.setProperty("name", link.name); tx.success(); } finally { tx.finish(); } } logger.debug("haha, it's ok!"); }
@Test public void deletedNewLabelShouldNotInfluenceEquality() { // bug test try (Transaction tx = database.beginTx()) { database.createNode(DynamicLabel.label("Accident")); database.createNode(DynamicLabel.label("RealLabel")); tx.success(); } try (Transaction tx = database.beginTx()) { database.getNodeById(0).delete(); tx.success(); } String cypher = "CREATE (n:RealLabel)"; assertSameGraph(database, cypher); }
private Node createNode( GraphDatabaseService beansAPI, Map<String, Object> properties, Label... labels) { try (Transaction tx = beansAPI.beginTx()) { Node node = beansAPI.createNode(labels); for (Map.Entry<String, Object> property : properties.entrySet()) node.setProperty(property.getKey(), property.getValue()); tx.success(); return node; } }
@Test public void equalArraysWithDifferentTypeShouldBeEqual() { try (Transaction tx = database.beginTx()) { database.createNode().setProperty("number", new int[] {123, 124}); tx.success(); } String cypher = "CREATE (n {number:[123,124]})"; assertSameGraph(database, cypher); }
@Test(expected = MultipleFoundException.class) public void shouldThrowWhenMulitpleResultsForSingleNode() throws Exception { // given GraphDatabaseService graph = dbRule.getGraphDatabaseService(); createIndex(graph, LABEL1, "name"); Node node1, node2; try (Transaction tx = graph.beginTx()) { node1 = graph.createNode(LABEL1); node1.setProperty("name", "Stefan"); node2 = graph.createNode(LABEL1); node2.setProperty("name", "Stefan"); tx.success(); } try (Transaction tx = graph.beginTx()) { graph.findNode(LABEL1, "name", "Stefan"); } }
@Test public void deletedNewPropsShouldNotInfluenceEquality() { // bug test try (Transaction tx = database.beginTx()) { database.createNode().setProperty("accident", "dummy"); database.createNode(); tx.success(); } try (Transaction tx = database.beginTx()) { database.getNodeById(0).delete(); tx.success(); } String cypher = "CREATE (n)"; assertSameGraph(database, cypher); }
@Test public void shouldUseDynamicPropertiesToIndexANodeWhenAddedAlongsideExistingPropertiesInASeparateTransaction() throws Exception { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); // When long id; { try (Transaction tx = beansAPI.beginTx()) { Node myNode = beansAPI.createNode(); id = myNode.getId(); myNode.setProperty("key0", true); myNode.setProperty("key1", true); tx.success(); } } { IndexDefinition indexDefinition; try (Transaction tx = beansAPI.beginTx()) { indexDefinition = beansAPI.schema().indexFor(LABEL1).on("key2").create(); tx.success(); } waitForIndex(beansAPI, indexDefinition); } Node myNode; { try (Transaction tx = beansAPI.beginTx()) { myNode = beansAPI.getNodeById(id); myNode.addLabel(LABEL1); myNode.setProperty("key2", LONG_STRING); myNode.setProperty("key3", LONG_STRING); tx.success(); } } // Then assertThat(myNode, inTx(beansAPI, hasProperty("key2").withValue(LONG_STRING))); assertThat(myNode, inTx(beansAPI, hasProperty("key3").withValue(LONG_STRING))); assertThat( findNodesByLabelAndProperty(LABEL1, "key2", LONG_STRING, beansAPI), containsOnly(myNode)); }
@Test public void deletedRelationshipWithNewTypeShouldNotInfluenceEquality() { // bug test try (Transaction tx = database.beginTx()) { Node node1 = database.createNode(); Node node2 = database.createNode(); node1.createRelationshipTo(node2, DynamicRelationshipType.withName("ACCIDENT")); tx.success(); } try (Transaction tx = database.beginTx()) { GlobalGraphOperations.at(database).getAllRelationships().iterator().next().delete(); tx.success(); } String cypher = "CREATE (n), (m)"; assertSameGraph(database, cypher); }
/* This test is a bit interesting. It tests a case where we've got a property that sits in one * property block and the value is of a long type. So given that plus that there's an index for that * label/property, do an update that changes the long value into a value that requires two property blocks. * This is interesting because the transaction logic compares before/after views per property record and * not per node as a whole. * * In this case this change will be converted into one "add" and one "remove" property updates instead of * a single "change" property update. At the very basic level it's nice to test for this corner-case so * that the externally observed behavior is correct, even if this test doesn't assert anything about * the underlying add/remove vs. change internal details. */ @Test public void shouldInterpretPropertyAsChangedEvenIfPropertyMovesFromOneRecordToAnother() throws Exception { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); long smallValue = 10L, bigValue = 1L << 62; Node myNode; { try (Transaction tx = beansAPI.beginTx()) { myNode = beansAPI.createNode(LABEL1); myNode.setProperty("pad0", true); myNode.setProperty("pad1", true); myNode.setProperty("pad2", true); // Use a small long here which will only occupy one property block myNode.setProperty("key", smallValue); tx.success(); } } { IndexDefinition indexDefinition; try (Transaction tx = beansAPI.beginTx()) { indexDefinition = beansAPI.schema().indexFor(LABEL1).on("key").create(); tx.success(); } waitForIndex(beansAPI, indexDefinition); } // WHEN try (Transaction tx = beansAPI.beginTx()) { // A big long value which will occupy two property blocks myNode.setProperty("key", bigValue); tx.success(); } // THEN assertThat( findNodesByLabelAndProperty(LABEL1, "key", bigValue, beansAPI), containsOnly(myNode)); assertThat(findNodesByLabelAndProperty(LABEL1, "key", smallValue, beansAPI), isEmpty()); }
@Override public Node createNode(Map<String, Object> props, Collection<String> labels) { return setProperties(delegate.createNode(toLabels(labels)), props); }