@Before public void before() { when( neoStores.getNodeStore() ).thenReturn( nodeStore ); when( neoStores.getPropertyStore() ).thenReturn( propertyStore ); }
@Override public void shutdown() throws Throwable { indexingService.shutdown(); labelScanStore.shutdown(); neoStores.close(); }
private void flushNeoStoreOnly() { NeoStores neoStores = ((GraphDatabaseAPI) db).getDependencyResolver() .resolveDependency( RecordStorageEngine.class ).testAccessNeoStores(); MetaDataStore metaDataStore = neoStores.getMetaDataStore(); metaDataStore.flush(); }
public DirectRecordAccessSet( NeoStores neoStores ) { this( neoStores.getNodeStore(), neoStores.getPropertyStore(), neoStores.getRelationshipStore(), neoStores.getRelationshipGroupStore(), neoStores.getPropertyKeyTokenStore(), neoStores.getRelationshipTypeTokenStore(), neoStores.getLabelTokenStore(), neoStores.getSchemaStore() ); }
public CacheInvalidationTransactionApplier( NeoStores neoStores, CacheAccessBackDoor cacheAccess ) { this.cacheAccess = cacheAccess; this.relationshipTypeTokenStore = neoStores.getRelationshipTypeTokenStore(); this.labelTokenStore = neoStores.getLabelTokenStore(); this.propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore(); }
public NeoStoreIndexStoreView( LockService locks, NeoStores neoStores ) { this.locks = locks; this.neoStores = neoStores; this.propertyStore = neoStores.getPropertyStore(); this.nodeStore = neoStores.getNodeStore(); this.relationshipStore = neoStores.getRelationshipStore(); this.counts = neoStores.getCounts(); }
@Test public void shouldCreateIndexForCreatedSchemaRule() throws Exception { // GIVEN SchemaRecord beforeRecords = serialize( rule, id, false, false); SchemaRecord afterRecords = serialize( rule, id, true, true); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); // WHEN visitSchemaRuleCommand( indexApplier, new SchemaRuleCommand( beforeRecords, afterRecords, rule ) ); // THEN verify( indexes ).createIndexes( rule ); }
@Test public void shouldSetLatestConstraintRule() throws Exception { // Given SchemaRecord beforeRecords = serialize( rule, id, true, true); SchemaRecord afterRecords = serialize( rule, id, true, false); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore ); ConstraintRule schemaRule = ConstraintRule.constraintRule( id, ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKey ), 0 ); // WHEN visitSchemaRuleCommand( storeApplier, new SchemaRuleCommand( beforeRecords, afterRecords, schemaRule ) ); // THEN verify( schemaStore ).updateRecord( Iterables.first( afterRecords ) ); verify( metaDataStore ).setLatestConstraintIntroducingTx( txId ); }
@Test public void shouldWriteSchemaRuleToLog() throws Exception { // GIVEN SchemaRecord beforeRecords = serialize( rule, id, false, false); SchemaRecord afterRecords = serialize( rule, id, true, true); SchemaRuleCommand command = new SchemaRuleCommand( beforeRecords, afterRecords, rule ); InMemoryClosableChannel buffer = new InMemoryClosableChannel(); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); // WHEN command.serialize( buffer ); Command readCommand = reader.read( buffer ); // THEN assertThat( readCommand, instanceOf( SchemaRuleCommand.class ) ); assertSchemaRule( (SchemaRuleCommand)readCommand ); }
@Before public void before() throws Exception { collectionsFactory = Mockito.spy( new TestCollectionsFactory() ); when( headerInformation.getAdditionalHeader() ).thenReturn( new byte[0] ); when( headerInformationFactory.create() ).thenReturn( headerInformation ); when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore ); when( storageEngine.newReader() ).thenReturn( readLayer ); doAnswer( invocation -> ((Collection<StorageCommand>) invocation.getArgument(0) ).add( new Command .RelationshipCountsCommand( 1, 2,3, 4L ) ) ) .when( storageEngine ).createCommands( anyCollection(), any( ReadableTransactionState.class ), any( StorageReader.class ), any( ResourceLocker.class ), anyLong(), any( TxStateVisitor.Decorator.class ) ); }
@Before public void setup() { when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore ); when( neoStores.getNodeStore() ).thenReturn( nodeStore ); when( neoStores.getRelationshipStore() ).thenReturn( relationshipStore ); when( neoStores.getPropertyStore() ).thenReturn( propertyStore ); when( neoStores.getRelationshipGroupStore() ).thenReturn( relationshipGroupStore ); when( neoStores.getRelationshipTypeTokenStore() ).thenReturn( relationshipTypeTokenStore ); when( neoStores.getLabelTokenStore() ).thenReturn( labelTokenStore ); when( neoStores.getPropertyKeyTokenStore() ).thenReturn( propertyKeyTokenStore ); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); when( nodeStore.getDynamicLabelStore() ).thenReturn( dynamicLabelStore ); when( lockService.acquireNodeLock( anyLong(), any() ) ) .thenReturn( LockService.NO_LOCK ); when( lockService.acquireRelationshipLock( anyLong(), any() ) ) .thenReturn( LockService.NO_LOCK ); when( transactionToApply.transactionId() ).thenReturn( transactionId ); }
@Before public void setUp() { when( labelScanStore.newReader() ).thenReturn( labelScanReader ); when( neoStores.getNodeStore() ).thenReturn( nodeStore ); }
@Test public void shouldValidateConstraintIndexAsPartOfExtraction() throws Throwable { // GIVEN NeoStores neoStores = neoStoresRule.builder().build(); TransactionRecordState recordState = newTransactionRecordState( neoStores ); final long indexId = neoStores.getSchemaStore().nextId(); final long constraintId = neoStores.getSchemaStore().nextId(); recordState.createSchemaRule( constraintRule( constraintId, uniqueForLabel( 1, 1 ), indexId ) ); // WHEN recordState.extractCommands( new ArrayList<>() ); // THEN verify( integrityValidator ).validateSchemaRule( any() ); }
LogProvider logProvider = NullLogProvider.getInstance(); StoreFactory storeFactory = new StoreFactory( testDirectory.databaseLayout(), Config.defaults(), new DefaultIdGeneratorFactory( fs.get() ), pageCache.getPageCache( fs.get() ), fs.get(), logProvider, EmptyVersionContextSupplier.EMPTY ); try ( NeoStores stores = storeFactory.openNeoStores( true, StoreType.RELATIONSHIP_GROUP ) ) RecordStore<RelationshipGroupRecord> store = spy( stores.getRelationshipGroupStore() ); InOrder verification = inOrder( store ); verification.verify( store ).getRecord( eq( group2.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store ).getRecord( eq( group4.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store ).getRecord( eq( group10.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store, never() ) .getRecord( eq( group23.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) );
@Test public void shouldDropUniquenessConstraintWithBackingIndexHavingNoOwner() throws Exception { // given try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( label ).assertPropertyIsUnique( key ).create(); tx.success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ); SchemaStore schemaStore = storageEngine.testAccessNeoStores().getSchemaStore(); SchemaRule indexRule = single( filter( rule -> rule instanceof StoreIndexDescriptor, schemaStore.loadAllSchemaRules() ) ); setOwnerNull( schemaStore, (StoreIndexDescriptor) indexRule ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.loadSchemaCache(); try ( Transaction tx = db.beginTx() ) { single( db.schema().getConstraints( label ).iterator() ).drop(); tx.success(); } // then try ( Transaction ignore = db.beginTx() ) { assertFalse( db.schema().getConstraints().iterator().hasNext() ); assertFalse( db.schema().getIndexes().iterator().hasNext() ); } }
@Test public void firstRecordOtherThanZeroIfNotFirst() { File storeDir = testDirectory.databaseDir(); GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase( storeDir ); Transaction tx = db.beginTx(); Node node = db.createNode(); node.setProperty( "name", "Yo" ); tx.success(); tx.close(); db.shutdown(); db = (GraphDatabaseAPI) factory.newImpermanentDatabase( storeDir ); tx = db.beginTx(); properties( db ).setProperty( "test", "something" ); tx.success(); tx.close(); db.shutdown(); Config config = Config.defaults(); StoreFactory storeFactory = new StoreFactory( testDirectory.databaseLayout(), config, new DefaultIdGeneratorFactory( fs.get() ), pageCacheRule.getPageCache( fs.get() ), fs.get(), NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY ); NeoStores neoStores = storeFactory.openAllNeoStores(); long prop = neoStores.getMetaDataStore().getGraphNextProp(); assertTrue( prop != 0 ); neoStores.close(); }
rel5 = db.createNode().createRelationshipTo( node, MyRelTypes.TEST ); rel6 = node.createRelationshipTo( node, MyRelTypes.TEST ); tx.success(); NeoStores neoStores = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ).testAccessNeoStores(); NodeStore nodeStore = neoStores.getNodeStore(); NodeRecord nodeRecord = getRecord( nodeStore, node.getId() ); long group = nodeRecord.getNextRel(); RecordStore<RelationshipGroupRecord> groupStore = neoStores.getRelationshipGroupStore(); RelationshipGroupRecord groupRecord = getRecord( groupStore, group ); assertEquals( -1, groupRecord.getNext() ); assertEquals( -1, groupRecord.getPrev() ); assertRelationshipChain( neoStores.getRelationshipStore(), node, groupRecord.getFirstOut(), rel1.getId(), rel4.getId() ); assertRelationshipChain( neoStores.getRelationshipStore(), node, groupRecord.getFirstIn(), rel2.getId(), rel5.getId() ); assertRelationshipChain( neoStores.getRelationshipStore(), node, groupRecord.getFirstLoop(), rel3.getId(), rel6.getId() );
try ( Transaction tx = db.beginTx() ) Node node1 = set( db.createNode() ); Node node2 = set( db.createNode(), property( "key", "value" ) ); node1.createRelationshipTo( node2, relationshipType ); node1.createRelationshipTo( node2, relationshipType ); node1.createRelationshipTo( node2, relationshipType ); node1.createRelationshipTo( node2, relationshipType ); tx.success(); RecordStorageEngine recordStorageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ); NeoStores neoStores = recordStorageEngine.testAccessNeoStores(); RelationshipStore relationshipStore = neoStores.getRelationshipStore(); RelationshipRecord relationshipRecord = new RelationshipRecord( -1 ); RelationshipRecord record = relationshipStore.getRecord( 4, relationshipRecord, RecordLoad.FORCE );
@Test public void verifyGroupIsDeletedWhenNeeded() { // TODO test on a lower level instead newDb( 2 ); Transaction tx = db.beginTx(); Node node = db.createNode(); Relationship rel1 = node.createRelationshipTo( db.createNode(), MyRelTypes.TEST ); Relationship rel2 = node.createRelationshipTo( db.createNode(), MyRelTypes.TEST ); Relationship rel3 = node.createRelationshipTo( db.createNode(), MyRelTypes.TEST ); Relationship rel4 = node.createRelationshipTo( db.createNode(), MyRelTypes.TEST2 ); Relationship rel5 = node.createRelationshipTo( db.createNode(), MyRelTypes.TEST2 ); Relationship rel6 = node.createRelationshipTo( db.createNode(), MyRelTypes.TEST2 ); tx.success(); tx.close(); NeoStores neoStores = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ).testAccessNeoStores(); NodeStore nodeStore = neoStores.getNodeStore(); NodeRecord nodeRecord = getRecord( nodeStore, node.getId() ); long group = nodeRecord.getNextRel(); RecordStore<RelationshipGroupRecord> groupStore = neoStores.getRelationshipGroupStore(); RelationshipGroupRecord groupRecord = getRecord( groupStore, group ); assertNotEquals( groupRecord.getNext(), -1 ); RelationshipGroupRecord otherGroupRecord = groupStore.getRecord( groupRecord.getNext(), groupStore.newRecord(), NORMAL ); assertEquals( -1, otherGroupRecord.getNext() ); // TODO Delete all relationships of one type and see to that the correct group is deleted. }
NeoStores neoStores = ((GraphDatabaseAPI)db).getDependencyResolver().resolveDependency( RecordStorageEngine.class ).testAccessNeoStores(); Function<String, Integer> labelTranslationTable = translationTable( neoStores.getLabelTokenStore(), StatementConstants.ANY_LABEL ); for ( Pair<Integer,Long> count : allNodeCounts( labelTranslationTable, expectedNodeCounts ) ) neoStores.getCounts() .nodeCount( count.first(), newDoubleLongRegister() ) .readSecond() ); translationTable( neoStores.getRelationshipTypeTokenStore(), StatementConstants.ANY_RELATIONSHIP_TYPE ); for ( Pair<RelationshipCountKey,Long> count : allRelationshipCounts( labelTranslationTable, relationshipTypeTranslationTable, expectedRelationshipCounts ) ) assertEquals( "Label count mismatch for label " + key, count.other().longValue(), neoStores.getCounts() .relationshipCount( key.startLabel, key.type, key.endLabel, newDoubleLongRegister() ) .readSecond() ); tx.success();