Search in sources :

Example 1 with StoreMigrationParticipant

use of org.neo4j.kernel.impl.storemigration.StoreMigrationParticipant in project neo4j by neo4j.

the class StoreUpgraderTest method shouldContinueMovingFilesIfUpgradeCancelledWhileMoving.

@Test
public void shouldContinueMovingFilesIfUpgradeCancelledWhileMoving() throws Exception {
    PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
    UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fileSystem, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fileSystem), getRecordFormats());
    String versionToMigrateTo = upgradableDatabase.currentVersion();
    String versionToMigrateFrom = upgradableDatabase.checkUpgradeable(dbDirectory).storeVersion();
    // GIVEN
    {
        StoreUpgrader upgrader = newUpgrader(upgradableDatabase, allowMigrateConfig, pageCache);
        String failureMessage = "Just failing";
        upgrader.addParticipant(participantThatWillFailWhenMoving(failureMessage));
        // WHEN
        try {
            upgrader.migrateIfNeeded(dbDirectory);
            fail("should have thrown");
        } catch (UnableToUpgradeException e) {
            // THEN
            assertTrue(e.getCause() instanceof IOException);
            assertEquals(failureMessage, e.getCause().getMessage());
        }
    }
    // AND WHEN
    {
        StoreUpgrader upgrader = newUpgrader(upgradableDatabase, pageCache);
        StoreMigrationParticipant observingParticipant = Mockito.mock(StoreMigrationParticipant.class);
        upgrader.addParticipant(observingParticipant);
        upgrader.migrateIfNeeded(dbDirectory);
        // THEN
        verify(observingParticipant, Mockito.times(0)).migrate(any(File.class), any(File.class), any(MigrationProgressMonitor.Section.class), eq(versionToMigrateFrom), eq(versionToMigrateTo));
        verify(observingParticipant, Mockito.times(1)).moveMigratedFiles(any(File.class), any(File.class), eq(versionToMigrateFrom), eq(versionToMigrateTo));
        verify(observingParticipant, Mockito.times(1)).cleanup(any(File.class));
    }
}
Also used : StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) UnableToUpgradeException(org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnableToUpgradeException) SilentMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor) MigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor) StoreMigrationParticipant(org.neo4j.kernel.impl.storemigration.StoreMigrationParticipant) AbstractStoreMigrationParticipant(org.neo4j.kernel.impl.storemigration.participant.AbstractStoreMigrationParticipant) UpgradableDatabase(org.neo4j.kernel.impl.storemigration.UpgradableDatabase) Matchers.containsString(org.hamcrest.Matchers.containsString) StoreUpgrader(org.neo4j.kernel.impl.storemigration.StoreUpgrader) IOException(java.io.IOException) LegacyStoreVersionCheck(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 PageCache (org.neo4j.io.pagecache.PageCache)1 StoreMigrationParticipant (org.neo4j.kernel.impl.storemigration.StoreMigrationParticipant)1 StoreUpgrader (org.neo4j.kernel.impl.storemigration.StoreUpgrader)1 UnableToUpgradeException (org.neo4j.kernel.impl.storemigration.StoreUpgrader.UnableToUpgradeException)1 StoreVersionCheck (org.neo4j.kernel.impl.storemigration.StoreVersionCheck)1 UpgradableDatabase (org.neo4j.kernel.impl.storemigration.UpgradableDatabase)1 LegacyStoreVersionCheck (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStoreVersionCheck)1 MigrationProgressMonitor (org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor)1 SilentMigrationProgressMonitor (org.neo4j.kernel.impl.storemigration.monitoring.SilentMigrationProgressMonitor)1 AbstractStoreMigrationParticipant (org.neo4j.kernel.impl.storemigration.participant.AbstractStoreMigrationParticipant)1