Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,36 @@ public static void reset() {
public static void injectEdge(EnvironmentEdge edge) {
EnvironmentEdgeManager.injectEdge(edge);
}

private static final class PackageEnvironmentEdgeWrapper implements EnvironmentEdge {

private final EnvironmentEdge delegate;

private final String packageName;

PackageEnvironmentEdgeWrapper(EnvironmentEdge delegate, String packageName) {
this.delegate = delegate;
this.packageName = packageName;
}

@Override
public long currentTime() {
StackTraceElement[] elements = new Exception().getStackTrace();
// the first element is us, the second one is EnvironmentEdgeManager, so let's check the third
// one
if (elements.length > 2 && elements[2].getClassName().startsWith(packageName)) {
return delegate.currentTime();
} else {
return System.currentTimeMillis();
}
}
}

/**
* Inject a {@link EnvironmentEdge} which only takes effect when calling directly from the classes
* in the given package.
*/
public static void injectEdgeForPackage(EnvironmentEdge edge, String packageName) {
injectEdge(new PackageEnvironmentEdgeWrapper(edge, packageName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", true);
// disable stream slow monitor check, as in this test we inject our own EnvironmentEdge
TEST_UTIL.getConfiguration().setInt("hbase.regionserver.async.wal.min.slow.detect.count",
Integer.MAX_VALUE);
TEST_UTIL.startMiniCluster(2);
TEST_UTIL.waitTableAvailable(QuotaTableUtil.QUOTA_TABLE_NAME);
QuotaCache.TEST_FORCE_REFRESH = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public final class ThrottleQuotaTestUtil {
private final static int REFRESH_TIME = 30 * 60000;
static {
envEdge.setValue(EnvironmentEdgeManager.currentTime());
EnvironmentEdgeManagerTestHelper.injectEdge(envEdge);
// only active the envEdge for quotas package
EnvironmentEdgeManagerTestHelper.injectEdgeForPackage(envEdge,
ThrottleQuotaTestUtil.class.getPackage().getName());
}

private ThrottleQuotaTestUtil() {
Expand Down