]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6414 Indexing tests should update updatedAt field 600/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 26 Oct 2015 17:00:02 +0000 (18:00 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 27 Oct 2015 08:13:58 +0000 (09:13 +0100)
server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestResultSetIteratorTest.java

index 8c8316e5dbf5c6a01500432565595c45cb5f58d7..96104efd45ad6ac28be04939216f83a5dfe360e0 100644 (file)
@@ -50,6 +50,7 @@ import static org.sonar.server.test.index.TestIndexDefinition.FIELD_PROJECT_UUID
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STACKTRACE;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STATUS;
 import static org.sonar.server.test.index.TestIndexDefinition.FIELD_TEST_UUID;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
 import static org.sonar.server.test.index.TestIndexDefinition.INDEX;
 import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
 
@@ -99,6 +100,7 @@ public class TestResultSetIterator extends ResultSetIterator<Row> {
       writer.prop(FIELD_DURATION_IN_MS, test.hasExecutionTimeMs() ? test.getExecutionTimeMs() : null);
       writer.prop(FIELD_MESSAGE, test.hasMsg() ? test.getMsg() : null);
       writer.prop(FIELD_STACKTRACE, test.hasStacktrace() ? test.getStacktrace() : null);
+      writer.prop(FIELD_UPDATED_AT, updatedAt.getTime());
       writer.name(FIELD_COVERED_FILES);
       writer.beginArray();
       for (DbFileSources.Test.CoveredFile coveredFile : test.getCoveredFileList()) {
index 1290f7b4b45621742f800bb9546baf628cda15c1..4a802feac1cf3da1a9171527e91f1514bc2b2486 100644 (file)
@@ -40,7 +40,6 @@ import org.sonar.api.config.Settings;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.protobuf.DbFileSources;
-import org.sonar.server.db.DbClient;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.source.index.FileSourcesUpdaterHelper;
 import org.sonar.server.test.db.TestTesting;
@@ -75,7 +74,7 @@ public class TestIndexerTest {
   public void setUp() {
     es.truncateIndices();
     db.truncateTables();
-    underTest = new TestIndexer(new DbClient(db.database(), db.myBatis()), es.client());
+    underTest = new TestIndexer(db.getDbClient(), es.client());
     underTest.setEnabled(true);
   }
 
index fac2e442108af934ee86210424ab2e42bdccc310..6d6b6acd60b28efc485309a616049709666153c5 100644 (file)
@@ -24,7 +24,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
-import org.assertj.core.data.MapEntry;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.junit.After;
 import org.junit.Rule;
@@ -39,6 +38,17 @@ import org.sonar.test.DbTests;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.data.MapEntry.entry;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_COVERED_FILES;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_DURATION_IN_MS;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_MESSAGE;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_NAME;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_PROJECT_UUID;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STACKTRACE;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STATUS;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_TEST_UUID;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
 
 @Category(DbTests.class)
 public class TestResultSetIteratorTest {
@@ -48,6 +58,27 @@ public class TestResultSetIteratorTest {
 
   TestResultSetIterator underTest;
 
+  private static List<DbFileSources.Test> newFakeTests(int numberOfTests) {
+    List<DbFileSources.Test> tests = new ArrayList<>();
+    for (int i = 1; i <= numberOfTests; i++) {
+      DbFileSources.Test.Builder test = DbFileSources.Test.newBuilder()
+        .setUuid("TEST_FILE_UUID_" + i)
+        .setName("NAME_" + i)
+        .setStatus(DbFileSources.Test.TestStatus.FAILURE)
+        .setStacktrace("STACKTRACE_" + i)
+        .setMsg("MESSAGE_" + i)
+        .setExecutionTimeMs(i);
+      for (int j = 1; j <= numberOfTests; j++) {
+        test.addCoveredFile(
+          DbFileSources.Test.CoveredFile.newBuilder()
+            .setFileUuid("MAIN_FILE_UUID_" + j)
+            .addCoveredLine(j));
+      }
+      tests.add(test.build());
+    }
+    return tests;
+  }
+
   @After
   public void after() {
     if (underTest != null) {
@@ -70,14 +101,15 @@ public class TestResultSetIteratorTest {
     UpdateRequest firstRequest = row.getUpdateRequests().get(0);
     Map<String, Object> doc = firstRequest.doc().sourceAsMap();
     assertThat(doc).contains(
-      MapEntry.entry(TestIndexDefinition.FIELD_PROJECT_UUID, "P1"),
-      MapEntry.entry(TestIndexDefinition.FIELD_FILE_UUID, "F1"),
-      MapEntry.entry(TestIndexDefinition.FIELD_TEST_UUID, "TEST_FILE_UUID_1"),
-      MapEntry.entry(TestIndexDefinition.FIELD_STATUS, "FAILURE"),
-      MapEntry.entry(TestIndexDefinition.FIELD_MESSAGE, "MESSAGE_1"),
-      MapEntry.entry(TestIndexDefinition.FIELD_DURATION_IN_MS, 1),
-      MapEntry.entry(TestIndexDefinition.FIELD_STACKTRACE, "STACKTRACE_1"),
-      MapEntry.entry(TestIndexDefinition.FIELD_NAME, "NAME_1"));
+      entry(FIELD_PROJECT_UUID, "P1"),
+      entry(FIELD_FILE_UUID, "F1"),
+      entry(FIELD_TEST_UUID, "TEST_FILE_UUID_1"),
+      entry(FIELD_STATUS, "FAILURE"),
+      entry(FIELD_MESSAGE, "MESSAGE_1"),
+      entry(FIELD_DURATION_IN_MS, 1),
+      entry(FIELD_STACKTRACE, "STACKTRACE_1"),
+      entry(FIELD_NAME, "NAME_1"),
+      entry(FIELD_UPDATED_AT, 1416239042000L));
   }
 
   /**
@@ -103,17 +135,19 @@ public class TestResultSetIteratorTest {
     UpdateRequest firstRequest = row.getUpdateRequests().get(0);
     Map<String, Object> doc = firstRequest.doc().sourceAsMap();
     assertThat(doc).contains(
-      MapEntry.entry(TestIndexDefinition.FIELD_PROJECT_UUID, "P1"),
-      MapEntry.entry(TestIndexDefinition.FIELD_FILE_UUID, "F1"),
-      MapEntry.entry(TestIndexDefinition.FIELD_TEST_UUID, "U1"),
-      MapEntry.entry(TestIndexDefinition.FIELD_NAME, "N1"));
+      entry(FIELD_PROJECT_UUID, "P1"),
+      entry(FIELD_FILE_UUID, "F1"),
+      entry(FIELD_TEST_UUID, "U1"),
+      entry(FIELD_NAME, "N1"),
+      entry(FIELD_UPDATED_AT, 1416239042000L));
+    ;
     // null values
     assertThat(doc).containsKeys(
-      TestIndexDefinition.FIELD_DURATION_IN_MS,
-      TestIndexDefinition.FIELD_STACKTRACE,
-      TestIndexDefinition.FIELD_MESSAGE,
-      TestIndexDefinition.FIELD_STATUS,
-      TestIndexDefinition.FIELD_COVERED_FILES);
+      FIELD_DURATION_IN_MS,
+      FIELD_STACKTRACE,
+      FIELD_MESSAGE,
+      FIELD_STATUS,
+      FIELD_COVERED_FILES);
   }
 
   @Test
@@ -170,25 +204,4 @@ public class TestResultSetIteratorTest {
     }
   }
 
-  private static List<DbFileSources.Test> newFakeTests(int numberOfTests) {
-    List<DbFileSources.Test> tests = new ArrayList<>();
-    for (int i = 1; i <= numberOfTests; i++) {
-      DbFileSources.Test.Builder test = DbFileSources.Test.newBuilder()
-        .setUuid("TEST_FILE_UUID_" + i)
-        .setName("NAME_" + i)
-        .setStatus(DbFileSources.Test.TestStatus.FAILURE)
-        .setStacktrace("STACKTRACE_" + i)
-        .setMsg("MESSAGE_" + i)
-        .setExecutionTimeMs(i);
-      for (int j = 1; j <= numberOfTests; j++) {
-        test.addCoveredFile(
-          DbFileSources.Test.CoveredFile.newBuilder()
-            .setFileUuid("MAIN_FILE_UUID_" + j)
-            .addCoveredLine(j));
-      }
-      tests.add(test.build());
-    }
-    return tests;
-  }
-
 }