BAEL-8902 Metrics Project Test Fails

- Fixed tests
This commit is contained in:
Dhawal Kapil 2018-09-11 12:48:31 +05:30
parent 977c50ad85
commit a05fc4f82a
4 changed files with 35 additions and 19 deletions

View File

@ -84,6 +84,13 @@
<artifactId>spectator-api</artifactId>
<version>${spectator-api.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>

View File

@ -1,8 +1,12 @@
package com.baeldung.metrics.micrometer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.Assertions.withinPercentage;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.collection.IsMapContaining.hasEntry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import io.micrometer.atlas.AtlasMeterRegistry;
@ -31,8 +35,10 @@ import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.assertj.core.data.Percentage;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import com.netflix.spectator.atlas.AtlasConfig;
@ -156,7 +162,8 @@ public class MicrometerAtlasIntegrationTest {
timer.record(30, TimeUnit.MILLISECONDS);
assertTrue(2 == timer.count());
assertTrue(50 > timer.totalTime(TimeUnit.MILLISECONDS) && 45 <= timer.totalTime(TimeUnit.MILLISECONDS));
assertThat(timer.totalTime(TimeUnit.MILLISECONDS)).isBetween(40.0, 55.0);
}
@Test
@ -173,7 +180,7 @@ public class MicrometerAtlasIntegrationTest {
}
long timeElapsed = longTaskTimer.stop(currentTaskId);
assertTrue(timeElapsed / (int) 1e6 == 2);
assertEquals(2L, timeElapsed/((int) 1e6),1L);
}
@Test

View File

@ -27,6 +27,9 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
/**
* Atlas server needs to be up and running for this live test to work.
*/
public class AtlasObserverLiveTest {
private final String atlasUri = "http://localhost:7101/api/v1";

View File

@ -109,20 +109,20 @@ public class MetricTypeManualTest {
.build(), MILLISECONDS);
Stopwatch stopwatch = timer.start();
MILLISECONDS.sleep(1);
timer.record(2, MILLISECONDS);
SECONDS.sleep(1);
timer.record(2, SECONDS);
stopwatch.stop();
assertEquals("timer should count 1 millisecond", 1, timer
assertEquals("timer should count 1 second", 1000, timer
.getValue()
.intValue());
assertEquals("timer should count 3 millisecond in total", 3, timer.getTotalTime()
.intValue());
.intValue(),1000);
assertEquals("timer should count 3 second in total", 3000, timer.getTotalTime()
.intValue(),1000);
assertEquals("timer should record 2 updates", 2, timer
.getCount()
.intValue());
assertEquals("timer should have max 2", 2, timer.getMax(), 0.01);
assertEquals("timer should have max 2", 2000, timer.getMax(), 0.01);
}
@Test
@ -161,7 +161,6 @@ public class MetricTypeManualTest {
}
@Test
//==
public void givenStatsTimer_whenExecuteTask_thenStatsCalculated() throws Exception {
System.setProperty("netflix.servo", "1000");
StatsTimer timer = new StatsTimer(MonitorConfig
@ -178,21 +177,21 @@ public class MetricTypeManualTest {
.build(), MILLISECONDS);
Stopwatch stopwatch = timer.start();
MILLISECONDS.sleep(1);
timer.record(3, MILLISECONDS);
SECONDS.sleep(1);
timer.record(3, SECONDS);
stopwatch.stop();
stopwatch = timer.start();
timer.record(6, MILLISECONDS);
MILLISECONDS.sleep(2);
timer.record(6, SECONDS);
SECONDS.sleep(2);
stopwatch.stop();
assertEquals("timer should count 12 milliseconds in total", 12, timer.getTotalTime());
assertEquals("timer should count 12 milliseconds in total", 12, timer.getTotalMeasurement());
assertEquals("timer should count 12 seconds in total", 12000, timer.getTotalTime(),500);
assertEquals("timer should count 12 seconds in total", 12000, timer.getTotalMeasurement(),500);
assertEquals("timer should record 4 updates", 4, timer.getCount());
assertEquals("stats timer value time-cost/update should be 2", 3, timer
assertEquals("stats timer value time-cost/update should be 2", 3000, timer
.getValue()
.intValue());
.intValue(),500);
final Map<String, Number> metricMap = timer
.getMonitors()
@ -235,4 +234,4 @@ public class MetricTypeManualTest {
assertEquals("information collected", informational.getValue());
}
}
}