Refine search
@Test public void shouldReturnEmptyListIfNoLabels() { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Node node = createNode( beansAPI ); // WHEN THEN assertThat( node, inTx( beansAPI, hasNoLabels() ) ); }
@Test public void shouldKeepFailedIndexesAsFailedAfterRestart() throws Exception { // Given IndexPopulator indexPopulator = mock( IndexPopulator.class ); when( mockedIndexProvider.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) .thenReturn( indexPopulator ); IndexAccessor indexAccessor = mock( IndexAccessor.class ); when( mockedIndexProvider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) .thenReturn( indexAccessor ); startDb(); createIndex( myLabel ); rotateLogsAndCheckPoint(); // And Given killDb(); when( mockedIndexProvider.getInitialState( any( StoreIndexDescriptor.class ) ) ) .thenReturn( InternalIndexState.FAILED ); // When startDb(); // Then assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.FAILED ) ) ); verify( mockedIndexProvider, times( 2 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ); }
@Test public void createNodeWithLabels() { // GIVEN GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); // WHEN Node node = null; try ( Transaction tx = db.beginTx() ) { node = db.createNode( Labels.values() ); tx.success(); } // THEN Set<String> names = Stream.of( Labels.values() ).map( Labels::name ).collect( toSet() ); assertThat( node, inTx( db, hasLabels( names ) ) ); }
@Test public void getNodesWithLabelCommitted() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); // When Node node = null; try ( Transaction tx = beansAPI.beginTx() ) { node = beansAPI.createNode(); node.addLabel( Labels.MY_LABEL ); tx.success(); } // THEN assertThat( beansAPI, inTx( beansAPI, hasNodes( Labels.MY_LABEL, node ) ) ); assertThat( beansAPI, inTx( beansAPI, hasNoNodes( Labels.MY_OTHER_LABEL ) ) ); }
@Test public void shouldBeAbleToRecoverInTheMiddleOfPopulatingAnIndex() throws Exception assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.POPULATING ) ) ); verify( mockedIndexProvider, times( 2 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) );
@Test public void shouldBeAbleToRecoverInTheMiddleOfPopulatingAnIndexWhereLogHasRotated() throws Exception assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.POPULATING ) ) ); verify( mockedIndexProvider, times( 2 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) );
@Test public void canAddMultipleShortStringsToTheSameNode() { Node node = graphdb.getGraphDatabaseAPI().createNode(); node.setProperty( "key", "value" ); node.setProperty( "reverse", "esrever" ); commit(); assertThat( node, inTx( graphdb.getGraphDatabaseAPI(), hasProperty( "key" ).withValue( "value" ) ) ); assertThat( node, inTx( graphdb.getGraphDatabaseAPI(), hasProperty( "reverse" ).withValue( "esrever" ) ) ); }
@Test public void removingCommittedLabel() { // Given GraphDatabaseService graphDatabase = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; Node myNode = createNode( graphDatabase, label ); // When try ( Transaction tx = graphDatabase.beginTx() ) { myNode.removeLabel( label ); tx.success(); } // Then assertThat( myNode, not( inTx( graphDatabase, hasLabel( label ) ) ) ); }
@Test public void shouldHandleRestartIndexThatHasNotComeOnlineYet() { // Given startDb(); createIndex(); // And Given stopDb(); provider.setInitialIndexState( POPULATING ); // When startDb(); assertThat( getIndexes( db, myLabel ), inTx( db, not( haveState( db, Schema.IndexState.FAILED ) ) ) ); assertEquals( 2, provider.populatorCallCount.get() ); }
@Test public void removingNonExistentLabel() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; // When Node myNode; try ( Transaction tx = beansAPI.beginTx() ) { myNode = beansAPI.createNode(); myNode.removeLabel( label ); tx.success(); } // THEN assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ); }
@Test public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.ONLINE ) ) ); verify( mockedIndexProvider, times( 1 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) );
@Test public void graphPropertiesAreLockedPerTx() throws Exception String value3 = "hello"; worker1.setProperty( key1, value1 ).get(); assertThat( properties, inTx( db, not( hasProperty( key1 ) ) ) ); assertFalse( worker2.hasProperty( key1 ) ); Future<Void> blockedSetProperty = worker2.setProperty( key2, value2 ); assertThat( properties, inTx( db, not( hasProperty( key1 ) ) ) ); assertThat( properties, inTx( db, not( hasProperty( key2 ) ) ) ); worker1.setProperty( key3, value3 ).get(); assertFalse( blockedSetProperty.isDone() ); assertThat( properties, inTx( db, not( hasProperty( key1 ) ) ) ); assertThat( properties, inTx( db, not( hasProperty( key2 ) ) ) ); assertThat( properties, inTx( db, not( hasProperty( key3 ) ) ) ); worker1.commitTx(); assertThat( properties, inTx( db, hasProperty( key1 ) ) ); assertThat( properties, inTx( db, not( hasProperty( key2 ) ) ) ); assertThat( properties, inTx( db, hasProperty( key3 ) ) ); blockedSetProperty.get(); assertTrue( blockedSetProperty.isDone() ); worker2.commitTx(); assertThat( properties, inTx( db, hasProperty( key1 ).withValue( value1 ) ) ); assertThat( properties, inTx( db, hasProperty( key2 ).withValue( value2 ) ) ); assertThat( properties, inTx( db, hasProperty( key3 ).withValue( value3 ) ) );
@Test public void removingExistingLabelFromUnlabeledNode() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; createNode( beansAPI, label ); Node myNode = createNode( beansAPI ); // When try ( Transaction tx = beansAPI.beginTx() ) { myNode.removeLabel( label ); tx.success(); } // THEN assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ); }
@Test public void addingALabelUsingAValidIdentifierShouldSucceed() { // Given GraphDatabaseService graphDatabase = dbRule.getGraphDatabaseAPI(); Node myNode = null; // When try ( Transaction tx = graphDatabase.beginTx() ) { myNode = graphDatabase.createNode(); myNode.addLabel( Labels.MY_LABEL ); tx.success(); } // Then assertThat( "Label should have been added to node", myNode, inTx( graphDatabase, hasLabel( Labels.MY_LABEL ) ) ); }
@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(); }
@Test public void canRemoveShortStringProperty() { GraphDatabaseService db = graphdb.getGraphDatabaseAPI(); Node node = db.createNode(); node.setProperty( "key", "value" ); newTx(); assertEquals( "value", node.getProperty( "key" ) ); node.removeProperty( "key" ); commit(); assertThat( node, inTx( db, not( hasProperty( "key" ) ) ) ); } }
@Documented( "Set property on node.\n" + "\n" + "Setting different properties will retain the existing ones for this node.\n" + "Note that a single value are submitted not as a map but just as a value\n" + "(which is valid JSON) like in the example\n" + "below." ) @Graph( nodes = {@NODE( name = "jim", properties = {@PROP( key = "foo2", value = "bar2" )} )} ) @Test public void shouldReturn204WhenPropertyIsSet() throws Exception { Node jim = data.get().get( "jim" ); gen.get().payload( JsonHelper.createJsonFrom( "bar" ) ).expectedStatus( 204 ).put( getPropertyUri( jim, "foo" ).toString() ); assertThat( jim, inTx(graphdb(), hasProperty( "foo" ) ) ); assertThat( jim, inTx(graphdb(), hasProperty( "foo2" ) ) ); }
@Documented( "Removing a non-existent label from a node." ) @Test @GraphDescription.Graph( nodes = { @NODE( name = "Clint Eastwood", setNameProperty = true ) } ) public void removing_a_non_existent_label_from_a_node() { Map<String,Node> nodes = data.get(); Node node = nodes.get( "Clint Eastwood" ); String nodeUri = getNodeUri( node ); String labelName = "Person"; gen.get() .expectedStatus( 204 ) .delete( nodeUri + "/labels/" + labelName ); assertThat( node, inTx( graphdb(), not( hasLabel( label( labelName ) ) ) ) ); }
@Test public void shouldIndexArrays() { long[] arrayPropertyValue = {42, 23, 87}; createIndex( db, label, propertyKey ); Node node1; try ( Transaction tx = db.beginTx() ) { node1 = createNode( label, propertyKey, arrayPropertyValue ); tx.success(); } restart(); assertThat( getIndexes( db, label ), inTx( db, haveState( db, IndexState.ONLINE ) )); assertThat( findNodesByLabelAndProperty( label, propertyKey, arrayPropertyValue, db ), containsOnly( node1 ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, new long[]{42, 23}, db ), isEmpty() ); assertThat( findNodesByLabelAndProperty( label, propertyKey, Arrays.toString( arrayPropertyValue ), db ), isEmpty() ); }
@Test public void canAddShortStringToRelationship() { GraphDatabaseService db = graphdb.getGraphDatabaseAPI(); Relationship rel = db.createNode().createRelationshipTo( db.createNode(), withName( "REL_TYPE" ) ); rel.setProperty( "type", "dimsedut" ); commit(); assertThat( rel, inTx( db, hasProperty( "type" ).withValue( "dimsedut" ) ) ); }