Search in sources :

Example 1 with MigrationSteps

use of org.sonar.server.platform.db.migration.step.MigrationSteps in project sonarqube by SonarSource.

the class SQDatabase method executeDbMigrations.

private void executeDbMigrations(NoopDatabase noopDatabase) {
    SpringComponentContainer container = new SpringComponentContainer();
    container.add(noopDatabase);
    MigrationConfigurationModule migrationConfigurationModule = new MigrationConfigurationModule();
    migrationConfigurationModule.configure(container);
    // dependencies required by DB migrations
    container.add(SonarRuntimeImpl.forSonarQube(Version.create(8, 0), SonarQubeSide.SERVER, SonarEdition.COMMUNITY));
    container.add(UuidFactoryFast.getInstance());
    container.add(System2.INSTANCE);
    container.add(MapSettings.class);
    container.startComponents();
    MigrationContainer migrationContainer = new MigrationContainerImpl(container, H2StepExecutor.class);
    MigrationSteps migrationSteps = migrationContainer.getComponentByType(MigrationSteps.class);
    MigrationStepsExecutor executor = migrationContainer.getComponentByType(MigrationStepsExecutor.class);
    executor.execute(migrationSteps.readAll());
}
Also used : SpringComponentContainer(org.sonar.core.platform.SpringComponentContainer) MigrationContainer(org.sonar.server.platform.db.migration.engine.MigrationContainer) MigrationConfigurationModule(org.sonar.server.platform.db.migration.MigrationConfigurationModule) MigrationStepsExecutor(org.sonar.server.platform.db.migration.step.MigrationStepsExecutor) MigrationContainerImpl(org.sonar.server.platform.db.migration.engine.MigrationContainerImpl) MigrationSteps(org.sonar.server.platform.db.migration.step.MigrationSteps)

Example 2 with MigrationSteps

use of org.sonar.server.platform.db.migration.step.MigrationSteps in project sonarqube by SonarSource.

the class MigrationHistoryMeddlerTest method verifyUpdateLastMigrationNumber.

public void verifyUpdateLastMigrationNumber(long oldVersion, long expectedNewVersion) {
    when(migrationHistory.getLastMigrationNumber()).thenReturn(Optional.of(oldVersion));
    List<RegisteredMigrationStep> stepsFromNewLastMigrationNumber = IntStream.range(0, 1 + new Random().nextInt(30)).mapToObj(i -> new RegisteredMigrationStep(i, "desc_" + i, MigrationStep.class)).collect(Collectors.toList());
    when(migrationSteps.readFrom(expectedNewVersion)).thenReturn(stepsFromNewLastMigrationNumber);
    underTest.meddle(migrationHistory);
    verify(migrationHistory).getLastMigrationNumber();
    verify(migrationSteps).readFrom(expectedNewVersion);
    verify(migrationHistory).done(stepsFromNewLastMigrationNumber.get(0));
    verifyNoMoreInteractions(migrationHistory, migrationSteps);
}
Also used : IntStream(java.util.stream.IntStream) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) RunWith(org.junit.runner.RunWith) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Optional(java.util.Optional) MigrationSteps(org.sonar.server.platform.db.migration.step.MigrationSteps) RegisteredMigrationStep(org.sonar.server.platform.db.migration.step.RegisteredMigrationStep) MigrationStep(org.sonar.server.platform.db.migration.step.MigrationStep) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) RegisteredMigrationStep(org.sonar.server.platform.db.migration.step.RegisteredMigrationStep)

Example 3 with MigrationSteps

use of org.sonar.server.platform.db.migration.step.MigrationSteps in project sonarqube by SonarSource.

the class MigrationContainerPopulatorImpl method populateFromMigrationSteps.

private static void populateFromMigrationSteps(MigrationContainer container) {
    MigrationSteps migrationSteps = container.getComponentByType(MigrationSteps.class);
    Set<Class<? extends MigrationStep>> classes = new HashSet<>();
    migrationSteps.readAll().forEach(step -> {
        Class<? extends MigrationStep> stepClass = step.getStepClass();
        if (!classes.contains(stepClass)) {
            container.add(stepClass);
            classes.add(stepClass);
        }
    });
}
Also used : MigrationStep(org.sonar.server.platform.db.migration.step.MigrationStep) MigrationSteps(org.sonar.server.platform.db.migration.step.MigrationSteps) HashSet(java.util.HashSet)

Aggregations

MigrationSteps (org.sonar.server.platform.db.migration.step.MigrationSteps)3 MigrationStep (org.sonar.server.platform.db.migration.step.MigrationStep)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 Mockito.when (org.mockito.Mockito.when)1 SpringComponentContainer (org.sonar.core.platform.SpringComponentContainer)1 MigrationConfigurationModule (org.sonar.server.platform.db.migration.MigrationConfigurationModule)1 MigrationContainer (org.sonar.server.platform.db.migration.engine.MigrationContainer)1