Skip to content

Commit b5478f7

Browse files
authored
Build opt 9 08 2017 (eugenp#2397)
* pCollections * Reformat * Refactor metrics * Refactor hoverfly
1 parent 69f3e11 commit b5478f7

9 files changed

Lines changed: 72 additions & 50 deletions

File tree

‎libraries/src/test/java/com/baeldung/hll/HLLUnitTest.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public void givenHLL_whenAddHugeAmountOfNumbers_thenShouldReturnEstimatedCardina
2323

2424
//when
2525
LongStream.range(0, numberOfElements).forEach(element -> {
26-
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
27-
hll.addRaw(hashedValue);
28-
}
26+
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
27+
hll.addRaw(hashedValue);
28+
}
2929
);
3030

3131
//then
@@ -44,15 +44,15 @@ public void givenTwoHLLs_whenAddHugeAmountOfNumbers_thenShouldReturnEstimatedCar
4444

4545
//when
4646
LongStream.range(0, numberOfElements).forEach(element -> {
47-
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
48-
firstHll.addRaw(hashedValue);
49-
}
47+
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
48+
firstHll.addRaw(hashedValue);
49+
}
5050
);
5151

5252
LongStream.range(numberOfElements, numberOfElements * 2).forEach(element -> {
53-
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
54-
secondHLL.addRaw(hashedValue);
55-
}
53+
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
54+
secondHLL.addRaw(hashedValue);
55+
}
5656
);
5757

5858
//then

libraries/src/test/java/com/baeldung/hoverfly/HoverflyApiTest.java renamed to libraries/src/test/java/com/baeldung/hoverfly/HoverflyApiIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import io.specto.hoverfly.junit.core.SimulationSource;
3232
import io.specto.hoverfly.junit.rule.HoverflyRule;
3333

