@Test public void mustReportSuccessfulForConsistentLabelScanStore() throws Exception { // given someData(); db.shutdownAndKeepStore(); // when ConsistencyCheckService.Result result = fullConsistencyCheck(); // then assertTrue( "Expected consistency check to succeed", result.isSuccessful() ); }
@Test public void reportNotCleanLabelIndexWithCorrectData() 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 ); db.shutdownAndKeepStore(); copyFile( labelIndexFileCopy, databaseLayout.labelScanStore() ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertTrue( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Label index was not properly shutdown and rebuild is required.") ) ); }
@Test public void reportNotCleanNativeIndexWithCorrectData() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); resolveComponent( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File indexesCopy = databaseLayout.file( "indexesCopy" ); File indexSources = resolveComponent( DefaultIndexProviderMap.class ).getDefaultProvider().directoryStructure().rootDirectory(); copyRecursively( indexSources, indexesCopy, SOURCE_COPY_FILE_FILTER ); db.shutdownAndKeepStore(); copyRecursively( indexesCopy, indexSources ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertTrue( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Index was not properly shutdown and rebuild is required.") ) ); }
@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.") ) ); }
@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 reportNotCleanNativeIndex() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); resolveComponent( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File indexesCopy = databaseLayout.file( "indexesCopy" ); File indexSources = resolveComponent( DefaultIndexProviderMap.class ).getDefaultProvider().directoryStructure().rootDirectory(); copyRecursively( indexSources, indexesCopy, SOURCE_COPY_FILE_FILTER ); try ( Transaction tx = db.beginTx() ) { createNewNode( new Label[]{LABEL_ONE} ); tx.success(); } db.shutdownAndKeepStore(); copyRecursively( indexesCopy, indexSources ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Index was not properly shutdown and rebuild is required.") ) ); }
/** * The test case is basically loads of concurrent CREATE/DELETE NODE or sometimes just CREATE, keeping the created node in an array * for dedicated deleter threads to pick up and delete as fast as they can see them. This concurrently with large creation transactions. */ @Test public void shouldStressIt() throws Throwable { // given Race race = new Race().withMaxDuration( 5, TimeUnit.SECONDS ); AtomicReferenceArray<Node> nodeHeads = new AtomicReferenceArray<>( NUMBER_OF_CREATORS ); for ( int i = 0; i < NUMBER_OF_CREATORS; i++ ) { race.addContestant( creator( nodeHeads, i ) ); } race.addContestants( NUMBER_OF_DELETORS, deleter( nodeHeads ) ); // when race.go(); // then DatabaseLayout dbLayout = db.databaseLayout(); db.shutdownAndKeepStore(); assertTrue( new ConsistencyCheckService().runFullConsistencyCheck( dbLayout, defaults(), NONE, toOutputStream( System.out ), false, new ConsistencyFlags( true, true, true, false ) ).isSuccessful() ); }