Search in sources :

Example 1 with ReplicationUtil

use of org.apache.accumulo.server.replication.ReplicationUtil in project accumulo by apache.

the class Metrics2ReplicationMetricsTest method testAddReplicationQueueTimeMetrics.

@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();
    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);
}
Also used : Master(org.apache.accumulo.master.Master) Path(org.apache.hadoop.fs.Path) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) MutableQuantiles(org.apache.hadoop.metrics2.lib.MutableQuantiles) ReplicationUtil(org.apache.accumulo.server.replication.ReplicationUtil) MutableStat(org.apache.hadoop.metrics2.lib.MutableStat) MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem) Test(org.junit.Test)

Aggregations

Master (org.apache.accumulo.master.Master)1 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)1 ReplicationUtil (org.apache.accumulo.server.replication.ReplicationUtil)1 Path (org.apache.hadoop.fs.Path)1 MetricsSystem (org.apache.hadoop.metrics2.MetricsSystem)1 MutableQuantiles (org.apache.hadoop.metrics2.lib.MutableQuantiles)1 MutableStat (org.apache.hadoop.metrics2.lib.MutableStat)1 Test (org.junit.Test)1