001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.replication; 019 020import java.io.IOException; 021import java.util.EnumSet; 022import org.apache.hadoop.hbase.ClusterMetrics; 023import org.apache.hadoop.hbase.HBaseClassTestRule; 024import org.apache.hadoop.hbase.ServerMetrics; 025import org.apache.hadoop.hbase.ServerName; 026import org.apache.hadoop.hbase.Waiter; 027import org.apache.hadoop.hbase.client.Admin; 028import org.apache.hadoop.hbase.testclassification.MediumTests; 029import org.apache.hadoop.hbase.testclassification.ReplicationTests; 030import org.junit.Assert; 031import org.junit.ClassRule; 032import org.junit.Test; 033import org.junit.experimental.categories.Category; 034 035@Category({ ReplicationTests.class, MediumTests.class }) 036public class TestReplicationStatusSink extends TestReplicationBase { 037 038 @ClassRule 039 public static final HBaseClassTestRule CLASS_RULE = 040 HBaseClassTestRule.forClass(TestReplicationStatusSink.class); 041 042 @Test 043 public void testReplicationStatusSink() throws Exception { 044 try (Admin admin = UTIL2.getConnection().getAdmin()) { 045 ServerName server = UTIL2.getHBaseCluster().getRegionServer(0).getServerName(); 046 ReplicationLoadSink loadSink = getLatestSinkMetric(admin, server); 047 // First checks if status of timestamp of last applied op is same as RS start, since no edits 048 // were replicated yet 049 Assert.assertEquals(loadSink.getTimestampStarted(), loadSink.getTimestampsOfLastAppliedOp()); 050 // now insert some rows on source, so that it gets delivered to target 051 TestReplicationStatus.insertRowsOnSource(); 052 long wait = 053 Waiter.waitFor(UTIL2.getConfiguration(), 10000, (Waiter.Predicate<Exception>) () -> { 054 ReplicationLoadSink loadSink1 = getLatestSinkMetric(admin, server); 055 return loadSink1.getTimestampsOfLastAppliedOp() > loadSink1.getTimestampStarted(); 056 }); 057 Assert.assertNotEquals(-1, wait); 058 } 059 } 060 061 private ReplicationLoadSink getLatestSinkMetric(Admin admin, ServerName server) 062 throws IOException { 063 ClusterMetrics metrics = 064 admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.LIVE_SERVERS)); 065 ServerMetrics sm = metrics.getLiveServerMetrics().get(server); 066 return sm.getReplicationLoadSink(); 067 } 068 069}