HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / replication / TestReplicationStatusSourceStartedTargetStoppedNewOp.java
blob243e24541bed955ec22dadb95fe6c921b0519bed
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.replication;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
24 import java.util.EnumSet;
25 import java.util.List;
26 import org.apache.hadoop.hbase.ClusterMetrics;
27 import org.apache.hadoop.hbase.ClusterMetrics.Option;
28 import org.apache.hadoop.hbase.HBaseClassTestRule;
29 import org.apache.hadoop.hbase.ServerName;
30 import org.apache.hadoop.hbase.client.Admin;
31 import org.apache.hadoop.hbase.client.Put;
32 import org.apache.hadoop.hbase.testclassification.MediumTests;
33 import org.apache.hadoop.hbase.testclassification.ReplicationTests;
34 import org.apache.hadoop.hbase.util.Bytes;
35 import org.junit.ClassRule;
36 import org.junit.Test;
37 import org.junit.experimental.categories.Category;
39 @Category({ ReplicationTests.class, MediumTests.class })
40 public class TestReplicationStatusSourceStartedTargetStoppedNewOp extends TestReplicationBase {
42 @ClassRule
43 public static final HBaseClassTestRule CLASS_RULE =
44 HBaseClassTestRule.forClass(TestReplicationStatusSourceStartedTargetStoppedNewOp.class);
46 @Test
47 public void testReplicationStatusSourceStartedTargetStoppedNewOp() throws Exception {
48 UTIL2.shutdownMiniHBaseCluster();
49 restartSourceCluster(1);
50 Admin hbaseAdmin = UTIL1.getAdmin();
51 // add some values to source cluster
52 for (int i = 0; i < NB_ROWS_IN_BATCH; i++) {
53 Put p = new Put(Bytes.toBytes("row" + i));
54 p.addColumn(famName, Bytes.toBytes("col1"), Bytes.toBytes("val" + i));
55 htable1.put(p);
57 Thread.sleep(10000);
58 ServerName serverName = UTIL1.getHBaseCluster().getRegionServer(0).getServerName();
59 ClusterMetrics metrics = hbaseAdmin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
60 List<ReplicationLoadSource> loadSources =
61 metrics.getLiveServerMetrics().get(serverName).getReplicationLoadSourceList();
62 assertEquals(1, loadSources.size());
63 ReplicationLoadSource loadSource = loadSources.get(0);
64 assertTrue(loadSource.hasEditsSinceRestart());
65 assertEquals(0, loadSource.getTimestampOfLastShippedOp());
66 assertTrue(loadSource.getReplicationLag() > 0);
67 assertFalse(loadSource.isRecovered());