private File file( String localname ) { return dbRule.databaseLayout().file( localname ); } }
private File badFile() { return dbRule.databaseLayout().file( BAD_FILE_NAME ); }
private File file( String localname ) { return dbRule.databaseLayout().file( localname ); }
private void createIndexDbFile() throws IOException { DatabaseLayout databaseLayout = db.databaseLayout(); final File indexFile = databaseLayout.file( "index.db" ); if ( !indexFile.exists() ) { assertTrue( indexFile.createNewFile() ); } }
private File copyLabelIndexFile() throws IOException { DatabaseLayout databaseLayout = db.databaseLayout(); File labelIndexFileCopy = databaseLayout.file( "label_index_copy" ); db.restartDatabase( ( fs, directory ) -> fs.copyFile( databaseLayout.labelScanStore(), labelIndexFileCopy ) ); return labelIndexFileCopy; }
private ConsistencyCheckService.Result fullConsistencyCheck() throws ConsistencyCheckIncompleteException, IOException { try ( FileSystemAbstraction fsa = new DefaultFileSystemAbstraction() ) { ConsistencyCheckService service = new ConsistencyCheckService(); Config config = Config.defaults(); return service.runFullConsistencyCheck( db.databaseLayout(), config, NONE, log, fsa, true ); } } }
private ConsistencyCheckService.Result fullConsistencyCheck() throws ConsistencyCheckIncompleteException, IOException { try ( FileSystemAbstraction fsa = new DefaultFileSystemAbstraction() ) { ConsistencyCheckService service = new ConsistencyCheckService(); Config config = Config.defaults(); return service.runFullConsistencyCheck( db.databaseLayout(), config, NONE, log, fsa, true, new ConsistencyFlags( config ) ); } } }
private void replaceLabelIndexWithCopy( File labelIndexFileCopy ) throws IOException { db.restartDatabase( ( fs, directory ) -> { DatabaseLayout databaseLayout = db.databaseLayout(); fs.deleteFile( databaseLayout.labelScanStore() ); fs.copyFile( labelIndexFileCopy, databaseLayout.labelScanStore() ); } ); }
@Test( expected = ReservedIdException.class ) public void makeSureCantCreateNodeWithMagicNumber() throws IOException { // given File path = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( path, fileSystemRule.get() ); try { // when long id = IdGeneratorImpl.INTEGER_MINUS_ONE; inserter.createNode( id, null ); // then throws } finally { inserter.shutdown(); } } }
dbRule.databaseLayout().file( storeType.getDatabaseFile() ).forEach( f -> assertTrue( f.exists() ) );
private void shouldPrintReferenceLinkAsPartOfErrorMessage( List<String> nodeIds, Iterator<RelationshipDataLine> relationshipDataLines, String message ) { Configuration config = Configuration.COMMAS; try { // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", nodeData( true, config, nodeIds, TRUE ).getAbsolutePath(), "--skip-bad-relationships", "false", "--relationships", relationshipData( true, config, relationshipDataLines, TRUE, true ).getAbsolutePath() ); fail( " Should fail during import." ); } catch ( Exception e ) { // EXPECT assertTrue( suppressOutput.getErrorVoice().containsMessage( message ) ); } for ( StoreType storeType : StoreType.values() ) { if ( storeType.isRecordStore() ) { dbRule.databaseLayout().file( storeType.getDatabaseFile() ).forEach( File::delete ); } } }
@Test public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception { File file = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); long nodeId = inserter.createNode( Collections.emptyMap() ); final Object finalValue1 = 87; final Object finalValue2 = 3.14; inserter.setNodeProperty( nodeId, "a", "some property value" ); inserter.setNodeProperty( nodeId, "a", 42 ); inserter.setNodeProperty( nodeId, "b", finalValue2 ); inserter.setNodeProperty( nodeId, "a", finalValue2 ); inserter.setNodeProperty( nodeId, "a", true ); inserter.setNodeProperty( nodeId, "a", finalValue1 ); inserter.shutdown(); GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction ignored = db.beginTx() ) { assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue1 ) ); assertThat( db.getNodeById( nodeId ).getProperty( "b" ), equalTo( finalValue2 ) ); } finally { db.shutdown(); } }
@Test public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception { File file = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); long nodeId = inserter.createNode( Collections.emptyMap() ); final Object finalValue = 87; inserter.setNodeProperty( nodeId, "a", "some property value" ); inserter.setNodeProperty( nodeId, "a", 42 ); inserter.setNodeProperty( nodeId, "a", 3.14 ); inserter.setNodeProperty( nodeId, "a", true ); inserter.setNodeProperty( nodeId, "a", finalValue ); inserter.shutdown(); GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction ignored = db.beginTx() ) { assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue ) ); } finally { db.shutdown(); } }
@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 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 shouldIndexNodesWithMultipleLabels() throws Exception { // Given File path = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( path, fileSystemRule.get() ); inserter.createNode( map( "name", "Bob" ), label( "User" ), label( "Admin" ) ); inserter.createDeferredSchemaIndex( label( "User" ) ).on( "name" ).create(); inserter.createDeferredSchemaIndex( label( "Admin" ) ).on( "name" ).create(); // When inserter.shutdown(); // Then GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { assertThat( count( db.findNodes( label( "User" ), "name", "Bob" ) ), equalTo(1L) ); assertThat( count( db.findNodes( label( "Admin" ), "name", "Bob" ) ), equalTo(1L) ); } finally { db.shutdown(); } }
@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() ); }