]> source.dussan.org Git - sonarqube.git/commitdiff
Refactor usage of EsTester
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 24 May 2016 20:36:34 +0000 (22:36 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 24 May 2016 21:12:58 +0000 (23:12 +0200)
 This JUnit ExternalResource has to be used
 as @Rule but not @ClassRule in order to
 prepare move to Elasticsearch 2.x.

63 files changed:
server/sonar-server/src/test/java/org/sonar/server/activity/ActivityServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/activity/index/ActivityResultSetIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/UsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchViewComponentsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/component/SettingsRepositoryTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/ScmAccountToUserLoaderTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/metric/MetricRepositoryImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ApplyPermissionsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistIssuesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/es/BulkIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/es/EsTester.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyBulkRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyCountRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyDeleteByQueryRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyFlushRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyGetRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyIndexRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyIndicesExistsRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyIndicesStatsRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyMultiGetRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyPutMappingRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyRefreshRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxySearchRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxySearchScrollRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueAuthorizationIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/search/FacetsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java

index aaed63dc7959b5ee9bff706c76ea719168388cc9..9904058376c39afcddf2615e33b97b4aec2e9dd0 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.Map;
 import org.assertj.core.data.MapEntry;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -45,8 +44,8 @@ public class ActivityServiceTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new ActivityIndexDefinition(new Settings()));
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone().login();
index ecbbe0d452e1df5d85275705526e36bd5a9aed58..484b073b85dd0903c79a8a0532065498b337ef8c 100644 (file)
 package org.sonar.server.activity.index;
 
 import com.google.common.collect.ImmutableMap;
+import java.util.Arrays;
+import java.util.Date;
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.server.activity.Activity;
@@ -29,15 +31,12 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 
-import java.util.Arrays;
-import java.util.Date;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class ActivityIndexTest {
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new ActivityIndexDefinition(new Settings()));
 
   ActivityIndex underTest;
 
index 6a49a0b1af58b703092d71323c053dc658ce23a1..ee56231d38957fb05b58737873806261112e99d6 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.activity.index;
 import java.util.Map;
 import org.assertj.core.data.MapEntry;
 import org.elasticsearch.action.update.UpdateRequest;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.DateUtils;
@@ -37,11 +36,6 @@ public class ActivityResultSetIteratorTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   /**
    * Iterate over two rows in table.
    */
index 944b683955b995de9ca54bdbacff301692b18451..3b957fddc2f86632331babf982b8f0d37643f9f7 100644 (file)
@@ -23,7 +23,6 @@ import java.io.ByteArrayInputStream;
 import java.util.Arrays;
 import javax.annotation.Nullable;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -71,8 +70,8 @@ public class IssuesActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new IssueIndexDefinition(new Settings()));
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
@@ -87,9 +86,6 @@ public class IssuesActionTest {
 
   @Before
   public void before() {
-    db.truncateTables();
-    es.truncateIndices();
-
     issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSessionRule);
     issueIndexer = new IssueIndexer(null, es.client());
     issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, es.client());
index 85577bd524597f1b41ca114a61f555bafd2795d2..f877b0e9d69238423835c75b690e6fdd8dacfbd4 100644 (file)
@@ -23,7 +23,6 @@ import java.io.ByteArrayInputStream;
 import java.util.Arrays;
 import java.util.List;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -46,8 +45,8 @@ public class UsersActionTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
@@ -60,11 +59,8 @@ public class UsersActionTest {
 
   @Before
   public void before() {
-    es.truncateIndices();
-
     userIndex = new UserIndex(es.client());
     usersAction = new UsersAction(userIndex, userSessionRule);
-
     tester = new WsTester(new BatchWs(new BatchIndex(mock(Server.class)), usersAction));
   }
 
index 054af12960be17300c40c617a257b9eed36c3a8f..054cd0c1b5969b9a0b84100cbce21606779cd4b4 100644 (file)
@@ -75,7 +75,6 @@ public class ComponentServiceTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
     when(i18n.message(Locale.getDefault(), "qualifier.TRK", "Project")).thenReturn("Project");
     service = new ComponentService(dbClient, i18n, userSessionRule, System2.INSTANCE, new ComponentFinder(dbClient));
   }
