diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-06-12 23:19:37 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-06-14 20:20:53 +0200 |
commit | b1bb97f72137393ee3ff96252869e848fbc65786 (patch) | |
tree | 1dd43992d1684ae69e3df9f69f4401c293f9dc7a /server | |
parent | 414fe2a8042189263c5d1d29adabff5076c600fc (diff) | |
download | sonarqube-b1bb97f72137393ee3ff96252869e848fbc65786.tar.gz sonarqube-b1bb97f72137393ee3ff96252869e848fbc65786.zip |
SONARCLOUD-75 Replace Stream by List in MigrationSteps
Diffstat (limited to 'server')
9 files changed, 47 insertions, 45 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationSteps.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationSteps.java index 1a06372cf93..8d80905cc0f 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationSteps.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationSteps.java @@ -19,7 +19,7 @@ */ package org.sonar.server.platform.db.migration.step; -import java.util.stream.Stream; +import java.util.List; public interface MigrationSteps { /** @@ -30,10 +30,10 @@ public interface MigrationSteps { /** * Reads all migration steps in order of increasing migration number. */ - Stream<RegisteredMigrationStep> readAll(); + List<RegisteredMigrationStep> readAll(); /** * Reads migration steps, in order of increasing migration number, from the specified migration number <strong>included</strong>. */ - Stream<RegisteredMigrationStep> readFrom(long migrationNumber); + List<RegisteredMigrationStep> readFrom(long migrationNumber); } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutor.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutor.java index 5dc9ea424b4..8d4d6d80df3 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutor.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutor.java @@ -19,7 +19,7 @@ */ package org.sonar.server.platform.db.migration.step; -import java.util.stream.Stream; +import java.util.List; /** * Responsible for: @@ -34,5 +34,5 @@ public interface MigrationStepsExecutor { /** * @throws MigrationStepExecutionException at the first failing migration step execution */ - void execute(Stream<RegisteredMigrationStep> steps); + void execute(List<RegisteredMigrationStep> steps); } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImpl.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImpl.java index d702d5dcbcb..ba98a13cc8f 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImpl.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImpl.java @@ -19,7 +19,7 @@ */ package org.sonar.server.platform.db.migration.step; -import java.util.stream.Stream; +import java.util.List; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.core.util.logs.Profiler; @@ -44,12 +44,12 @@ public class MigrationStepsExecutorImpl implements MigrationStepsExecutor { } @Override - public void execute(Stream<RegisteredMigrationStep> steps) { + public void execute(List<RegisteredMigrationStep> steps) { Profiler globalProfiler = Profiler.create(LOGGER); globalProfiler.startInfo(GLOBAL_START_MESSAGE); boolean allStepsExecuted = false; try { - steps.forEachOrdered(this::execute); + steps.forEach(this::execute); allStepsExecuted = true; } finally { if (allStepsExecuted) { diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsImpl.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsImpl.java index 5c934b19403..c375b57ad73 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsImpl.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsImpl.java @@ -19,8 +19,8 @@ */ package org.sonar.server.platform.db.migration.step; +import java.util.Collections; import java.util.List; -import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.ImmutableList.copyOf; @@ -42,18 +42,18 @@ class MigrationStepsImpl implements MigrationSteps { } @Override - public Stream<RegisteredMigrationStep> readAll() { - return steps.stream(); + public List<RegisteredMigrationStep> readAll() { + return steps; } @Override - public Stream<RegisteredMigrationStep> readFrom(long migrationNumber) { + public List<RegisteredMigrationStep> readFrom(long migrationNumber) { validate(migrationNumber); int startingIndex = lookupIndexOfClosestTo(migrationNumber); if (startingIndex < 0) { - return Stream.empty(); + return Collections.emptyList(); } - return steps.subList(startingIndex, steps.size()).stream(); + return steps.subList(startingIndex, steps.size()); } private int lookupIndexOfClosestTo(long startingPoint) { diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImplTest.java index ef3a754f009..c5aea1c7fcb 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImplTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImplTest.java @@ -31,6 +31,8 @@ import org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl; import org.sonar.server.platform.db.migration.step.RegisteredMigrationStep; import org.sonar.server.platform.db.migration.version.DbVersion; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -61,7 +63,7 @@ public class MigrationContainerPopulatorImplTest { return Stream.of(Clazz1.class, Clazz3.class); } }); - when(migrationSteps.readAll()).thenReturn(Stream.empty()); + when(migrationSteps.readAll()).thenReturn(emptyList()); underTest.populateContainer(migrationContainer); @@ -72,7 +74,7 @@ public class MigrationContainerPopulatorImplTest { @Test public void populateContainer_adds_MigrationStepsExecutorImpl() { - when(migrationSteps.readAll()).thenReturn(Stream.empty()); + when(migrationSteps.readAll()).thenReturn(emptyList()); // add MigrationStepsExecutorImpl's dependencies migrationContainer.add(mock(MigrationHistory.class)); @@ -84,7 +86,7 @@ public class MigrationContainerPopulatorImplTest { @Test public void populateContainer_adds_classes_of_all_steps_defined_in_MigrationSteps() { - when(migrationSteps.readAll()).thenReturn(Stream.of( + when(migrationSteps.readAll()).thenReturn(asList( new RegisteredMigrationStep(1, "foo", MigrationStep1.class), new RegisteredMigrationStep(2, "bar", MigrationStep2.class), new RegisteredMigrationStep(3, "dor", MigrationStep3.class))); @@ -98,7 +100,7 @@ public class MigrationContainerPopulatorImplTest { @Test public void populateCotnainer_does_not_fail_if_same_class_is_used_for_more_than_one_migration() { - when(migrationSteps.readAll()).thenReturn(Stream.of( + when(migrationSteps.readAll()).thenReturn(asList( new RegisteredMigrationStep(1, "foo", MigrationStep1.class), new RegisteredMigrationStep(2, "bar", MigrationStep2.class), new RegisteredMigrationStep(3, "bar2", MigrationStep2.class), diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationEngineImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationEngineImplTest.java index d412a9dd293..9b82616da45 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationEngineImplTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationEngineImplTest.java @@ -19,9 +19,10 @@ */ package org.sonar.server.platform.db.migration.engine; +import java.util.List; import java.util.Optional; -import java.util.stream.Stream; import org.junit.Test; +import org.sonar.api.config.Configuration; import org.sonar.core.platform.ComponentContainer; import org.sonar.server.platform.db.migration.history.MigrationHistory; import org.sonar.server.platform.db.migration.step.MigrationStep; @@ -29,6 +30,7 @@ import org.sonar.server.platform.db.migration.step.MigrationSteps; import org.sonar.server.platform.db.migration.step.MigrationStepsExecutor; import org.sonar.server.platform.db.migration.step.RegisteredMigrationStep; +import static java.util.Collections.singletonList; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -45,12 +47,13 @@ public class MigrationEngineImplTest { }; private MigrationSteps migrationSteps = mock(MigrationSteps.class); - private MigrationEngineImpl underTest = new MigrationEngineImpl(migrationHistory, serverContainer, populator, migrationSteps); + private Configuration configuration; + private MigrationEngineImpl underTest = new MigrationEngineImpl(migrationHistory, serverContainer, populator, migrationSteps, configuration); @Test public void execute_execute_all_steps_of_there_is_no_last_migration_number() { when(migrationHistory.getLastMigrationNumber()).thenReturn(Optional.empty()); - Stream<RegisteredMigrationStep> steps = Stream.of(new RegisteredMigrationStep(1, "doo", MigrationStep.class)); + List<RegisteredMigrationStep> steps = singletonList(new RegisteredMigrationStep(1, "doo", MigrationStep.class)); when(migrationSteps.readAll()).thenReturn(steps); underTest.execute(); @@ -62,7 +65,7 @@ public class MigrationEngineImplTest { @Test public void execute_execute_steps_from_last_migration_number_plus_1() { when(migrationHistory.getLastMigrationNumber()).thenReturn(Optional.of(50L)); - Stream<RegisteredMigrationStep> steps = Stream.of(new RegisteredMigrationStep(1, "doo", MigrationStep.class)); + List<RegisteredMigrationStep> steps = singletonList(new RegisteredMigrationStep(1, "doo", MigrationStep.class)); when(migrationSteps.readFrom(51)).thenReturn(steps); underTest.execute(); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepRegistryImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepRegistryImplTest.java index 9cdebd2a4e3..4c57241e841 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepRegistryImplTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepRegistryImplTest.java @@ -22,7 +22,6 @@ package org.sonar.server.platform.db.migration.step; import java.sql.SQLException; import java.util.List; import java.util.Random; -import java.util.stream.Collectors; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -94,7 +93,7 @@ public class MigrationStepRegistryImplTest { MigrationSteps migrationSteps = underTest.build(); assertThat(migrationSteps).isInstanceOf(MigrationStepsImpl.class); - List<RegisteredMigrationStep> registeredMigrationSteps = migrationSteps.readAll().collect(Collectors.toList()); + List<RegisteredMigrationStep> registeredMigrationSteps = migrationSteps.readAll(); assertThat(registeredMigrationSteps).hasSize(4); verify(registeredMigrationSteps.get(0), 2, "aaaa", MigrationStep4.class); verify(registeredMigrationSteps.get(1), 5, "aazsa", MigrationStep1.class); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java index 2a548be4118..7eb3a99d25f 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java @@ -22,9 +22,9 @@ package org.sonar.server.platform.db.migration.step; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.stream.Stream; import org.junit.Rule; import org.junit.Test; import org.sonar.api.utils.log.LogTester; @@ -34,6 +34,7 @@ import org.sonar.server.platform.db.migration.engine.SimpleMigrationContainer; import org.sonar.server.platform.db.migration.history.MigrationHistory; import static com.google.common.base.Preconditions.checkState; +import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; @@ -48,7 +49,7 @@ public class MigrationStepsExecutorImplTest { @Test public void execute_does_not_fail_when_stream_is_empty_and_log_start_stop_INFO() { - underTest.execute(Stream.empty()); + underTest.execute(Collections.emptyList()); assertThat(logTester.logs()).hasSize(2); assertLogLevel(LoggerLevel.INFO, "Executing DB migrations...", "Executed DB migrations: success | time="); @@ -56,7 +57,7 @@ public class MigrationStepsExecutorImplTest { @Test public void execute_fails_with_ISE_if_no_instance_of_computation_step_exist_in_container() { - Stream<RegisteredMigrationStep> steps = Stream.of(registeredStepOf(1, MigrationStep1.class)); + List<RegisteredMigrationStep> steps = asList(registeredStepOf(1, MigrationStep1.class)); try { underTest.execute(steps); @@ -87,7 +88,7 @@ public class MigrationStepsExecutorImplTest { public void execute_execute_the_instance_of_type_specified_in_step_in_stream_order() { migrationContainer.add(MigrationStep1.class, MigrationStep2.class, MigrationStep3.class); - underTest.execute(Stream.of( + underTest.execute(asList( registeredStepOf(1, MigrationStep2.class), registeredStepOf(2, MigrationStep1.class), registeredStepOf(3, MigrationStep3.class))); @@ -113,7 +114,7 @@ public class MigrationStepsExecutorImplTest { @Test public void execute_throws_MigrationStepExecutionException_on_first_failing_step_execution_throws_SQLException() { migrationContainer.add(MigrationStep2.class, SqlExceptionFailingMigrationStep.class, MigrationStep3.class); - Stream<RegisteredMigrationStep> steps = Stream.of( + List<RegisteredMigrationStep> steps = asList( registeredStepOf(1, MigrationStep2.class), registeredStepOf(2, SqlExceptionFailingMigrationStep.class), registeredStepOf(3, MigrationStep3.class)); @@ -141,7 +142,7 @@ public class MigrationStepsExecutorImplTest { public void execute_throws_MigrationStepExecutionException_on_first_failing_step_execution_throws_any_exception() { migrationContainer.add(MigrationStep2.class, RuntimeExceptionFailingMigrationStep.class, MigrationStep3.class); - Stream<RegisteredMigrationStep> steps = Stream.of( + List<RegisteredMigrationStep> steps = asList( registeredStepOf(1, MigrationStep2.class), registeredStepOf(2, RuntimeExceptionFailingMigrationStep.class), registeredStepOf(3, MigrationStep3.class)); diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsImplTest.java index 487f3ec44e8..4511fc80ac7 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsImplTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsImplTest.java @@ -23,8 +23,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -78,7 +76,7 @@ public class MigrationStepsImplTest { @Test public void readAll_iterates_over_all_steps_in_constructor_list_argument() { - verifySteamContainsNumbers(underTest.readAll(), 1L, 2L, 8L); + verifyContainsNumbers(underTest.readAll(), 1L, 2L, 8L); } @Test @@ -91,24 +89,23 @@ public class MigrationStepsImplTest { @Test public void readFrom_returns_stream_of_sublist_from_the_first_migration_with_number_greater_or_equal_to_argument() { - verifySteamContainsNumbers(underTest.readFrom(1), 1L, 2L, 8L); - verifySteamContainsNumbers(underTest.readFrom(2), 2L, 8L); - verifySteamContainsNumbers(underTest.readFrom(3), 8L); - verifySteamContainsNumbers(underTest.readFrom(4), 8L); - verifySteamContainsNumbers(underTest.readFrom(5), 8L); - verifySteamContainsNumbers(underTest.readFrom(6), 8L); - verifySteamContainsNumbers(underTest.readFrom(7), 8L); - verifySteamContainsNumbers(underTest.readFrom(8), 8L); + verifyContainsNumbers(underTest.readFrom(1), 1L, 2L, 8L); + verifyContainsNumbers(underTest.readFrom(2), 2L, 8L); + verifyContainsNumbers(underTest.readFrom(3), 8L); + verifyContainsNumbers(underTest.readFrom(4), 8L); + verifyContainsNumbers(underTest.readFrom(5), 8L); + verifyContainsNumbers(underTest.readFrom(6), 8L); + verifyContainsNumbers(underTest.readFrom(7), 8L); + verifyContainsNumbers(underTest.readFrom(8), 8L); } @Test public void readFrom_returns_an_empty_stream_if_argument_is_greater_than_biggest_migration_number() { - verifySteamContainsNumbers(underTest.readFrom(9)); - verifySteamContainsNumbers(unorderedSteps.readFrom(9)); + verifyContainsNumbers(underTest.readFrom(9)); + verifyContainsNumbers(unorderedSteps.readFrom(9)); } - private static void verifySteamContainsNumbers(Stream<RegisteredMigrationStep> stream, Long... expectedMigrationNumbers) { - List<RegisteredMigrationStep> steps = stream.collect(Collectors.toList()); + private static void verifyContainsNumbers(List<RegisteredMigrationStep> steps, Long... expectedMigrationNumbers) { assertThat(steps).hasSize(expectedMigrationNumbers.length); Iterator<RegisteredMigrationStep> iterator = steps.iterator(); Arrays.stream(expectedMigrationNumbers).forEach(expected -> assertThat(iterator.next().getMigrationNumber()).isEqualTo(expected)); |