protected void prepareSampleDatabase( String version, FileSystemAbstraction fileSystem, DatabaseLayout databaseLayout, File databaseDirectory ) throws IOException { MigrationTestUtils.prepareSampleLegacyDatabase( version, fileSystem, databaseLayout.databaseDirectory(), databaseDirectory ); }
@Test public void shouldUpgradeAutomaticallyOnDatabaseStartup() throws ConsistencyCheckIncompleteException { // when GraphDatabaseService database = createGraphDatabaseService(); database.shutdown(); // then assertTrue( "Some store files did not have the correct version", checkNeoStoreHasDefaultFormatVersion( check, workingDatabaseLayout ) ); assertConsistentStore( workingDatabaseLayout ); }
static File findFormatStoreDirectoryForVersion( String version, File targetDir ) throws IOException { if ( StandardV2_3.STORE_VERSION.equals( version ) ) { return find23FormatStoreDirectory( targetDir ); } else if ( StandardV3_0.STORE_VERSION.equals( version ) ) { return find30FormatStoreDirectory( targetDir ); } else { throw new IllegalArgumentException( "Unknown version" ); } }
throws IOException, ConsistencyCheckIncompleteException MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, workingDatabaseLayout.databaseDirectory(), prepareDirectory ); PageCache pageCache = pageCacheRule.getPageCache( fs ); StoreVersionCheck check = new StoreVersionCheck( pageCache ); assertTrue( checkNeoStoreHasDefaultFormatVersion( check, workingDatabaseLayout ) ); .migrateIfNeeded( workingDatabaseLayout ); assertTrue( checkNeoStoreHasDefaultFormatVersion( check, workingDatabaseLayout ) );
@Test public void shouldRefuseToUpgradeIfAnyOfTheStoresWereNotShutDownCleanly() throws IOException { File comparisonDirectory = directory.directory( "shouldRefuseToUpgradeIfAnyOfTheStoresWereNotShutDownCleanly-comparison" ); removeCheckPointFromTxLog( fileSystem, databaseLayout.databaseDirectory() ); fileSystem.deleteRecursively( comparisonDirectory ); fileSystem.copyRecursively( databaseLayout.databaseDirectory(), comparisonDirectory ); PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache ); try { newUpgrader( upgradableDatabase, pageCache ).migrateIfNeeded( databaseLayout ); fail( "Should throw exception" ); } catch ( StoreUpgrader.UnableToUpgradeException e ) { // expected } verifyFilesHaveSameContent( fileSystem, comparisonDirectory, databaseLayout.databaseDirectory() ); }
@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 ) ); } }
public static void prepareSampleLegacyDatabase( String version, FileSystemAbstraction workingFs, File workingDirectory, File prepareDirectory ) throws IOException { if ( !prepareDirectory.exists() ) { throw new IllegalArgumentException( "bad prepare directory" ); } File resourceDirectory = findFormatStoreDirectoryForVersion( version, prepareDirectory ); workingFs.deleteRecursively( workingDirectory ); workingFs.mkdirs( workingDirectory ); workingFs.copyRecursively( resourceDirectory, workingDirectory ); }
throws IOException, ConsistencyCheckIncompleteException MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, workingDatabaseLayout.databaseDirectory(), prepareDirectory ); PageCache pageCache = pageCacheRule.getPageCache( fs ); StoreVersionCheck check = new StoreVersionCheck( pageCache ); newUpgrader( upgradableDatabase, pageCache, progressMonitor, indexMigrator, migrator ).migrateIfNeeded( workingDatabaseLayout ); assertTrue( checkNeoStoreHasDefaultFormatVersion( check, workingDatabaseLayout ) );
@Test public void shouldRefuseToUpgradeIfAllOfTheStoresWereNotShutDownCleanly() throws IOException { File comparisonDirectory = directory.directory( "shouldRefuseToUpgradeIfAllOfTheStoresWereNotShutDownCleanly-comparison" ); removeCheckPointFromTxLog( fileSystem, databaseLayout.databaseDirectory() ); fileSystem.deleteRecursively( comparisonDirectory ); fileSystem.copyRecursively( databaseLayout.databaseDirectory(), comparisonDirectory ); PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache ); try { newUpgrader( upgradableDatabase, pageCache ).migrateIfNeeded( databaseLayout ); fail( "Should throw exception" ); } catch ( StoreUpgrader.UnableToUpgradeException e ) { // expected } verifyFilesHaveSameContent( fileSystem, comparisonDirectory, databaseLayout.databaseDirectory() ); }
@Before public void setup() throws IOException { fileSystem = fileSystemRule.get(); PageCache pageCache = pageCacheRule.getPageCache( fileSystem ); workingStoreDir = testDir.storeDir( "working_" + version ); workingDatabaseLayout = testDir.databaseLayout( workingStoreDir ); check = new StoreVersionCheck( pageCache ); File prepareDirectory = testDir.directory( "prepare_" + version ); prepareSampleLegacyDatabase( version, fileSystem, workingDatabaseLayout.databaseDirectory(), prepareDirectory ); }
@Test public void shouldComputeTheLastTxInfoCorrectly() throws Exception { // given DatabaseLayout databaseLayout = directory.databaseLayout(); File prepare = directory.directory( "prepare" ); MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, databaseLayout.databaseDirectory(), prepare ); // and a state of the migration saying that it has done the actual migration LogService logService = NullLogService.getInstance(); PageCache pageCache = pageCacheRule.getPageCache( fs ); LogTailScanner tailScanner = getTailScanner( databaseLayout.databaseDirectory() ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache, tailScanner ); String versionToMigrateFrom = upgradableDatabase.checkUpgradable( databaseLayout ).storeVersion(); SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); DatabaseLayout migrationLayout = directory.databaseLayout( StoreUpgrader.MIGRATION_DIRECTORY ); // when migrator.migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); // then assertTrue( txIdComparator.apply( migrator.readLastTxInformation( migrationLayout ) ) ); }
@Test public void shouldComputeTheLastTxLogPositionCorrectly() throws Throwable { // GIVEN a legacy database DatabaseLayout databaseLayout = directory.databaseLayout(); File prepare = directory.directory( "prepare" ); MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, databaseLayout.databaseDirectory(), prepare ); // and a state of the migration saying that it has done the actual migration LogService logService = NullLogService.getInstance(); PageCache pageCache = pageCacheRule.getPageCache( fs ); LogTailScanner tailScanner = getTailScanner( databaseLayout.databaseDirectory() ); UpgradableDatabase upgradableDatabase = getUpgradableDatabase( pageCache, tailScanner ); String versionToMigrateFrom = upgradableDatabase.checkUpgradable( databaseLayout ).storeVersion(); SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor(); StoreMigrator migrator = new StoreMigrator( fs, pageCache, CONFIG, logService, jobScheduler ); DatabaseLayout migrationLayout = directory.databaseLayout( StoreUpgrader.MIGRATION_DIRECTORY ); // WHEN migrating migrator.migrate( databaseLayout, migrationLayout, progressMonitor.startSection( "section" ), versionToMigrateFrom, upgradableDatabase.currentVersion() ); // THEN it should compute the correct last tx log position assertEquals( expectedLogPosition, migrator.readLastTxLogPosition( migrationLayout ) ); }
MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, databaseLayout.databaseDirectory(), prepare );
MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, databaseLayout.databaseDirectory(), prepare );
MigrationTestUtils.prepareSampleLegacyDatabase( version, fs, databaseLayout.databaseDirectory(), prepare );