@Override public void setNodeProperty( long node, String propertyName, Object propertyValue ) { delegate.setNodeProperty( node, propertyName, propertyValue ); }
@Test public void replaceWithBiggerPropertySpillsOverIntoNewPropertyRecord() { // GIVEN BatchInserter batchInserter = globalInserter; Map<String, Object> props = new HashMap<>(); props.put( "name", "One" ); props.put( "count", 1 ); props.put( "tags", new String[] { "one", "two" } ); long id = batchInserter.createNode( props ); batchInserter.setNodeProperty( id, "name", "NewOne" ); // WHEN batchInserter.setNodeProperty( id, "count", "something" ); // THEN assertEquals( "something", batchInserter.getNodeProperties( id ).get( "count" ) ); }
@Test public void propertiesCanBeReSetUsingBatchInserter2() { // GIVEN BatchInserter batchInserter = globalInserter; long id = batchInserter.createNode( new HashMap<>() ); // WHEN batchInserter.setNodeProperty( id, "test", "looooooooooong test" ); batchInserter.setNodeProperty( id, "test", "small test" ); // THEN assertEquals( "small test", batchInserter.getNodeProperties( id ).get( "test" ) ); }
@Test public void testSetAndAddNodeProperties() { BatchInserter inserter = globalInserter; long tehNode = inserter.createNode( MapUtil.map( "one", "one" ,"two","two","three","three") ); inserter.setNodeProperty( tehNode, "four", "four" ); inserter.setNodeProperty( tehNode, "five", "five" ); Map<String, Object> props = getNodeProperties( inserter, tehNode ); assertEquals( 5, props.size() ); assertEquals( "one", props.get( "one" ) ); assertEquals( "five", props.get( "five" ) ); }
@Test public void propertiesCanBeReSetUsingBatchInserter() { // GIVEN BatchInserter batchInserter = globalInserter; Map<String, Object> props = new HashMap<>(); props.put( "name", "One" ); props.put( "count", 1 ); props.put( "tags", new String[] { "one", "two" } ); props.put( "something", "something" ); long nodeId = batchInserter.createNode( props ); batchInserter.setNodeProperty( nodeId, "name", "NewOne" ); batchInserter.removeNodeProperty( nodeId, "count" ); batchInserter.removeNodeProperty( nodeId, "something" ); // WHEN setting new properties batchInserter.setNodeProperty( nodeId, "name", "YetAnotherOne" ); batchInserter.setNodeProperty( nodeId, "additional", "something" ); // THEN there should be no problems doing so assertEquals( "YetAnotherOne", batchInserter.getNodeProperties( nodeId ).get( "name" ) ); assertEquals("something", batchInserter.getNodeProperties( nodeId ).get( "additional" ) ); }
@Test public void shouldUpdateStringArrayPropertiesOnNodesUsingBatchInserter1() { // Given BatchInserter inserter = globalInserter; String[] array1 = { "1" }; String[] array2 = { "a" }; long id1 = inserter.createNode(map("array", array1)); long id2 = inserter.createNode( map() ); // When inserter.getNodeProperties( id1 ).get( "array" ); inserter.setNodeProperty( id1, "array", array1 ); inserter.setNodeProperty( id2, "array", array2 ); inserter.getNodeProperties( id1 ).get( "array" ); inserter.setNodeProperty( id1, "array", array1 ); inserter.setNodeProperty( id2, "array", array2 ); // Then assertThat( inserter.getNodeProperties( id1 ).get( "array" ), equalTo( array1 ) ); }
@Test public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception { File file = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); long nodeId = inserter.createNode( Collections.emptyMap() ); final Object finalValue = 87; inserter.setNodeProperty( nodeId, "a", "some property value" ); inserter.setNodeProperty( nodeId, "a", 42 ); inserter.setNodeProperty( nodeId, "a", 3.14 ); inserter.setNodeProperty( nodeId, "a", true ); inserter.setNodeProperty( nodeId, "a", finalValue ); inserter.shutdown(); GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction ignored = db.beginTx() ) { assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue ) ); } finally { db.shutdown(); } }
@Test public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception { File file = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); long nodeId = inserter.createNode( Collections.emptyMap() ); final Object finalValue1 = 87; final Object finalValue2 = 3.14; inserter.setNodeProperty( nodeId, "a", "some property value" ); inserter.setNodeProperty( nodeId, "a", 42 ); inserter.setNodeProperty( nodeId, "b", finalValue2 ); inserter.setNodeProperty( nodeId, "a", finalValue2 ); inserter.setNodeProperty( nodeId, "a", true ); inserter.setNodeProperty( nodeId, "a", finalValue1 ); inserter.shutdown(); GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction ignored = db.beginTx() ) { assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue1 ) ); assertThat( db.getNodeById( nodeId ).getProperty( "b" ), equalTo( finalValue2 ) ); } finally { db.shutdown(); } }
@Test public void shouldBeAbleToOverwriteDynamicProperty() { // Only triggered if assertions are enabled // GIVEN BatchInserter batchInserter = globalInserter; String key = "tags"; long nodeId = batchInserter.createNode( MapUtil.map( key, new String[] { "one", "two", "three" } ) ); // WHEN String[] secondValue = new String[] { "four", "five", "six" }; batchInserter.setNodeProperty( nodeId, key, secondValue ); // THEN assertTrue( Arrays.equals( secondValue, (String[]) getNodeProperties( batchInserter, nodeId ).get( key ) ) ); }
assertThat( (String[]) getNodeProperties( inserter, personNodeId ).get( "email" ), is( emptyArray() ) ); inserter.setNodeProperty( personNodeId, "email", new String[]{"Edward1099511659993@gmail.com"} ); assertThat( (String[]) getNodeProperties( inserter, personNodeId ).get( "email" ), arrayContaining( "Edward1099511659993@gmail.com" ) ); inserter.setNodeProperty( personNodeId, "email", new String[]{"Edward1099511659993@gmail.com", "backup@gmail.com"} );
@Test public void givenBatchInserterWhenArrayPropertyUpdated4TimesThenShouldNotFail() throws IOException { BatchInserter batchInserter = BatchInserters.inserter( testDirectory.databaseDir(), fileSystemRule.get() ); long nodeId = batchInserter.createNode( Collections.emptyMap() ); for ( int i = 0; i < 4; i++ ) { batchInserter.setNodeProperty( nodeId, "array", new byte[]{2, 3, 98, 1, 43, 50, 3, 33, 51, 55, 116, 16, 23, 56, 9, -10, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1} ); } batchInserter.getNodeProperties( nodeId ); //fails here batchInserter.shutdown(); } }
inserter.setNodeProperty( tehNode, "foo2", "bar2" ); Map<String, Object> props = getNodeProperties( inserter, tehNode ); assertEquals( 2, props.size() ); assertEquals( "bar2", props.get( "foo2" ) ); inserter.setNodeProperty( tehNode, "foo", "bar3" );
@Test public void setSingleProperty() throws Exception { BatchInserter inserter = newBatchInserter(); long node = inserter.createNode( null ); String value = "Something"; String key = "name"; inserter.setNodeProperty( node, key, value ); GraphDatabaseService db = switchToEmbeddedGraphDatabaseService( inserter ); assertThat( getNodeInTx( node, db ), inTx( db, hasProperty( key ).withValue( value ) ) ); db.shutdown(); }
/** * {@inheritDoc} */ @Override public void setProperty(String key, Object value) { batchInserter.setNodeProperty(id, key, value); }
@Override public void setNodeProperty( long node, String propertyName, Object propertyValue ) { delegate.setNodeProperty( node, propertyName, propertyValue ); }
private static void flushCache(BatchInserter sourceDb, long node) { Map<String, Object> nodeProperties = sourceDb.getNodeProperties(node); Iterator<Map.Entry<String, Object>> iterator = nodeProperties.entrySet().iterator(); if (iterator.hasNext()) { Map.Entry<String, Object> firstProp = iterator.next(); sourceDb.nodeHasProperty(node,firstProp.getKey()); sourceDb.setNodeProperty(node, firstProp.getKey(), firstProp.getValue()); // force flush System.out.print(" flush"); } }