@Test public void canUpdateShortStringInplace() throws Exception { try { long recordCount = dynamicRecordsInUse(); long propCount = propertyRecordsInUse(); Node node = graphdb.getGraphDatabaseService().createNode(); node.setProperty("key", "value"); newTx(); assertEquals(recordCount, dynamicRecordsInUse()); assertEquals(propCount + 1, propertyRecordsInUse()); assertEquals("value", node.getProperty("key")); node.setProperty("key", "other"); commit(); assertEquals(recordCount, dynamicRecordsInUse()); assertEquals(propCount + 1, propertyRecordsInUse()); assertThat( node, inTx(graphdb.getGraphDatabaseService(), hasProperty("key").withValue("other"))); } catch (Exception e) { e.printStackTrace(); throw e; } }
private void encode(String string, boolean isShort) { long recordCount = dynamicRecordsInUse(); Node node = graphdb.getGraphDatabaseService().createNode(); node.setProperty("key", string); newTx(); if (isShort) { assertEquals(recordCount, dynamicRecordsInUse()); } else { assertTrue(recordCount < dynamicRecordsInUse()); } graphdb.clearCache(); assertEquals(string, node.getProperty("key")); }
@Test public void canAddMultipleShortStringsToTheSameNode() throws Exception { long recordCount = dynamicRecordsInUse(); Node node = graphdb.getGraphDatabaseService().createNode(); node.setProperty("key", "value"); node.setProperty("reverse", "esrever"); commit(); assertEquals(recordCount, dynamicRecordsInUse()); assertThat( node, inTx(graphdb.getGraphDatabaseService(), hasProperty("key").withValue("value"))); assertThat( node, inTx(graphdb.getGraphDatabaseService(), hasProperty("reverse").withValue("esrever"))); }
private PropertyStore propertyStore() { return graphdb .getGraphDatabaseAPI() .getDependencyResolver() .resolveDependency(NeoStoreDataSource.class) .getNeoStore() .getPropertyStore(); }
@Test public void canAddShortStringToRelationship() throws Exception { long recordCount = dynamicRecordsInUse(); GraphDatabaseService db = graphdb.getGraphDatabaseService(); Relationship rel = db.createNode().createRelationshipTo(db.createNode(), withName("REL_TYPE")); rel.setProperty("type", "dimsedut"); commit(); assertEquals(recordCount, dynamicRecordsInUse()); assertThat(rel, inTx(db, hasProperty("type").withValue("dimsedut"))); }
@Test public void canReplaceShortStringWithLongString() throws Exception { long recordCount = dynamicRecordsInUse(); long propCount = propertyRecordsInUse(); Node node = graphdb.getGraphDatabaseService().createNode(); node.setProperty("key", "value"); newTx(); assertEquals(recordCount, dynamicRecordsInUse()); assertEquals(propCount + 1, propertyRecordsInUse()); assertEquals("value", node.getProperty("key")); node.setProperty("key", LONG_STRING); commit(); assertEquals(recordCount + 1, dynamicRecordsInUse()); assertEquals(propCount + 1, propertyRecordsInUse()); assertThat( node, inTx(graphdb.getGraphDatabaseService(), hasProperty("key").withValue(LONG_STRING))); }
@Before public void before() { GraphDatabaseAPI graphDatabaseAPI = dbRule.getGraphDatabaseAPI(); this.db = graphDatabaseAPI; DependencyResolver dependencyResolver = graphDatabaseAPI.getDependencyResolver(); this.bridge = dependencyResolver.resolveDependency(ThreadToStatementContextBridge.class); graphDatabaseAPI .getDependencyResolver() .resolveDependency(Monitors.class) .addMonitorListener(indexOnlineMonitor); }
@Test public void canRemoveShortStringProperty() throws Exception { long recordCount = dynamicRecordsInUse(); long propCount = propertyRecordsInUse(); GraphDatabaseService db = graphdb.getGraphDatabaseService(); Node node = db.createNode(); node.setProperty("key", "value"); newTx(); assertEquals(recordCount, dynamicRecordsInUse()); assertEquals(propCount + 1, propertyRecordsInUse()); assertEquals("value", node.getProperty("key")); node.removeProperty("key"); commit(); assertEquals(recordCount, dynamicRecordsInUse()); assertEquals(propCount, propertyRecordsInUse()); assertThat(node, inTx(db, not(hasProperty("key")))); }
@Test public void testSimpleGraph() throws Exception { GraphDatabaseService neo = dbRule.getGraphDatabaseService(); Transaction tx = neo.beginTx(); try { final Node emil = neo.createNode(); emil.setProperty("name", "Emil Eifrém"); emil.setProperty("age", 30); final Node tobias = neo.createNode(); tobias.setProperty("name", "Tobias \"thobe\" Ivarsson"); tobias.setProperty("age", 23); tobias.setProperty("hours", new int[] {10, 10, 4, 4, 0}); final Node johan = neo.createNode(); johan.setProperty("!<>)", "!<>)"); johan.setProperty("name", "!<>Johan '\\n00b' !<>Svensson"); final Relationship emilKNOWStobias = emil.createRelationshipTo(tobias, type.KNOWS); emilKNOWStobias.setProperty("since", "2003-08-17"); final Relationship johanKNOWSemil = johan.createRelationshipTo(emil, type.KNOWS); final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo(johan, type.KNOWS); final Relationship tobiasWORKS_FORemil = tobias.createRelationshipTo(emil, type.WORKS_FOR); OutputStream out = new ByteArrayOutputStream(); GraphvizWriter writer = new GraphvizWriter(); writer.emit( out, Walker.crosscut( emil.traverse( Order.DEPTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL, type.KNOWS, Direction.BOTH, type.WORKS_FOR, Direction.BOTH), type.KNOWS, type.WORKS_FOR)); tx.success(); out.toString(); } finally { tx.finish(); } }
public void commit() { tx.success(); graphdb.clearCache(); }