34-
public class HoverflyApiTest {
34+
public class HoverflyApiIntegrationTest {
3535

3636
private static final SimulationSource source = dsl(
3737
service("http://www.baeldung.com")

‎libraries/src/test/java/com/baeldung/pcollections/PCollectionsUnitTest.java‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package com.baeldung.pcollections;
22

33
import org.junit.Test;
4-
import org.pcollections.*;
4+
import org.pcollections.HashPMap;
5+
import org.pcollections.HashTreePMap;
6+
import org.pcollections.HashTreePSet;
7+
import org.pcollections.MapPSet;
8+
import org.pcollections.PVector;
9+
import org.pcollections.TreePVector;
510

611
import java.util.Arrays;
712
import java.util.HashMap;
@@ -27,7 +32,7 @@ public void givenKeyValue_whenSingleton_thenCreateNonEmptyHashPMap() {
2732

2833
@Test
2934
public void givenExistingHashMap_whenFrom_thenCreateHashPMap() {
30-
Map map = new HashMap();
35+
Map<String, String> map = new HashMap<>();
3136
map.put("mkey1", "mval1");
3237
map.put("mkey2", "mval2");
3338

@@ -41,7 +46,7 @@ public void whenHashPMapMethods_thenPerformOperations() {
4146
HashPMap<String, String> pmap = HashTreePMap.empty();
4247
HashPMap<String, String> pmap0 = pmap.plus("key1", "value1");
4348

44-
Map map = new HashMap();
49+
Map<String, String> map = new HashMap<>();
4550
map.put("key2", "val2");
4651
map.put("key3", "val3");
4752

@@ -57,30 +62,32 @@ public void whenHashPMapMethods_thenPerformOperations() {
5762

5863
@Test
5964
public void whenTreePVectorMethods_thenPerformOperations() {
60-
TreePVector pVector = TreePVector.empty();
65+
TreePVector<String> pVector = TreePVector.empty();
66+
67+
TreePVector<String> pV1 = pVector.plus("e1");
68+
TreePVector<String> pV2 = pV1.plusAll(Arrays.asList("e2", "e3", "e4"));
6169

62-
TreePVector pV1 = pVector.plus("e1");
63-
TreePVector pV2 = pV1.plusAll(Arrays.asList("e2", "e3", "e4"));
6470
assertEquals(1, pV1.size());
6571
assertEquals(4, pV2.size());
6672

67-
TreePVector pV3 = pV2.minus("e1");
68-
TreePVector pV4 = pV3.minusAll(Arrays.asList("e2", "e3", "e4"));
73+
TreePVector<String> pV3 = pV2.minus("e1");
74+
TreePVector<String> pV4 = pV3.minusAll(Arrays.asList("e2", "e3", "e4"));
75+
6976
assertEquals(pV3.size(), 3);
7077
assertEquals(pV4.size(), 0);
7178

72-
TreePVector pSub = pV2.subList(0, 2);
79+
TreePVector<String> pSub = pV2.subList(0, 2);
7380
assertTrue(pSub.contains("e1") && pSub.contains("e2"));
7481

75-
TreePVector pVW = (TreePVector) pV2.with(0, "e10");
82+
PVector<String> pVW = pV2.with(0, "e10");
7683
assertEquals(pVW.get(0), "e10");
7784
}
7885

7986
@Test
8087
public void whenMapPSetMethods_thenPerformOperations() {
8188

8289
MapPSet pSet = HashTreePSet.empty()
83-
.plusAll(Arrays.asList("e1","e2","e3","e4"));
90+
.plusAll(Arrays.asList("e1", "e2", "e3", "e4"));
8491
assertEquals(pSet.size(), 4);
8592

8693
MapPSet pSet1 = pSet.minus("e4");

‎metrics/src/test/java/com/baeldung/metrics/servo/AtlasObserverLiveTest.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
import static org.hamcrest.CoreMatchers.not;
2828
import static org.junit.Assert.assertThat;
2929

30-
/**
31-
* @author aiet
32-
*/
3330
public class AtlasObserverLiveTest {
3431

3532
private final String atlasUri = "http://localhost:7101/api/v1";

metrics/src/test/java/com/baeldung/metrics/servo/MetricAnnotationTest.java renamed to metrics/src/test/java/com/baeldung/metrics/servo/MetricAnnotationManualTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
import static org.junit.Assert.assertThat;
2323
import static org.junit.Assert.assertTrue;
2424

25-
/**
26-
* @author aiet
27-
*/
28-
public class MetricAnnotationTest extends MetricTestBase {
25+
public class MetricAnnotationManualTest extends MetricTestBase {
2926

3027
@Monitor(name = "integerCounter", type = DataSourceType.COUNTER, description = "Total number of update operations.")
3128
private final AtomicInteger updateCount = new AtomicInteger(0);

metrics/src/test/java/com/baeldung/metrics/servo/MetricObserverTest.java renamed to metrics/src/test/java/com/baeldung/metrics/servo/MetricObserverManualTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313

1414
import static com.netflix.servo.annotations.DataSourceType.GAUGE;
1515
import static java.util.concurrent.TimeUnit.SECONDS;
16-
import static org.hamcrest.Matchers.*;
16+
import static org.hamcrest.Matchers.allOf;
17+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
18+
import static org.hamcrest.Matchers.hasItem;
19+
import static org.hamcrest.Matchers.hasProperty;
20+
import static org.hamcrest.Matchers.hasSize;
21+
import static org.hamcrest.Matchers.is;
1722
import static org.junit.Assert.assertEquals;
1823
import static org.junit.Assert.assertThat;
1924

20-
/**
21-
* @author aiet
22-
*/
23-
public class MetricObserverTest extends MetricTestBase {
25+
public class MetricObserverManualTest extends MetricTestBase {
2426

2527
@Test
2628
public void givenMetrics_whenRegister_thenMonitored() throws InterruptedException {

metrics/src/test/java/com/baeldung/metrics/servo/MetricPollerTest.java renamed to metrics/src/test/java/com/baeldung/metrics/servo/MetricPollerManualTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package com.baeldung.metrics.servo;
22

33
import com.netflix.servo.Metric;
4-
import com.netflix.servo.publish.*;
4+
import com.netflix.servo.publish.BasicMetricFilter;
5+
import com.netflix.servo.publish.JvmMetricPoller;
6+
import com.netflix.servo.publish.MemoryMetricObserver;
7+
import com.netflix.servo.publish.PollRunnable;
8+
import com.netflix.servo.publish.PollScheduler;
59
import org.junit.Test;
610

711
import java.util.List;
812

913
import static java.util.concurrent.TimeUnit.SECONDS;
1014
import static java.util.stream.Collectors.toList;
11-
import static org.hamcrest.Matchers.*;
15+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
16+
import static org.hamcrest.Matchers.hasItems;
17+
import static org.hamcrest.Matchers.hasSize;
1218
import static org.junit.Assert.assertThat;
1319

14-
/**
15-
* @author aiet
16-
*/
17-
public class MetricPollerTest {
20+
public class MetricPollerManualTest {
1821

1922
@Test
2023
public void givenJvmPoller_whenMonitor_thenDataCollected() throws Exception {

‎metrics/src/test/java/com/baeldung/metrics/servo/MetricTestBase.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package com.baeldung.metrics.servo;
22

3-
import com.netflix.servo.publish.*;
3+
import com.netflix.servo.publish.BasicMetricFilter;
4+
import com.netflix.servo.publish.MemoryMetricObserver;
5+
import com.netflix.servo.publish.MetricFilter;
6+
import com.netflix.servo.publish.MonitorRegistryMetricPoller;
7+
import com.netflix.servo.publish.PollRunnable;
8+
import com.netflix.servo.publish.PollScheduler;
49
import org.junit.After;
510
import org.junit.Before;
611

712
import static java.util.concurrent.TimeUnit.SECONDS;
813

9-
/**
10-
* @author aiet
11-
*/
1214
abstract class MetricTestBase {
1315

1416
MemoryMetricObserver observer;

‎metrics/src/test/java/com/baeldung/metrics/servo/MetricTypeTest.java‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
package com.baeldung.metrics.servo;
22

3-
import com.netflix.servo.monitor.*;
3+
import com.netflix.servo.monitor.BasicCounter;
4+
import com.netflix.servo.monitor.BasicGauge;
5+
import com.netflix.servo.monitor.BasicInformational;
6+
import com.netflix.servo.monitor.BasicTimer;
7+
import com.netflix.servo.monitor.BucketConfig;
8+
import com.netflix.servo.monitor.BucketTimer;
9+
import com.netflix.servo.monitor.Counter;
10+
import com.netflix.servo.monitor.Gauge;
11+
import com.netflix.servo.monitor.MaxGauge;
12+
import com.netflix.servo.monitor.Monitor;
13+
import com.netflix.servo.monitor.MonitorConfig;
14+
import com.netflix.servo.monitor.Monitors;
15+
import com.netflix.servo.monitor.PeakRateCounter;
16+
import com.netflix.servo.monitor.StatsTimer;
17+
import com.netflix.servo.monitor.StepCounter;
18+
import com.netflix.servo.monitor.Stopwatch;
419
import com.netflix.servo.stats.StatsConfig;
520
import org.junit.Ignore;
621
import org.junit.Test;
@@ -9,13 +24,12 @@
924

1025
import static java.util.concurrent.TimeUnit.SECONDS;
1126
import static java.util.stream.Collectors.toMap;
12-
import static org.hamcrest.Matchers.*;
27+
import static org.hamcrest.Matchers.allOf;
28+
import static org.hamcrest.Matchers.containsInAnyOrder;
29+
import static org.hamcrest.Matchers.hasEntry;
1330
import static org.junit.Assert.assertEquals;
1431
import static org.junit.Assert.assertThat;
1532

16-
/**
17-
* Unit test for simple App.
18-
*/
1933
public class MetricTypeTest {
2034

2135
@Test
@@ -113,7 +127,7 @@ public void givenBucketTimer_whenRecord_thenStatsCalculated() throws Exception {
113127
BucketTimer timer = new BucketTimer(MonitorConfig
114128
.builder("test")
115129
.build(), new BucketConfig.Builder()
116-
.withBuckets(new long[] { 2L, 5L })
130+
.withBuckets(new long[]{2L, 5L})
117131
.withTimeUnit(SECONDS)
118132
.build(), SECONDS);
119133
timer.record(3);
@@ -150,7 +164,7 @@ public void givenStatsTimer_whenExecuteTask_thenStatsCalculated() throws Excepti
150164
.builder("test")
151165
.build(), new StatsConfig.Builder()
152166
.withComputeFrequencyMillis(2000)
153-
.withPercentiles(new double[] { 99.0, 95.0, 90.0 })
167+
.withPercentiles(new double[]{99.0, 95.0, 90.0})
154168
.withPublishMax(true)
155169
.withPublishMin(true)
156170
.withPublishCount(true)

0 commit comments

Comments
 (0)