private Map<String,Integer> getLabelsNameIdMap() { try ( Transaction ignored = embeddedDatabase.beginTx() ) { return getLabelIdsByName( COUNTRY_LABEL, COLOR_LABEL, CAR_LABEL ); } }
private int getPropertyId() { try ( Transaction ignored = embeddedDatabase.beginTx() ) { return getPropertyIdByName( NAME_PROPERTY ); } }
private void waitAndActivateIndexes( Map<String,Integer> labelsIds, int propertyId ) throws IndexNotFoundKernelException, IndexPopulationFailedKernelException, InterruptedException, IndexActivationFailedKernelException { try ( Transaction ignored = embeddedDatabase.beginTx() ) { for ( int labelId : labelsIds.values() ) { waitIndexOnline( indexService, propertyId, labelId ); } } }
private List<Pair<Long,Label[]>> someData( int numberOfModifications ) { List<Pair<Long,Label[]>> existingNodes; existingNodes = new ArrayList<>(); try ( Transaction tx = db.beginTx() ) { randomModifications( existingNodes, numberOfModifications ); tx.success(); } return existingNodes; }
private void removeOldNodes( LongStream idRange ) { try ( Transaction transaction = database.beginTx() ) { idRange.mapToObj( id -> database.getNodeById( id ) ).forEach( Node::delete ); transaction.success(); } }
private void updateOldNodes( LongStream idRange ) { try ( Transaction transaction = database.beginTx() ) { List<Node> nodes = idRange.mapToObj( id -> database.getNodeById( id ) ).collect( Collectors.toList() ); for ( int i = 0; i < NUMBER_OF_INDEXES; i++ ) { String propertyName = PROPERTY_PREFIX + i; nodes.forEach( node -> node.setProperty( propertyName, randomRule.nextLong() ) ); } transaction.success(); } }
@Override public void run() { try ( Transaction transaction = databaseRule.beginTx() ) { databaseRule.execute( "CREATE (n:staff {name:{name}})", map( "name", name ) ); transaction.success(); } } }
private void testNodeCreationTransaction( Label label, int i ) { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( label ); node.setProperty( "property" + i, i ); transaction.success(); } }
@Override public void run() { int guy = random.nextInt( NUMBER_OF_CREATORS ); Node node = nodeHeads.getAndSet( guy, null ); if ( node != null ) { try ( Transaction tx = db.beginTx() ) { node.delete(); tx.success(); } catch ( NotFoundException e ) { // This is OK in this test } } } };
private void createIndex( Label label, String propertyKey ) { try ( Transaction transaction = databaseRule.beginTx() ) { databaseRule.schema().indexFor( label ).on( propertyKey ).create(); transaction.success(); } try ( Transaction ignored = databaseRule.beginTx() ) { databaseRule.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); } }
List<Pair<Long,Label[]>> someData( int numberOfModifications ) { List<Pair<Long,Label[]>> existingNodes; existingNodes = new ArrayList<>(); try ( Transaction tx = db.beginTx() ) { randomModifications( existingNodes, numberOfModifications ); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().indexFor( LABEL_ONE ).on( PROPERTY_KEY ).create(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); tx.success(); } return existingNodes; }
@Test public void readLatestIndexDataAfterUsingExhaustedNodeRelationshipIterator() throws Exception { try ( Transaction transaction = databaseRule.beginTx() ) { addStaffMember( "Fry" ); assertEquals( 1, countStaff().intValue() ); Node fry = databaseRule.getNodeById( 0 ); Iterable<Relationship> fryRelationships = fry.getRelationships(); assertFalse( fryRelationships.iterator().hasNext() ); addStaffMember( "Lila" ); assertEquals( 2, countStaff().intValue() ); addStaffMember( "Bender" ); assertEquals( 3, countStaff().intValue() ); } }
private void prepareDatabase( Label label ) { generateData( label ); try ( Transaction transaction = database.beginTx() ) { for ( int i = 0; i < 10; i++ ) { database.schema().indexFor( label ).on( PROPERTY_PREFIX + i ).create(); } transaction.success(); } try ( Transaction ignored = database.beginTx() ) { database.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); } checkPointer = resolveDependency( CheckPointer.class ); indexingService = resolveDependency( IndexingService.class ); fileSystem = resolveDependency( FileSystemAbstraction.class ); }
@Test public void takeLabelLockForQueryWithIndexUsages() throws Exception { String labelName = "Human"; Label human = Label.label( labelName ); String propertyKey = "name"; createIndex( human, propertyKey ); try ( Transaction transaction = databaseRule.beginTx() ) { Node node = databaseRule.createNode( human ); node.setProperty( propertyKey, RandomStringUtils.randomAscii( 10 ) ); transaction.success(); } String query = "MATCH (n:" + labelName + ") where n." + propertyKey + " = \"Fry\" RETURN n "; List<LockOperationRecord> lockOperationRecords = traceQueryLocks( query ); assertThat( "Observed list of lock operations is: " + lockOperationRecords, lockOperationRecords, hasSize( 1 ) ); LockOperationRecord operationRecord = lockOperationRecords.get( 0 ); assertTrue( operationRecord.acquisition ); assertFalse( operationRecord.exclusive ); assertEquals( ResourceTypes.LABEL, operationRecord.resourceType ); }
@Test public void mustNotLeakFileDescriptorsFromMerge() { // GIVEN try ( Transaction tx = db.beginTx() ) { db.execute( "create constraint on (n:Node) assert n.id is unique" ); tx.success(); } cycleMerge( 1 ); long initialFDs = OsBeanUtil.getOpenFileDescriptors(); // WHEN cycleMerge( 300 ); // THEN long finalFDs = OsBeanUtil.getOpenFileDescriptors(); long upperBoundFDs = initialFDs + 50; // allow some slack assertThat( finalFDs, lessThan( upperBoundFDs ) ); }
@Test public void mustReportExtraLabelsOnExistingNode() throws Exception { // given List<Pair<Long,Label[]>> nodesInStore = someData(); File labelIndexFileCopy = copyLabelIndexFile(); // when try ( Transaction tx = db.beginTx() ) { removeLabelFromExistingNode( nodesInStore ); tx.success(); } // and replaceLabelIndexWithCopy( labelIndexFileCopy ); db.shutdownAndKeepStore(); // then ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); }
@Test public void mustReportExtraNode() throws Exception { // given List<Pair<Long,Label[]>> nodesInStore = someData(); File labelIndexFileCopy = copyLabelIndexFile(); // when try ( Transaction tx = db.beginTx() ) { removeExistingNode( nodesInStore ); tx.success(); } // and replaceLabelIndexWithCopy( labelIndexFileCopy ); db.shutdownAndKeepStore(); // then ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); }
@Test public void mustReportMissingNode() throws Exception { // given someData(); File labelIndexFileCopy = copyLabelIndexFile(); // when try ( Transaction tx = db.beginTx() ) { db.createNode( LABEL_ONE ); tx.success(); } // and replaceLabelIndexWithCopy( labelIndexFileCopy ); db.shutdownAndKeepStore(); // then ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); }
@Test public void mustReportMissingLabel() throws Exception { // given List<Pair<Long,Label[]>> nodesInStore = someData(); File labelIndexFileCopy = copyLabelIndexFile(); // when try ( Transaction tx = db.beginTx() ) { addLabelToExistingNode( nodesInStore ); tx.success(); } // and replaceLabelIndexWithCopy( labelIndexFileCopy ); db.shutdownAndKeepStore(); // then ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); }
@Test public void reportNotCleanLabelIndex() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); db.resolveDependency( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File labelIndexFileCopy = databaseLayout.file( "label_index_copy" ); copyFile( databaseLayout.labelScanStore(), labelIndexFileCopy ); try ( Transaction tx = db.beginTx() ) { db.createNode( LABEL_ONE ); tx.success(); } db.shutdownAndKeepStore(); copyFile( labelIndexFileCopy, databaseLayout.labelScanStore() ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Label index was not properly shutdown and rebuild is required.") ) ); }