Skip to content

Commit

Permalink
Merge pull request #215 from brharrington/reformat-test-case
Browse files Browse the repository at this point in the history
reformat test case to be consistent
  • Loading branch information
brharrington committed Sep 4, 2015
2 parents b557cd3 + 27e5c63 commit a8f14ec
Showing 1 changed file with 44 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spectator.aws;

import com.amazonaws.DefaultRequest;
Expand All @@ -37,56 +36,56 @@

public class SpectatorRequestMetricCollectorTest {

Registry registry;
SpectatorRequestMetricCollector collector;
Registry registry;
SpectatorRequestMetricCollector collector;

@Before
public void setUp() {
registry = new DefaultRegistry();
collector = new SpectatorRequestMetricCollector(registry);
}
@Before
public void setUp() {
registry = new DefaultRegistry();
collector = new SpectatorRequestMetricCollector(registry);
}

@Test
public void testMetricCollection() {
//setup
AWSRequestMetrics metrics = new AWSRequestMetricsFullSupport();
String counterName = "BytesProcessed";
String timerName = "ClientExecuteTime";
metrics.setCounter(counterName, 12345);
metrics.getTimingInfo().addSubMeasurement(timerName, TimingInfo.unmodifiableTimingInfo(100000L, 200000L));
@Test
public void testMetricCollection() {
//setup
AWSRequestMetrics metrics = new AWSRequestMetricsFullSupport();
String counterName = "BytesProcessed";
String timerName = "ClientExecuteTime";
metrics.setCounter(counterName, 12345);
metrics.getTimingInfo().addSubMeasurement(timerName, TimingInfo.unmodifiableTimingInfo(100000L, 200000L));

Request<?> req = new DefaultRequest("foo");
req.setAWSRequestMetrics(metrics);
req.setEndpoint(URI.create("http://foo"));
Request<?> req = new DefaultRequest("foo");
req.setAWSRequestMetrics(metrics);
req.setEndpoint(URI.create("http://foo"));

HttpResponse hr = new HttpResponse(req, new HttpPost("http://foo"));
hr.setStatusCode(200);
Response<?> resp = new Response<>(null, new HttpResponse(req, new HttpPost("http://foo")));
HttpResponse hr = new HttpResponse(req, new HttpPost("http://foo"));
hr.setStatusCode(200);
Response<?> resp = new Response<>(null, new HttpResponse(req, new HttpPost("http://foo")));

//when
collector.collectMetrics(req, resp);
//when
collector.collectMetrics(req, resp);

//then
List<Meter> allMetrics = new ArrayList<>();
registry.iterator().forEachRemaining(allMetrics::add);
//then
List<Meter> allMetrics = new ArrayList<>();
registry.iterator().forEachRemaining(allMetrics::add);

assertEquals(2, allMetrics.size());
Optional<Timer> expectedTimer = allMetrics
.stream()
.filter(m -> m instanceof Timer && m.id().name().equals(SpectatorRequestMetricCollector.idName(timerName)))
.map(m -> (Timer) m)
.findFirst();
assertTrue(expectedTimer.isPresent());
Timer timer = expectedTimer.get();
assertEquals(1, timer.count());
assertEquals(100000, timer.totalTime());
assertEquals(2, allMetrics.size());
Optional<Timer> expectedTimer = allMetrics
.stream()
.filter(m -> m instanceof Timer && m.id().name().equals(SpectatorRequestMetricCollector.idName(timerName)))
.map(m -> (Timer) m)
.findFirst();
assertTrue(expectedTimer.isPresent());
Timer timer = expectedTimer.get();
assertEquals(1, timer.count());
assertEquals(100000, timer.totalTime());

Optional<Counter> expectedCounter = allMetrics
.stream()
.filter(m -> m.id().name().equals(SpectatorRequestMetricCollector.idName(counterName)))
.map(m -> (Counter) m)
.findFirst();
assertTrue(expectedCounter.isPresent());
assertEquals(12345L, expectedCounter.get().count());
}
Optional<Counter> expectedCounter = allMetrics
.stream()
.filter(m -> m.id().name().equals(SpectatorRequestMetricCollector.idName(counterName)))
.map(m -> (Counter) m)
.findFirst();
assertTrue(expectedCounter.isPresent());
assertEquals(12345L, expectedCounter.get().count());
}
}

0 comments on commit a8f14ec

Please sign in to comment.