Skip to content

Commit

Permalink
resolve failed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
terence-yoo committed May 31, 2019
1 parent 9949122 commit 4cad231
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,23 @@ public static void loginUserFromSubject(Configuration conf, Subject subject) thr
}

@SuppressWarnings("SortedCollectionWithNonComparableKeys")
public static NavigableMap<RegionInfo, ServerName> regionServerMap(Args args, Admin admin, final boolean offlined) throws IOException {
public static NavigableMap<RegionInfo, ServerName> regionServerMap(Args args, Admin admin) throws IOException {
long timestamp = System.currentTimeMillis();

final Set<TableName> disabledTables = new HashSet<>();
Set<TableName> tables = Args.tables(args, admin);
if (tables.size() == 0) {
for (TableDescriptor td : admin.listTableDescriptors()) {
if (admin.isTableDisabled(td.getTableName()))
disabledTables.add(td.getTableName());
}
} else {
for (TableName table : Args.tables(args, admin)) {
if (admin.isTableDisabled(table))
disabledTables.add(table);
}
}

final NavigableMap<RegionInfo, ServerName> regions = new TreeMap<>();
MetaTableAccessor.Visitor visitor = new MetaTableAccessor.DefaultVisitorBase() {
@Override
Expand All @@ -131,8 +145,9 @@ public boolean visitInternal(Result result) {
for (HRegionLocation loc : locations.getRegionLocations()) {
if (loc != null) {
RegionInfo regionInfo = loc.getRegion();
if (regionInfo.getTable().getNameAsString().startsWith("hbase:")) return true;
if (regionInfo.isOffline() && !offlined) return true;
TableName table = regionInfo.getTable();
if (table.getNameAsString().startsWith("hbase:")) return true;
if (disabledTables.contains(table)) return true;
regions.put(regionInfo, loc.getServerName());
}
}
Expand All @@ -147,13 +162,19 @@ public boolean visitInternal(Result result) {

@SuppressWarnings("SortedCollectionWithNonComparableKeys")
public static NavigableMap<RegionInfo, ServerName> regionServerMap(Args args,
Admin admin, final Set<TableName> tableNames, final boolean offlined) throws IOException {
Admin admin, final Set<TableName> tableNames) throws IOException {
long timestamp = System.currentTimeMillis();

final NavigableMap<RegionInfo, ServerName> regions = new TreeMap<>();
if (tableNames.size() == 1) {
return regionServerMap(args, admin, tableNames.toArray(new TableName[1])[0], offlined);
return regionServerMap(args, admin, tableNames.toArray(new TableName[1])[0]);
} else if (tableNames.size() > 1) {
final Set<TableName> disableTables = new HashSet<>();
for (TableName tableName : tableNames) {
if (admin.isTableDisabled(tableName))
disableTables.add(tableName);
}

MetaTableAccessor.Visitor visitor = new MetaTableAccessor.DefaultVisitorBase() {
@Override
public boolean visitInternal(Result result) {
Expand All @@ -164,7 +185,7 @@ public boolean visitInternal(Result result) {
RegionInfo regionInfo = loc.getRegion();
TableName table = regionInfo.getTable();
if (table.getNameAsString().startsWith("hbase:")) return true;
if (regionInfo.isOffline() && !offlined) return true;
if (disableTables.contains(table)) return true;
if (tableNames.contains(table))
regions.put(regionInfo, loc.getServerName());
}
Expand All @@ -181,9 +202,10 @@ public boolean visitInternal(Result result) {

@SuppressWarnings("SortedCollectionWithNonComparableKeys")
private static NavigableMap<RegionInfo, ServerName> regionServerMap(Args args,
Admin admin, final TableName tableName, final boolean offlined) throws IOException {
Admin admin, final TableName tableName) throws IOException {
long timestamp = System.currentTimeMillis();

final boolean tableDisabled = admin.isTableDisabled(tableName);
final NavigableMap<RegionInfo, ServerName> regions = new TreeMap<>();
MetaTableAccessor.Visitor visitor = new MetaTableAccessor.TableVisitorBase(tableName) {
@Override
Expand All @@ -193,7 +215,7 @@ public boolean visitInternal(Result result) {
for (HRegionLocation loc : locations.getRegionLocations()) {
if (loc != null) {
RegionInfo regionInfo = loc.getRegion();
if (regionInfo.isOffline() && !offlined) return true;
if (tableDisabled) return true;
regions.put(regionInfo, loc.getServerName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ private void initializeRegionServerMap() throws Exception {

Set<TableName> tables = Args.tables(args, admin);
if (tables.isEmpty()) {
regionServerMap = CommandAdapter.regionServerMap(args, admin, false);
regionServerMap = CommandAdapter.regionServerMap(args, admin);
} else {
regionServerMap = CommandAdapter.regionServerMap(args, admin, tables, false);
regionServerMap = CommandAdapter.regionServerMap(args, admin, tables);
}
clean(regionServerMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.Test;

import java.util.Set;
import java.util.regex.Pattern;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -53,15 +52,11 @@ public void testDisableEnableDrop() throws Exception {
Assert.assertEquals(loadEntryLength, command.getLoad().getSummaryPrev().size());

// disable table
System.out.println(admin.listTableDescriptors(Pattern.compile(".*")));
admin.disableTable(tableName);
waitForDisabled(tableName);
System.out.println(admin.isTableDisabled(tableName));
System.out.println(admin.listTableDescriptors(Pattern.compile(".*")));

// iteration 3
command.run();
//fixme
Assert.assertEquals(0, command.getLoad().getLoadMap().size());
Assert.assertEquals(1, command.getLoad().getLoadMapPrev().size());
Assert.assertEquals(0, command.getLoad().getSummary().size());
Expand Down Expand Up @@ -107,7 +102,6 @@ public void testAllTables() throws Exception {
TableStat command = new TableStat(admin, new StatArgs(args));

// iteration 1
//fixme
command.run();
Assert.assertEquals(1, command.getLoad().getLoadMap().size());
Assert.assertEquals(0, command.getLoad().getLoadMapPrev().size());
Expand Down Expand Up @@ -149,7 +143,6 @@ public void testTableRegex() throws Exception {
waitForDisabled(tableName);

// iteration 2
//fixme
command.run();
Assert.assertEquals(1, command.getLoad().getLoadMap().size());
Assert.assertEquals(2, command.getLoad().getLoadMapPrev().size());
Expand Down

0 comments on commit 4cad231

Please sign in to comment.