private static GraphDatabaseService startDatabase( File storeDir ) { return new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir ); }
@BeforeClass public static void createDatabase() { graphdb = new TestGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.storeDir() ); File databaseDirectory = testDirectory.databaseLayout( "read_only" ).databaseDirectory(); new TestGraphDatabaseFactory().newEmbeddedDatabase( databaseDirectory ).shutdown(); graphDbReadOnly = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( databaseDirectory ). setConfig( GraphDatabaseSettings.read_only, TRUE ). newGraphDatabase(); }
@Before public void setUp() { db = new TestGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.storeDir() ); numberOfWorkers = Runtime.getRuntime().availableProcessors(); executors = Executors.newFixedThreadPool( numberOfWorkers ); }
private GraphDatabaseAPI database() { return (GraphDatabaseAPI) new TestGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.databaseDir() ); }
private GraphDatabaseService newDb() { return new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir() ); }
private GraphDatabaseService startDatabase( File storeDir ) { return new TestGraphDatabaseFactory().setInternalLogProvider( logProvider ).newEmbeddedDatabase( storeDir ); }
@Before public void before() { db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.storeDir() ); }
@BeforeClass public static void setUpStuff() { graphDb = new TestGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.storeDir() ); }
@Before public void doBefore() { db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newEmbeddedDatabase( testDirectory.databaseDir() ); }
@Test public void doNotTruncateNewerTransactionLogFileWhenFailOnError() throws IOException { GraphDatabaseAPI database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir ); for ( int i = 0; i < 10; i++ ) { generateTransaction( database ); } database.shutdown(); removeLastCheckpointRecordFromLastLogFile(); addRandomBytesToLastLogFile( this::randomPositiveBytes ); expectedException.expectCause( new RootCauseMatcher<>( UnsupportedLogVersionException.class ) ); database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir ); database.shutdown(); }
@Test public void repetitiveRecoveryIfCorruptedLogsWithCheckpoints() throws IOException { GraphDatabaseAPI database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir ); generateTransactionsAndRotate( database, 4, true ); database.shutdown(); while ( logFiles.getHighestLogVersion() > 0 ) { int bytesToTrim = 1 + random.nextInt( 100 ); truncateBytesFromLastLogFile( bytesToTrim ); databaseFactory.newEmbeddedDatabase( storeDir ).shutdown(); int numberOfRecoveredTransactions = recoveryMonitor.getNumberOfRecoveredTransactions(); assertThat( numberOfRecoveredTransactions, Matchers.greaterThanOrEqualTo( 0 ) ); } File corruptedLogArchives = new File( storeDir, CorruptedLogsTruncator.CORRUPTED_TX_LOGS_BASE_NAME ); assertThat( corruptedLogArchives.listFiles(), not( emptyArray() ) ); }
@Before public void setUp() { storeDir = testDirectory.storeDir(); logProvider = new AssertableLogProvider(); database = new TestGraphDatabaseFactory().setInternalLogProvider( logProvider ).newEmbeddedDatabase( storeDir ); }
@Test public void failToRecoverFirstCorruptedTransactionSingleFileNoCheckpointIfFailOnCorruption() throws IOException { addCorruptedCommandsToLastLogFile(); expectedException.expectCause( new RootCauseMatcher<>( NegativeArraySizeException.class ) ); GraphDatabaseService recoveredDatabase = databaseFactory.newEmbeddedDatabase( storeDir ); recoveredDatabase.shutdown(); }
@Test public void repetitiveRecoveryOfCorruptedLogs() throws IOException { GraphDatabaseAPI database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir ); generateTransactionsAndRotate( database, 4, false ); database.shutdown(); removeLastCheckpointRecordFromLastLogFile(); int expectedRecoveredTransactions = 7; while ( expectedRecoveredTransactions > 0 ) { truncateBytesFromLastLogFile( 1 + random.nextInt( 10 ) ); databaseFactory.newEmbeddedDatabase( storeDir ).shutdown(); int numberOfRecoveredTransactions = recoveryMonitor.getNumberOfRecoveredTransactions(); assertEquals( expectedRecoveredTransactions, numberOfRecoveredTransactions ); expectedRecoveredTransactions--; removeLastCheckpointRecordFromLastLogFile(); } }
private void prepareEmpty23Database() throws IOException { new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir ).shutdown(); fileSystem.deleteFile( nativeLabelIndex ); MetaDataStore.setRecord( pageCache, databaseLayout.metadataStore(), Position.STORE_VERSION, versionStringToLong( StandardV2_3.STORE_VERSION ) ); }
@Test public void schemaTransactionsShouldSurviveRecovery() throws Exception { // given File storeDir = testDirectory.absolutePath(); Process process = new CreateConstraintButDoNotShutDown().start( storeDir ); process.waitForSchemaTransactionCommitted(); SubProcess.kill( process ); // when GraphDatabaseService recoveredDatabase = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir ); // then assertEquals(1, constraints( recoveredDatabase ).size()); assertEquals(1, indexes( recoveredDatabase ).size()); recoveredDatabase.shutdown(); }
@Override protected void startup( File storeDir ) { GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir ); try ( Transaction transaction = database.beginTx() ) { database.schema().constraintFor( label("User") ).assertPropertyIsUnique( "uuid" ).create(); transaction.success(); } started = true; }
@Test public void truncateNewerTransactionLogFileWhenForced() throws IOException { GraphDatabaseAPI database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir ); for ( int i = 0; i < 10; i++ ) { generateTransaction( database ); } TransactionIdStore transactionIdStore = getTransactionIdStore( database ); long numberOfClosedTransactions = transactionIdStore.getLastClosedTransactionId() - 1; database.shutdown(); removeLastCheckpointRecordFromLastLogFile(); addRandomBytesToLastLogFile( this::randomBytes ); database = startDbNoRecoveryOfCorruptedLogs(); database.shutdown(); logProvider.assertContainsMessageContaining( "Fail to read transaction log version 0." ); logProvider.assertContainsMessageContaining( "Fail to read transaction log version 0. Last valid transaction start offset is: 5668." ); assertEquals( numberOfClosedTransactions, recoveryMonitor.getNumberOfRecoveredTransactions() ); }
@Test public void shutdownDatabaseDuringIndexPopulations() { AssertableLogProvider assertableLogProvider = new AssertableLogProvider( true ); File storeDir = directory.directory( "shutdownDbTest" ); Label testLabel = Label.label( "testLabel" ); String propertyName = "testProperty"; GraphDatabaseService shutDownDb = new TestGraphDatabaseFactory().setInternalLogProvider( assertableLogProvider ) .newEmbeddedDatabase( storeDir ); prePopulateDatabase( shutDownDb, testLabel, propertyName ); try ( Transaction transaction = shutDownDb.beginTx() ) { shutDownDb.schema().indexFor( testLabel ).on( propertyName ).create(); transaction.success(); } shutDownDb.shutdown(); assertableLogProvider.assertNone( AssertableLogProvider.inLog( IndexPopulationJob.class ).anyError() ); }
@Test public void shouldBeEmptyWhenFirstStarted() { // When File storeDir = testDir.absolutePath(); GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDir ); // Then try ( Transaction ignore = db.beginTx() ) { assertEquals( 0, count( db.getAllNodes() ) ); assertEquals( 0, count( db.getAllRelationships() ) ); assertEquals( 0, count( db.getAllRelationshipTypes() ) ); assertEquals( 0, count( db.getAllLabels() ) ); assertEquals( 0, count( db.getAllPropertyKeys() ) ); } db.shutdown(); } }