Refine search
private Node createLabeledNode( Label... labels ) { try ( Transaction tx = dbRule.beginTx() ) { Node node = dbRule.createNode( labels ); tx.success(); return node; } }
@Test( timeout = 10000 ) public void logRotationMustNotObstructStartingWriteTransaction() { try ( Transaction tx = db.beginTx() ) { db.createNode(); tx.success(); completeLogRotationLatch.countDown(); } } }
@Test public void shouldThrowHumaneExceptionsWhenPropertyDoesNotExist() { // Given a database without PROPERTY_KEY in it // When try ( Transaction ignored = db.beginTx() ) { Node node = db.createNode(); node.getProperty( PROPERTY_KEY ); } // Then catch ( NotFoundException exception ) { assertThat( exception.getMessage(), containsString( PROPERTY_KEY ) ); } }
@Test public void shouldGiveHelpfulExceptionWhenDeletingNodeWithRels() { // Given Node node; node = db.createNode(); Node node2 = db.createNode(); node.createRelationshipTo( node2, RelationshipType.withName( "MAYOR_OF" ) ); tx.success(); // And given a transaction deleting just the node tx.begin(); node.delete(); // Expect exception.expect( ConstraintViolationException.class ); exception.expectMessage( "Cannot delete node<" + node.getId() + ">, because it still has relationships. " + "To delete this node, you must first delete its relationships." ); // When I commit tx.success(); }
private void runTransaction( LoginContext loginContext, Map<String,Object> metaData ) { try ( Transaction transaction = db.beginTransaction( KernelTransaction.Type.explicit, loginContext ); Statement statement = db.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class ).get() ) { statement.queryRegistration().setMetaData( metaData ); db.createNode(); transaction.success(); } }
@Test( expected = NotFoundException.class ) public void deletionOfAlreadyDeletedNodeShouldThrow() { // Given Node node; try ( Transaction tx = db.beginTx() ) { node = db.createNode(); tx.success(); } try ( Transaction tx = db.beginTx() ) { node.delete(); tx.success(); } // When try ( Transaction tx = db.beginTx() ) { node.delete(); // should throw NotFoundException as this node is already deleted tx.success(); } }
@Test public void shouldThrowHumaneExceptionsWhenPropertyDoesNotExistOnNode() { // Given a database with PROPERTY_KEY in it createNodeWith( PROPERTY_KEY ); // When trying to get property from node without it try ( Transaction ignored = db.beginTx() ) { Node node = db.createNode(); node.getProperty( PROPERTY_KEY ); fail( "Expected exception to have been thrown" ); } // Then catch ( NotFoundException exception ) { assertThat( exception.getMessage(), containsString( PROPERTY_KEY ) ); } }
private Node createSomeData() { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.createRelationshipTo( db.createNode(), MyRelTypes.TEST ); node.createRelationshipTo( db.createNode(), MyRelTypes.TEST2 ); tx.success(); return node; } } }
@Test( timeout = 30_000 ) public void terminateExpiredTransaction() throws Exception { try ( Transaction transaction = database.beginTx() ) { database.createNode(); transaction.success(); } expectedException.expectMessage( "The transaction has been terminated." ); try ( Transaction transaction = database.beginTx() ) { Node nodeById = database.getNodeById( NODE_ID ); nodeById.setProperty( "a", "b" ); executor.submit( startAnotherTransaction() ).get(); } }
@Test public void lookupWithinTransactionWithCacheEviction() { try ( Transaction tx = db.beginTx() ) { // when db.createNode( label( "Node" ) ).setProperty( "prop", store ); // then assertEquals( 1, count( db.findNodes( label( "Node" ), "prop", lookup ) ) ); // no need to actually commit this node } }
private Node createTree( int depth, int width ) { try ( Transaction tx = dbRule.beginTx() ) { Node root = dbRule.createNode( TestLabels.LABEL_ONE ); createTree( root, depth, width, 0 ); tx.success(); return root; } }
@Test public void shouldReuseExcessBatchIdsWhichWerentUsedBeforeClose() throws Exception { // given Node firstNode; try ( Transaction tx = db.beginTx() ) { firstNode = db.createNode(); tx.success(); } // when db.restartDatabase(); Node secondNode; try ( Transaction tx = db.beginTx() ) { secondNode = db.createNode(); tx.success(); } // then assertEquals( firstNode.getId() + 1, secondNode.getId() ); } }
@Test public void lookupWithinTransaction() { try ( Transaction tx = db.beginTx() ) { // when db.createNode( label( "Node" ) ).setProperty( "prop", store ); // then assertEquals( 1, count( db.findNodes( label( "Node" ), "prop", lookup ) ) ); // no need to actually commit this node } }
private void createNodeWith( String key ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( key, 1 ); tx.success(); } } }
@Test public void testAsLittleAsPossibleRecoveryScenario() throws Exception { try ( Transaction tx = db.beginTx() ) { db.index().forNodes( "my-index" ).add( db.createNode(), "key", "value" ); tx.success(); } forceRecover(); }
@Test public void shutdownWhileFinishingTransactionWithIndexUpdates() { createConstraint( database ); waitIndexesOnline( database ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( constraintIndexLabel ); node.setProperty( UNIQUE_PROPERTY_NAME, indexProvider.getAndIncrement() ); DependencyResolver dependencyResolver = database.getDependencyResolver(); NeoStoreDataSource dataSource = dependencyResolver.resolveDependency( NeoStoreDataSource.class ); LifeSupport dataSourceLife = dataSource.getLife(); TransactionCloseListener closeListener = new TransactionCloseListener( transaction ); dataSourceLife.addLifecycleListener( closeListener ); dataSource.stop(); assertTrue( "Transaction should be closed and no exception should be thrown.", closeListener.isTransactionClosed() ); } }
private void createNamed( Label label, String name ) { try ( Transaction tx = db.beginTx() ) { db.createNode( label ).setProperty( "name", name ); tx.success(); } } }
@Test public void shouldBeAbleToForceTypeChangeOfProperty() { // Given Relationship relationship; try ( Transaction tx = db.beginTx() ) { relationship = db.createNode().createRelationshipTo( db.createNode(), withName( "R" ) ); relationship.setProperty( "prop", 1337 ); tx.success(); } // When try ( Transaction tx = db.beginTx() ) { relationship.setProperty( "prop", 1337.0 ); tx.success(); } // Then try ( Transaction ignore = db.beginTx() ) { assertThat( relationship.getProperty( "prop" ), instanceOf( Double.class ) ); } }
private Node createNode( String... properties ) { try ( Transaction tx = dbRule.beginTx() ) { Node node = dbRule.createNode(); for ( int i = 0; i < properties.length; i++ ) { node.setProperty( properties[i++], properties[i] ); } tx.success(); return node; } }
@Test public void txMustFailIfExceedingIndexKeySizeLimit() { createIndex(); // Write try ( Transaction tx = db.beginTx() ) { String propValue = getString( keySizeLimit + 1 ); db.createNode( LABEL_ONE ).setProperty( propKey, propValue ); tx.success(); } catch ( IllegalArgumentException e ) { assertThat( e.getMessage(), Matchers.containsString( "Property value size is too large for index. Please see index documentation for limitations." ) ); } }