diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index c1897cfac89..0ef788790f7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -99,6 +99,7 @@ import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException; import org.apache.hadoop.hbase.regionserver.wal.MetricsWAL; import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener; import org.apache.hadoop.hbase.security.User; +import org.apache.hadoop.hbase.security.visibility.VisibilityLabelsCache; import org.apache.hadoop.hbase.tool.Canary; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.FSTableDescriptors; @@ -3851,6 +3852,37 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { waitFor(timeout, predicateNoRegionsInTransition()); } + /** + * Wait until labels is ready in VisibilityLabelsCache. + * @param timeoutMillis + * @param labels + */ + public void waitLabelAvailable(long timeoutMillis, final String... labels) { + final VisibilityLabelsCache labelsCache = VisibilityLabelsCache.get(); + waitFor(timeoutMillis, new Waiter.ExplainingPredicate() { + + @Override + public boolean evaluate() { + for (String label : labels) { + if (labelsCache.getLabelOrdinal(label) == 0) { + return false; + } + } + return true; + } + + @Override + public String explainFailure() { + for (String label : labels) { + if (labelsCache.getLabelOrdinal(label) == 0) { + return label + " is not available yet"; + } + } + return ""; + } + }); + } + /** * Create a set of column descriptors with the combination of compression, * encoding, bloom codecs available. diff --git a/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.rb b/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.rb index 0815d83c015..47ac292d148 100644 --- a/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/visibility_labels_admin_test.rb @@ -54,6 +54,7 @@ module Hbase label = 'TEST_AUTHS' user = org.apache.hadoop.hbase.security.User.getCurrent().getName(); visibility_admin.add_labels(label) + $TEST_CLUSTER.waitLabelAvailable(10000, label) count = visibility_admin.get_auths(user).length # verifying the set functionality @@ -74,6 +75,7 @@ module Hbase label = 'TEST_VISIBILITY' user = org.apache.hadoop.hbase.security.User.getCurrent().getName(); visibility_admin.add_labels(label) + $TEST_CLUSTER.waitLabelAvailable(10000, label) visibility_admin.set_auths(user, label) # verifying put functionality