Search in sources :

Example 1 with MetricsReplicationTableSource

use of org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationTableSource in project hbase by apache.

the class TestReplicationEndpoint method testMetricsSourceBaseSourcePassThrough.

@Test
public void testMetricsSourceBaseSourcePassThrough() {
    /*
     * The replication MetricsSource wraps a MetricsReplicationTableSourceImpl,
     * MetricsReplicationSourceSourceImpl and a MetricsReplicationGlobalSourceSource,
     * so that metrics get written to both namespaces. Both of those classes wrap a
     * MetricsReplicationSourceImpl that implements BaseSource, which allows
     * for custom JMX metrics. This test checks to make sure the BaseSource decorator logic on
     * MetricsSource actually calls down through the two layers of wrapping to the actual
     * BaseSource.
     */
    String id = "id";
    DynamicMetricsRegistry mockRegistry = mock(DynamicMetricsRegistry.class);
    MetricsReplicationSourceImpl singleRms = mock(MetricsReplicationSourceImpl.class);
    when(singleRms.getMetricsRegistry()).thenReturn(mockRegistry);
    MetricsReplicationSourceImpl globalRms = mock(MetricsReplicationSourceImpl.class);
    when(globalRms.getMetricsRegistry()).thenReturn(mockRegistry);
    MetricsReplicationSourceSource singleSourceSource = new MetricsReplicationSourceSourceImpl(singleRms, id);
    MetricsReplicationGlobalSourceSource globalSourceSource = new MetricsReplicationGlobalSourceSourceImpl(globalRms);
    MetricsReplicationGlobalSourceSource spyglobalSourceSource = spy(globalSourceSource);
    doNothing().when(spyglobalSourceSource).incrFailedRecoveryQueue();
    Map<String, MetricsReplicationTableSource> singleSourceSourceByTable = new HashMap<>();
    MetricsSource source = new MetricsSource(id, singleSourceSource, spyglobalSourceSource, singleSourceSourceByTable);
    String gaugeName = "gauge";
    String singleGaugeName = "source.id." + gaugeName;
    String globalGaugeName = "source." + gaugeName;
    long delta = 1;
    String counterName = "counter";
    String singleCounterName = "source.id." + counterName;
    String globalCounterName = "source." + counterName;
    long count = 2;
    source.decGauge(gaugeName, delta);
    source.getMetricsContext();
    source.getMetricsDescription();
    source.getMetricsJmxContext();
    source.getMetricsName();
    source.incCounters(counterName, count);
    source.incGauge(gaugeName, delta);
    source.init();
    source.removeMetric(gaugeName);
    source.setGauge(gaugeName, delta);
    source.updateHistogram(counterName, count);
    source.incrFailedRecoveryQueue();
    verify(singleRms).decGauge(singleGaugeName, delta);
    verify(globalRms).decGauge(globalGaugeName, delta);
    verify(globalRms).getMetricsContext();
    verify(globalRms).getMetricsJmxContext();
    verify(globalRms).getMetricsName();
    verify(singleRms).incCounters(singleCounterName, count);
    verify(globalRms).incCounters(globalCounterName, count);
    verify(singleRms).incGauge(singleGaugeName, delta);
    verify(globalRms).incGauge(globalGaugeName, delta);
    verify(globalRms).init();
    verify(singleRms).removeMetric(singleGaugeName);
    verify(globalRms).removeMetric(globalGaugeName);
    verify(singleRms).setGauge(singleGaugeName, delta);
    verify(globalRms).setGauge(globalGaugeName, delta);
    verify(singleRms).updateHistogram(singleCounterName, count);
    verify(globalRms).updateHistogram(globalCounterName, count);
    verify(spyglobalSourceSource).incrFailedRecoveryQueue();
    // check singleSourceSourceByTable metrics.
    // singleSourceSourceByTable map entry will be created only
    // after calling #setAgeOfLastShippedOpByTable
    boolean containsRandomNewTable = source.getSingleSourceSourceByTable().containsKey("RandomNewTable");
    Assert.assertEquals(false, containsRandomNewTable);
    source.updateTableLevelMetrics(createWALEntriesWithSize("RandomNewTable"));
    containsRandomNewTable = source.getSingleSourceSourceByTable().containsKey("RandomNewTable");
    Assert.assertEquals(true, containsRandomNewTable);
    MetricsReplicationTableSource msr = source.getSingleSourceSourceByTable().get("RandomNewTable");
    // age should be greater than zero we created the entry with time in the past
    Assert.assertTrue(msr.getLastShippedAge() > 0);
    Assert.assertTrue(msr.getShippedBytes() > 0);
}
Also used : MetricsReplicationTableSource(org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationTableSource) MetricsSource(org.apache.hadoop.hbase.replication.regionserver.MetricsSource) HashMap(java.util.HashMap) MetricsReplicationGlobalSourceSourceImpl(org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationGlobalSourceSourceImpl) MetricsReplicationSourceSourceImpl(org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceSourceImpl) MetricsReplicationSourceSource(org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceSource) MetricsReplicationGlobalSourceSource(org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationGlobalSourceSource) MetricsReplicationSourceImpl(org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceImpl) DynamicMetricsRegistry(org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 MetricsReplicationGlobalSourceSource (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationGlobalSourceSource)1 MetricsReplicationGlobalSourceSourceImpl (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationGlobalSourceSourceImpl)1 MetricsReplicationSourceImpl (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceImpl)1 MetricsReplicationSourceSource (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceSource)1 MetricsReplicationSourceSourceImpl (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationSourceSourceImpl)1 MetricsReplicationTableSource (org.apache.hadoop.hbase.replication.regionserver.MetricsReplicationTableSource)1 MetricsSource (org.apache.hadoop.hbase.replication.regionserver.MetricsSource)1 DynamicMetricsRegistry (org.apache.hadoop.metrics2.lib.DynamicMetricsRegistry)1 Test (org.junit.Test)1