public static ServerStartupException translateToServerStartupError( Throwable cause ) { Throwable rootCause = Exceptions.rootCause( cause ); if ( rootCause instanceof UpgradeNotAllowedException ) { return new UpgradeDisallowedStartupException( (UpgradeNotAllowedException) rootCause ); } return new ServerStartupException( format( "Starting Neo4j failed: %s", cause.getMessage() ), cause ); } }
private void verifyAcquisitionFailure( Future<Boolean> lockAcquisition ) throws InterruptedException { try { lockAcquisition.get(); fail("Lock acquisition should fail."); } catch ( ExecutionException e ) { assertThat( Exceptions.rootCause( e ), instanceOf( LockAcquisitionTimeoutException.class ) ); } } }
@Test void shouldThrowAppropriateExceptionIfStartFails() { RuntimeException startupError = new RuntimeException(); GraphDatabaseFacadeFactory db = newFaultyGraphDatabaseFacadeFactory( startupError ); RuntimeException startException = assertThrows( RuntimeException.class, () -> db.initFacade( testDirectory.storeDir(), Collections.emptyMap(), deps, mockFacade ) ); assertEquals( startupError, Exceptions.rootCause( startException ) ); }
@Test public void mustNotLeakTasksOnCrash() { // Given String exceptionMessage = "When there's no more room in hell, the dead will walk the earth"; CrashGenerationCleaner cleaner = newCrashingCrashGenerationCleaner( exceptionMessage ); ExecutorService executorService = Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors() ); try { // When cleaner.clean( executorService ); fail( "Expected to throw" ); } catch ( Throwable e ) { Throwable rootCause = Exceptions.rootCause( e ); assertTrue( rootCause instanceof IOException ); assertEquals( exceptionMessage, rootCause.getMessage() ); } finally { // Then List<Runnable> tasks = executorService.shutdownNow(); assertEquals( 0, tasks.size() ); } }
private static Exception executeFailingTransaction( RecordStorageEngine engine ) throws IOException { Exception applicationError = new UnderlyingStorageException( "No space left on device" ); TransactionToApply txToApply = newTransactionThatFailsWith( applicationError ); try { engine.apply( txToApply, TransactionApplicationMode.INTERNAL ); fail( "Exception expected" ); } catch ( Exception e ) { assertSame( applicationError, Exceptions.rootCause( e ) ); } return applicationError; }
@Test public void shouldAbortOnNonCleanlyShutdown() throws Throwable { // given removeCheckPointFromTxLog( fileSystem, workingDatabaseLayout.databaseDirectory() ); try { // when GraphDatabaseService database = createGraphDatabaseService(); database.shutdown();// shutdown db in case test fails fail( "Should have been unable to start upgrade on old version" ); } catch ( RuntimeException e ) { // then assertThat( Exceptions.rootCause( e ), Matchers.instanceOf( StoreUpgrader.UnableToUpgradeException.class ) ); } }
@Test public void panicOnExceptionDuringCommandsApply() { IllegalStateException failure = new IllegalStateException( "Too many open files" ); RecordStorageEngine engine = storageEngineRule.getWith( fsRule.get(), pageCacheRule.getPageCache( fsRule.get() ), testDirectory.databaseLayout() ) .databaseHealth( databaseHealth ) .transactionApplierTransformer( facade -> transactionApplierFacadeTransformer( facade, failure ) ) .build(); CommandsToApply commandsToApply = mock( CommandsToApply.class ); try { engine.apply( commandsToApply, TransactionApplicationMode.INTERNAL ); fail( "Exception expected" ); } catch ( Exception exception ) { assertSame( failure, Exceptions.rootCause( exception ) ); } verify( databaseHealth ).panic( any( Throwable.class ) ); }
@Test void latestRecordNotMigratedWhenFormatBumped() { GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_2.NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); node.setProperty( "a", "b" ); transaction.success(); } database.shutdown(); Throwable exception = assertThrows( Throwable.class, () -> startDatabaseWithFormatUnspecifiedUpgrade( storeDir, Standard.LATEST_NAME ) ); assertSame( UpgradeNotAllowedByConfigurationException.class, Exceptions.rootCause( exception ).getClass() ); }
@Test void failToDowngradeFormatWhenUpgradeNotAllowed() { GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_4.NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); node.setProperty( "a", "b" ); transaction.success(); } database.shutdown(); Throwable throwable = assertThrows( Throwable.class, () -> startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_2.NAME ) ); assertSame( UpgradeNotAllowedByConfigurationException.class, Exceptions.rootCause( throwable ).getClass() ); }
@Test void failToOpenStoreWithDatePropertyUsingOldFormat() { File storeDir = testDirectory.storeDir(); GraphDatabaseService database = startDatabaseWithFormat( storeDir, StandardV3_4.NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); node.setProperty( "a", DateValue.date( 1991, 5, 3 ) ); transaction.success(); } database.shutdown(); Throwable throwable = assertThrows( Throwable.class, () -> startDatabaseWithFormat( storeDir, StandardV3_2.NAME ) ); assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( throwable ).getClass() ); } }
@Test void failToOpenStoreWithPointPropertyUsingOldFormat() { File storeDir = testDirectory.storeDir(); GraphDatabaseService database = startDatabaseWithFormat( storeDir, StandardV3_4.NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); node.setProperty( "a", pointValue( Cartesian, 1.0, 2.0 ) ); transaction.success(); } database.shutdown(); Throwable throwable = assertThrows( Throwable.class, () -> startDatabaseWithFormat( storeDir, StandardV3_2.NAME ) ); assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( throwable ).getClass() ); } }
@Test void failToDowngradeFormatWheUpgradeAllowed() { GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_4.NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); node.setProperty( "a", "b" ); transaction.success(); } database.shutdown(); Throwable throwable = assertThrows( Throwable.class, () -> new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ) .setConfig( record_format, StandardV3_2.NAME ) .setConfig( allow_upgrade, Settings.TRUE ).newGraphDatabase() ); assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( throwable ).getClass() ); }
@Test void failToCreatePointArrayOnOldDatabase() { File storeDir = testDirectory.storeDir(); GraphDatabaseService nonUpgradedStore = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME ); PointValue point = pointValue( Cartesian, 1.0, 2.0 ); TransactionFailureException exception = assertThrows( TransactionFailureException.class, () -> { try ( Transaction transaction = nonUpgradedStore.beginTx() ) { Node node = nonUpgradedStore.createNode(); node.setProperty( "a", new PointValue[]{point, point} ); transaction.success(); } } ); assertEquals( "Current record format does not support POINT_PROPERTIES. Please upgrade your store to the format that support requested capability.", Exceptions.rootCause( exception ).getMessage() ); nonUpgradedStore.shutdown(); GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME ); try ( Transaction transaction = restartedOldFormatDatabase.beginTx() ) { Node node = restartedOldFormatDatabase.createNode(); node.setProperty( "c", "d" ); transaction.success(); } restartedOldFormatDatabase.shutdown(); }
@Test void failToCreatePointOnOldDatabase() { File storeDir = testDirectory.storeDir(); GraphDatabaseService nonUpgradedStore = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME ); TransactionFailureException exception = assertThrows( TransactionFailureException.class, () -> { try ( Transaction transaction = nonUpgradedStore.beginTx() ) { Node node = nonUpgradedStore.createNode(); node.setProperty( "a", pointValue( Cartesian, 1.0, 2.0 ) ); transaction.success(); } } ); assertEquals( "Current record format does not support POINT_PROPERTIES. Please upgrade your store to the format that support requested capability.", Exceptions.rootCause( exception ).getMessage() ); nonUpgradedStore.shutdown(); GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME ); try ( Transaction transaction = restartedOldFormatDatabase.beginTx() ) { Node node = restartedOldFormatDatabase.createNode(); node.setProperty( "c", "d" ); transaction.success(); } restartedOldFormatDatabase.shutdown(); }
@Test void failToCreateDateOnOldDatabase() { File storeDir = testDirectory.storeDir(); GraphDatabaseService nonUpgradedStore = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME ); TransactionFailureException failureException = assertThrows( TransactionFailureException.class, () -> { try ( Transaction transaction = nonUpgradedStore.beginTx() ) { Node node = nonUpgradedStore.createNode(); node.setProperty( "a", DateValue.date( 1991, 5, 3 ).asObjectCopy() ); transaction.success(); } } ); assertEquals( "Current record format does not support TEMPORAL_PROPERTIES. Please upgrade your store to the format that support requested capability.", Exceptions.rootCause( failureException ).getMessage() ); nonUpgradedStore.shutdown(); GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME ); try ( Transaction transaction = restartedOldFormatDatabase.beginTx() ) { Node node = restartedOldFormatDatabase.createNode(); node.setProperty( "c", "d" ); transaction.success(); } restartedOldFormatDatabase.shutdown(); }
@Test void failToCreateDateArrayOnOldDatabase() { File storeDir = testDirectory.storeDir(); GraphDatabaseService nonUpgradedStore = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME ); LocalDate date = DateValue.date( 1991, 5, 3 ).asObjectCopy(); TransactionFailureException failureException = assertThrows( TransactionFailureException.class, () -> { try ( Transaction transaction = nonUpgradedStore.beginTx() ) { Node node = nonUpgradedStore.createNode(); node.setProperty( "a", new LocalDate[]{date, date} ); transaction.success(); } } ); assertEquals( "Current record format does not support TEMPORAL_PROPERTIES. Please upgrade your store " + "to the format that support requested capability.", Exceptions.rootCause( failureException ).getMessage() ); nonUpgradedStore.shutdown(); GraphDatabaseService restartedOldFormatDatabase = startNonUpgradableDatabaseWithFormat( storeDir, StandardV3_2.NAME ); try ( Transaction transaction = restartedOldFormatDatabase.beginTx() ) { Node node = restartedOldFormatDatabase.createNode(); node.setProperty( "c", "d" ); transaction.success(); } restartedOldFormatDatabase.shutdown(); }
Throwable root = Exceptions.rootCause( e ); if ( root instanceof IndexEntryConflictException )
public static ServerStartupException translateToServerStartupError( Throwable cause ) { Throwable rootCause = Exceptions.rootCause( cause ); if ( rootCause instanceof UpgradeNotAllowedException ) { return new UpgradeDisallowedStartupException( (UpgradeNotAllowedException) rootCause ); } return new ServerStartupException( format( "Starting Neo4j failed: %s", cause.getMessage() ), cause ); } }
if ( rootCause( e ) instanceof UpgradeNotAllowedByConfigurationException )