List of usage examples for org.apache.hadoop.metrics2.lib MutableStat add
public synchronized void add(long value)
From source file:org.apache.accumulo.master.metrics.Metrics2ReplicationMetricsTest.java
License:Apache License
@Test public void testAddReplicationQueueTimeMetrics() throws Exception { Master master = EasyMock.createMock(Master.class); MetricsSystem system = EasyMock.createMock(MetricsSystem.class); VolumeManager fileSystem = EasyMock.createMock(VolumeManager.class); ReplicationUtil util = EasyMock.createMock(ReplicationUtil.class); MutableStat stat = EasyMock.createMock(MutableStat.class); MutableQuantiles quantiles = EasyMock.createMock(MutableQuantiles.class); Path path1 = new Path("hdfs://localhost:9000/accumulo/wal/file1"); Path path2 = new Path("hdfs://localhost:9000/accumulo/wal/file2"); // First call will initialize the map of paths to modification time EasyMock.expect(util.getPendingReplicationPaths()).andReturn(ImmutableSet.of(path1, path2)); EasyMock.expect(master.getFileSystem()).andReturn(fileSystem); EasyMock.expect(fileSystem.getFileStatus(path1)).andReturn(createStatus(100)); EasyMock.expect(master.getFileSystem()).andReturn(fileSystem); EasyMock.expect(fileSystem.getFileStatus(path2)).andReturn(createStatus(200)); // Second call will recognize the missing path1 and add the latency stat EasyMock.expect(util.getPendingReplicationPaths()).andReturn(ImmutableSet.of(path2)); // Expect a call to reset the min/max stat.resetMinMax();/* ww w . j a v a 2 s.com*/ EasyMock.expectLastCall(); // Expect the calls of adding the stats quantiles.add(currentTime - 100); EasyMock.expectLastCall(); stat.add(currentTime - 100); EasyMock.expectLastCall(); EasyMock.replay(master, system, fileSystem, util, stat, quantiles); Metrics2ReplicationMetrics metrics = new TestMetrics2ReplicationMetrics(master, system); // Inject our mock objects replaceField(metrics, "replicationUtil", util); replaceField(metrics, "replicationQueueTimeQuantiles", quantiles); replaceField(metrics, "replicationQueueTimeStat", stat); // Two calls to this will initialize the map and then add metrics metrics.addReplicationQueueTimeMetrics(); metrics.addReplicationQueueTimeMetrics(); EasyMock.verify(master, system, fileSystem, util, stat, quantiles); }