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 static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertNotEquals; 022 023import java.io.IOException; 024import java.util.EnumSet; 025import org.apache.hadoop.hbase.ClusterMetrics; 026import org.apache.hadoop.hbase.ServerMetrics; 027import org.apache.hadoop.hbase.ServerName; 028import org.apache.hadoop.hbase.Waiter; 029import org.apache.hadoop.hbase.client.Admin; 030import org.apache.hadoop.hbase.testclassification.MediumTests; 031import org.apache.hadoop.hbase.testclassification.ReplicationTests; 032import org.junit.jupiter.api.Tag; 033import org.junit.jupiter.api.Test; 034 035@Tag(ReplicationTests.TAG) 036@Tag(MediumTests.TAG) 037public class TestReplicationStatusSink extends TestReplicationBase { 038 039 @Test 040 public void testReplicationStatusSink() throws Exception { 041 try (Admin admin = UTIL2.getConnection().getAdmin()) { 042 ServerName server = UTIL2.getHBaseCluster().getRegionServer(0).getServerName(); 043 ReplicationLoadSink loadSink = getLatestSinkMetric(admin, server); 044 // First checks if status of timestamp of last applied op is same as RS start, since no edits 045 // were replicated yet 046 assertEquals(loadSink.getTimestampStarted(), loadSink.getTimestampsOfLastAppliedOp()); 047 // now insert some rows on source, so that it gets delivered to target 048 TestReplicationStatus.insertRowsOnSource(); 049 long wait = 050 Waiter.waitFor(UTIL2.getConfiguration(), 10000, (Waiter.Predicate<Exception>) () -> { 051 ReplicationLoadSink loadSink1 = getLatestSinkMetric(admin, server); 052 return loadSink1.getTimestampsOfLastAppliedOp() > loadSink1.getTimestampStarted(); 053 }); 054 assertNotEquals(-1, wait); 055 } 056 } 057 058 private ReplicationLoadSink getLatestSinkMetric(Admin admin, ServerName server) 059 throws IOException { 060 ClusterMetrics metrics = 061 admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.LIVE_SERVERS)); 062 ServerMetrics sm = metrics.getLiveServerMetrics().get(server); 063 return sm.getReplicationLoadSink(); 064 } 065 066}