drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ar...@apache.org
Subject [12/12] drill git commit: DRILL-6208: Fix FunctionInitializerTest#testConcurrentFunctionBodyLoad to use Mockito instead of JMockit
Date Sun, 04 Mar 2018 17:13:52 GMT
DRILL-6208: Fix FunctionInitializerTest#testConcurrentFunctionBodyLoad to use Mockito instead
of JMockit

closes #1149


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/36159e22
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/36159e22
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/36159e22

Branch: refs/heads/master
Commit: 36159e2282153dbce52b8345d19e9bd95d67d377
Parents: 863ff0b
Author: Arina Ielchiieva <arina.yelchiyeva@gmail.com>
Authored: Sat Mar 3 21:00:50 2018 +0200
Committer: Arina Ielchiieva <arina.yelchiyeva@gmail.com>
Committed: Sun Mar 4 17:46:55 2018 +0200

----------------------------------------------------------------------
 .../drill/exec/expr/fn/FunctionInitializer.java |  5 +--
 .../exec/expr/fn/FunctionInitializerTest.java   | 33 ++++++++++----------
 2 files changed, 20 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/36159e22/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionInitializer.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionInitializer.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionInitializer.java
index 20b1d12..e9d98f2 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionInitializer.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionInitializer.java
@@ -17,13 +17,13 @@
  */
 package org.apache.drill.exec.expr.fn;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringReader;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.drill.common.exceptions.UserException;
 import org.apache.drill.common.util.DrillFileUtils;
 import org.codehaus.commons.compiler.CompileException;
@@ -126,7 +126,8 @@ public class FunctionInitializer {
    * @return compilation unit
    * @throws IOException if did not find class or could not load it
    */
-  private CompilationUnit convertToCompilationUnit(Class<?> clazz) throws IOException
{
+  @VisibleForTesting
+  CompilationUnit convertToCompilationUnit(Class<?> clazz) throws IOException {
     String path = clazz.getName();
     path = path.replaceFirst("\\$.*", "");
     path = path.replace(".", DrillFileUtils.SEPARATOR);

http://git-wip-us.apache.org/repos/asf/drill/blob/36159e22/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/FunctionInitializerTest.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/FunctionInitializerTest.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/FunctionInitializerTest.java
index c2d4bdb..edbd341 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/FunctionInitializerTest.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/FunctionInitializerTest.java
@@ -17,18 +17,17 @@
 package org.apache.drill.exec.expr.fn;
 
 import com.google.common.collect.Lists;
-import mockit.Invocation;
-import mockit.Mock;
-import mockit.MockUp;
-import mockit.integration.junit4.JMockit;
 import org.apache.drill.categories.SqlFunctionTest;
 import org.apache.drill.test.TestTools;
 import org.apache.drill.exec.util.JarUtil;
-import org.codehaus.janino.Java;
+import org.codehaus.janino.Java.CompilationUnit;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
 
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -45,9 +44,11 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.spy;
 
-
-@RunWith(JMockit.class)
+@RunWith(MockitoJUnitRunner.class)
 @Category(SqlFunctionTest.class)
 public class FunctionInitializerTest {
 
@@ -92,16 +93,16 @@ public class FunctionInitializerTest {
 
   @Test
   public void testConcurrentFunctionBodyLoad() throws Exception {
-    final FunctionInitializer functionInitializer = new FunctionInitializer(CLASS_NAME, classLoader);
-
+    final FunctionInitializer spyFunctionInitializer = spy(new FunctionInitializer(CLASS_NAME,
classLoader));
     final AtomicInteger counter = new AtomicInteger();
-    new MockUp<FunctionInitializer>() {
-      @Mock
-      Java.CompilationUnit convertToCompilationUnit(Invocation inv, Class<?> clazz)
{
+
+    doAnswer(new Answer<CompilationUnit>() {
+      @Override
+      public CompilationUnit answer(InvocationOnMock invocation) throws Throwable {
         counter.incrementAndGet();
-        return inv.proceed();
+        return (CompilationUnit) invocation.callRealMethod();
       }
-    };
+    }).when(spyFunctionInitializer).convertToCompilationUnit(any(Class.class));
 
     int threadsNumber = 5;
     ExecutorService executor = Executors.newFixedThreadPool(threadsNumber);
@@ -109,8 +110,8 @@ public class FunctionInitializerTest {
     try {
       List<Future<String>> results = executor.invokeAll(Collections.nCopies(threadsNumber,
new Callable<String>() {
         @Override
-        public String call() throws Exception {
-          return functionInitializer.getMethod("eval");
+        public String call() {
+          return spyFunctionInitializer.getMethod("eval");
         }
       }));
 


Mime
View raw message