aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-08-03 15:02:55 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-09-07 08:33:31 +0200
commit019d17348791cccaa65c8709070d58f73e11c8db (patch)
treebdc4385e32325198a74055f942e00c0750320f0b
parente992c54eda36632088c2da41174f703a49282c35 (diff)
downloadsonarqube-019d17348791cccaa65c8709070d58f73e11c8db.tar.gz
sonarqube-019d17348791cccaa65c8709070d58f73e11c8db.zip
Improve test isolation
When some assertions fail, components are not stopped, and that lead to failures in other tests.
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java95
1 files changed, 51 insertions, 44 deletions
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
index 130b892622b..0215ca1c134 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
@@ -96,13 +96,16 @@ public class ComputeEngineContainerImplTest {
underTest
.start(new Props(properties));
- MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
- assertThat(
- picoContainer.getComponentAdapters().stream()
- .map(ComponentAdapter::getComponentImplementation)
- .collect(Collectors.toList())).contains((Class) HazelcastClientWrapperImpl.class,
- (Class) CeDistributedInformationImpl.class);
- underTest.stop();
+ try {
+ MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
+ assertThat(
+ picoContainer.getComponentAdapters().stream()
+ .map(ComponentAdapter::getComponentImplementation)
+ .collect(Collectors.toList())).contains((Class) HazelcastClientWrapperImpl.class,
+ (Class) CeDistributedInformationImpl.class);
+ } finally {
+ underTest.stop();
+ }
}
@Test
@@ -116,44 +119,48 @@ public class ComputeEngineContainerImplTest {
underTest
.start(new Props(properties));
MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
- assertThat(picoContainer.getComponentAdapters())
- .hasSize(
+
+ try {
+ assertThat(picoContainer.getComponentAdapters())
+ .hasSize(
+ CONTAINER_ITSELF
+ + 72 // level 4
+ + 4 // content of CeConfigurationModule
+ + 4 // content of CeQueueModule
+ + 4 // content of CeHttpModule
+ + 3 // content of CeTaskCommonsModule
+ + 4 // content of ProjectAnalysisTaskModule
+ + 5 // content of CeTaskProcessorModule
+ + 3 // CeCleaningModule + its content
+ + 1 // CeDistributedInformation
+ );
+ assertThat(picoContainer.getParent().getComponentAdapters()).hasSize(
+ CONTAINER_ITSELF
+ + 5 // level 3
+ );
+ assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
CONTAINER_ITSELF
- + 72 // level 4
- + 4 // content of CeConfigurationModule
- + 4 // content of CeQueueModule
- + 4 // content of CeHttpModule
- + 3 // content of CeTaskCommonsModule
- + 4 // content of ProjectAnalysisTaskModule
- + 5 // content of CeTaskProcessorModule
- + 3 // CeCleaningModule + its content
- + 1 // CeDistributedInformation
- );
- assertThat(picoContainer.getParent().getComponentAdapters()).hasSize(
- CONTAINER_ITSELF
- + 5 // level 3
- );
- assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
- CONTAINER_ITSELF
- + 12 // MigrationConfigurationModule
- + 17 // level 2
- );
- assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
- COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION
- + 25 // level 1
- + 47 // content of DaoModule
- + 3 // content of EsSearchModule
- + 61 // content of CorePropertyDefinitions
- + 1 // StopFlagContainer
- );
- assertThat(
- picoContainer.getComponentAdapters().stream()
- .map(ComponentAdapter::getComponentImplementation)
- .collect(Collectors.toList())).doesNotContain((Class) HazelcastClientWrapperImpl.class,
- (Class) CeDistributedInformationImpl.class).contains(
- (Class) StandaloneCeDistributedInformation.class);
- assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull();
- underTest.stop();
+ + 12 // MigrationConfigurationModule
+ + 17 // level 2
+ );
+ assertThat(picoContainer.getParent().getParent().getParent().getComponentAdapters()).hasSize(
+ COMPONENTS_IN_LEVEL_1_AT_CONSTRUCTION
+ + 25 // level 1
+ + 47 // content of DaoModule
+ + 3 // content of EsSearchModule
+ + 61 // content of CorePropertyDefinitions
+ + 1 // StopFlagContainer
+ );
+ assertThat(
+ picoContainer.getComponentAdapters().stream()
+ .map(ComponentAdapter::getComponentImplementation)
+ .collect(Collectors.toList())).doesNotContain((Class) HazelcastClientWrapperImpl.class,
+ (Class) CeDistributedInformationImpl.class).contains(
+ (Class) StandaloneCeDistributedInformation.class);
+ assertThat(picoContainer.getParent().getParent().getParent().getParent()).isNull();
+ } finally {
+ underTest.stop();
+ }
assertThat(picoContainer.getLifecycleState().isStarted()).isFalse();
assertThat(picoContainer.getLifecycleState().isStopped()).isFalse();