View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.client;
21  
22  import java.util.List;
23  import org.junit.Assert;
24  import org.junit.Test;
25  import org.junit.experimental.categories.Category;
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.hadoop.hbase.Cell;
28  import org.apache.hadoop.hbase.HBaseTestingUtility;
29  import org.apache.hadoop.hbase.HConstants;
30  import org.apache.hadoop.hbase.MetaTableAccessor;
31  import org.apache.hadoop.hbase.TableName;
32  import org.apache.hadoop.hbase.testclassification.LargeTests;
33  import org.apache.hadoop.hbase.util.Bytes;
34  
35  @Category({ LargeTests.class})
36  public class TestZKLessAssignment {
37  
38    private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
39  
40    @Test
41    public void testZkLessAssignmentRollbackAndRollForward() throws Exception {
42      Configuration config = TEST_UTIL.getConfiguration();
43      config.setBoolean("hbase.assignment.usezk.migrating", true);
44      TEST_UTIL.startMiniCluster(2);
45      TableName tableName = TableName.valueOf("testZkLessAssignmentRollbackAndRollForward");
46      TEST_UTIL.createTable(tableName.getName(), new byte[][] { Bytes.toBytes("cf1") }, config)
47        .close();
48  
49      try (Connection connection = ConnectionFactory.createConnection(config)) {
50        List<Result> results = MetaTableAccessor.fullScanOfMeta(connection);
51        boolean isSNQualifierExist = false;
52        boolean isStateQualifierExist = false;
53        for (Result result : results) {
54          Cell cell =
55            result.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.SERVERNAME_QUALIFIER);
56          if (cell != null && cell.getValueLength() > 0) {
57            isSNQualifierExist = true;
58          }
59          cell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER);
60          if (cell != null && cell.getValueLength() > 0) {
61            isStateQualifierExist = true;
62          }
63        }
64        Assert.assertTrue(isSNQualifierExist);
65        Assert.assertTrue(isStateQualifierExist);
66      }
67  
68      TEST_UTIL.shutdownMiniHBaseCluster();
69      config.unset("hbase.assignment.usezk.migrating");
70      TEST_UTIL.restartHBaseCluster(2);
71  
72      try (Connection connection = ConnectionFactory.createConnection(config)) {
73        List<Result> results = MetaTableAccessor.fullScanOfMeta(connection);
74        boolean isSNQualifierExist = false;
75        boolean isStateQualifierExist = false;
76        for (Result result : results) {
77          Cell cell =
78            result.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.SERVERNAME_QUALIFIER);
79          if (cell != null && cell.getValueLength() > 0) {
80            isSNQualifierExist = true;
81          }
82          cell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER);
83          if (cell != null && cell.getValueLength() > 0) {
84            isStateQualifierExist = true;
85          }
86        }
87        Assert.assertFalse(isSNQualifierExist);
88        Assert.assertFalse(isStateQualifierExist);
89      }
90    }
91  
92  }