]> source.dussan.org Git - sonarqube.git/commitdiff
Stabilize TelemetryDaemonTest
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 20 Oct 2017 15:20:20 +0000 (17:20 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Mon, 23 Oct 2017 15:06:39 +0000 (17:06 +0200)
server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java

index 84a20d03de66c9898249cc35b1abe6e18e633d78..091be0cd577dc1248b19ccd926b8d3af91a0ed60 100644 (file)
 
 package org.sonar.server.telemetry;
 
-import com.google.common.collect.ImmutableMap;
 import java.io.IOException;
 import java.sql.DatabaseMetaData;
 import java.sql.SQLException;
 import java.util.List;
-import java.util.Map;
 import java.util.stream.IntStream;
 import org.junit.After;
 import org.junit.Rule;
@@ -63,6 +61,8 @@ import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -91,7 +91,7 @@ public class TelemetryDaemonTest {
   public LogTester logger = new LogTester().setLevel(LoggerLevel.DEBUG);
 
   private TelemetryClient client = mock(TelemetryClient.class);
-  private InternalProperties internalProperties = new MapInternalProperties();
+  private InternalProperties internalProperties = spy(new MapInternalProperties());
   private FakeServer server = new FakeServer();
   private PluginRepository pluginRepository = mock(PluginRepository.class);
   private TestSystem2 system2 = new TestSystem2().setNow(System.currentTimeMillis());
@@ -245,11 +245,12 @@ public class TelemetryDaemonTest {
     system2.setNow(today + 15 * ONE_HOUR);
     long sevenDaysAgo = today - (ONE_DAY * 7L);
     internalProperties.write("telemetry.lastPing", String.valueOf(sevenDaysAgo));
+    reset(internalProperties);
 
     underTest.start();
 
-    verify(client, timeout(2_000).times(1)).upload(anyString());
-    assertThat(internalProperties.read("telemetry.lastPing").get()).isEqualTo(String.valueOf(today));
+    verify(internalProperties, timeout(4_000)).write("telemetry.lastPing", String.valueOf(today));
+    verify(client).upload(anyString());
   }
 
   @Test
@@ -268,8 +269,4 @@ public class TelemetryDaemonTest {
     return new PluginInfo(key)
       .setVersion(Version.create(version));
   }
-
-  private static Map<String, Object> newMeasure(String key, Object value) {
-    return ImmutableMap.of("key", key, "value", value);
-  }
 }