agozhiy commented on a change in pull request #1910: DRILL-7393: Revisit Drill
tests to ensure that patching is executed b…
URL: https://github.com/apache/drill/pull/1910#discussion_r352359784
##########
File path: common/src/main/java/org/apache/drill/common/util/GuavaPatcher.java
##########
@@ -24,154 +24,157 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
-import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtMethod;
import javassist.CtNewMethod;
-import javassist.NotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GuavaPatcher {
private static final Logger logger =
LoggerFactory.getLogger(GuavaPatcher.class);
- private static boolean patched;
+ private static boolean patchingAttempted;
public static synchronized void patch() {
- if (!patched) {
- try {
- patchStopwatch();
- patchCloseables();
- patchPreconditions();
- patched = true;
- } catch (Throwable e) {
- logger.warn("Unable to patch Guava classes.", e);
- }
+ if (!patchingAttempted) {
+ patchingAttempted = true;
+ patchStopwatch();
+ patchCloseables();
+ patchPreconditions();
}
}
/**
* Makes Guava stopwatch look like the old version for compatibility with
hbase-server (for test purposes).
*/
- private static void patchStopwatch() throws Exception {
-
- ClassPool cp = ClassPool.getDefault();
- CtClass cc = cp.get("com.google.common.base.Stopwatch");
-
- // Expose the constructor for Stopwatch for old libraries who use the
pattern new Stopwatch().start().
- for (CtConstructor c : cc.getConstructors()) {
- if (!Modifier.isStatic(c.getModifiers())) {
- c.setModifiers(Modifier.PUBLIC);
+ private static void patchStopwatch() {
+ try {
+ ClassPool cp = ClassPool.getDefault();
+ CtClass cc = cp.get("com.google.common.base.Stopwatch");
+
+ // Expose the constructor for Stopwatch for old libraries who use the
pattern new Stopwatch().start().
+ for (CtConstructor c : cc.getConstructors()) {
+ if (!Modifier.isStatic(c.getModifiers())) {
+ c.setModifiers(Modifier.PUBLIC);
+ }
}
- }
- // Add back the Stopwatch.elapsedMillis() method for old consumers.
- CtMethod newMethod = CtNewMethod.make(
- "public long elapsedMillis() { return
elapsed(java.util.concurrent.TimeUnit.MILLISECONDS); }", cc);
- cc.addMethod(newMethod);
+ // Add back the Stopwatch.elapsedMillis() method for old consumers.
+ CtMethod newMethod = CtNewMethod.make(
+ "public long elapsedMillis() { return
elapsed(java.util.concurrent.TimeUnit.MILLISECONDS); }", cc);
+ cc.addMethod(newMethod);
- // Load the modified class instead of the original.
- cc.toClass();
+ // Load the modified class instead of the original.
+ cc.toClass();
- logger.info("Google's Stopwatch patched for old HBase Guava version.");
+ logger.info("Google's Stopwatch patched for old HBase Guava version.");
+ } catch (Exception e) {
+ logger.warn("Unable to patch Guava classes.", e);
Review comment:
I didn't change the behavior.
What do you suggest? Tests are executed by JUnit, so in case of an exception
they will fail just as well, but with a less clear message (because BaseTest
would fail to initialize).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services