]> source.dussan.org Git - sonarqube.git/commitdiff
Added introspections to monitor Tests failures.
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 4 Aug 2014 14:16:37 +0000 (16:16 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 4 Aug 2014 15:19:22 +0000 (17:19 +0200)
server/sonar-server/src/main/java/org/sonar/server/search/ESNode.java
server/sonar-server/src/main/java/org/sonar/server/search/IndexQueue.java
server/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/activity/SearchMediumTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexMediumTest.java

index d10ccad680edb881c17cbb03447a9d923b720793..56b57009d28b71cc6656435baaae45b11b132472 100644 (file)
@@ -155,11 +155,30 @@ public class ESNode implements Startable {
       .put("cluster.name", "cluster-mem-" + NetworkUtils.getLocalAddress().getHostName())
       .put("index.store.type", "memory")
       .put("index.store.fs.memory.enabled", "true")
-      .put("gateway.type", "none")
+//      .put("gateway.type", "none")
       .put("index.number_of_shards", "1")
       .put("index.number_of_replicas", "0")
-      .put("cluster.routing.schedule", "50ms")
-      .put("node.local", true);
+//      .put("cluster.routing.schedule", "50ms")
+      .put("node.local", true)
+
+      .put("index.search.slowlog.threshold.query.warn", "10ms")
+        // Cannot use anything else but warn
+      .put("index.search.slowlog.threshold.query.info", "10ms")
+      .put("index.search.slowlog.threshold.query.debug", "10ms")
+      .put("index.search.slowlog.threshold.query.trace", "10ms")
+
+      .put("index.search.slowlog.threshold.fetch.warn", "10ms")
+        // Cannot use anything else but warn
+      .put("index.search.slowlog.threshold.fetch.info", "10ms")
+      .put("index.search.slowlog.threshold.fetch.debug", "10ms")
+      .put("index.search.slowlog.threshold.fetch.trace", "10ms")
+
+      .put("index.indexing.slowlog.threshold.index.warn", "10ms")
+        // Cannot use anything else but warn
+      .put("index.indexing.slowlog.threshold.index.info", "10ms")
+      .put("index.indexing.slowlog.threshold.index.debug", "10ms")
+      .put("index.indexing.slowlog.threshold.index.trace", "10ms");
+    ;
   }
 
   private void initDataES(ImmutableSettings.Builder builder) {
index edb234c5e55eed5f260270dfc0ddc21c18b7efb2..ebb7b07371a142ce782d37a4f6a4b1bad521bfa2 100644 (file)
@@ -46,7 +46,7 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
   private static final int TIMEOUT = 30000;
 
   public IndexQueue() {
-    super(DEFAULT_QUEUE_SIZE);
+    super(IndexQueue.DEFAULT_QUEUE_SIZE);
   }
 
   @Override
@@ -73,7 +73,7 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
       action.setLatch(latch);
       try {
         indexTime = System.currentTimeMillis();
-        this.offer(action, TIMEOUT, TimeUnit.SECONDS);
+        this.offer(action, TIMEOUT, TimeUnit.MILLISECONDS);
         if (!latch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
           throw new IllegalStateException("ES update could not be completed within: " + TIMEOUT + "ms");
         }
@@ -115,7 +115,7 @@ public class IndexQueue extends LinkedBlockingQueue<Runnable>
         indexTime = System.currentTimeMillis();
         for (IndexAction action : itemActions) {
           action.setLatch(itemLatch);
-          this.offer(action, TIMEOUT, TimeUnit.SECONDS);
+          this.offer(action, TIMEOUT, TimeUnit.MILLISECONDS);
           types.add(action.getPayloadClass().getSimpleName());
           bcount++;
 
index c20b68b8ddd9617accebb3dcb55b0b7ce6b9e954..18748f2295e42cef9a5c9040c5a448d6cac8ccff 100644 (file)
@@ -23,51 +23,38 @@ package org.sonar.server.activity;
 import com.google.common.collect.ImmutableMap;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.common.collect.Iterables;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Test;
 import org.sonar.core.activity.Activity;
 import org.sonar.core.activity.ActivityLog;
-import org.sonar.core.persistence.DbSession;
 import org.sonar.server.activity.db.ActivityDao;
 import org.sonar.server.activity.index.ActivityIndex;
 import org.sonar.server.activity.index.ActivityQuery;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.search.QueryOptions;
 import org.sonar.server.search.Result;
-import org.sonar.server.tester.ServerTester;
 
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
 import java.util.Iterator;
 import java.util.Map;
 
 import static org.fest.assertions.Assertions.assertThat;
 
-public class ActivityBackendMediumTest {
+public class ActivityBackendMediumTest extends SearchMediumTest {
 
-  @ClassRule
-  public static ServerTester tester = new ServerTester();
 
   ActivityService service = tester.get(ActivityService.class);
   ActivityDao dao = tester.get(ActivityDao.class);
   ActivityIndex index = tester.get(ActivityIndex.class);
-  DbClient db;
-  DbSession dbSession;
-
-  @Before
-  public void before() {
-    tester.clearDbAndIndexes();
-    db = tester.get(DbClient.class);
-    dbSession = tester.get(DbClient.class).openSession(false);
-  }
-
-  @After
-  public void after() {
-    dbSession.close();
-  }
 
   @Test
   public void insert_find_text_log() throws InterruptedException {
+
+
+    System.out.println("tester = " + ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage());
+    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
+    System.out.println("mem.getNonHeapMemoryUsage() = " + mem.getNonHeapMemoryUsage());
+    System.out.println("mem.getHeapMemoryUsage() = " + mem.getHeapMemoryUsage());
+
     final String testValue = "hello world";
     service.write(dbSession, Activity.Type.QPROFILE, testValue);
     dbSession.commit();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/activity/SearchMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/activity/SearchMediumTest.java
new file mode 100644 (file)
index 0000000..2dba3d0
--- /dev/null
@@ -0,0 +1,42 @@
+package org.sonar.server.activity;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.tester.ServerTester;
+
+import java.lang.management.ManagementFactory;
+
+public abstract class SearchMediumTest {
+
+
+  private static Logger LOGGER = LoggerFactory.getLogger(SearchMediumTest.class);
+
+  @ClassRule
+  public static ServerTester tester = new ServerTester();
+
+  protected DbClient db;
+  protected DbSession dbSession;
+
+  @Before
+  public void before() {
+    tester.clearDbAndIndexes();
+    db = tester.get(DbClient.class);
+    dbSession = tester.get(DbClient.class).openSession(false);
+
+    ManagementFactory.getMemoryMXBean();
+    LOGGER.info("* Environment ({})", ManagementFactory.getOperatingSystemMXBean().getName());
+    LOGGER.info("* heap:\t{}", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage());
+    LOGGER.info("* load:\t{}", ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage());
+  }
+
+  @After
+  public void after() {
+    dbSession.close();
+  }
+
+}
index 3537e1ccaf887f86ca4ef134c0ad75e8c287e847..e1a2ed3cdce4fee54d4240ced68ffeeb440e7a40 100644 (file)
@@ -21,27 +21,23 @@ package org.sonar.server.qualityprofile;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Multimap;
-import org.junit.After;
 import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
 import org.sonar.api.server.debt.DebtRemediationFunction;
-import org.sonar.core.persistence.DbSession;
 import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
 import org.sonar.core.qualityprofile.db.QualityProfileDto;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleParamDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.server.activity.SearchMediumTest;
 import org.sonar.server.platform.Platform;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
 import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer;
 import org.sonar.server.rule.RuleTesting;
 import org.sonar.server.search.FacetValue;
-import org.sonar.server.tester.ServerTester;
 
 import java.util.Collection;
 import java.util.Date;
@@ -50,28 +46,15 @@ import java.util.Map;
 
 import static org.fest.assertions.Assertions.assertThat;
 
-public class ActiveRuleBackendMediumTest {
+public class ActiveRuleBackendMediumTest extends SearchMediumTest {
 
-  @ClassRule
-  public static ServerTester tester = new ServerTester();
-
-  DbClient db;
-  DbSession dbSession;
   ActiveRuleIndex index;
 
   @Before
   public void before() {
-    tester.clearDbAndIndexes();
-    db = tester.get(DbClient.class);
-    dbSession = db.openSession(false);
     index = tester.get(ActiveRuleIndex.class);
   }
 
-  @After
-  public void after() throws Exception {
-    dbSession.close();
-  }
-
   @Test
   public void synchronize_index() throws Exception {
 
index 66a3ba6ab0b3071ed3a0631c96d30f1cdad82a7d..11c2fdf71d4a36d56042e97fded3412dbe5d4175 100644 (file)
@@ -24,20 +24,16 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 import org.apache.commons.lang.time.DateUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
-import org.sonar.core.persistence.DbSession;
 import org.sonar.core.qualityprofile.db.ActiveRuleDto;
 import org.sonar.core.qualityprofile.db.QualityProfileDto;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.RuleParamDto;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
-import org.sonar.server.db.DbClient;
+import org.sonar.server.activity.SearchMediumTest;
 import org.sonar.server.debt.DebtTesting;
 import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.qualityprofile.QProfileTesting;
@@ -47,7 +43,6 @@ import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.search.FacetValue;
 import org.sonar.server.search.QueryOptions;
 import org.sonar.server.search.Result;
-import org.sonar.server.tester.ServerTester;
 
 import javax.annotation.Nullable;
 import java.util.Arrays;
@@ -63,27 +58,12 @@ import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
 import static org.fest.assertions.Fail.fail;
 
-public class RuleIndexMediumTest {
+public class RuleIndexMediumTest extends SearchMediumTest {
 
-  @ClassRule
-  public static ServerTester tester = new ServerTester();
 
   RuleDao dao = tester.get(RuleDao.class);
   RuleIndex index = tester.get(RuleIndex.class);
-  DbClient db;
-  DbSession dbSession;
 
-  @Before
-  public void before() {
-    tester.clearDbAndIndexes();
-    db = tester.get(DbClient.class);
-    dbSession = db.openSession(false);
-  }
-
-  @After
-  public void after() {
-    dbSession.close();
-  }
 
   @Test
   public void getByKey() throws InterruptedException {