Skip to content
Permalink
Browse files
HBASE-22984 [HBCK2] HBCKMetaTableAccessor.deleteFromMetaTable throwin…
…g java.lang.UnsupportedOperationException at runtime (#24)

Signed-off-by: Sean Busbey <busbey@apache.org>
  • Loading branch information
wchevreuil committed Sep 6, 2019
1 parent 9445b8a commit 4f3f9a7179e334a286f022ecb6a01081e9b02db3
Showing 2 changed files with 87 additions and 1 deletion.
@@ -131,7 +131,8 @@ private static void deleteFromMetaTable(final Connection connection, final Delet
throw new IOException("connection is closed");
}
try (Table t = connection.getTable(TableName.META_TABLE_NAME)) {
List<Delete> deletes = Arrays.asList(d);
List<Delete> deletes = new ArrayList<>();
deletes.add(d);
LOG.debug("Add {} delete to meta table", deletes);
t.delete(deletes);
}
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hbase;

import static org.junit.Assert.assertFalse;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.logging.log4j.LogManager;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* Test class for the MetaTableAccessor wrapper.
*/
public class TestHBCKMetaTableAccessor {

private static final org.apache.logging.log4j.Logger LOG = LogManager.getLogger(TestHBCK2.class);
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();

@Rule
public TestName testName = new TestName();

@BeforeClass
public static void beforeClass() throws Exception {
TEST_UTIL.startMiniCluster(3);
}

@Test
public void testDeleteRegionInfo() throws Exception {
TableName tableName = createTestTable(5);
List<RegionInfo> regions = TEST_UTIL.getAdmin().getRegions(tableName);
RegionInfo toBeDeleted = regions.get(0);
HBCKMetaTableAccessor.deleteRegionInfo(TEST_UTIL.getConnection(), toBeDeleted);
assertFalse(listRegionsInMeta().contains(toBeDeleted));
}

private List<RegionInfo> listRegionsInMeta() throws Exception {
Connection connection = TEST_UTIL.getConnection();
Table table = connection.getTable(TableName.META_TABLE_NAME);
Scan scan = new Scan();
scan.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
ResultScanner scanner = table.getScanner(scan);
final List<RegionInfo> regionInfos = new ArrayList<>();
for(Result r : scanner) {
regionInfos.add(RegionInfo.parseFrom(r.getValue(HConstants.CATALOG_FAMILY,
HConstants.REGIONINFO_QUALIFIER)));
}
return regionInfos;
}

private TableName createTestTable(int totalRegions) throws IOException {
TableName tableName = TableName.valueOf(testName.getMethodName());
TEST_UTIL.createMultiRegionTable(tableName, Bytes.toBytes("family1"), totalRegions);
return tableName;
}
}

0 comments on commit 4f3f9a7

Please sign in to comment.