index 19081b3c6989fd5e1471a279ba9badf6a9cc6688..f24c5e7e16ee5d0d21e601cb53d8f76e91d1a2d6 100644 (file)
@@ -50,7 +50,6 @@ public class SearchViewComponentsActionTest {
 
   @Before
   public void setUp() {
-    db.truncateTables();
     ws = new WsTester(new ComponentsWs(mock(AppAction.class), new SearchViewComponentsAction(db.getDbClient(), userSessionRule, new ComponentFinder(db.getDbClient()))));
   }
 
index a51fe7a8e68f12c243779a2f2160b0767139dca1..74a4130788e4c8f2de7cff937548fd9a918579dc 100644 (file)
@@ -55,7 +55,6 @@ public class SettingsRepositoryTest {
 
   @Before
   public void createDao() {
-    dbTester.truncateTables();
     globalSettings = new Settings();
     PropertiesDao propertiesDao = new PropertiesDao(dbTester.myBatis());
     session = dbClient.openSession(false);
index 596de5ef38cd43deda4e4e0f031cbe088545ef94..4127332a2e7725163044a672ecb6272234b1bc38 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.computation.issue;
 
 import java.util.Collections;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.log.LogTester;
@@ -37,16 +35,11 @@ import static org.junit.Assert.fail;
 
 public class ScmAccountToUserLoaderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @org.junit.Rule
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new Settings()));
 
-  @ClassRule
-  public static LogTester logTester = new LogTester();
-
-  @Before
-  public void setUp() {
-    esTester.truncateIndices();
-  }
+  @org.junit.Rule
+  public LogTester logTester = new LogTester();
 
   @Test
   public void load_login_for_scm_account() throws Exception {
index 5ddc98e7621f2fc26f15c0fffcb2d63a004ecc79..51686da4df777c69d663f6649b94792f35010d4b 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.computation.metric;
 
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -42,11 +41,6 @@ public class MetricRepositoryImplTest {
   private DbClient dbClient = dbTester.getDbClient();
   private MetricRepositoryImpl underTest = new MetricRepositoryImpl(dbClient);
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-  }
-
   @Test(expected = NullPointerException.class)
   public void getByKey_throws_NPE_if_arg_is_null() {
     underTest.getByKey(null);
index bdd0e090e05bbd76abd362101142e6a7ca4f6002..112e46168f1e0488499565b60e46e51dec21f4f6 100644 (file)
@@ -24,7 +24,6 @@ import java.util.Map;
 import org.elasticsearch.search.SearchHit;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -61,8 +60,8 @@ public class ApplyPermissionsStepTest extends BaseStepTest {
   private static final String ROOT_UUID = "ROOT_UUID";
   private static final long SOME_DATE = 1000L;
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -77,7 +76,7 @@ public class ApplyPermissionsStepTest extends BaseStepTest {
 
   DbClient dbClient = dbTester.getDbClient();
 
-  Settings settings;
+  Settings settings = new Settings();
 
   IssueAuthorizationIndexer issueAuthorizationIndexer;
 
@@ -86,8 +85,6 @@ public class ApplyPermissionsStepTest extends BaseStepTest {
   @Before
   public void setUp() {
     dbSession = dbClient.openSession(false);
-    settings = new Settings();
-    esTester.truncateIndices();
 
     issueAuthorizationIndexer = new IssueAuthorizationIndexer(dbClient, esTester.client());
     issueAuthorizationIndexer.setEnabled(true);
index fc1566dc6645bac73c4652fa1473073eb24cccee..c4595916cb28bc31e764f471461f49c9a2c52e73 100644 (file)
@@ -21,8 +21,6 @@ package org.sonar.server.computation.step;
 
 import java.util.List;
 import org.elasticsearch.search.SearchHit;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -45,19 +43,14 @@ public class IndexTestsStepTest extends BaseStepTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new TestIndexDefinition(new Settings()));
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
 
   DbClient dbClient = dbTester.getDbClient();
 
-  @Before
-  public void setUp() {
-    esTester.truncateIndices();
-  }
-
   @Override
   protected ComputationStep step() {
     TestIndexer testIndexer = new TestIndexer(dbClient, esTester.client());
index 9303a915f21049d25f4e8c7600fd26eca96d9f3f..ab745ff41b5adab014c81f473ae559bba06f121d 100644 (file)
@@ -85,7 +85,6 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
 
   @Before
   public void setup() {
-    dbTester.truncateTables();
     when(system2.now()).thenReturn(NOW);
     underTest = new PersistFileSourcesStep(dbClient, system2, treeRootHolder, reportReader, fileSourceRepository, scmInfoRepository, duplicationRepository);
   }
index 4266a76e38de786c5b56757467f89a3db3e9acf8..6a2aca06c0f01312cf13ff4e6b68de23f8928dfe 100644 (file)
@@ -80,7 +80,6 @@ public class PersistIssuesStepTest extends BaseStepTest {
 
   @Before
   public void setup() throws Exception {
-    dbTester.truncateTables();
     issueCache = new IssueCache(temp.newFile(), System2.INSTANCE);
     system2 = mock(System2.class);
     when(system2.now()).thenReturn(NOW);
index 3616ff99dd3182c44f139331b2e9c4c5420defaf..0f7f087fe5adf77693525971dc07f911472ae7b5 100644 (file)
@@ -34,12 +34,10 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class BulkIndexerTest {
 
   @Rule
-  public EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition().setReplicas(1));
+  public EsTester esTester = new EsTester(new FakeIndexDefinition().setReplicas(1));
 
   @Test
   public void index_nothing() {
-    esTester.truncateIndices();
-
     BulkIndexer indexer = new BulkIndexer(esTester.client(), FakeIndexDefinition.INDEX);
     indexer.start();
     indexer.stop();
index 5961d334abe8dc99e0cdbc4313423ec296ced978..83285e45cea98e1b06358d489676ed4541e5be1b 100644 (file)
@@ -24,7 +24,9 @@ import com.google.common.base.Throwables;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.Iterables;
-import java.util.Collections;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.Nonnull;
@@ -49,58 +51,30 @@ import org.junit.rules.ExternalResource;
 import org.sonar.api.config.Settings;
 import org.sonar.core.platform.ComponentContainer;
 
+import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
 
 public class EsTester extends ExternalResource {
 
-  private static final int INSTANCE_ID = RandomUtils.nextInt();
-  private Node node;
-  private EsClient client;
-  private final List<IndexDefinition> definitions = newArrayList();
+  private final List<IndexDefinition> indexDefinitions;
+  private EsClient client = new EsClient(new Settings(), NodeHolder.INSTANCE.node.client());
+  private ComponentContainer container;
 
-  public EsTester addDefinitions(IndexDefinition... defs) {
-    Collections.addAll(definitions, defs);
-    return this;
+  public EsTester(IndexDefinition... defs) {
+    this.indexDefinitions = asList(defs);
   }
 
+  @Override
   protected void before() throws Throwable {
-    String nodeName = "tmp-es-" + INSTANCE_ID;
-    node = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder()
-      .put("cluster.name", nodeName)
-      .put("node.name", nodeName)
-      // the two following properties are probably not used because they are
-      // declared on indices too
-      .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
-      .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
-      // limit the number of threads created (see org.elasticsearch.common.util.concurrent.EsExecutors)
-      .put("processors", 1)
-      .put("http.enabled", false)
-      .put("config.ignore_system_properties", true)
-      // reuse the same directory than other tests for faster initialization
-      .put("path.home", "target/" + nodeName)
-      .put("gateway.type", "none"))
-      .build();
-    node.start();
-    assertThat(DiscoveryNode.localNode(node.settings())).isTrue();
-
-    // wait for node to be ready
-    node.client().admin().cluster().prepareHealth()
-      .setWaitForGreenStatus()
-      .get();
-
-    // delete the indices created by previous tests
-    DeleteIndexResponse response = node.client().admin().indices().prepareDelete("_all").get();
-    assertThat(response.isAcknowledged()).isTrue();
-
-    client = new EsClient(new Settings(), node.client());
     client.start();
+    truncateIndices();
 
-    if (!definitions.isEmpty()) {
-      ComponentContainer container = new ComponentContainer();
+    if (!indexDefinitions.isEmpty()) {
+      container = new ComponentContainer();
       container.addSingleton(new Settings());
-      container.addSingletons(definitions);
+      container.addSingletons(indexDefinitions);
       container.addSingleton(client);
       container.addSingleton(IndexDefinitions.class);
       container.addSingleton(IndexCreator.class);
@@ -110,20 +84,16 @@ public class EsTester extends ExternalResource {
 
   @Override
   protected void after() {
+    if (container != null) {
+      container.stopComponents();
+    }
     if (client != null) {
       client.stop();
     }
-    if (node != null) {
-      node.stop();
-      node.close();
-    }
   }
 
-  public void truncateIndices() {
-    String[] indices = client.prepareState().get().getState().getMetaData().concreteAllIndices();
-    for (String index : indices) {
-      BulkIndexer.delete(client, index, client().prepareSearch(index).setQuery(matchAllQuery()));
-    }
+  private void truncateIndices() {
+    client.nativeClient().admin().indices().prepareDelete("_all").get();
   }
 
   public void putDocuments(String index, String type, BaseDoc... docs) throws Exception {
@@ -141,7 +111,7 @@ public class EsTester extends ExternalResource {
   }
 
   public long countDocuments(String indexName, String typeName) {
-    return client().prepareCount(indexName).setTypes(typeName).get().getCount();
+    return client().prepareSearch(indexName).setTypes(typeName).setSize(0).get().getHits().totalHits();
   }
 
   /**
@@ -200,10 +170,6 @@ public class EsTester extends ExternalResource {
     return FluentIterable.from(getDocuments(indexName, typeName)).transform(SearchHitToId.INSTANCE).toList();
   }
 
-  public Node node() {
-    return node;
-  }
-
   public EsClient client() {
     return client;
   }
@@ -217,4 +183,43 @@ public class EsTester extends ExternalResource {
     }
   }
 
+  private static class NodeHolder {
+    private static final NodeHolder INSTANCE = new NodeHolder();
+
+    private final Node node;
+
+    private NodeHolder() {
+      try {
+        String nodeName = "tmp-es-" + RandomUtils.nextInt();
+        Path tmpDir = Files.createTempDirectory("tmp-es");
+        tmpDir.toFile().deleteOnExit();
+
+        node = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder()
+          .put("cluster.name", nodeName)
+          .put("node.name", nodeName)
+          // the two following properties are probably not used because they are
+          // declared on indices too
+          .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
+          .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
+          // limit the number of threads created (see org.elasticsearch.common.util.concurrent.EsExecutors)
+          .put("processors", 1)
+          .put("http.enabled", false)
+          .put("config.ignore_system_properties", true)
+          .put("path.home", tmpDir))
+          .build();
+        node.start();
+        checkState(DiscoveryNode.localNode(node.settings()));
+        checkState(!node.isClosed());
+
+        // wait for node to be ready
+        node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get();
+
+        // delete the indices (should not exist)
+        DeleteIndexResponse response = node.client().admin().indices().prepareDelete("_all").get();
+        checkState(response.isAcknowledged());
+      } catch (IOException e) {
+        throw Throwables.propagate(e);
+      }
+    }
+  }
 }
index 5f958488d9872f20f91d7e71e4b9865559596892..cbde5ce9afcf77e143816d3fed6789cc36bfbab3 100644 (file)
@@ -25,7 +25,6 @@ import org.elasticsearch.action.delete.DeleteRequest;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -37,8 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class ProxyBulkRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -47,14 +46,14 @@ public class ProxyBulkRequestBuilderTest {
   public void no_trace_logs() {
     logTester.setLevel(LoggerLevel.INFO);
     testBulk();
-    assertThat(logTester.logs()).isEmpty();
+    assertThat(logTester.logs(LoggerLevel.TRACE)).isEmpty();
   }
 
   @Test
   public void trace_logs() {
     logTester.setLevel(LoggerLevel.TRACE);
     testBulk();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   private void testBulk() {
index 8bce58858e9ecff409fe9df541abc59d60170d3e..6017fde0059031206b018b46a7cdf7a6ece0dd3f 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -33,8 +32,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyCountRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -56,7 +55,7 @@ public class ProxyCountRequestBuilderTest {
     logTester.setLevel(LoggerLevel.TRACE);
 
     esTester.client().prepareCount(FakeIndexDefinition.INDEX).get();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index 5397467920495b4d556ee5a1cdc288ca84e3eb8d..a3f3a75f49de4f2061f06b98850b946cf356bf09 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.es.request;
 
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.index.query.QueryBuilders;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -34,8 +33,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyDeleteByQueryRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -58,7 +57,7 @@ public class ProxyDeleteByQueryRequestBuilderTest {
 
     esTester.client().prepareDeleteByQuery(FakeIndexDefinition.INDEX).setQuery(QueryBuilders.matchAllQuery()).get();
 
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index f8922b80ebd4a87c8809763f1c73d5f5aff176ac..91f946e3585c94a7b142a2bbe5301d937d8becbb 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -33,8 +32,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyFlushRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -55,7 +54,7 @@ public class ProxyFlushRequestBuilderTest {
     logTester.setLevel(LoggerLevel.TRACE);
 
     esTester.client().prepareFlush(FakeIndexDefinition.INDEX).get();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index c57fb5abec1c011ef4fa3b696320f614dd20a0cb..572f55519b9c4ebdaa9552b50a44bc156fbd3cc0 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.es.request;
 
 import org.elasticsearch.action.get.GetRequestBuilder;
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -34,8 +33,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyGetRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -58,7 +57,7 @@ public class ProxyGetRequestBuilderTest {
       .setType(FakeIndexDefinition.TYPE)
       .setId("ruleKey")
       .get();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index 2e29c37abc466d440074dfbd7245136ceccf55a1..1c88b72b0600728c2caacace3b71fc24a97b1c48 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.es.request;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.index.IndexResponse;
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -35,8 +34,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyIndexRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -56,7 +55,7 @@ public class ProxyIndexRequestBuilderTest {
       .setSource(FakeIndexDefinition.newDoc(42).getFields())
       .get();
     assertThat(response.isCreated()).isTrue();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index ed7342893d5c3710ba956c9bf67b20feae39f5cd..be342886725b868bb996e62e6214174511ddf2f2 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -33,8 +32,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyIndicesExistsRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -51,7 +50,7 @@ public class ProxyIndicesExistsRequestBuilderTest {
 
     esTester.client().prepareIndicesExist(FakeIndexDefinition.INDEX).get();
 
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index daf01f90f6213611c7ea1ea34c33d19e26836e77..ef54a5e2a27e7cd187076ff05ecf74846b4b6b37 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -33,8 +32,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyIndicesStatsRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -56,7 +55,7 @@ public class ProxyIndicesStatsRequestBuilderTest {
 
     esTester.client().prepareStats(FakeIndexDefinition.INDEX).get();
 
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index 69b0685b2238ee79137a53ed955846b5275be4cf..6ae12093aacbc60e973b6d833459d00dfc5d909e 100644 (file)
@@ -23,7 +23,6 @@ import org.elasticsearch.action.get.MultiGetRequest;
 import org.elasticsearch.action.get.MultiGetRequestBuilder;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.search.fetch.source.FetchSourceContext;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -36,8 +35,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyMultiGetRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -69,7 +68,7 @@ public class ProxyMultiGetRequestBuilderTest {
       .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
     request.get();
 
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index e51b4c90c1d6b5109fa5cee4d7ed51f30880b80b..4f686ccab3017c00e95c7ef10803e11af3c0b21c 100644 (file)
 package org.sonar.server.es.request;
 
 import com.google.common.collect.ImmutableMap;
+import java.util.HashMap;
+import java.util.Map;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -30,16 +31,13 @@ import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.FakeIndexDefinition;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 
 public class ProxyPutMappingRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -71,7 +69,7 @@ public class ProxyPutMappingRequestBuilderTest {
       .setSource(mapDomain());
     requestBuilder.get();
 
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index 98ce132801b8b18565af277d7bd17d3985d1e975..fba746723abd2be8e601f4fab2016ee30b76e51b 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.es.request;
 
 import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -34,8 +33,8 @@ import static org.junit.Assert.fail;
 
 public class ProxyRefreshRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -58,7 +57,7 @@ public class ProxyRefreshRequestBuilderTest {
 
     RefreshRequestBuilder requestBuilder = esTester.client().prepareRefresh(FakeIndexDefinition.INDEX);
     requestBuilder.get();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index cdb6aafebdc6121ff8ca039b4df7ea49e4ad6f72..b14be2ea80ce945877e6f38d519d6ec6454b7efe 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.es.request;
 
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -33,8 +32,8 @@ import static org.junit.Assert.fail;
 
 public class ProxySearchRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
@@ -57,7 +56,7 @@ public class ProxySearchRequestBuilderTest {
     logTester.setLevel(LoggerLevel.TRACE);
 
     esTester.client().prepareSearch(FakeIndexDefinition.INDEX).get();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
index 52e5275e91795dc0b283a1d107cf5124a5ef8155..82a37aa21d139aecd2f43e5cf22f9677f8efa37f 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.es.request;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.action.search.SearchType;
 import org.elasticsearch.common.unit.TimeValue;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
@@ -35,8 +34,8 @@ import static org.junit.Assert.fail;
 
 public class ProxySearchScrollRequestBuilderTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+  @Rule
+  public EsTester esTester = new EsTester(new FakeIndexDefinition());
 
   @Rule
   public LogTester logTester = new LogTester();
index 86a5c3645fd112427e305184ebcfb604380df34d..b5db7b389f0f500b3bc91f7327fc2084940106d4 100644 (file)
@@ -23,8 +23,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import org.elasticsearch.search.SearchHit;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -41,14 +39,8 @@ public class IssueAuthorizationIndexerTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
-
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-    esTester.truncateIndices();
-  }
+  @Rule
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
 
   @Test
   public void index_nothing() {
index 0adf6a29cb3ad25e9b82b4dcc944b9cd8594334a..72e023b37ec4dadb22c32994abde3cd1d0695885 100644 (file)
@@ -24,7 +24,6 @@ import java.util.Map;
 import java.util.TimeZone;
 import javax.annotation.Nullable;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -56,8 +55,9 @@ import static org.sonarqube.ws.client.issue.IssueFilterParameters.FACET_MODE_EFF
 
 public class IssueIndexDebtTest {
 
-  @ClassRule
-  public static EsTester tester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+  @Rule
+  public EsTester tester = new EsTester(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
@@ -69,14 +69,12 @@ public class IssueIndexDebtTest {
 
   @Before
   public void setUp() {
-    tester.truncateIndices();
     issueIndexer = new IssueIndexer(null, tester.client());
     issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, tester.client());
     viewIndexer = new ViewIndexer(null, tester.client());
     System2 system = mock(System2.class);
     when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("+01:00"));
     when(system.now()).thenReturn(System.currentTimeMillis());
-
     index = new IssueIndex(tester.client(), system, userSessionRule);
   }
 
index c27afc2ffe5f0c15b49405b0cdda7d0626b1706a..f395b8513ea4bdc685a29ea28d9b03000ac69d98 100644 (file)
@@ -30,7 +30,6 @@ import java.util.TimeZone;
 import javax.annotation.Nullable;
 import org.assertj.core.api.Fail;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -66,8 +65,9 @@ import static org.sonar.api.utils.DateUtils.parseDateTime;
 
 public class IssueIndexTest {
 
-  @ClassRule
-  public static EsTester tester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+  @Rule
+  public EsTester tester = new EsTester(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
@@ -79,7 +79,6 @@ public class IssueIndexTest {
 
   @Before
   public void setUp() {
-    tester.truncateIndices();
     issueIndexer = new IssueIndexer(null, tester.client());
     issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, tester.client());
     viewIndexer = new ViewIndexer(null, tester.client());
index 81e46971b41c4255adf4f670b384cf7d24977871..e656d554a672d9307fa47c1080125fc0fe42c6fc 100644 (file)
@@ -26,8 +26,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import javax.annotation.Nonnull;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -44,16 +42,11 @@ import static org.sonar.server.issue.IssueTesting.newDoc;
 
 public class IssueIndexerTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-    esTester.truncateIndices();
-  }
+  @Rule
+  public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
   @Test
   public void index_nothing() {
index 977e85895ae81ea2c5ee243fd6bec00743c8b674..a53bc8b8b3d9012b361668f8791a7827429c8b5b 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 import org.assertj.core.data.Offset;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -78,8 +77,8 @@ public class CreateActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
 
   DbClient dbClient = db.getDbClient();
 
@@ -91,7 +90,6 @@ public class CreateActionTest {
   public void setUp() {
     ws = new WsTester(new CustomMeasuresWs(new CreateAction(dbClient, userSession, System2.INSTANCE, new CustomMeasureValidator(newFullTypeValidations()),
       new CustomMeasureJsonWriter(new UserJsonWriter(userSession)), new ComponentFinder(dbClient))));
-    db.truncateTables();
     userSession.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
 
     db.getDbClient().userDao().insert(dbSession, new UserDto()
index be70459b8e95c11de28e629bda63320328e9f768..338f0efa3fd677afd5677fcc434eb81e3b0f6557 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.measure.custom.ws;
 
 import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -56,8 +54,8 @@ public class MetricsActionTest {
   private static final String DEFAULT_PROJECT_UUID = "project-uuid";
   private static final String DEFAULT_PROJECT_KEY = "project-key";
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
@@ -70,17 +68,13 @@ public class MetricsActionTest {
   WsTester ws;
   ComponentDto defaultProject;
 
-  @BeforeClass
-  public static void setUpClass() throws Exception {
+  @Before
+  public void setUp() throws Exception {
     es.putDocuments(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, new UserDoc()
       .setLogin("login")
       .setName("Login")
       .setEmail("login@login.com")
       .setActive(true));
-  }
-
-  @Before
-  public void setUp() {
     ws = new WsTester(new CustomMeasuresWs(new MetricsAction(dbClient, userSession, new ComponentFinder(dbClient))));
     userSession.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
     defaultProject = insertDefaultProject();
index 052d91d92df1a2bf9c4bd47e8d9fdf87543debfc..3fee4cdd97fff0a388901fe23e421a15e86a2c4c 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.measure.custom.ws;
 import java.util.Date;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -70,8 +69,8 @@ public class SearchActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
 
   WsTester ws;
   DbClient dbClient = db.getDbClient();
index be6c67d4f67ec68fe0523fb886d8c3309686f03d..f17dcbd5d4922e266a9dcac12a7e6e1945696770 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.measure.custom.ws;
 
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -64,10 +63,10 @@ public class UpdateActionTest {
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
   DbClient dbClient = db.getDbClient();
-  final DbSession dbSession = db.getSession();
+  DbSession dbSession = db.getSession();
   System2 system = mock(System2.class);
   WsTester ws;
 
index 174987fc7bf0b76b0a75034ecc470b7eb6364e88..3f3c79940ed0d029d380cbe615d9a0b61c8fa646 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.platform;
 
 import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -41,8 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class BackendCleanupMediumTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(
+  @Rule
+  public EsTester esTester = new EsTester(
     new RuleIndexDefinition(new Settings()),
     new IssueIndexDefinition(new Settings()),
     new ViewIndexDefinition(new Settings())
@@ -51,12 +49,7 @@ public class BackendCleanupMediumTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  BackendCleanup backendCleanup;
-
-  @Before
-  public void setUp() {
-    backendCleanup = new BackendCleanup(esTester.client(), dbTester.myBatis());
-  }
+  BackendCleanup backendCleanup = new BackendCleanup(esTester.client(), dbTester.myBatis());
 
   @Test
   public void clear_db() {
index 47ec8a303114c8024e89a17d40b899c87ac13d03..e02092137f6621eec699ecca1e317cc5752a0ff7 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.platform.monitoring;
 
 import java.util.Map;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.server.es.EsTester;
@@ -32,8 +32,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class EsMonitorTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()));
 
   EsMonitor underTest = new EsMonitor(esTester.client());
 
index eec29c730fe0e9bb975db344b728593a9ad2569b..d8b55783f85737c2ad6c55c8fa92e2b42bbf7974 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.project.ws;
 import com.google.common.collect.ImmutableMap;
 import java.util.Arrays;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -71,11 +70,12 @@ import static org.sonar.server.project.ws.BulkDeleteAction.PARAM_KEYS;
 public class BulkDeleteActionTest {
 
   private static final String ACTION = "bulk_delete";
+
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()),
+  @Rule
+  public EsTester es = new EsTester(new IssueIndexDefinition(new Settings()),
     new TestIndexDefinition(new Settings()));
 
   @Rule
@@ -104,8 +104,6 @@ public class BulkDeleteActionTest {
         dbClient,
         userSessionRule)));
     userSessionRule.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
-    db.truncateTables();
-    es.truncateIndices();
   }
 
   @Test
index 9642a3b5daf784fd3e9450c0b1735a872f6e7baa..8a073530bdd9497cc4ab8ad3133380d2db06ab29 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.project.ws;
 
 import com.google.common.collect.ImmutableMap;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -71,8 +70,9 @@ public class DeleteActionTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()),
+  @Rule
+  public EsTester es = new EsTester(
+    new IssueIndexDefinition(new Settings()),
     new TestIndexDefinition(new Settings()));
 
   @Rule
@@ -108,8 +108,6 @@ public class DeleteActionTest {
         dbClient,
         userSessionRule)));
     userSessionRule.login("login").setGlobalPermissions(UserRole.ADMIN);
-    db.truncateTables();
-    es.truncateIndices();
   }
 
   @Test
index a74b001aafe32266f92065cb11e17e6420269c85..d81d64044655fd3802a410e3bbe5bcd8406e9f24 100644 (file)
@@ -25,7 +25,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.api.rule.RuleKey;
@@ -52,23 +52,20 @@ import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
 
 public class ActiveRuleIndexTest {
 
-  static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
-  static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
+  private static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
+  private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
+  private static final String QUALITY_PROFILE_KEY1 = "qp1";
+  private static final String QUALITY_PROFILE_KEY2 = "qp2";
 
-  static final String QUALITY_PROFILE_KEY1 = "qp1";
-  static final String QUALITY_PROFILE_KEY2 = "qp2";
-
-  @ClassRule
-  public static EsTester tester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+  @Rule
+  public EsTester tester = new EsTester(new RuleIndexDefinition(new Settings()));
 
   ActiveRuleIndex index;
-
   ActiveRuleIndexer activeRuleIndexer;
   RuleIndexer ruleIndexer;
 
   @Before
   public void setUp() {
-    tester.truncateIndices();
     activeRuleIndexer = new ActiveRuleIndexer(null, tester.client());
     ruleIndexer = new RuleIndexer(null, tester.client());
     index = new ActiveRuleIndex(tester.client());
index 01c2f5ad0513f302a9983079f0a88527a9d7fa99..578b5778cac34960ec478a877a83472877491f91 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.qualityprofile.index;
 import com.google.common.collect.Iterators;
 import java.util.Arrays;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -58,8 +57,8 @@ public class ActiveRuleIndexerTest {
   static final String QUALITY_PROFILE_KEY1 = "qp1";
   static final String QUALITY_PROFILE_KEY2 = "qp2";
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new Settings()));
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -68,7 +67,6 @@ public class ActiveRuleIndexerTest {
 
   @Before
   public void setUp() {
-    esTester.truncateIndices();
     indexer = new ActiveRuleIndexer(dbTester.getDbClient(), esTester.client());
     indexer.setEnabled(true);
   }
index 57048a50f583565a88934cdc318286bb3d606a89..30893c9a2a46117cfa83ce8664a5841910704a94 100644 (file)
@@ -24,7 +24,6 @@ import java.util.Date;
 import java.util.Map;
 import org.joda.time.DateTime;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -61,8 +60,8 @@ public class ChangelogActionTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new ActivityIndexDefinition(new Settings()));
 
   private DbClient db = dbTester.getDbClient();
   private DbSession dbSession = dbTester.getSession();
@@ -71,11 +70,6 @@ public class ChangelogActionTest {
 
   @Before
   public void before() {
-    dbTester.truncateTables();
-    esTester.truncateIndices();
-
-    System2 system = mock(System2.class);
-
     // create pre-defined rules
     RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR");
     db.ruleDao().insert(dbSession, xooRule1);
index f67746d1018eafbc15a5a6ce20bbb742569a4f1b..a78379b87c138b94ec8b795be0b12adcff1b643c 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.rule;
 import java.util.Date;
 import java.util.List;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.api.resources.Language;
@@ -69,8 +68,8 @@ public class RegisterRulesTest {
   @org.junit.Rule
   public DbTester dbTester = DbTester.create(system);
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+  @org.junit.Rule
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new Settings()));
 
   RuleActivator ruleActivator = mock(RuleActivator.class);
 
@@ -83,7 +82,6 @@ public class RegisterRulesTest {
 
   @Before
   public void before() {
-    esTester.truncateIndices();
     when(system.now()).thenReturn(DATE1.getTime());
     ruleIndexer = new RuleIndexer(dbClient, esTester.client());
     ruleIndexer.setEnabled(true);
index 6aa48078555a555ff7d3e99d4ce892c8597692eb..e1ca4f008885f29b4997640a958ea008c1f17fe2 100644 (file)
@@ -43,7 +43,7 @@ public class RuleIndexDefinitionTest {
   RuleIndexDefinition underTest = new RuleIndexDefinition(settings);
 
   @Rule
-  public EsTester tester = new EsTester().addDefinitions(underTest);
+  public EsTester tester = new EsTester(underTest);
 
   @Test
   public void test_definition_of_index() {
index d63c14fe102440fd931525f2ab0a6144ece683c1..a60151de0fa54e84a0da68bddde1c4799f754b16 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.api.rule.RuleKey;
@@ -74,17 +74,15 @@ public class RuleIndexTest {
   static final String QUALITY_PROFILE_KEY1 = "qp1";
   static final String QUALITY_PROFILE_KEY2 = "qp2";
 
-  @ClassRule
-  public static EsTester tester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+  @Rule
+  public EsTester tester = new EsTester(new RuleIndexDefinition(new Settings()));
 
   RuleIndex index;
-
   RuleIndexer ruleIndexer;
   ActiveRuleIndexer activeRuleIndexer;
 
   @Before
   public void setUp() {
-    tester.truncateIndices();
     ruleIndexer = new RuleIndexer(null, tester.client());
     activeRuleIndexer = new ActiveRuleIndexer(null, tester.client());
     index = new RuleIndex(tester.client());
index b4b7bc1f3cfad1f21406860896a24517da3c5a82..a23f9c1e5e65d7c2a087bd560f97cfd9ddb494d9 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.rule.index;
 
 import com.google.common.collect.Iterators;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -41,8 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class RuleIndexerTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new Settings()));
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -68,11 +66,6 @@ public class RuleIndexerTest {
     .setCreatedAt(1500000000000L)
     .setUpdatedAt(1600000000000L);
 
-  @Before
-  public void setUp() {
-    esTester.truncateIndices();
-  }
-
   @Test
   public void index_nothing() {
     RuleIndexer indexer = createIndexer();
index d4b12a50a31d0b1c4faf40504e1fd80f63f8cc18..a4131becc04fb17d89dfa6950a3a09dafd61a237 100644 (file)
@@ -27,8 +27,7 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
 import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogram.Interval;
-import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.server.es.EsTester;
@@ -45,13 +44,8 @@ public class FacetsMediumTest {
   private static final String FIELD_TAGS = "tags";
   private static final String FIELD_CREATED_AT = "createdAt";
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new FacetsTestDefinition());
-
-  @Before
-  public void setUp() {
-    esTester.truncateIndices();
-  }
+  @Rule
+  public EsTester esTester = new EsTester(new FacetsTestDefinition());
 
   @Test
   public void should_ignore_result_without_aggregations() {
index cd31054a11fbaa5d3c4857043cf8cc24282becc4..fe866e201c14e6872d3e5332a63a2e8a815f29ab 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.startup;
 
 import javax.annotation.Nullable;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -54,8 +53,8 @@ public class ClearRulesOverloadedDebtTest {
   @Rule
   public DbTester tester = DbTester.create(system2);
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new RuleIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new RuleIndexDefinition(new Settings()));
 
   @Rule
   public LogTester logTester = new LogTester();
index 5dae3fda48fd56667b561fe3e995dfa05a30f16f..7d91e5e71c7c96a6c2ccec04aeacbcaa7f5b1b44 100644 (file)
@@ -22,8 +22,7 @@ package org.sonar.server.test.index;
 import com.google.common.base.Optional;
 import java.util.Arrays;
 import java.util.List;
-import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.server.es.EsTester;
@@ -33,16 +32,11 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.guava.api.Assertions.assertThat;
 
 public class TestIndexTest {
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new TestIndexDefinition(new Settings()));
 
   TestIndex underTest = new TestIndex(es.client());
 
-  @Before
-  public void setup() {
-    es.truncateIndices();
-  }
-
   @Test
   public void coveredFiles() throws Exception {
     es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
index cec9a7dac6536eb93445201d4121f881f439424d..ee3d15f35c45c42ff94db1632678e1ab2ab10a12 100644 (file)
@@ -31,7 +31,6 @@ import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.search.SearchHit;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -59,19 +58,16 @@ import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
 
 public class TestIndexerTest {
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new TestIndexDefinition(new Settings()));
 
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private TestIndexer underTest;
+  private TestIndexer underTest = new TestIndexer(db.getDbClient(), es.client());
 
   @Before
   public void setUp() {
-    es.truncateIndices();
-    db.truncateTables();
-    underTest = new TestIndexer(db.getDbClient(), es.client());
     underTest.setEnabled(true);
   }
 
index f015a432a6f0781dff3a4e30a1c5f6959e7af323..5c02d4830aaedf11e93cc7635d6e74c2e080433b 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.test.ws;
 import java.util.Arrays;
 import java.util.List;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -43,18 +42,20 @@ import org.sonar.server.test.index.TestIndexDefinition;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
-
 public class ListActionTest {
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new TestIndexDefinition(new Settings()));
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
+
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
+
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
+
   DbClient dbClient = db.getDbClient();
 
   TestIndex testIndex;
@@ -62,10 +63,7 @@ public class ListActionTest {
 
   @Before
   public void setUp() {
-    db.truncateTables();
-    es.truncateIndices();
     testIndex = new TestIndex(es.client());
-
     ws = new WsTester(new TestsWs(new ListAction(dbClient, testIndex, userSessionRule, new ComponentFinder(dbClient))));
   }
 
index e660fa494e3b61acbc1ef870c6d02acb28c57d6e..88968af76e9acbead7086a23cd124594ec8d28ad 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.base.Strings;
 import java.util.List;
 import org.elasticsearch.search.SearchHit;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -65,8 +64,8 @@ public class UserUpdaterTest {
 
   static final String DEFAULT_LOGIN = "marius";
 
-  @ClassRule
-  public static EsTester es = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @Rule
+  public EsTester es = new EsTester(new UserIndexDefinition(new Settings()));
 
   System2 system2 = mock(System2.class);
 
@@ -90,8 +89,6 @@ public class UserUpdaterTest {
 
   @Before
   public void setUp() {
-    es.truncateIndices();
-
     userIndexer = (UserIndexer) new UserIndexer(dbClient, es.client()).setEnabled(true);
     userUpdater = new UserUpdater(newUserNotifier, settings, dbClient,
       userIndexer, system2);
index 350774b3a039c4afe306fbde3c5d51156794b3c2..e6f708e3f551f6f7a55200618ed601840473ac98 100644 (file)
@@ -24,7 +24,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.server.es.EsTester;
@@ -42,14 +42,13 @@ public class UserIndexTest {
   private static final long DATE_1 = 1_500_000_000_000L;
   private static final long DATE_2 = 1_500_000_000_001L;
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new Settings()));
 
   private UserIndex index;
 
   @Before
   public void setUp() {
-    esTester.truncateIndices();
     index = new UserIndex(esTester.client());
   }
 
index 7747d073660a9e160d50bfc1b8fd3e031e8fa858..83130df526d5f5eace7db6be57c08a216a9cdf10 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.user.index;
 
 import java.util.List;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -32,20 +30,13 @@ import org.sonar.server.es.EsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-
 public class UserIndexerTest {
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
-
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-    esTester.truncateIndices();
-  }
+  @Rule
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new Settings()));
 
   @Test
   public void index_nothing() {
index 3af93c7c91f43dccfa63fe5910188e71a74d5474..6e5611fb4ee155b269f73e85caec83511bb5cf53 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.user.ws;
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -62,8 +61,8 @@ public class ChangePasswordActionTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
+  @Rule
+  public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone().login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
@@ -86,9 +85,6 @@ public class ChangePasswordActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
-    esTester.truncateIndices();
-
     System2 system2 = new System2();
     UserDao userDao = new UserDao(dbTester.myBatis(), system2);
     UserGroupDao userGroupDao = new UserGroupDao();
index 4ea9775c36a3e7080f6c4beade20405c5ebb5ac3..57b3a94197f711e5a6bfce7012fb4a7cb39a6771 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.user.ws;
 import java.util.Locale;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -55,13 +54,13 @@ import static org.mockito.Mockito.when;
 
 public class CreateActionTest {
 
-  static final Settings settings = new Settings().setProperty("sonar.defaultGroup", "sonar-users");
+  private static final Settings settings = new Settings().setProperty("sonar.defaultGroup", "sonar-users");
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
+  @Rule
+  public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
@@ -82,9 +81,6 @@ public class CreateActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
-    esTester.truncateIndices();
-
     System2 system2 = new System2();
     UserDao userDao = new UserDao(dbTester.myBatis(), system2);
     UserGroupDao userGroupDao = new UserGroupDao();
index a3cfd80c62f156bdf372f7977c24e02b6ce5ad40..37a743a25cca0509625698a9eb0256978c8c073b 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.user.ws;
 
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -57,8 +56,10 @@ public class DeactivateActionTest {
 
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
-  @ClassRule
-  public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
+
+  @Rule
+  public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
+
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
@@ -67,13 +68,10 @@ public class DeactivateActionTest {
   UserIndex index;
   DbClient dbClient;
   UserIndexer userIndexer;
-
   DbSession dbSession;
 
   @Before
   public void setUp() {
-    esTester.truncateIndices();
-
     System2 system2 = new System2();
     UserDao userDao = new UserDao(db.myBatis(), system2);
     dbClient = new DbClient(db.database(), db.myBatis(), userDao, new GroupMembershipDao(db.myBatis()), new UserTokenDao());
index ee48a84a72ece43b50670c1d5e2cbb359734aa48..bbd00030f9ccfeb4bbb60b27d0f0c398c1cf81c7 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.user.ws;
 import com.google.common.collect.Lists;
 import java.util.List;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -55,23 +54,25 @@ import static org.sonar.test.JsonAssert.assertJson;
 
 public class SearchActionTest {
 
-  @ClassRule
-  public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new UserIndexDefinition(new Settings()));
+
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
+
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
+
   UserDbTester userDb = new UserDbTester(db);
   GroupDbTester groupDb = new GroupDbTester(db);
   DbClient dbClient = db.getDbClient();
-  final DbSession dbSession = db.getSession();
+  DbSession dbSession = db.getSession();
 
   WsTester ws;
   UserIndex index;
 
   @Before
   public void setUp() {
-    esTester.truncateIndices();
     index = new UserIndex(esTester.client());
     ws = new WsTester(new UsersWs(new SearchAction(index, dbClient, new UserJsonWriter(userSession))));
   }
index 863f210fd73b1279bc9a097b46fcbbbe5d5243cb..26afff94651f8d6fc6f4ab3724104492da256102 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.user.ws;
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -55,8 +54,8 @@ public class UpdateActionTest {
 
   @Rule
   public DbTester dbTester = DbTester.create(system2);
-  @ClassRule
-  public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
+  @Rule
+  public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
   @Rule
   public final UserSessionRule userSessionRule = UserSessionRule.standalone().login("admin")
     .setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
@@ -73,9 +72,6 @@ public class UpdateActionTest {
 
   @Before
   public void setUp() {
-    dbTester.truncateTables();
-    esTester.truncateIndices();
-
     dbClient.groupDao().insert(session, new GroupDto().setName("sonar-users"));
     session.commit();
 
index e57623751559aff45cd5a7c21bf7eebc5e812c57..9d5683218809e57c0e34f3c4b8eed3d2a48eb657 100644 (file)
@@ -20,8 +20,7 @@
 package org.sonar.server.view.index;
 
 import java.util.List;
-import org.junit.Before;
-import org.junit.ClassRule;
+import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 import org.sonar.server.es.EsTester;
@@ -34,16 +33,10 @@ import static org.sonar.server.view.index.ViewIndexDefinition.TYPE_VIEW;
 
 public class ViewIndexTest {
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new ViewIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new ViewIndexDefinition(new Settings()));
 
-  private ViewIndex index;
-
-  @Before
-  public void setUp() {
-    esTester.truncateIndices();
-    index = new ViewIndex(esTester.client());
-  }
+  ViewIndex index = new ViewIndex(esTester.client());
 
   @Test
   public void find_all_view_uuids() throws Exception {
index 1427ed948928ed761f43b7dda937cb004e26730e..9a0adb7f83918a9f1f3b6949d2812ccc1b530a4c 100644 (file)
@@ -23,8 +23,6 @@ import com.google.common.base.Function;
 import com.google.common.collect.Maps;
 import java.util.List;
 import java.util.Map;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
@@ -60,8 +58,8 @@ public class ViewIndexerTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  @ClassRule
-  public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
+  @Rule
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new Settings()), new ViewIndexDefinition(new Settings()));
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
@@ -72,12 +70,6 @@ public class ViewIndexerTest {
 
   ViewIndexer indexer = (ViewIndexer) new ViewIndexer(dbClient, esTester.client()).setEnabled(true);
 
-  @Before
-  public void setUp() {
-    dbTester.truncateTables();
-    esTester.truncateIndices();
-  }
-
   @Test
   public void index_nothing() {
     indexer.index();