@Test public void shouldScanAllInUseRelationships() { // given RelationshipStore relationshipStore = neoStores.getRelationshipStore(); int count = 100; relationshipStore.setHighId( count ); Set<Long> expected = new HashSet<>(); for ( long id = 0; id < count; id++ ) { boolean inUse = random.nextBoolean(); createRelationshipRecord( id, 1, relationshipStore, inUse ); if ( inUse ) { expected.add( id ); } } // when assertSeesRelationships( expected, ANY_RELATIONSHIP_TYPE ); }
@Test public void shouldScanAllInUseRelationshipsOfCertainType() { // given RelationshipStore relationshipStore = neoStores.getRelationshipStore(); int count = 100; relationshipStore.setHighId( count ); Set<Long> expected = new HashSet<>(); int theType = 1; for ( long id = 0; id < count; id++ ) { boolean inUse = random.nextBoolean(); int type = random.nextInt( 3 ); createRelationshipRecord( id, type, relationshipStore, inUse ); if ( inUse && type == theType ) { expected.add( id ); } } // when assertSeesRelationships( expected, theType ); }
@Test public void retrieveUnusedRelationship() { RelationshipStore relationshipStore = neoStores.getRelationshipStore(); relationshipStore.setHighId( 10 ); createRelationshipRecord( RELATIONSHIP_ID, 1, relationshipStore, false ); try ( RecordRelationshipScanCursor cursor = createRelationshipCursor() ) { cursor.single( RELATIONSHIP_ID ); assertFalse( cursor.next() ); } }
@Test public void retrieveRelationshipChainWithUnusedLink() { neoStores.getRelationshipStore().setHighId( 10 ); createRelationshipChain( 4 ); unUseRecord( 3 ); int[] expectedRelationshipIds = new int[]{1, 2, 4}; int relationshipIndex = 0; try ( RecordRelationshipTraversalCursor cursor = getNodeRelationshipCursor() ) { cursor.init( FIRST_OWNING_NODE, 1 ); while ( cursor.next() ) { assertEquals( "Should load next relationship in a sequence", expectedRelationshipIds[relationshipIndex++], cursor.entityReference() ); } } }
@Test public void shouldDeleteIdGeneratorsWhenOpeningExistingStore() throws IOException { // given long expectedHighId; try ( BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), storage.pageCache(), PageCacheTracer.NULL, storage.directory().absolutePath(), LATEST_RECORD_FORMATS, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.createNew(); RelationshipStore relationshipStore = stores.getRelationshipStore(); RelationshipRecord record = relationshipStore.newRecord(); long no = NULL_REFERENCE.longValue(); record.initialize( true, no, 1, 2, 0, no, no, no, no, true, true ); record.setId( relationshipStore.nextId() ); expectedHighId = relationshipStore.getHighId(); relationshipStore.updateRecord( record ); // fiddle with the highId relationshipStore.setHighId( record.getId() + 999 ); } // when try ( BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache( storage.fileSystem(), storage.pageCache(), PageCacheTracer.NULL, storage.directory().absolutePath(), LATEST_RECORD_FORMATS, DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults() ) ) { stores.pruneAndOpenExistingStore( Predicates.alwaysTrue(), Predicates.alwaysTrue() ); // then assertEquals( expectedHighId, stores.getRelationshipStore().getHighId() ); } }