diff options
author | Timothy Farkas <timothyfarkas@apache.org> | 2018-01-11 14:59:41 -0800 |
---|---|---|
committer | Arina Ielchiieva <arina.yelchiyeva@gmail.com> | 2018-01-26 13:42:27 +0200 |
commit | 186536d544d02ffc01339a4645e2a533545a2f86 (patch) | |
tree | 24ddcb013b243ee501d5dfa1d73eb9c0a1511510 /exec/java-exec/src/test/java | |
parent | 9926eda21c748e96d67bce341a76dac3114002af (diff) |
DRILL-5730: Mock testing improvements and interface improvements
closes #1045
Diffstat (limited to 'exec/java-exec/src/test/java')
65 files changed, 1489 insertions, 1735 deletions
diff --git a/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java b/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java index 8a8e8d234..472419aea 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java +++ b/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java @@ -20,9 +20,6 @@ package org.apache.drill; import java.io.IOException; import java.net.URL; -import mockit.Mocked; -import mockit.NonStrictExpectations; - import org.apache.calcite.jdbc.CalciteSchema; import org.apache.calcite.schema.SchemaPlus; import org.apache.drill.common.config.DrillConfig; @@ -58,16 +55,14 @@ import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.google.common.io.Resources; -public class PlanningBase extends ExecTest{ - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PlanningBase.class); +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +public class PlanningBase extends ExecTest { @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(10000); - @Mocked DrillbitContext dbContext; private final DrillConfig config = DrillConfig.create(); - @Mocked QueryContext context; - BufferAllocator allocator = RootAllocatorFactory.newRoot(config); protected void testSqlPlanFromFile(String file) throws Exception { @@ -75,6 +70,9 @@ public class PlanningBase extends ExecTest{ } protected void testSqlPlan(String sqlCommands) throws Exception { + final DrillbitContext dbContext = mock(DrillbitContext.class); + final QueryContext context = mock(QueryContext.class); + final String[] sqlStrings = sqlCommands.split(";"); final LocalPersistentStoreProvider provider = new LocalPersistentStoreProvider(config); provider.start(); @@ -84,28 +82,17 @@ public class PlanningBase extends ExecTest{ systemOptions.init(); @SuppressWarnings("resource") final UserSession userSession = UserSession.Builder.newBuilder().withOptionManager(systemOptions).build(); - final SessionOptionManager sessionOptions = (SessionOptionManager) userSession.getOptions(); + final SessionOptionManager sessionOptions = userSession.getOptions(); final QueryOptionManager queryOptions = new QueryOptionManager(sessionOptions); final ExecutionControls executionControls = new ExecutionControls(queryOptions, DrillbitEndpoint.getDefaultInstance()); - new NonStrictExpectations() { - { - dbContext.getMetrics(); - result = new MetricRegistry(); - dbContext.getAllocator(); - result = allocator; - dbContext.getConfig(); - result = config; - dbContext.getOptionManager(); - result = systemOptions; - dbContext.getStoreProvider(); - result = provider; - dbContext.getClasspathScan(); - result = scanResult; - dbContext.getLpPersistence(); - result = logicalPlanPersistence; - } - }; + when(dbContext.getMetrics()).thenReturn(new MetricRegistry()); + when(dbContext.getAllocator()).thenReturn(allocator); + when(dbContext.getConfig()).thenReturn(config); + when(dbContext.getOptionManager()).thenReturn(systemOptions); + when(dbContext.getStoreProvider()).thenReturn(provider); + when(dbContext.getClasspathScan()).thenReturn(scanResult); + when(dbContext.getLpPersistence()).thenReturn(logicalPlanPersistence); final StoragePluginRegistry registry = new StoragePluginRegistryImpl(dbContext); registry.init(); @@ -114,38 +101,20 @@ public class PlanningBase extends ExecTest{ final SchemaPlus root = CalciteSchema.createRootSchema(false, false).plus(); registry.getSchemaFactory().registerSchemas(SchemaConfig.newBuilder("foo", context).build(), root); - new NonStrictExpectations() { - { - context.getNewDefaultSchema(); - result = root; - context.getLpPersistence(); - result = new LogicalPlanPersistence(config, ClassPathScanner.fromPrescan(config)); - context.getStorage(); - result = registry; - context.getFunctionRegistry(); - result = functionRegistry; - context.getSession(); - result = UserSession.Builder.newBuilder().setSupportComplexTypes(true).build(); - context.getCurrentEndpoint(); - result = DrillbitEndpoint.getDefaultInstance(); - context.getActiveEndpoints(); - result = ImmutableList.of(DrillbitEndpoint.getDefaultInstance()); - context.getPlannerSettings(); - result = new PlannerSettings(queryOptions, functionRegistry); - context.getOptions(); - result = queryOptions; - context.getConfig(); - result = config; - context.getDrillOperatorTable(); - result = table; - context.getAllocator(); - result = allocator; - context.getExecutionControls(); - result = executionControls; - dbContext.getLpPersistence(); - result = logicalPlanPersistence; - } - }; + when(context.getNewDefaultSchema()).thenReturn(root); + when(context.getLpPersistence()).thenReturn(new LogicalPlanPersistence(config, ClassPathScanner.fromPrescan(config))); + when(context.getStorage()).thenReturn(registry); + when(context.getFunctionRegistry()).thenReturn(functionRegistry); + when(context.getSession()).thenReturn(UserSession.Builder.newBuilder().setSupportComplexTypes(true).build()); + when(context.getCurrentEndpoint()).thenReturn(DrillbitEndpoint.getDefaultInstance()); + when(context.getActiveEndpoints()).thenReturn(ImmutableList.of(DrillbitEndpoint.getDefaultInstance())); + when(context.getPlannerSettings()).thenReturn(new PlannerSettings(queryOptions, functionRegistry)); + when(context.getOptions()).thenReturn(queryOptions); + when(context.getConfig()).thenReturn(config); + when(context.getDrillOperatorTable()).thenReturn(table); + when(context.getAllocator()).thenReturn(allocator); + when(context.getExecutionControls()).thenReturn(executionControls); + when(context.getLpPersistence()).thenReturn(logicalPlanPersistence); for (final String sql : sqlStrings) { if (sql.trim().isEmpty()) { diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestDynamicUDFSupport.java b/exec/java-exec/src/test/java/org/apache/drill/TestDynamicUDFSupport.java index 0786b6684..d68dc0d96 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/TestDynamicUDFSupport.java +++ b/exec/java-exec/src/test/java/org/apache/drill/TestDynamicUDFSupport.java @@ -18,9 +18,9 @@ package org.apache.drill; import com.google.common.collect.Lists; -import mockit.Deencapsulation; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.drill.categories.SlowTest; import org.apache.drill.categories.SqlFunctionTest; import org.apache.drill.common.config.CommonConstants; @@ -481,8 +481,8 @@ public class TestDynamicUDFSupport extends BaseTestQuery { .baselineValues("a") .go(); - Path localUdfDirPath = hadoopToJavaPath((org.apache.hadoop.fs.Path) Deencapsulation.getField( - getDrillbitContext().getFunctionImplementationRegistry(), "localUdfDir")); + Path localUdfDirPath = hadoopToJavaPath((org.apache.hadoop.fs.Path)FieldUtils.readField( + getDrillbitContext().getFunctionImplementationRegistry(), "localUdfDir", true)); assertTrue("Binary should exist in local udf directory", localUdfDirPath.resolve(default_binary_name).toFile().exists()); @@ -548,8 +548,8 @@ public class TestDynamicUDFSupport extends BaseTestQuery { test("create function using jar '%s'", default_binary_name); test("select custom_lower('A') from (values(1))"); - Path localUdfDirPath = hadoopToJavaPath((org.apache.hadoop.fs.Path)Deencapsulation.getField( - getDrillbitContext().getFunctionImplementationRegistry(), "localUdfDir")); + Path localUdfDirPath = hadoopToJavaPath((org.apache.hadoop.fs.Path)FieldUtils.readField( + getDrillbitContext().getFunctionImplementationRegistry(), "localUdfDir", true)); assertTrue("Binary should exist in local udf directory", localUdfDirPath.resolve(default_binary_name).toFile().exists()); @@ -896,8 +896,8 @@ public class TestDynamicUDFSupport extends BaseTestQuery { thread2.join(); verify(functionImplementationRegistry, times(2)).syncWithRemoteRegistry(anyLong()); - LocalFunctionRegistry localFunctionRegistry = Deencapsulation.getField( - functionImplementationRegistry, "localFunctionRegistry"); + LocalFunctionRegistry localFunctionRegistry = (LocalFunctionRegistry)FieldUtils.readField( + functionImplementationRegistry, "localFunctionRegistry", true); assertEquals("Sync function registry version should match", 1L, localFunctionRegistry.getVersion()); } @@ -934,8 +934,8 @@ public class TestDynamicUDFSupport extends BaseTestQuery { } verify(functionImplementationRegistry, times(2)).syncWithRemoteRegistry(anyLong()); - LocalFunctionRegistry localFunctionRegistry = Deencapsulation.getField( - functionImplementationRegistry, "localFunctionRegistry"); + LocalFunctionRegistry localFunctionRegistry = (LocalFunctionRegistry)FieldUtils.readField( + functionImplementationRegistry, "localFunctionRegistry", true); assertEquals("Sync function registry version should match", 1L, localFunctionRegistry.getVersion()); } @@ -962,19 +962,19 @@ public class TestDynamicUDFSupport extends BaseTestQuery { FileUtils.copyFile(src.resolve(name).toFile(), destFile); } - private RemoteFunctionRegistry spyRemoteFunctionRegistry() { + private RemoteFunctionRegistry spyRemoteFunctionRegistry() throws IllegalAccessException { FunctionImplementationRegistry functionImplementationRegistry = getDrillbitContext().getFunctionImplementationRegistry(); RemoteFunctionRegistry remoteFunctionRegistry = functionImplementationRegistry.getRemoteFunctionRegistry(); RemoteFunctionRegistry spy = spy(remoteFunctionRegistry); - Deencapsulation.setField(functionImplementationRegistry, "remoteFunctionRegistry", spy); + FieldUtils.writeField(functionImplementationRegistry, "remoteFunctionRegistry", spy, true); return spy; } - private FunctionImplementationRegistry spyFunctionImplementationRegistry() { + private FunctionImplementationRegistry spyFunctionImplementationRegistry() throws IllegalAccessException { DrillbitContext drillbitContext = getDrillbitContext(); FunctionImplementationRegistry spy = spy(drillbitContext.getFunctionImplementationRegistry()); - Deencapsulation.setField(drillbitContext, "functionRegistry", spy); + FieldUtils.writeField(drillbitContext, "functionRegistry", spy, true); return spy; } @@ -1013,5 +1013,4 @@ public class TestDynamicUDFSupport extends BaseTestQuery { } } } - } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/ExecTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/ExecTest.java index e60533ba0..fe8bbb69d 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/ExecTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/ExecTest.java @@ -18,9 +18,9 @@ package org.apache.drill.exec; import com.codahale.metrics.MetricRegistry; +import com.google.common.io.Files; import mockit.Mock; import mockit.MockUp; -import mockit.NonStrictExpectations; import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; @@ -48,10 +48,13 @@ import org.junit.After; import org.junit.BeforeClass; import org.junit.ClassRule; +import java.io.File; import java.io.IOException; import java.text.DateFormatSymbols; import java.util.Locale; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class ExecTest extends DrillTest { @@ -91,15 +94,28 @@ public class ExecTest extends DrillTest { return FileSystem.get(configuration); } - protected void mockDrillbitContext(final DrillbitContext bitContext) throws Exception { - new NonStrictExpectations() {{ - bitContext.getMetrics(); result = new MetricRegistry(); - bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c); - bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(ClassPathScanner.fromPrescan(c)); - bitContext.getConfig(); result = c; - bitContext.getOptionManager(); result = optionManager; - bitContext.getCompiler(); result = CodeCompilerTestFactory.getTestCompiler(c); - }}; + /** + * Create a temp directory to store the given <i>dirName</i>. + * Directory will be deleted on exit. + * @param dirName directory name + * @return Full path including temp parent directory and given directory name. + */ + public static String getTempDir(final String dirName) { + final File dir = Files.createTempDir(); + return dir.getAbsolutePath() + File.separator + dirName; + } + + protected DrillbitContext mockDrillbitContext() throws Exception { + final DrillbitContext context = mock(DrillbitContext.class); + + when(context.getMetrics()).thenReturn(new MetricRegistry()); + when(context.getAllocator()).thenReturn(RootAllocatorFactory.newRoot(c)); + when(context.getOperatorCreatorRegistry()).thenReturn(new OperatorCreatorRegistry(ClassPathScanner.fromPrescan(c))); + when(context.getConfig()).thenReturn(c); + when(context.getOptionManager()).thenReturn(optionManager); + when(context.getCompiler()).thenReturn(CodeCompilerTestFactory.getTestCompiler(c)); + + return context; } protected LogicalExpression parseExpr(String expr) throws RecognitionException { diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/RunRootExec.java b/exec/java-exec/src/test/java/org/apache/drill/exec/RunRootExec.java index 8d6cc0cb8..a3fd2e746 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/RunRootExec.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/RunRootExec.java @@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.scanner.ClassPathScanner; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -52,7 +52,7 @@ public class RunRootExec { PhysicalPlanReader reader = bitContext.getPlanReader(); PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(new File(path), Charsets.UTF_8)); FunctionImplementationRegistry registry = bitContext.getFunctionImplementationRegistry(); - FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), null, registry); + FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), null, registry); SimpleRootExec exec; for (int i = 0; i < iterations; i ++) { Stopwatch w = Stopwatch.createStarted(); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java index 63957f4e4..8aba833e9 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/client/DumpCatTest.java @@ -27,7 +27,7 @@ import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -46,7 +46,7 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; +import org.mockito.Mockito; /** * The unit test case will read a physical plan in json format. The physical plan contains a "trace" operator, @@ -54,28 +54,27 @@ import mockit.Injectable; */ public class DumpCatTest extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DumpCatTest.class); private final DrillConfig c = DrillConfig.create(); @Test - public void testDumpCat(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable + public void testDumpCat() throws Throwable { - - mockDrillbitContext(bitContext); + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/trace/simple_trace.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { } - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); exec.close(); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java index fbbb4c828..a5a53895b 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/ExpressionTest.java @@ -18,10 +18,9 @@ package org.apache.drill.exec.expr; import static org.junit.Assert.assertEquals; -import mockit.Expectations; -import mockit.Injectable; -import mockit.NonStrict; -import mockit.NonStrictExpectations; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.exceptions.ExpressionParsingException; @@ -42,7 +41,6 @@ import org.apache.drill.exec.record.RecordBatch; import org.apache.drill.exec.record.TypedFieldId; import org.apache.drill.exec.record.VectorWrapper; import org.apache.drill.exec.vector.IntVector; -import org.apache.drill.exec.vector.ValueVector; import org.junit.Test; public class ExpressionTest extends ExecTest { @@ -52,68 +50,61 @@ public class ExpressionTest extends ExecTest { private final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); @Test - public void testBasicExpression(@Injectable RecordBatch batch) throws Exception { - System.out.println(getExpressionCode("if(true) then 1 else 0 end", batch)); + public void testBasicExpression() throws Exception { + System.out.println(getExpressionCode("if(true) then 1 else 0 end")); } @Test - public void testExprParseUpperExponent(@Injectable RecordBatch batch) throws Exception { - getExpressionCode("multiply(`$f0`, 1.0E-4)", batch); + public void testExprParseUpperExponent() throws Exception { + getExpressionCode("multiply(`$f0`, 1.0E-4)"); } @Test - public void testExprParseLowerExponent(@Injectable RecordBatch batch) throws Exception { - getExpressionCode("multiply(`$f0`, 1.0e-4)", batch); + public void testExprParseLowerExponent() throws Exception { + getExpressionCode("multiply(`$f0`, 1.0e-4)"); } @Test - public void testSpecial(final @Injectable RecordBatch batch, @Injectable ValueVector vector) throws Exception { + public void testSpecial() throws Exception { + final RecordBatch batch = mock(RecordBatch.class); + final VectorWrapper wrapper = mock(VectorWrapper.class); final TypeProtos.MajorType type = Types.optional(MinorType.INT); final TypedFieldId tfid = new TypedFieldId(type, false, 0); - new NonStrictExpectations() { - @NonStrict VectorWrapper<?> wrapper; - { - batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN)); - result = tfid; - batch.getValueAccessorById(IntVector.class, tfid.getFieldIds()); - result = wrapper; - wrapper.getValueVector(); - result = new IntVector(MaterializedField.create("result", type), RootAllocatorFactory.newRoot(c)); - } - - }; + when(wrapper.getValueVector()).thenReturn(new IntVector(MaterializedField.create("result", type), RootAllocatorFactory.newRoot(c))); + + when(batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN))).thenReturn(tfid); + when(batch.getValueAccessorById(IntVector.class, tfid.getFieldIds())).thenReturn(wrapper); + System.out.println(getExpressionCode("1 + 1", batch)); } @Test - public void testSchemaExpression(final @Injectable RecordBatch batch) throws Exception { - final TypedFieldId tfid = new TypedFieldId(Types.optional(MinorType.BIGINT), false, 0); - - new Expectations() { - { - batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN)); - result = tfid; - // batch.getValueVectorById(tfid); result = new Fixed4(null, null); - } + public void testSchemaExpression() throws Exception { + final RecordBatch batch = mock(RecordBatch.class); + when(batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN))) + .thenReturn(new TypedFieldId(Types.optional(MinorType.BIGINT), false, 0)); - }; System.out.println(getExpressionCode("1 + alpha", batch)); - } @Test(expected = ExpressionParsingException.class) - public void testExprParseError(@Injectable RecordBatch batch) throws Exception { - getExpressionCode("less than(1, 2)", batch); + public void testExprParseError() throws Exception { + getExpressionCode("less than(1, 2)"); } @Test - public void testExprParseNoError(@Injectable RecordBatch batch) throws Exception { - getExpressionCode("equal(1, 2)", batch); + public void testExprParseNoError() throws Exception { + getExpressionCode("equal(1, 2)"); } // HELPER METHODS // + private String getExpressionCode(String expression) throws Exception { + final RecordBatch batch = mock(RecordBatch.class); + return getExpressionCode(expression, batch); + } + private String getExpressionCode(String expression, RecordBatch batch) throws Exception { final LogicalExpression expr = parseExpr(expression); final ErrorCollector error = new ErrorCollectorImpl(); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java index 56181e6df..31d3d919d 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/expr/fn/impl/TestStringFunctions.java @@ -19,7 +19,6 @@ package org.apache.drill.exec.expr.fn.impl; import static org.junit.Assert.assertTrue; -import mockit.integration.junit4.JMockit; import org.apache.drill.categories.UnlikelyTest; import org.apache.drill.test.BaseTestQuery; import org.apache.drill.categories.SqlFunctionTest; @@ -29,13 +28,11 @@ import org.junit.Test; import com.google.common.collect.ImmutableList; import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; -@RunWith(JMockit.class) @Category({SqlFunctionTest.class, UnlikelyTest.class}) public class TestStringFunctions extends BaseTestQuery { diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java index 5a853193e..ffaa9e953 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMathFunctions.java @@ -28,7 +28,7 @@ import org.apache.drill.common.expression.SchemaPath; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -45,23 +45,23 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category(OperatorTest.class) public class TestMathFunctions extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMathFunctions.class); private final DrillConfig c = DrillConfig.create(); @Test - public void testBasicMathFunctions(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable + public void testBasicMathFunctions() throws Throwable { - mockDrillbitContext(bitContext); + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/simple_math_functions.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -76,9 +76,9 @@ public class TestMathFunctions extends ExecTest { assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0); } - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMultiInputAdd.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMultiInputAdd.java index 237b01a82..472c76a46 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMultiInputAdd.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestMultiInputAdd.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * <p> * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,8 +22,6 @@ import static org.junit.Assert.assertTrue; import java.util.List; -import mockit.Injectable; - import org.apache.drill.categories.OperatorTest; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.DrillFileUtils; @@ -32,9 +30,7 @@ import org.apache.drill.exec.pop.PopUnitTestBase; import org.apache.drill.exec.record.RecordBatchLoader; import org.apache.drill.exec.record.VectorWrapper; import org.apache.drill.exec.rpc.user.QueryDataBatch; -import org.apache.drill.exec.rpc.UserClientConnection; import org.apache.drill.exec.server.Drillbit; -import org.apache.drill.exec.server.DrillbitContext; import org.apache.drill.exec.server.RemoteServiceSet; import org.apache.drill.exec.vector.ValueVector; import org.junit.Test; @@ -45,41 +41,35 @@ import org.junit.experimental.categories.Category; @Category(OperatorTest.class) public class TestMultiInputAdd extends PopUnitTestBase { + private final DrillConfig c = DrillConfig.create(); -// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMathFunctions.class); - - DrillConfig c = DrillConfig.create(); - - - @Test - public void testMultiInputAdd(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable - { - try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); - Drillbit bit = new Drillbit(CONFIG, serviceSet); - DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) { - - // run query. - bit.run(); - client.connect(); - List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, - Files.toString(DrillFileUtils.getResourceAsFile("/functions/multi_input_add_test.json"), Charsets.UTF_8)); + @Test + public void testMultiInputAdd() throws Throwable { + try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); + Drillbit bit = new Drillbit(CONFIG, serviceSet); + DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) { + // run query. + bit.run(); + client.connect(); + List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, + Files.toString(DrillFileUtils.getResourceAsFile("/functions/multi_input_add_test.json"), Charsets.UTF_8)); - RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator()); + RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator()); - QueryDataBatch batch = results.get(0); - assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData())); + QueryDataBatch batch = results.get(0); + assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData())); - for (VectorWrapper<?> v : batchLoader) { + for (VectorWrapper<?> v : batchLoader) { - ValueVector.Accessor accessor = v.getValueVector().getAccessor(); + ValueVector.Accessor accessor = v.getValueVector().getAccessor(); - assertTrue((accessor.getObject(0)).equals(10)); - } + assertTrue((accessor.getObject(0)).equals(10)); + } - batchLoader.clear(); - for(QueryDataBatch b : results){ - b.release(); - } - } + batchLoader.clear(); + for (QueryDataBatch b : results) { + b.release(); + } } + } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java index 8862f8ca8..59188d459 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestNewMathFunctions.java @@ -28,7 +28,7 @@ import org.apache.drill.categories.UnlikelyTest; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -45,16 +45,15 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Resources; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category({UnlikelyTest.class, OperatorTest.class}) public class TestNewMathFunctions extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestNewMathFunctions.class); private final DrillConfig c = DrillConfig.create(); private PhysicalPlanReader reader; private FunctionImplementationRegistry registry; - private FragmentContext context; + private FragmentContextImpl context; public Object[] getRunResult(SimpleRootExec exec) { int size = 0; @@ -74,9 +73,10 @@ public class TestNewMathFunctions extends ExecTest { return res; } - public void runTest(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable { - mockDrillbitContext(bitContext); + public void runTest(Object[] expectedResults, String planPath) throws Throwable { + + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8); if (reader == null) { @@ -86,7 +86,7 @@ public class TestNewMathFunctions extends ExecTest { registry = new FunctionImplementationRegistry(c); } if (context == null) { - context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); //new FragmentContext(bitContext, ExecProtos.FragmentHandle.getDefaultInstance(), connection, registry); + context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); } final PhysicalPlan plan = reader.readPhysicalPlan(planString); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); @@ -101,40 +101,36 @@ public class TestNewMathFunctions extends ExecTest { } } - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void testTrigoMathFunc(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testTrigoMathFunc() throws Throwable { final Object [] expected = new Object[] {Math.sin(45), Math.cos(45), Math.tan(45),Math.asin(45), Math.acos(45), Math.atan(45),Math.sinh(45), Math.cosh(45), Math.tanh(45)}; - runTest(bitContext, connection, expected, "functions/testTrigoMathFunctions.json"); + runTest(expected, "functions/testTrigoMathFunctions.json"); } @Test - public void testExtendedMathFunc(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testExtendedMathFunc() throws Throwable { final BigDecimal d = new BigDecimal("100111111111111111111111111111111111.00000000000000000000000000000000000000000000000000001"); final Object [] expected = new Object[] {Math.cbrt(1000), Math.log(10), (Math.log(64.0)/Math.log(2.0)), Math.exp(10), Math.toDegrees(0.5), Math.toRadians(45.0), Math.PI, Math.cbrt(d.doubleValue()), Math.log(d.doubleValue()), (Math.log(d.doubleValue())/Math.log(2)), Math.exp(d.doubleValue()), Math.toDegrees(d.doubleValue()), Math.toRadians(d.doubleValue())}; - runTest(bitContext, connection, expected, "functions/testExtendedMathFunctions.json"); + runTest(expected, "functions/testExtendedMathFunctions.json"); } @Test - public void testTruncDivMod(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable{ + public void testTruncDivMod() throws Throwable{ final Object [] expected = new Object[] {101.0, 0, 101, 1010.0, 101, 481.0, 0.001099999999931267}; - runTest(bitContext, connection, expected, "functions/testDivModTruncFunctions.json"); + runTest(expected, "functions/testDivModTruncFunctions.json"); } @Test - public void testIsNumeric(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable{ + public void testIsNumeric() throws Throwable{ final Object [] expected = new Object[] {1, 1, 1, 0}; - runTest(bitContext, connection, expected, "functions/testIsNumericFunction.json"); + runTest(expected, "functions/testIsNumericFunction.json"); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java index fedd30aa8..952a1a396 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/impl/TestRepeatedFunction.java @@ -27,7 +27,7 @@ import org.apache.drill.common.expression.SchemaPath; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -44,23 +44,22 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category(OperatorTest.class) -public class TestRepeatedFunction extends ExecTest{ - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestRepeatedFunction.class); +public class TestRepeatedFunction extends ExecTest { private final DrillConfig c = DrillConfig.create(); @Test - public void testRepeated(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { -// System.out.println(System.getProperty("java.class.path")); - mockDrillbitContext(bitContext); + public void testRepeated() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/physical_repeated_1.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); boolean oneIsOne = false; @@ -93,9 +92,9 @@ public class TestRepeatedFunction extends ExecTest{ } } - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java index eaf5e02db..493a3b66f 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/fn/interp/ExpressionInterpreterTest.java @@ -35,7 +35,7 @@ import org.apache.drill.exec.expr.ExpressionTreeMaterializer; import org.apache.drill.exec.expr.TypeHelper; import org.apache.drill.exec.expr.fn.interpreter.InterpreterEvaluator; import org.apache.drill.exec.expr.holders.TimeStampHolder; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.impl.ScanBatch; import org.apache.drill.exec.pop.PopUnitTestBase; import org.apache.drill.exec.proto.BitControl; @@ -198,9 +198,9 @@ public class ExpressionInterpreterTest extends PopUnitTestBase { final MockScanBatchCreator creator = new MockScanBatchCreator(); try { - final FragmentContext context = - new FragmentContext(bit.getContext(), planFragment, null, bit.getContext().getFunctionImplementationRegistry()); - return (ScanBatch) creator.getBatch(context, scanPOP, children); + final FragmentContextImpl context = + new FragmentContextImpl(bit.getContext(), planFragment, null, bit.getContext().getFunctionImplementationRegistry()); + return creator.getBatch(context,scanPOP, children); } catch (Exception ex) { throw new DrillRuntimeException("Error when setup fragment context" + ex); } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/impersonation/TestInboundImpersonation.java b/exec/java-exec/src/test/java/org/apache/drill/exec/impersonation/TestInboundImpersonation.java index ee57ad949..aa92b08e6 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/impersonation/TestInboundImpersonation.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/impersonation/TestInboundImpersonation.java @@ -66,8 +66,7 @@ public class TestInboundImpersonation extends BaseTestImpersonation { .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)) .withValue(ExecConstants.IMPERSONATION_ENABLED, - ConfigValueFactory.fromAnyRef(true)), - false); + ConfigValueFactory.fromAnyRef(true))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestAllocators.java b/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestAllocators.java index e903166d2..b4a655cef 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestAllocators.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/memory/TestAllocators.java @@ -33,7 +33,7 @@ import org.apache.drill.common.types.TypeProtos; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.exception.OutOfMemoryException; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.ops.OpProfileDef; import org.apache.drill.exec.ops.OperatorContext; import org.apache.drill.exec.ops.OperatorStats; @@ -198,8 +198,8 @@ public class TestAllocators extends DrillTest { pfBuilder2.setMemInitial(500000); BitControl.PlanFragment pf2 = pfBuilder1.build(); - FragmentContext fragmentContext1 = new FragmentContext(bitContext, pf1, null, functionRegistry); - FragmentContext fragmentContext2 = new FragmentContext(bitContext, pf2, null, functionRegistry); + FragmentContextImpl fragmentContext1 = new FragmentContextImpl(bitContext, pf1, null, functionRegistry); + FragmentContextImpl fragmentContext2 = new FragmentContextImpl(bitContext, pf2, null, functionRegistry); // Get a few physical operators. Easiest way is to read a physical plan. PhysicalPlanReader planReader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(bitContext, @@ -246,7 +246,7 @@ public class TestAllocators extends DrillTest { pfBuilder3.setMemInitial(1000000); BitControl.PlanFragment pf3 = pfBuilder3.build(); - FragmentContext fragmentContext3 = new FragmentContext(bitContext, pf3, null, functionRegistry); + FragmentContextImpl fragmentContext3 = new FragmentContextImpl(bitContext, pf3, null, functionRegistry); // New fragment starts an operator that allocates an amount within the limit def = new OpProfileDef(physicalOperator5.getOperatorId(), UserBitShared.CoreOperatorType.UNION_VALUE, diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/SimpleRootExec.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/SimpleRootExec.java index 42d2193f5..da3a6d80e 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/SimpleRootExec.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/SimpleRootExec.java @@ -23,7 +23,7 @@ import java.util.List; import org.apache.drill.common.DeferredException; import org.apache.drill.common.expression.SchemaPath; import org.apache.drill.exec.ops.FragmentContext; -import org.apache.drill.exec.ops.FragmentContext.ExecutorState; +import org.apache.drill.exec.ops.RootFragmentContext; import org.apache.drill.exec.physical.impl.ScreenCreator.ScreenRoot; import org.apache.drill.exec.proto.ExecProtos.FragmentHandle; import org.apache.drill.exec.record.RecordBatch; @@ -37,8 +37,6 @@ import com.google.common.collect.Lists; @Deprecated public class SimpleRootExec implements RootExec, Iterable<ValueVector> { -// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SimpleRootExec.class); - private final RecordBatch incoming; private final ScreenRoot screenRoot; @@ -49,10 +47,11 @@ public class SimpleRootExec implements RootExec, Iterable<ValueVector> { } else { throw new UnsupportedOperationException(); } - incoming.getContext().setExecutorState(new DummyExecutorState()); + + screenRoot.getContext().setExecutorState(new DummyExecutorState()); } - private class DummyExecutorState implements ExecutorState { + private class DummyExecutorState implements FragmentContext.ExecutorState { final DeferredException ex = new DeferredException(); @Override @@ -77,9 +76,8 @@ public class SimpleRootExec implements RootExec, Iterable<ValueVector> { } - - public FragmentContext getContext() { - return incoming.getContext(); + public RootFragmentContext getContext() { + return screenRoot.getContext(); } public SelectionVector2 getSelectionVector2() { diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestCastFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestCastFunctions.java index 11f739d15..96d2944db 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestCastFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestCastFunctions.java @@ -34,7 +34,7 @@ import org.apache.drill.exec.expr.holders.Float8Holder; import org.apache.drill.exec.expr.holders.IntHolder; import org.apache.drill.exec.expr.holders.VarBinaryHolder; import org.apache.drill.exec.expr.holders.VarCharHolder; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.planner.PhysicalPlanReader; @@ -60,20 +60,19 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; +import org.mockito.Mockito; public class TestCastFunctions extends PopUnitTestBase { @Test // cast to bigint. - public void testCastBigInt(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - - mockDrillbitContext(bitContext); + public void testCastBigInt() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastBigInt.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -95,23 +94,22 @@ public class TestCastFunctions extends PopUnitTestBase { context.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test //cast to int - public void testCastInt(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - - mockDrillbitContext(bitContext); + public void testCastInt() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastInt.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -132,22 +130,22 @@ public class TestCastFunctions extends PopUnitTestBase { context.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test //cast to float4 - public void testCastFloat4(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testCastFloat4() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastFloat4.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -169,22 +167,22 @@ public class TestCastFunctions extends PopUnitTestBase { context.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test //cast to float8 - public void testCastFloat8(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testCastFloat8() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastFloat8.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -206,22 +204,22 @@ public class TestCastFunctions extends PopUnitTestBase { context.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test //cast to varchar(length) - public void testCastVarChar(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testCastVarChar() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastVarChar.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -242,22 +240,22 @@ public class TestCastFunctions extends PopUnitTestBase { context.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test //cast to varbinary(length) - public void testCastVarBinary(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testCastVarBinary() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastVarBinary.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -278,23 +276,22 @@ public class TestCastFunctions extends PopUnitTestBase { context.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test //nested: cast is nested in another cast, or another function. - public void testCastNested(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - - mockDrillbitContext(bitContext); + public void testCastNested() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastNested.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -315,24 +312,23 @@ public class TestCastFunctions extends PopUnitTestBase { context.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test(expected = NumberFormatException.class) - public void testCastNumException(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - - mockDrillbitContext(bitContext); + public void testCastNumException() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/cast/testCastNumException.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -342,10 +338,10 @@ public class TestCastFunctions extends PopUnitTestBase { context.close(); - assertTrue(context.isFailed()); + assertTrue(context.getExecutorState().isFailed()); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java index b26e0cfbe..010acbd87 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestComparisonFunctions.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertTrue; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.planner.PhysicalPlanReader; @@ -36,19 +36,17 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Resources; -import mockit.Injectable; +import org.mockito.Mockito; public class TestComparisonFunctions extends ExecTest { -// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestComparisonFunctions.class); - private final DrillConfig c = DrillConfig.create(); private final String COMPARISON_TEST_PHYSICAL_PLAN = "functions/comparisonTest.json"; private PhysicalPlanReader reader; private FunctionImplementationRegistry registry; - public void runTest(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection, String expression, int expectedResults) throws Throwable { - mockDrillbitContext(bitContext); + public void runTest(String expression, int expectedResults) throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final String planString = Resources.toString(Resources.getResource(COMPARISON_TEST_PHYSICAL_PLAN), Charsets.UTF_8).replaceAll("EXPRESSION", expression); if (reader == null) { @@ -57,92 +55,83 @@ public class TestComparisonFunctions extends ExecTest { if (registry == null) { registry = new FunctionImplementationRegistry(c); } - final FragmentContext context = - new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = + new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final PhysicalPlan plan = reader.readPhysicalPlan(planString); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { assertEquals(String.format("Expression: %s;", expression), expectedResults, exec.getSelectionVector2().getCount()); -// for (ValueVector vv: exec) { -// vv.close(); -// } } exec.close(); context.close(); - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void testInt(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - runTest(bitContext, connection, "intColumn == intColumn", 100); - runTest(bitContext, connection, "intColumn != intColumn", 0); - runTest(bitContext, connection, "intColumn > intColumn", 0); - runTest(bitContext, connection, "intColumn < intColumn", 0); - runTest(bitContext, connection, "intColumn >= intColumn", 100); - runTest(bitContext, connection, "intColumn <= intColumn", 100); + public void testInt() throws Throwable { + runTest("intColumn == intColumn", 100); + runTest("intColumn != intColumn", 0); + runTest("intColumn > intColumn", 0); + runTest("intColumn < intColumn", 0); + runTest("intColumn >= intColumn", 100); + runTest("intColumn <= intColumn", 100); } @Test - public void testBigInt(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - runTest(bitContext, connection, "bigIntColumn == bigIntColumn", 100); - runTest(bitContext, connection, "bigIntColumn != bigIntColumn", 0); - runTest(bitContext, connection, "bigIntColumn > bigIntColumn", 0); - runTest(bitContext, connection, "bigIntColumn < bigIntColumn", 0); - runTest(bitContext, connection, "bigIntColumn >= bigIntColumn", 100); - runTest(bitContext, connection, "bigIntColumn <= bigIntColumn", 100); + public void testBigInt() throws Throwable { + runTest("bigIntColumn == bigIntColumn", 100); + runTest("bigIntColumn != bigIntColumn", 0); + runTest("bigIntColumn > bigIntColumn", 0); + runTest("bigIntColumn < bigIntColumn", 0); + runTest("bigIntColumn >= bigIntColumn", 100); + runTest("bigIntColumn <= bigIntColumn", 100); } @Test - public void testFloat4(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - runTest(bitContext, connection, "float4Column == float4Column", 100); - runTest(bitContext, connection, "float4Column != float4Column", 0); - runTest(bitContext, connection, "float4Column > float4Column", 0); - runTest(bitContext, connection, "float4Column < float4Column", 0); - runTest(bitContext, connection, "float4Column >= float4Column", 100); - runTest(bitContext, connection, "float4Column <= float4Column", 100); + public void testFloat4() throws Throwable { + runTest("float4Column == float4Column", 100); + runTest("float4Column != float4Column", 0); + runTest("float4Column > float4Column", 0); + runTest("float4Column < float4Column", 0); + runTest("float4Column >= float4Column", 100); + runTest("float4Column <= float4Column", 100); } @Test - public void testFloat8(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - runTest(bitContext, connection, "float8Column == float8Column", 100); - runTest(bitContext, connection, "float8Column != float8Column", 0); - runTest(bitContext, connection, "float8Column > float8Column", 0); - runTest(bitContext, connection, "float8Column < float8Column", 0); - runTest(bitContext, connection, "float8Column >= float8Column", 100); - runTest(bitContext, connection, "float8Column <= float8Column", 100); + public void testFloat8() throws Throwable { + runTest("float8Column == float8Column", 100); + runTest("float8Column != float8Column", 0); + runTest("float8Column > float8Column", 0); + runTest("float8Column < float8Column", 0); + runTest("float8Column >= float8Column", 100); + runTest("float8Column <= float8Column", 100); } @Test - public void testIntNullable(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - runTest(bitContext, connection, "intNullableColumn == intNullableColumn", 50); - runTest(bitContext, connection, "intNullableColumn != intNullableColumn", 0); - runTest(bitContext, connection, "intNullableColumn > intNullableColumn", 0); - runTest(bitContext, connection, "intNullableColumn < intNullableColumn", 0); - runTest(bitContext, connection, "intNullableColumn >= intNullableColumn", 50); - runTest(bitContext, connection, "intNullableColumn <= intNullableColumn", 50); + public void testIntNullable() throws Throwable { + runTest("intNullableColumn == intNullableColumn", 50); + runTest("intNullableColumn != intNullableColumn", 0); + runTest("intNullableColumn > intNullableColumn", 0); + runTest("intNullableColumn < intNullableColumn", 0); + runTest("intNullableColumn >= intNullableColumn", 50); + runTest("intNullableColumn <= intNullableColumn", 50); } @Test - public void testBigIntNullable(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - runTest(bitContext, connection, "bigIntNullableColumn == bigIntNullableColumn", 50); - runTest(bitContext, connection, "bigIntNullableColumn != bigIntNullableColumn", 0); - runTest(bitContext, connection, "bigIntNullableColumn > bigIntNullableColumn", 0); - runTest(bitContext, connection, "bigIntNullableColumn < bigIntNullableColumn", 0); - runTest(bitContext, connection, "bigIntNullableColumn >= bigIntNullableColumn", 50); - runTest(bitContext, connection, "bigIntNullableColumn <= bigIntNullableColumn", 50); + public void testBigIntNullable() throws Throwable { + runTest("bigIntNullableColumn == bigIntNullableColumn", 50); + runTest("bigIntNullableColumn != bigIntNullableColumn", 0); + runTest("bigIntNullableColumn > bigIntNullableColumn", 0); + runTest("bigIntNullableColumn < bigIntNullableColumn", 0); + runTest("bigIntNullableColumn >= bigIntNullableColumn", 50); + runTest("bigIntNullableColumn <= bigIntNullableColumn", 50); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java index c1951a3e7..06d761f6d 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestConvertFunctions.java @@ -39,8 +39,6 @@ import org.apache.drill.exec.proto.UserBitShared.QueryType; import org.apache.drill.exec.record.RecordBatchLoader; import org.apache.drill.exec.rpc.RpcException; import org.apache.drill.exec.rpc.user.QueryDataBatch; -import org.apache.drill.exec.rpc.UserClientConnection; -import org.apache.drill.exec.server.DrillbitContext; import org.apache.drill.exec.server.options.OptionValue; import org.apache.drill.exec.util.ByteBufUtil.HadoopWritables; import org.apache.drill.exec.util.VectorUtil; @@ -55,7 +53,6 @@ import com.google.common.base.Charsets; import com.google.common.io.Resources; import io.netty.buffer.DrillBuf; -import mockit.Injectable; import org.junit.experimental.categories.Category; @Category(UnlikelyTest.class) @@ -478,32 +475,27 @@ public class TestConvertFunctions extends BaseTestQuery { } @Test - public void testFloats5(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testFloats5() throws Throwable { verifyPhysicalPlan("convert_from(convert_to(cast(77 as float8), 'DOUBLE'), 'DOUBLE')", 77.0); } @Test - public void testFloats5be(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testFloats5be() throws Throwable { verifyPhysicalPlan("convert_from(convert_to(cast(77 as float8), 'DOUBLE_BE'), 'DOUBLE_BE')", 77.0); } @Test - public void testFloats6(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testFloats6() throws Throwable { verifyPhysicalPlan("convert_to(cast(77 as float8), 'DOUBLE')", new byte[] {0, 0, 0, 0, 0, 64, 83, 64}); } @Test - public void testFloats7(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testFloats7() throws Throwable { verifyPhysicalPlan("convert_to(4.9e-324, 'DOUBLE')", new byte[] {1, 0, 0, 0, 0, 0, 0, 0}); } @Test - public void testFloats8(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testFloats8() throws Throwable { verifyPhysicalPlan("convert_to(1.7976931348623157e+308, 'DOUBLE')", new byte[] {-1, -1, -1, -1, -1, -1, -17, 127}); } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java index c0c3aae7b..b40bee8a3 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestImplicitCastFunctions.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertTrue; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.planner.PhysicalPlanReader; @@ -37,15 +37,13 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Resources; -import mockit.Injectable; +import org.mockito.Mockito; public class TestImplicitCastFunctions extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestImplicitCastFunctions.class); - private final DrillConfig c = DrillConfig.create(); private PhysicalPlanReader reader; private FunctionImplementationRegistry registry; - private FragmentContext context; + private FragmentContextImpl context; public Object[] getRunResult(SimpleRootExec exec) { int size = 0; @@ -61,10 +59,9 @@ public class TestImplicitCastFunctions extends ExecTest { return res; } - public void runTest(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable { - - mockDrillbitContext(bitContext); + public void runTest(Object[] expectedResults, String planPath) throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8); if (reader == null) { @@ -74,7 +71,7 @@ public class TestImplicitCastFunctions extends ExecTest { registry = new FunctionImplementationRegistry(c); } if (context == null) { - context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); } final PhysicalPlan plan = reader.readPhysicalPlan(planString); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); @@ -90,16 +87,15 @@ public class TestImplicitCastFunctions extends ExecTest { } } - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void testImplicitCastWithConstant(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable{ + public void testImplicitCastWithConstant() throws Throwable{ final Object [] expected = new Object[21]; expected [0] = new Double (30.1); expected [1] = new Double (30.1); @@ -126,12 +122,11 @@ public class TestImplicitCastFunctions extends ExecTest { expected [19] = Boolean.TRUE; expected [20] = Boolean.TRUE; - runTest(bitContext, connection, expected, "functions/cast/testICastConstant.json"); + runTest(expected, "functions/cast/testICastConstant.json"); } @Test - public void testImplicitCastWithMockColumn(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable{ + public void testImplicitCastWithMockColumn() throws Throwable{ final Object [] expected = new Object[5]; expected [0] = new Integer (0); expected [1] = new Integer (0); @@ -139,12 +134,11 @@ public class TestImplicitCastFunctions extends ExecTest { expected [3] = new Float (-2.14748365E9); expected [4] = new Double (-9.223372036854776E18); - runTest(bitContext, connection, expected, "functions/cast/testICastMockCol.json"); + runTest(expected, "functions/cast/testICastMockCol.json"); } @Test - public void testImplicitCastWithNullExpression(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable{ + public void testImplicitCastWithNullExpression() throws Throwable{ final Object [] expected = new Object[10]; expected [0] = Boolean.TRUE; @@ -159,6 +153,6 @@ public class TestImplicitCastFunctions extends ExecTest { expected [8] = null; expected [9] = null; - runTest(bitContext, connection, expected, "functions/cast/testICastNullExp.json"); + runTest(expected, "functions/cast/testICastNullExp.json"); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestOptiqPlans.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestOptiqPlans.java deleted file mode 100644 index b6bc497a8..000000000 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestOptiqPlans.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.drill.exec.physical.impl; - -import java.util.List; - -import mockit.Injectable; -import mockit.NonStrictExpectations; - -import org.apache.drill.categories.PlannerTest; -import org.apache.drill.common.config.DrillConfig; -import org.apache.drill.common.logical.LogicalPlan; -import org.apache.drill.common.util.DrillFileUtils; -import org.apache.drill.exec.ExecTest; -import org.apache.drill.exec.client.DrillClient; -import org.apache.drill.exec.coord.ClusterCoordinator; -import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.expr.holders.VarBinaryHolder; -import org.apache.drill.exec.memory.RootAllocatorFactory; -import org.apache.drill.exec.ops.FragmentContext; -import org.apache.drill.exec.ops.QueryContext; -import org.apache.drill.exec.opt.BasicOptimizer; -import org.apache.drill.exec.physical.PhysicalPlan; -import org.apache.drill.exec.physical.base.FragmentRoot; -import org.apache.drill.exec.planner.PhysicalPlanReader; -import org.apache.drill.exec.planner.PhysicalPlanReaderTestFactory; -import org.apache.drill.exec.proto.BitControl.PlanFragment; -import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint; -import org.apache.drill.exec.proto.UserBitShared.QueryId; -import org.apache.drill.exec.record.RecordBatchLoader; -import org.apache.drill.exec.record.VectorWrapper; -import org.apache.drill.exec.rpc.control.Controller; -import org.apache.drill.exec.rpc.control.WorkEventBus; -import org.apache.drill.exec.rpc.data.DataConnectionCreator; -import org.apache.drill.exec.rpc.user.QueryDataBatch; -import org.apache.drill.exec.rpc.UserClientConnection; -import org.apache.drill.exec.rpc.user.UserSession; -import org.apache.drill.exec.server.BootStrapContext; -import org.apache.drill.exec.server.Drillbit; -import org.apache.drill.exec.server.DrillbitContext; -import org.apache.drill.exec.server.RemoteServiceSet; -import org.apache.drill.exec.store.StoragePluginRegistry; -import org.apache.drill.exec.store.StoragePluginRegistryImpl; -import org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider; -import org.apache.drill.exec.vector.ValueVector; -import org.apache.drill.exec.vector.VarBinaryVector; -import org.junit.Ignore; -import org.junit.Test; - -import com.codahale.metrics.MetricRegistry; -import com.google.common.base.Charsets; -import com.google.common.io.Files; -import com.google.common.io.Resources; -import org.junit.experimental.categories.Category; - -@Ignore -@Category(PlannerTest.class) -public class TestOptiqPlans extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestOptiqPlans.class); - private final DrillConfig config = DrillConfig.create(); - - @Test - public void orderBy(@Injectable final BootStrapContext ctxt, @Injectable UserClientConnection connection, - @Injectable ClusterCoordinator coord, @Injectable DataConnectionCreator com, - @Injectable Controller controller, @Injectable WorkEventBus workBus) throws Throwable { - final SimpleRootExec exec = doLogicalTest(ctxt, connection, "/logical_order.json", coord, com, controller, workBus); - } - - @Test - public void stringFilter(@Injectable final BootStrapContext ctxt, @Injectable UserClientConnection connection, - @Injectable ClusterCoordinator coord, @Injectable DataConnectionCreator com, - @Injectable Controller controller, @Injectable WorkEventBus workBus) throws Throwable { - final SimpleRootExec exec = doLogicalTest(ctxt, connection, "/logical_string_filter.json", coord, com, controller, workBus); - } - - @Test - public void groupBy(@Injectable final BootStrapContext bitContext, @Injectable UserClientConnection connection, - @Injectable ClusterCoordinator coord, @Injectable DataConnectionCreator com, - @Injectable Controller controller, @Injectable WorkEventBus workBus) throws Throwable { - final SimpleRootExec exec = doLogicalTest(bitContext, connection, "/logical_group.json", coord, com, controller, workBus); - } - - private SimpleRootExec doLogicalTest(final BootStrapContext context, UserClientConnection connection, String file, - ClusterCoordinator coord, DataConnectionCreator com, Controller controller, WorkEventBus workBus) throws Exception { - new NonStrictExpectations() { - { - context.getMetrics(); - result = new MetricRegistry(); - context.getAllocator(); - result = RootAllocatorFactory.newRoot(config); - context.getConfig(); - result = config; - } - }; - final RemoteServiceSet lss = RemoteServiceSet.getLocalServiceSet(); - final DrillbitContext bitContext = new DrillbitContext( - DrillbitEndpoint.getDefaultInstance(), - context, - coord, - controller, - com, - workBus, - new LocalPersistentStoreProvider(config)); - final QueryContext qc = new QueryContext(UserSession.Builder.newBuilder().setSupportComplexTypes(true).build(), - bitContext, QueryId.getDefaultInstance()); - final PhysicalPlanReader reader = bitContext.getPlanReader(); - final LogicalPlan plan = reader.readLogicalPlan(Files.toString(DrillFileUtils.getResourceAsFile(file), Charsets.UTF_8)); - final PhysicalPlan pp = new BasicOptimizer(qc, connection).optimize(new BasicOptimizer.BasicOptimizationContext(qc), plan); - - final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(config); - final FragmentContext fctxt = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); - final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(fctxt, (FragmentRoot) pp.getSortedOperators(false) - .iterator().next())); - return exec; - - } - - @Test - public void testFilterPlan() throws Exception { - final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); - - try (final Drillbit bit1 = new Drillbit(config, serviceSet); - final DrillClient client = new DrillClient(config, serviceSet.getCoordinator());) { - bit1.run(); - client.connect(); - final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, - Resources.toString(Resources.getResource("physical_filter.json"), Charsets.UTF_8)); - final RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator()); - for (final QueryDataBatch b : results) { - System.out.println(String.format("Got %d results", b.getHeader().getRowCount())); - loader.load(b.getHeader().getDef(), b.getData()); - for (final VectorWrapper<?> vw : loader) { - System.out.println(vw.getValueVector().getField().getName()); - final ValueVector vv = vw.getValueVector(); - for (int i = 0; i < vv.getAccessor().getValueCount(); i++) { - final Object o = vv.getAccessor().getObject(i); - System.out.println(o); - } - } - loader.clear(); - b.release(); - } - client.close(); - } - } - - @Test - public void testJoinPlan() throws Exception { - final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); - - try (final Drillbit bit1 = new Drillbit(config, serviceSet); - final DrillClient client = new DrillClient(config, serviceSet.getCoordinator());) { - bit1.run(); - client.connect(); - final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, - Resources.toString(Resources.getResource("physical_join.json"), Charsets.UTF_8)); - final RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator()); - for (final QueryDataBatch b : results) { - System.out.println(String.format("Got %d results", b.getHeader().getRowCount())); - loader.load(b.getHeader().getDef(), b.getData()); - for (final VectorWrapper<?> vw : loader) { - System.out.println(vw.getValueVector().getField().getName()); - final ValueVector vv = vw.getValueVector(); - for (int i = 0; i < vv.getAccessor().getValueCount(); i++) { - final Object o = vv.getAccessor().getObject(i); - System.out.println(o); - } - } - loader.clear(); - b.release(); - } - client.close(); - } - } - - @Test - public void testFilterString() throws Exception { - final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); - - try (final Drillbit bit1 = new Drillbit(config, serviceSet); - final DrillClient client = new DrillClient(config, serviceSet.getCoordinator());) { - bit1.run(); - client.connect(); - final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.LOGICAL, - Resources.toString(Resources.getResource("logical_string_filter.json"), Charsets.UTF_8)); - final RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator()); - for (final QueryDataBatch b : results) { - System.out.println(String.format("Got %d results", b.getHeader().getRowCount())); - loader.load(b.getHeader().getDef(), b.getData()); - for (final VectorWrapper<?> vw : loader) { - System.out.println(vw.getValueVector().getField().getName()); - final ValueVector vv = vw.getValueVector(); - for (int i = 0; i < vv.getAccessor().getValueCount(); i++) { - final Object o = vv.getAccessor().getObject(i); - if (vv instanceof VarBinaryVector) { - final VarBinaryVector.Accessor x = ((VarBinaryVector) vv).getAccessor(); - final VarBinaryHolder vbh = new VarBinaryHolder(); - x.get(i, vbh); - System.out.printf("%d..%d", vbh.start, vbh.end); - - System.out.println("[" + new String((byte[]) vv.getAccessor().getObject(i)) + "]"); - } else { - System.out.println(vv.getAccessor().getObject(i)); - } - - } - } - loader.clear(); - b.release(); - } - client.close(); - } - } - - @Test - public void testLogicalJsonScan() throws Exception { - final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); - - try (final Drillbit bit1 = new Drillbit(config, serviceSet); - final DrillClient client = new DrillClient(config, serviceSet.getCoordinator());) { - bit1.run(); - client.connect(); - final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.LOGICAL, - Resources.toString(Resources.getResource("logical_json_scan.json"), Charsets.UTF_8)); - final RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator()); - for (final QueryDataBatch b : results) { - System.out.println(String.format("Got %d results", b.getHeader().getRowCount())); - loader.load(b.getHeader().getDef(), b.getData()); - for (final VectorWrapper vw : loader) { - System.out.println(vw.getValueVector().getField().getName()); - final ValueVector vv = vw.getValueVector(); - for (int i = 0; i < vv.getAccessor().getValueCount(); i++) { - final Object o = vv.getAccessor().getObject(i); - if (vv instanceof VarBinaryVector) { - final VarBinaryVector.Accessor x = ((VarBinaryVector) vv).getAccessor(); - final VarBinaryHolder vbh = new VarBinaryHolder(); - x.get(i, vbh); - System.out.printf("%d..%d", vbh.start, vbh.end); - - System.out.println("[" + new String((byte[]) vv.getAccessor().getObject(i)) + "]"); - } else { - System.out.println(vv.getAccessor().getObject(i)); - } - - } - } - loader.clear(); - b.release(); - } - client.close(); - } - } - - @Test - public void testOrderVarbinary() throws Exception { - final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); - - try (final Drillbit bit1 = new Drillbit(config, serviceSet); - final DrillClient client = new DrillClient(config, serviceSet.getCoordinator());) { - bit1.run(); - client.connect(); - final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, - Resources.toString(Resources.getResource("physical_order_varbinary.json"), Charsets.UTF_8)); - final RecordBatchLoader loader = new RecordBatchLoader(bit1.getContext().getAllocator()); - for (final QueryDataBatch b : results) { - System.out.println(String.format("Got %d results", b.getHeader().getRowCount())); - loader.load(b.getHeader().getDef(), b.getData()); - for (final VectorWrapper vw : loader) { - System.out.println(vw.getValueVector().getField().getName()); - final ValueVector vv = vw.getValueVector(); - for (int i = 0; i < vv.getAccessor().getValueCount(); i++) { - final Object o = vv.getAccessor().getObject(i); - if (vv instanceof VarBinaryVector) { - final VarBinaryVector.Accessor x = ((VarBinaryVector) vv).getAccessor(); - final VarBinaryHolder vbh = new VarBinaryHolder(); - x.get(i, vbh); - System.out.printf("%d..%d", vbh.start, vbh.end); - - System.out.println("[" + new String((byte[]) vv.getAccessor().getObject(i)) + "]"); - } else { - System.out.println(vv.getAccessor().getObject(i)); - } - - } - } - loader.clear(); - b.release(); - } - client.close(); - } - } - - private SimpleRootExec doPhysicalTest(final DrillbitContext bitContext, UserClientConnection connection, String file) - throws Exception { - mockDrillbitContext(bitContext); - - final StoragePluginRegistry reg = new StoragePluginRegistryImpl(bitContext); - - final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(config, reg); - final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile(file), Charsets.UTF_8)); - final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(config); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); - final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false) - .iterator().next())); - return exec; - } -} diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestReverseImplicitCast.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestReverseImplicitCast.java index 84d68f56a..36cbfc401 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestReverseImplicitCast.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestReverseImplicitCast.java @@ -23,17 +23,13 @@ import static org.junit.Assert.assertTrue; import java.util.Iterator; import java.util.List; -import mockit.Injectable; - import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.client.DrillClient; import org.apache.drill.exec.pop.PopUnitTestBase; import org.apache.drill.exec.record.RecordBatchLoader; import org.apache.drill.exec.record.VectorWrapper; import org.apache.drill.exec.rpc.user.QueryDataBatch; -import org.apache.drill.exec.rpc.UserClientConnection; import org.apache.drill.exec.server.Drillbit; -import org.apache.drill.exec.server.DrillbitContext; import org.apache.drill.exec.server.RemoteServiceSet; import org.apache.drill.exec.vector.ValueVector; import org.junit.Test; @@ -44,8 +40,7 @@ import com.google.common.io.Files; public class TestReverseImplicitCast extends PopUnitTestBase { @Test - public void twoWayCast(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void twoWayCast() throws Throwable { // Function checks for casting from Float, Double to Decimal data types try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java index 1f83fc4e2..192c1ad7a 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSimpleFunctions.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.expression.ExpressionPosition; import org.apache.drill.common.expression.FunctionCall; import org.apache.drill.common.expression.LogicalExpression; @@ -40,7 +39,7 @@ import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; import org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers; import org.apache.drill.exec.expr.holders.NullableVarBinaryHolder; import org.apache.drill.exec.expr.holders.NullableVarCharHolder; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.planner.PhysicalPlanReader; @@ -58,7 +57,7 @@ import com.google.common.base.Charsets; import com.google.common.io.Files; import com.sun.codemodel.JClassAlreadyExistsException; -import mockit.Injectable; +import org.mockito.Mockito; public class TestSimpleFunctions extends ExecTest { @@ -67,69 +66,44 @@ public class TestSimpleFunctions extends ExecTest { @SuppressWarnings("resource") final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); // test required vs nullable Int input - resolveHash(c, - new TypedNullConstant(Types.optional(TypeProtos.MinorType.INT)), - Types.optional(TypeProtos.MinorType.INT), - Types.required(TypeProtos.MinorType.INT), + resolveHash(new TypedNullConstant(Types.optional(TypeProtos.MinorType.INT)), TypeProtos.DataMode.OPTIONAL, registry); - resolveHash(c, - new ValueExpressions.IntExpression(1, ExpressionPosition.UNKNOWN), - Types.required(TypeProtos.MinorType.INT), - Types.required(TypeProtos.MinorType.INT), + resolveHash(new ValueExpressions.IntExpression(1, ExpressionPosition.UNKNOWN), TypeProtos.DataMode.REQUIRED, registry); // test required vs nullable float input - resolveHash(c, - new TypedNullConstant(Types.optional(TypeProtos.MinorType.FLOAT4)), - Types.optional(TypeProtos.MinorType.FLOAT4), - Types.required(TypeProtos.MinorType.FLOAT4), + resolveHash(new TypedNullConstant(Types.optional(TypeProtos.MinorType.FLOAT4)), TypeProtos.DataMode.OPTIONAL, registry); - resolveHash(c, - new ValueExpressions.FloatExpression(5.0f, ExpressionPosition.UNKNOWN), - Types.required(TypeProtos.MinorType.FLOAT4), - Types.required(TypeProtos.MinorType.FLOAT4), + resolveHash(new ValueExpressions.FloatExpression(5.0f, ExpressionPosition.UNKNOWN), TypeProtos.DataMode.REQUIRED, registry); // test required vs nullable long input - resolveHash(c, - new TypedNullConstant(Types.optional(TypeProtos.MinorType.BIGINT)), - Types.optional(TypeProtos.MinorType.BIGINT), - Types.required(TypeProtos.MinorType.BIGINT), + resolveHash(new TypedNullConstant(Types.optional(TypeProtos.MinorType.BIGINT)), TypeProtos.DataMode.OPTIONAL, registry); - resolveHash(c, - new ValueExpressions.LongExpression(100L, ExpressionPosition.UNKNOWN), - Types.required(TypeProtos.MinorType.BIGINT), - Types.required(TypeProtos.MinorType.BIGINT), + resolveHash(new ValueExpressions.LongExpression(100L, ExpressionPosition.UNKNOWN), TypeProtos.DataMode.REQUIRED, registry); // test required vs nullable double input - resolveHash(c, - new TypedNullConstant(Types.optional(TypeProtos.MinorType.FLOAT8)), - Types.optional(TypeProtos.MinorType.FLOAT8), - Types.required(TypeProtos.MinorType.FLOAT8), + resolveHash(new TypedNullConstant(Types.optional(TypeProtos.MinorType.FLOAT8)), TypeProtos.DataMode.OPTIONAL, registry); - resolveHash(c, - new ValueExpressions.DoubleExpression(100.0, ExpressionPosition.UNKNOWN), - Types.required(TypeProtos.MinorType.FLOAT8), - Types.required(TypeProtos.MinorType.FLOAT8), + resolveHash(new ValueExpressions.DoubleExpression(100.0, ExpressionPosition.UNKNOWN), TypeProtos.DataMode.REQUIRED, registry); } - public void resolveHash(DrillConfig config, LogicalExpression arg, TypeProtos.MajorType expectedArg, - TypeProtos.MajorType expectedOut, TypeProtos.DataMode expectedBestInputMode, - FunctionImplementationRegistry registry) throws JClassAlreadyExistsException, IOException { + public void resolveHash(LogicalExpression arg, TypeProtos.DataMode expectedBestInputMode, + FunctionImplementationRegistry registry) throws JClassAlreadyExistsException, IOException { final List<LogicalExpression> args = new ArrayList<>(); args.add(arg); FunctionCall call = new FunctionCall( @@ -143,14 +117,14 @@ public class TestSimpleFunctions extends ExecTest { } @Test - public void testSubstring(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testSubstring() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/testSubstring.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -169,21 +143,21 @@ public class TestSimpleFunctions extends ExecTest { assertEquals(50, count); } - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void testSubstringNegative(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testSubstringNegative() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/testSubstringNegative.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -203,21 +177,21 @@ public class TestSimpleFunctions extends ExecTest { assertEquals(50, count); } - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void testByteSubstring(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testByteSubstring() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/functions/testByteSubstring.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -236,9 +210,9 @@ public class TestSimpleFunctions extends ExecTest { assertEquals(50, count); } - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java index 84d837bbb..27ef5e115 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestStringFunctions.java @@ -24,7 +24,7 @@ import org.apache.drill.categories.UnlikelyTest; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.planner.PhysicalPlanReader; @@ -39,16 +39,15 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Resources; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category({UnlikelyTest.class}) public class TestStringFunctions extends ExecTest { - private final DrillConfig c = DrillConfig.create(); private PhysicalPlanReader reader; private FunctionImplementationRegistry registry; - private FragmentContext context; + private FragmentContextImpl context; public Object[] getRunResult(SimpleRootExec exec) { int size = 0; @@ -68,10 +67,9 @@ public class TestStringFunctions extends ExecTest { return res; } - public void runTest(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection, Object[] expectedResults, String planPath) throws Throwable { - - mockDrillbitContext(bitContext); + public void runTest(Object[] expectedResults, String planPath) throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final String planString = Resources.toString(Resources.getResource(planPath), Charsets.UTF_8); if (reader == null) { @@ -81,7 +79,7 @@ public class TestStringFunctions extends ExecTest { registry = new FunctionImplementationRegistry(c); } if (context == null) { - context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); //new FragmentContext(bitContext, ExecProtos.FragmentHandle.getInstance(), connection, registry); + context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); } final PhysicalPlan plan = reader.readPhysicalPlan(planString); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); @@ -96,138 +94,121 @@ public class TestStringFunctions extends ExecTest { } } - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void testCharLength(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testCharLength() throws Throwable { Object [] expected = new Object[] {new Long(8), new Long(0), new Long(5), new Long(5), new Long(8), new Long(0), new Long(5), new Long(5), new Long(8), new Long(0), new Long(5), new Long(5),}; - runTest(bitContext, connection, expected, "functions/string/testCharLength.json"); + runTest(expected, "functions/string/testCharLength.json"); } @Test - public void testLike(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testLike() throws Throwable { final Object [] expected = new Object[] {Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE}; - runTest(bitContext, connection, expected, "functions/string/testLike.json"); + runTest(expected, "functions/string/testLike.json"); } @Test - public void testSimilar(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testSimilar() throws Throwable { final Object [] expected = new Object[] {Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE}; - runTest(bitContext, connection, expected, "functions/string/testSimilar.json"); + runTest(expected, "functions/string/testSimilar.json"); } @Test - public void testLtrim(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testLtrim() throws Throwable { final Object [] expected = new Object[] {"def", "abcdef", "dabc", "", "", ""}; - runTest(bitContext, connection, expected, "functions/string/testLtrim.json"); + runTest(expected, "functions/string/testLtrim.json"); } @Test - public void testTrim(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testTrim() throws Throwable { final Object [] expected = new Object[] {"fghI", "", "", "!", " aaa "}; - runTest(bitContext, connection, expected, "functions/string/testTrim.json"); + runTest(expected, "functions/string/testTrim.json"); } @Test - public void testReplace(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testReplace() throws Throwable { final Object [] expected = new Object[] {"aABABcdf", "ABABbABbcdf", "aababcdf", "acdf", "ABCD", "abc"}; - runTest(bitContext, connection, expected, "functions/string/testReplace.json"); + runTest(expected, "functions/string/testReplace.json"); } @Test - public void testRtrim(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testRtrim() throws Throwable { final Object [] expected = new Object[] {"abc", "abcdef", "ABd", "", "", ""}; - runTest(bitContext, connection, expected, "functions/string/testRtrim.json"); + runTest(expected, "functions/string/testRtrim.json"); } @Test - public void testConcat(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testConcat() throws Throwable { final Object [] expected = new Object[] {"abcABC", "abc", "ABC", ""}; - runTest(bitContext, connection, expected, "functions/string/testConcat.json"); + runTest(expected, "functions/string/testConcat.json"); } @Test - public void testLower(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testLower() throws Throwable { final Object [] expected = new Object[] {"abcefgh", "abc", ""}; - runTest(bitContext, connection, expected, "functions/string/testLower.json"); + runTest(expected, "functions/string/testLower.json"); } @Test - public void testPosition(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testPosition() throws Throwable { final Object [] expected = new Object[] {new Long(2), new Long(0), new Long(0), new Long(0), new Long(2), new Long(0), new Long(0), new Long(0)}; - runTest(bitContext, connection, expected, "functions/string/testPosition.json"); + runTest(expected, "functions/string/testPosition.json"); } @Test - public void testRight(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testRight() throws Throwable { final Object [] expected = new Object[] {"ef", "abcdef", "abcdef", "cdef", "f", "", ""}; - runTest(bitContext, connection, expected, "functions/string/testRight.json"); + runTest(expected, "functions/string/testRight.json"); } @Test - public void testSubstr(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testSubstr() throws Throwable { final Object [] expected = new Object[] {"abc", "bcd", "bcdef", "bcdef", "", "", "", "", "भारत", "वर्ष", "वर्ष", "cdef", "", "", "", "ड्रिल"}; - runTest(bitContext, connection, expected, "functions/string/testSubstr.json"); + runTest(expected, "functions/string/testSubstr.json"); } @Test - public void testLeft(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testLeft() throws Throwable { final Object [] expected = new Object[] {"ab", "abcdef", "abcdef", "abcd", "a", "", ""}; - runTest(bitContext, connection, expected, "functions/string/testLeft.json"); + runTest(expected, "functions/string/testLeft.json"); } @Test - public void testLpad(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testLpad() throws Throwable { final Object [] expected = new Object[] {"", "", "abcdef", "ab", "ab", "abcdef", "AAAAabcdef", "ABABabcdef", "ABCAabcdef", "ABCDabcdef"}; - runTest(bitContext, connection, expected, "functions/string/testLpad.json"); + runTest(expected, "functions/string/testLpad.json"); } @Test - public void testRegexpReplace(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testRegexpReplace() throws Throwable { final Object [] expected = new Object[] {"ThM", "Th", "Thomas"}; - runTest(bitContext, connection, expected, "functions/string/testRegexpReplace.json"); + runTest(expected, "functions/string/testRegexpReplace.json"); } @Test - public void testRpad(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testRpad() throws Throwable { final Object [] expected = new Object[] {"", "", "abcdef", "ab", "ab", "abcdef", "abcdefAAAA", "abcdefABAB", "abcdefABCA", "abcdefABCD"}; - runTest(bitContext, connection, expected, "functions/string/testRpad.json"); + runTest(expected, "functions/string/testRpad.json"); } @Test - public void testUpper(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void testUpper() throws Throwable { final Object [] expected = new Object[] {"ABCEFGH", "ABC", ""}; - runTest(bitContext, connection, expected, "functions/string/testUpper.json"); + runTest(expected, "functions/string/testUpper.json"); } @Test - public void testNewStringFuncs(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { + public void testNewStringFuncs() throws Throwable { final Object [] expected = new Object[] {97, 65, -32, "A", "btrim", "Peace Peace Peace ", "हकुना मताता हकुना मताता ", "katcit", "\u00C3\u00A2pple", "नदम"}; - runTest(bitContext, connection, expected, "functions/string/testStringFuncs.json"); + runTest(expected, "functions/string/testStringFuncs.json"); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java index f07352c0d..e4b1376f5 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/agg/TestAgg.java @@ -26,7 +26,7 @@ import org.apache.drill.common.expression.SchemaPath; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -44,29 +44,28 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category(OperatorTest.class) public class TestAgg extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestAgg.class); private final DrillConfig c = DrillConfig.create(); - private SimpleRootExec doTest(final DrillbitContext bitContext, UserClientConnection connection, String file) throws Exception { - - mockDrillbitContext(bitContext); + private SimpleRootExec doTest(String file) throws Exception { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile(file), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); return exec; } @Test - public void oneKeyAgg(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - final SimpleRootExec exec = doTest(bitContext, connection, "/agg/test1.json"); + public void oneKeyAgg() throws Throwable { + final SimpleRootExec exec = doTest("/agg/test1.json"); while(exec.next()) { final BigIntVector cnt = exec.getValueVectorById(SchemaPath.getSimplePath("cnt"), BigIntVector.class); @@ -80,16 +79,16 @@ public class TestAgg extends ExecTest { } } - if(exec.getContext().getFailureCause() != null) { - throw exec.getContext().getFailureCause(); + if(exec.getContext().getExecutorState().getFailureCause() != null) { + throw exec.getContext().getExecutorState().getFailureCause(); } - assertTrue(!exec.getContext().isFailed()); + assertTrue(!exec.getContext().getExecutorState().isFailed()); } @Test - public void twoKeyAgg(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - SimpleRootExec exec = doTest(bitContext, connection, "/agg/twokey.json"); + public void twoKeyAgg() throws Throwable { + SimpleRootExec exec = doTest("/agg/twokey.json"); while(exec.next()) { final IntVector key1 = exec.getValueVectorById(SchemaPath.getSimplePath("key1"), IntVector.class); @@ -102,14 +101,6 @@ public class TestAgg extends ExecTest { final long[] totalArr = {0,34,68,0,34,68}; for(int i = 0; i < exec.getRecordCount(); i++) { -// System.out.print(key1.getAccessor().getObject(i)); -// System.out.print("\t"); -// System.out.print(key2.getAccessor().getObject(i)); -// System.out.print("\t"); -// System.out.print(cnt.getAccessor().getObject(i)); -// System.out.print("\t"); -// System.out.print(total.getAccessor().getObject(i)); -// System.out.println(); assertEquals((Long) cntArr[i], cnt.getAccessor().getObject(i)); assertEquals(keyArr1[i], key1.getAccessor().getObject(i)); assertEquals((Long) keyArr2[i], key2.getAccessor().getObject(i)); @@ -117,9 +108,9 @@ public class TestAgg extends ExecTest { } } - if(exec.getContext().getFailureCause() != null){ - throw exec.getContext().getFailureCause(); + if(exec.getContext().getExecutorState().getFailureCause() != null){ + throw exec.getContext().getExecutorState().getFailureCause(); } - assertTrue(!exec.getContext().isFailed()); + assertTrue(!exec.getContext().getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java index 750276cd2..354343ee7 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/filter/TestSimpleFilter.java @@ -25,7 +25,7 @@ import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -41,23 +41,22 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category(OperatorTest.class) public class TestSimpleFilter extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleFilter.class); private final DrillConfig c = DrillConfig.create(); @Test - public void testFilter(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { -// System.out.println(System.getProperty("java.class.path")); - mockDrillbitContext(bitContext); + public void testFilter() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/filter/test1.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { assertEquals(50, exec.getRecordCount()); @@ -65,21 +64,22 @@ public class TestSimpleFilter extends ExecTest { exec.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test @Ignore ("Filter does not support SV4") - public void testSV4Filter(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testSV4Filter() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/filter/test_sv4.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int recordCount = 0; while(exec.next()) { @@ -91,9 +91,9 @@ public class TestSimpleFilter extends ExecTest { exec.close(); assertEquals(50, recordCount); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java index cee84dc19..1abd4e544 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestHashJoin.java @@ -27,10 +27,10 @@ import org.apache.drill.categories.OperatorTest; import org.apache.drill.categories.SlowTest; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.DrillFileUtils; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.test.TestTools; import org.apache.drill.exec.client.DrillClient; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -55,24 +55,24 @@ import org.junit.rules.TestRule; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; +import org.mockito.Mockito; @Category({SlowTest.class, OperatorTest.class}) public class TestHashJoin extends PopUnitTestBase { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMergeJoin.class); - @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(100000); private final DrillConfig c = DrillConfig.create(); - private void testHJMockScanCommon(final DrillbitContext bitContext, UserClientConnection connection, String physicalPlan, int expectedRows) throws Throwable { + private void testHJMockScanCommon(String physicalPlan, int expectedRows) throws Throwable { + + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); - mockDrillbitContext(bitContext); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile(physicalPlan), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int totalRecordCount = 0; @@ -82,31 +82,28 @@ public class TestHashJoin extends PopUnitTestBase { exec.close(); assertEquals(expectedRows, totalRecordCount); System.out.println("Total Record Count: " + totalRecordCount); - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void multiBatchEqualityJoin(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void multiBatchEqualityJoin() throws Throwable { - testHJMockScanCommon(bitContext, connection, "/join/hash_join_multi_batch.json", 200000); + testHJMockScanCommon("/join/hash_join_multi_batch.json", 200000); } @Test - public void multiBatchRightOuterJoin(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void multiBatchRightOuterJoin() throws Throwable { - testHJMockScanCommon(bitContext, connection, "/join/hj_right_outer_multi_batch.json", 100000); + testHJMockScanCommon("/join/hj_right_outer_multi_batch.json", 100000); } @Test - public void multiBatchLeftOuterJoin(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { + public void multiBatchLeftOuterJoin() throws Throwable { - testHJMockScanCommon(bitContext, connection, "/join/hj_left_outer_multi_batch.json", 100000); + testHJMockScanCommon("/join/hj_left_outer_multi_batch.json", 100000); } @Test @@ -151,9 +148,7 @@ public class TestHashJoin extends PopUnitTestBase { } @Test - public void hjWithExchange(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - + public void hjWithExchange() throws Throwable { // Function tests with hash join with exchanges try (final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); final Drillbit bit = new Drillbit(CONFIG, serviceSet); @@ -179,9 +174,7 @@ public class TestHashJoin extends PopUnitTestBase { } @Test - public void multipleConditionJoin(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - + public void multipleConditionJoin() throws Throwable { // Function tests hash join with multiple join conditions try (final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); final Drillbit bit = new Drillbit(CONFIG, serviceSet); @@ -225,9 +218,7 @@ public class TestHashJoin extends PopUnitTestBase { } @Test - public void hjWithExchange1(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - + public void hjWithExchange1() throws Throwable { // Another test for hash join with exchanges try (final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); final Drillbit bit = new Drillbit(CONFIG, serviceSet); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoin.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoin.java index 1c16fa464..56e04feed 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoin.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestMergeJoin.java @@ -28,7 +28,7 @@ import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.client.DrillClient; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -52,25 +52,23 @@ import com.google.common.base.Charsets; import com.google.common.collect.Lists; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category({SlowTest.class, OperatorTest.class}) public class TestMergeJoin extends PopUnitTestBase { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestMergeJoin.class); private final DrillConfig c = DrillConfig.create(); @Test @Ignore // this doesn't have a sort. it also causes an infinite loop. these may or may not be related. - public void simpleEqualityJoin(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - - mockDrillbitContext(bitContext); + public void simpleEqualityJoin() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/join/merge_join.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int totalRecordCount = 0; @@ -102,17 +100,17 @@ public class TestMergeJoin extends PopUnitTestBase { } assertEquals(100, totalRecordCount); System.out.println("Total Record Count: " + totalRecordCount); - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test @Ignore - public void orderedEqualityLeftJoin(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void orderedEqualityLeftJoin() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c, new StoragePluginRegistryImpl(bitContext)); @@ -122,7 +120,7 @@ public class TestMergeJoin extends PopUnitTestBase { .replace("#{LEFT_FILE}", DrillFileUtils.getResourceAsFile("/join/merge_single_batch.left.json").toURI().toString()) .replace("#{RIGHT_FILE}", DrillFileUtils.getResourceAsFile("/join/merge_single_batch.right.json").toURI().toString())); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int totalRecordCount = 0; @@ -153,17 +151,17 @@ public class TestMergeJoin extends PopUnitTestBase { System.out.println("Total Record Count: " + totalRecordCount); assertEquals(25, totalRecordCount); - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test @Ignore - public void orderedEqualityInnerJoin(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void orderedEqualityInnerJoin() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c, new StoragePluginRegistryImpl(bitContext)); @@ -173,7 +171,7 @@ public class TestMergeJoin extends PopUnitTestBase { .replace("#{LEFT_FILE}", DrillFileUtils.getResourceAsFile("/join/merge_single_batch.left.json").toURI().toString()) .replace("#{RIGHT_FILE}", DrillFileUtils.getResourceAsFile("/join/merge_single_batch.right.json").toURI().toString())); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int totalRecordCount = 0; @@ -204,17 +202,17 @@ public class TestMergeJoin extends PopUnitTestBase { System.out.println("Total Record Count: " + totalRecordCount); assertEquals(23, totalRecordCount); - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test @Ignore - public void orderedEqualityMultiBatchJoin(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void orderedEqualityMultiBatchJoin() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c, new StoragePluginRegistryImpl(bitContext)); @@ -224,7 +222,7 @@ public class TestMergeJoin extends PopUnitTestBase { .replace("#{LEFT_FILE}", DrillFileUtils.getResourceAsFile("/join/merge_multi_batch.left.json").toURI().toString()) .replace("#{RIGHT_FILE}", DrillFileUtils.getResourceAsFile("/join/merge_multi_batch.right.json").toURI().toString())); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int totalRecordCount = 0; @@ -254,30 +252,31 @@ public class TestMergeJoin extends PopUnitTestBase { System.out.println("Total Record Count: " + totalRecordCount); assertEquals(25, totalRecordCount); - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void testJoinBatchSize(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable{ - mockDrillbitContext(bitContext); + public void testJoinBatchSize() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/join/join_batchsize.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); exec.next(); // skip schema batch while (exec.next()) { assertEquals(100, exec.getRecordCount()); } - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java index 2032afca3..e7a14f8c7 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/limit/TestSimpleLimit.java @@ -25,7 +25,7 @@ import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -42,23 +42,26 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category(OperatorTest.class) public class TestSimpleLimit extends ExecTest { private final DrillConfig c = DrillConfig.create(); @Test - public void testLimit(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { + public void testLimit() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); - mockDrillbitContext(bitContext); verifyLimitCount(bitContext, connection, "test1.json", 5); } @Test - public void testLimitNoEnd(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testLimitNoEnd() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); + verifyLimitCount(bitContext, connection, "test3.json", 95); } @@ -68,24 +71,23 @@ public class TestSimpleLimit extends ExecTest { // However, when evaluate the increasingBitInt(0), if the outgoing batch could not hold the new value, doEval() return false, and start the // next batch. But the value has already been increased by 1 in the prior failed try. Therefore, the sum of the generated number could be different, // depending on the size of each outgoing batch, and when the batch could not hold any more values. - public void testLimitAcrossBatches(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { + public void testLimitAcrossBatches() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); - mockDrillbitContext(bitContext); verifyLimitCount(bitContext, connection, "test2.json", 69999); final long start = 30000; final long end = 100000; final long expectedSum = (end - start) * (end + start - 1) / 2; //Formula for sum of series verifySum(bitContext, connection, "test4.json", 70000, expectedSum); - - } private void verifyLimitCount(DrillbitContext bitContext, UserClientConnection connection, String testPlan, int expectedCount) throws Throwable { final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/limit/" + testPlan), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int recordCount = 0; while(exec.next()) { @@ -94,18 +96,18 @@ public class TestSimpleLimit extends ExecTest { assertEquals(expectedCount, recordCount); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } private void verifySum(DrillbitContext bitContext, UserClientConnection connection, String testPlan, int expectedCount, long expectedSum) throws Throwable { final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/limit/" + testPlan), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int recordCount = 0; long sum = 0; @@ -120,9 +122,9 @@ public class TestSimpleLimit extends ExecTest { assertEquals(expectedCount, recordCount); assertEquals(expectedSum, sum); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java index 544ed49ae..c431fea74 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/partitionsender/TestPartitionSender.java @@ -33,7 +33,7 @@ import org.apache.drill.categories.OperatorTest; import org.apache.drill.PlanTestBase; import org.apache.drill.exec.exception.OutOfMemoryException; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.ops.OperatorStats; import org.apache.drill.exec.physical.MinorFragmentEndpoint; import org.apache.drill.exec.physical.PhysicalPlan; @@ -218,9 +218,9 @@ public class TestPartitionSender extends PlanTestBase { continue; } MockPartitionSenderRootExec partionSenderRootExec = null; - FragmentContext context = null; + FragmentContextImpl context = null; try { - context = new FragmentContext(drillbitContext, planFragment, null, registry); + context = new FragmentContextImpl(drillbitContext, planFragment, null, registry); final int majorFragmentId = planFragment.getHandle().getMajorFragmentId(); final HashPartitionSender partSender = new HashPartitionSender(majorFragmentId, hashToRandomExchange, hashToRandomExchange.getExpression(), mfEndPoints); partionSenderRootExec = new MockPartitionSenderRootExec(context, incoming, partSender); @@ -347,7 +347,7 @@ public class TestPartitionSender extends PlanTestBase { */ private static class MockPartitionSenderRootExec extends PartitionSenderRootExec { - public MockPartitionSenderRootExec(FragmentContext context, + public MockPartitionSenderRootExec(FragmentContextImpl context, RecordBatch incoming, HashPartitionSender operator) throws OutOfMemoryException { super(context, incoming, operator); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java index 022d15380..2c360fc6f 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/project/TestSimpleProjection.java @@ -27,7 +27,7 @@ import org.apache.drill.common.expression.SchemaPath; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -44,29 +44,28 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Category(OperatorTest.class) public class TestSimpleProjection extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleProjection.class); private final DrillConfig c = DrillConfig.create(); @Test - public void project(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void project() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/project/test1.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while (exec.next()) { VectorUtil.showVectorAccessibleContent(exec.getIncoming(), "\t"); final NullableBigIntVector c1 = exec.getValueVectorById(new SchemaPath("col1", ExpressionPosition.UNKNOWN), NullableBigIntVector.class); final NullableBigIntVector c2 = exec.getValueVectorById(new SchemaPath("col2", ExpressionPosition.UNKNOWN), NullableBigIntVector.class); - int x = 0; final NullableBigIntVector.Accessor a1 = c1.getAccessor(); final NullableBigIntVector.Accessor a2 = c2.getAccessor(); @@ -74,13 +73,13 @@ public class TestSimpleProjection extends ExecTest { if (!a1.isNull(i)) { assertEquals(a1.get(i)+1, a2.get(i)); } - x += a1.isNull(i) ? 0 : a1.get(i); } } - if (context.getFailureCause() != null) { - throw context.getFailureCause(); + if (context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java index 98c997f10..4492bde37 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/sort/TestSimpleSort.java @@ -27,7 +27,7 @@ import org.apache.drill.common.expression.SchemaPath; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -45,23 +45,23 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; @Ignore @Category(OperatorTest.class) public class TestSimpleSort extends ExecTest { - // private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleSort.class); private final DrillConfig c = DrillConfig.create(); @Test - public void sortOneKeyAscending(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void sortOneKeyAscending() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/sort/one_key_sort.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int previousInt = Integer.MIN_VALUE; @@ -86,20 +86,21 @@ public class TestSimpleSort extends ExecTest { System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount)); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } @Test - public void sortTwoKeysOneAscendingOneDescending(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void sortTwoKeysOneAscendingOneDescending() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/sort/two_key_sort.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int previousInt = Integer.MIN_VALUE; @@ -126,15 +127,14 @@ public class TestSimpleSort extends ExecTest { } assertTrue(previousLong >= a2.get(i)); - //System.out.println(previousInt + "\t" + a2.get(i)); } } System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount)); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java index 51d1e7b34..9d0877b05 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceMultiRecordBatch.java @@ -24,7 +24,7 @@ import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -40,8 +40,8 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; /* * This test uses a physical plan with the mock scan that generates 100k records. @@ -53,17 +53,17 @@ import org.junit.experimental.categories.Category; */ @Category(OperatorTest.class) public class TestTraceMultiRecordBatch extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestTraceOutputDump.class); private final DrillConfig c = DrillConfig.create(); @Test - public void testFilter(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testFilter() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/trace/multi_record_batch_trace.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -74,9 +74,9 @@ public class TestTraceMultiRecordBatch extends ExecTest { exec.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java index 780c83dd6..f3382a2ff 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/trace/TestTraceOutputDump.java @@ -26,7 +26,7 @@ import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.cache.VectorAccessibleSerializable; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -48,8 +48,8 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; /* * This test uses a simple physical plan with a mock-scan that @@ -67,17 +67,17 @@ import org.junit.experimental.categories.Category; */ @Category(OperatorTest.class) public class TestTraceOutputDump extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestTraceOutputDump.class); private final DrillConfig c = DrillConfig.create(); @Test - public void testFilter(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testFilter() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/trace/simple_trace.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while(exec.next()) { @@ -85,10 +85,10 @@ public class TestTraceOutputDump extends ExecTest { exec.close(); - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); final FragmentHandle handle = context.getHandle(); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java index 4f4935525..49a42cc0a 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/union/TestSimpleUnion.java @@ -25,7 +25,7 @@ import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.physical.base.FragmentRoot; import org.apache.drill.exec.physical.impl.ImplCreator; @@ -40,23 +40,23 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; -import mockit.Injectable; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; // See also TestUnionDistinct for a test that does not need JMockit @Category(OperatorTest.class) public class TestSimpleUnion extends ExecTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestSimpleUnion.class); private final DrillConfig c = DrillConfig.create(); @Test - public void testUnion(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { - mockDrillbitContext(bitContext); + public void testUnion() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(DrillFileUtils.getResourceAsFile("/union/test1.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); final int[] counts = new int[]{0, 100,50}; // first batch : 0-row schema-only batch. @@ -66,9 +66,9 @@ public class TestSimpleUnion extends ExecTest { assertEquals(counts[i++], exec.getRecordCount()); } - if(context.getFailureCause() != null) { - throw context.getFailureCause(); + if(context.getExecutorState().getFailureCause() != null) { + throw context.getExecutorState().getFailureCause(); } - assertTrue(!context.isFailed()); + assertTrue(!context.getExecutorState().isFailed()); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestSortImpl.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestSortImpl.java index 7c3c4cffa..cdca30e1e 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestSortImpl.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestSortImpl.java @@ -40,7 +40,6 @@ import org.apache.drill.exec.record.BatchSchema; import org.apache.drill.exec.record.VectorContainer; import org.apache.drill.test.DrillTest; import org.apache.drill.test.OperatorFixture; -import org.apache.drill.test.OperatorFixture.OperatorFixtureBuilder; import org.apache.drill.test.rowSet.DirectRowSet; import org.apache.drill.test.rowSet.HyperRowSetImpl; import org.apache.drill.test.rowSet.IndirectRowSet; @@ -190,7 +189,6 @@ public class TestSortImpl extends DrillTest { * row set format. For historical reasons, the sort dumps its output into a vector * container (normally attached to the external sort batch, here used stand-alone.) * - * @param fixture operator test fixture * @param results sort results iterator * @param dest container that holds the sort results * @return @@ -582,7 +580,7 @@ public class TestSortImpl extends DrillTest { @Test public void testSpill() throws Exception { - OperatorFixtureBuilder builder = OperatorFixture.builder(); + OperatorFixture.Builder builder = OperatorFixture.builder(); builder.configBuilder() .put(ExecConstants.EXTERNAL_SORT_BATCH_LIMIT, 2); try (OperatorFixture fixture = builder.build()) { diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/unit/MiniPlanUnitTestBase.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/unit/MiniPlanUnitTestBase.java index 754d85860..e6e72e7b6 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/unit/MiniPlanUnitTestBase.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/unit/MiniPlanUnitTestBase.java @@ -20,7 +20,6 @@ package org.apache.drill.exec.physical.unit; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -import mockit.NonStrictExpectations; import org.apache.drill.test.DrillTestWrapper; import org.apache.drill.common.expression.SchemaPath; import org.apache.drill.exec.physical.base.PhysicalOperator; @@ -29,12 +28,12 @@ import org.apache.drill.exec.physical.impl.ScanBatch; import org.apache.drill.exec.record.BatchSchema; import org.apache.drill.exec.record.MaterializedField; import org.apache.drill.exec.record.RecordBatch; -import org.apache.drill.exec.rpc.NamedThreadFactory; import org.apache.drill.exec.store.RecordReader; import org.apache.drill.exec.store.dfs.DrillFileSystem; import org.apache.drill.exec.store.parquet.ParquetDirectByteBufferAllocator; import org.apache.drill.exec.store.parquet.ParquetReaderUtility; import org.apache.drill.exec.store.parquet.columnreaders.ParquetRecordReader; +import org.apache.drill.test.OperatorFixture; import org.apache.hadoop.fs.Path; import org.apache.parquet.hadoop.CodecFactory; import org.apache.parquet.hadoop.ParquetFileReader; @@ -47,8 +46,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import static org.apache.drill.exec.physical.base.AbstractBase.INIT_ALLOCATION; import static org.apache.drill.exec.physical.base.AbstractBase.MAX_ALLOCATION; @@ -63,9 +60,6 @@ import static org.apache.drill.exec.physical.base.AbstractBase.MAX_ALLOCATION; */ public class MiniPlanUnitTestBase extends PhysicalOpUnitTestBase { - - private final ExecutorService scanExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("scan-")); - public static class MiniPlanTestBuilder { protected List<Map<String, Object>> baselineRecords; protected RecordBatch root; @@ -386,14 +380,12 @@ public class MiniPlanUnitTestBase extends PhysicalOpUnitTestBase { @Override public PopBuilder buildAddAsInput() throws Exception { - mockOpContext(popConfig, this.initReservation, this.maxAllocation); RecordBatch scanBatch = getScanBatch(); return parent.addInput(scanBatch); } @Override public RecordBatch build() throws Exception { - mockOpContext(popConfig, this.initReservation, this.maxAllocation); return getScanBatch(); } @@ -411,7 +403,7 @@ public class MiniPlanUnitTestBase extends PhysicalOpUnitTestBase { readerList.add(readers.next()); } - RecordBatch scanBatch = new ScanBatch(null, fragContext, readerList); + RecordBatch scanBatch = new ScanBatch(new MockPhysicalOperator(), fragContext, readerList); return scanBatch; } } @@ -467,7 +459,7 @@ public class MiniPlanUnitTestBase extends PhysicalOpUnitTestBase { } } - RecordBatch scanBatch = new ScanBatch(null, fragContext, readers); + RecordBatch scanBatch = new ScanBatch(new MockPhysicalOperator(), fragContext, readers); return scanBatch; } } // end of ParquetScanBuilder @@ -475,12 +467,5 @@ public class MiniPlanUnitTestBase extends PhysicalOpUnitTestBase { @Override protected void mockOpContext(PhysicalOperator popConfig, long initReservation, long maxAllocation) throws Exception { super.mockOpContext(popConfig, initReservation, maxAllocation); - - // mock ScanExecutor used by parquet reader. - new NonStrictExpectations() { - { - opContext.getScanExecutor();result = scanExecutor; - } - }; } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/unit/PhysicalOpUnitTestBase.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/unit/PhysicalOpUnitTestBase.java index 088994f4c..b01dd3e13 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/unit/PhysicalOpUnitTestBase.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/unit/PhysicalOpUnitTestBase.java @@ -21,15 +21,27 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -import mockit.Delegate; -import mockit.Injectable; -import mockit.NonStrictExpectations; import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; import org.apache.calcite.rel.RelFieldCollation; +import org.apache.drill.exec.coord.ClusterCoordinator; +import org.apache.drill.exec.ops.AccountingDataTunnel; +import org.apache.drill.exec.ops.AccountingUserConnection; +import org.apache.drill.exec.ops.ExecutorFragmentContext; +import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentStats; +import org.apache.drill.exec.physical.base.PhysicalVisitor; +import org.apache.drill.exec.planner.PhysicalPlanReader; +import org.apache.drill.exec.proto.CoordinationProtos; +import org.apache.drill.exec.rpc.control.Controller; +import org.apache.drill.exec.rpc.control.WorkEventBus; +import org.apache.drill.exec.rpc.user.UserServer; +import org.apache.drill.exec.server.QueryProfileStoreContext; +import org.apache.drill.exec.server.options.OptionManager; import org.apache.drill.exec.store.dfs.DrillFileSystem; import org.apache.drill.exec.store.easy.json.JSONRecordReader; +import org.apache.drill.exec.work.batch.IncomingBuffers; import org.apache.drill.test.DrillTestWrapper; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.exceptions.ExecutionSetupException; @@ -45,67 +57,70 @@ import org.apache.drill.common.logical.data.Order; import org.apache.drill.common.scanner.ClassPathScanner; import org.apache.drill.common.scanner.persistence.ScanResult; import org.apache.drill.exec.ExecTest; -import org.apache.drill.exec.compile.CodeCompiler; -import org.apache.drill.exec.compile.TemplateClassDefinition; -import org.apache.drill.exec.exception.ClassTransformationException; -import org.apache.drill.exec.exception.SchemaChangeException; -import org.apache.drill.exec.expr.ClassGenerator; -import org.apache.drill.exec.expr.CodeGenerator; -import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.memory.RootAllocatorFactory; -import org.apache.drill.exec.ops.BufferManagerImpl; -import org.apache.drill.exec.ops.FragmentContext; -import org.apache.drill.exec.ops.OperatorContext; -import org.apache.drill.exec.ops.OperatorStats; import org.apache.drill.exec.physical.base.AbstractBase; import org.apache.drill.exec.physical.base.PhysicalOperator; import org.apache.drill.exec.physical.impl.BatchCreator; import org.apache.drill.exec.physical.impl.OperatorCreatorRegistry; import org.apache.drill.exec.physical.impl.ScanBatch; -import org.apache.drill.exec.physical.impl.project.Projector; -import org.apache.drill.exec.physical.impl.project.ProjectorTemplate; -import org.apache.drill.exec.proto.ExecProtos; import org.apache.drill.exec.record.RecordBatch; import org.apache.drill.exec.record.VectorAccessible; import org.apache.drill.exec.server.DrillbitContext; import org.apache.drill.exec.store.RecordReader; -import org.apache.drill.exec.testing.ExecutionControls; +import org.apache.drill.exec.rpc.NamedThreadFactory; +import org.apache.drill.test.OperatorFixture; +import org.junit.After; import org.junit.Before; +import org.mockito.Mockito; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; -/** - * Look! Doesn't extend BaseTestQuery!! - */ public class PhysicalOpUnitTestBase extends ExecTest { - @Injectable FragmentContext fragContext; - @Injectable DrillbitContext drillbitContext; - @Injectable OperatorContext opContext; - @Injectable OperatorStats opStats; - @Injectable PhysicalOperator popConf; - @Injectable ExecutionControls executionControls; + protected MockExecutorFragmentContext fragContext; + protected DrillbitContext drillbitContext; + protected OperatorFixture.MockOperatorContext opContext; + protected OperatorFixture operatorFixture; + protected ExecutorService scanExecutor; + protected ExecutorService scanDecodeExecutor; private final DrillConfig drillConf = DrillConfig.create(); - private final BufferAllocator allocator = RootAllocatorFactory.newRoot(drillConf); - private final BufferManagerImpl bufManager = new BufferManagerImpl(allocator); private final ScanResult classpathScan = ClassPathScanner.fromPrescan(drillConf); - private final FunctionImplementationRegistry funcReg = new FunctionImplementationRegistry(drillConf, classpathScan); - private final TemplateClassDefinition<Projector> templateClassDefinition = new TemplateClassDefinition<Projector>(Projector.class, ProjectorTemplate.class); private final OperatorCreatorRegistry opCreatorReg = new OperatorCreatorRegistry(classpathScan); @Before public void setup() throws Exception { + scanExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("scan-")); + scanDecodeExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("scanDecoder-")); + + drillbitContext = Mockito.mock(DrillbitContext.class); + Mockito.when(drillbitContext.getScanExecutor()).thenReturn(scanExecutor); + Mockito.when(drillbitContext.getScanDecodeExecutor()).thenReturn(scanDecodeExecutor); + + final OperatorFixture.Builder builder = new OperatorFixture.Builder(); + builder.configBuilder().configProps(drillConf); + operatorFixture = builder + .setScanExecutor(scanExecutor) + .setScanDecoderExecutor(scanDecodeExecutor) + .build(); mockFragmentContext(); } + @After + public void teardown() { + scanExecutor.shutdownNow(); + scanDecodeExecutor.shutdownNow(); + } + @Override protected LogicalExpression parseExpr(String expr) { ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr)); @@ -207,7 +222,7 @@ public class PhysicalOpUnitTestBase extends ExecTest { List<RecordBatch> incomingStreams = Lists.newArrayList(); if (inputStreamsJSON != null) { for (List<String> batchesJson : inputStreamsJSON) { - incomingStreams.add(new ScanBatch(null, fragContext, + incomingStreams.add(new ScanBatch(popConfig, fragContext, getReaderListForJsonBatches(batchesJson, fragContext))); } } @@ -222,8 +237,6 @@ public class PhysicalOpUnitTestBase extends ExecTest { throw new RuntimeException(e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); - } catch (SchemaChangeException e) { - throw new RuntimeException(e); } catch (Exception e) { throw new RuntimeException(e); } @@ -285,69 +298,146 @@ public class PhysicalOpUnitTestBase extends ExecTest { } } - protected void mockFragmentContext() throws Exception{ - final CodeCompiler compiler = new CodeCompiler(drillConf, optionManager); -// final BufferAllocator allocator = this.allocator.newChildAllocator("allocator_for_operator_test", initReservation, maxAllocation); - new NonStrictExpectations() { - { -// optManager.getOption(withAny(new TypeValidators.BooleanValidator("", false))); result = false; -// // TODO(DRILL-4450) - Probably want to just create a default option manager, this is a hack to prevent -// // the code compilation from failing when trying to decide of scalar replacement is turned on -// // this will cause other code paths to fail because this return value won't be valid for most -// // string options -// optManager.getOption(withAny(new TypeValidators.StringValidator("", "try"))); result = "try"; -// optManager.getOption(withAny(new TypeValidators.PositiveLongValidator("", 1l, 1l))); result = 10; - drillbitContext.getCompiler(); result = new CodeCompiler(drillConf, optionManager); - fragContext.getOptions(); result = optionManager; - fragContext.getOptions(); result = optionManager; - fragContext.getManagedBuffer(); result = bufManager.getManagedBuffer(); - fragContext.shouldContinue(); result = true; - fragContext.getExecutionControls(); result = executionControls; - fragContext.getFunctionRegistry(); result = funcReg; - fragContext.getConfig(); result = drillConf; - fragContext.getHandle(); result = ExecProtos.FragmentHandle.getDefaultInstance(); - fragContext.getFunctionRegistry(); result = funcReg; - fragContext.getDrillbitContext(); result = drillbitContext; - try { - CodeGenerator<?> cg = CodeGenerator.get(templateClassDefinition); - cg.plainJavaCapable(true); - // cg.saveCodeForDebugging(true); - fragContext.getImplementationClass(withAny(cg)); - result = new Delegate<Object>() - { - @SuppressWarnings("unused") - Object getImplementationClass(CodeGenerator<Object> gen) throws IOException, ClassTransformationException { - return compiler.createInstance(gen); - } - }; - fragContext.getImplementationClass(withAny(CodeGenerator.get(templateClassDefinition).getRoot())); - result = new Delegate<Object>() - { - @SuppressWarnings("unused") - Object getImplementationClass(ClassGenerator<Object> gen) throws IOException, ClassTransformationException { - return compiler.createInstance(gen.getCodeGenerator()); - } - }; - } catch (ClassTransformationException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - }; + /** + * <h2>Note</h2> + * <p> + * The {@link MockExecutorFragmentContext} should only be used in {@link PhysicalOpUnitTestBase} because {@link PhysicalOpUnitTestBase} + * needs a dummy {@link ExecutorFragmentContext} to be passed to batch creators. If you are unit testing operators and need a mock fragment context + * please use {@link OperatorFixture.MockFragmentContext}. + * </p> + */ + protected static class MockExecutorFragmentContext extends OperatorFixture.MockFragmentContext implements ExecutorFragmentContext { + + public MockExecutorFragmentContext(final FragmentContext fragmentContext) { + super(fragmentContext.getConfig(), fragmentContext.getOptions(), fragmentContext.getAllocator(), + fragmentContext.getScanExecutor(), fragmentContext.getScanDecodeExecutor()); + } + + @Override + public PhysicalPlanReader getPlanReader() { + throw new UnsupportedOperationException(); + } + + @Override + public ClusterCoordinator getClusterCoordinator() { + throw new UnsupportedOperationException(); + } + + @Override + public CoordinationProtos.DrillbitEndpoint getForemanEndpoint() { + throw new UnsupportedOperationException(); + } + + @Override + public CoordinationProtos.DrillbitEndpoint getEndpoint() { + throw new UnsupportedOperationException(); + } + + @Override + public Collection<CoordinationProtos.DrillbitEndpoint> getBits() { + throw new UnsupportedOperationException(); + } + + @Override + public OperatorCreatorRegistry getOperatorCreatorRegistry() { + return null; + } + + @Override + public void setBuffers(IncomingBuffers buffers) { + } + + @Override + public QueryProfileStoreContext getProfileStoreContext() { + return null; + } + + @Override + public WorkEventBus getWorkEventbus() { + return null; + } + + @Override + public Set<Map.Entry<UserServer.BitToUserConnection, UserServer.BitToUserConnectionConfig>> getUserConnections() { + return null; + } + + @Override + public void waitForSendComplete() { + throw new UnsupportedOperationException(); + } + + @Override + public AccountingDataTunnel getDataTunnel(CoordinationProtos.DrillbitEndpoint endpoint) { + throw new UnsupportedOperationException(); + } + + @Override + public AccountingUserConnection getUserDataTunnel() { + throw new UnsupportedOperationException(); + } + + @Override + public Controller getController() { + return null; + } + + @Override + public IncomingBuffers getBuffers() { + return null; + } + + @Override + public FragmentStats getStats() { + return null; + } + + @Override + public void setExecutorState(ExecutorState executorState) { + } + + @Override + public boolean isUserAuthenticationEnabled() { + return false; + } } - protected void mockOpContext(final PhysicalOperator popConfig, long initReservation, long maxAllocation) throws Exception{ - final BufferAllocator allocator = this.allocator.newChildAllocator("allocator_for_operator_test", initReservation, maxAllocation); - new NonStrictExpectations() { - { - opContext.getStats();result = opStats; - opContext.getAllocator(); result = allocator; - opContext.getFragmentContext(); result = fragContext; - opContext.getOperatorDefn(); result = popConfig; - fragContext.newOperatorContext(withAny(popConf)); result = opContext; - } - }; + /** + * <h2>Note</h2> + * <p> + * The {@link MockPhysicalOperator} should only be used in {@link PhysicalOpUnitTestBase} because {@link PhysicalOpUnitTestBase} + * needs a dummy {@link MockPhysicalOperator} to be passed to Scanners. + * </p> + */ + protected static class MockPhysicalOperator extends AbstractBase + { + @Override + public <T, X, E extends Throwable> T accept(PhysicalVisitor<T, X, E> physicalVisitor, X value) throws E { + return null; + } + + @Override + public PhysicalOperator getNewWithChildren(List<PhysicalOperator> children) throws ExecutionSetupException { + return null; + } + + @Override + public int getOperatorType() { + return 0; + } + + @Override + public Iterator<PhysicalOperator> iterator() { + return null; + } + } + + protected void mockFragmentContext() throws Exception { + fragContext = new MockExecutorFragmentContext(operatorFixture.getFragmentContext()); + } + + protected void mockOpContext(final PhysicalOperator popConfig, long initReservation, long maxAllocation) throws Exception { + opContext = (OperatorFixture.MockOperatorContext)operatorFixture.operatorContext(popConfig); } protected OperatorCreatorRegistry getOpCreatorReg() { @@ -367,7 +457,6 @@ public class PhysicalOpUnitTestBase extends ExecTest { return readerList; } - /** * Create JSONRecordReader from input strings. * @param jsonBatches : list of input strings, each element represent a batch. Each string could either diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/fragment/TestHardAffinityFragmentParallelizer.java b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/fragment/TestHardAffinityFragmentParallelizer.java index 9d94e9a45..95363a7e7 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/planner/fragment/TestHardAffinityFragmentParallelizer.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/planner/fragment/TestHardAffinityFragmentParallelizer.java @@ -19,8 +19,6 @@ package org.apache.drill.exec.planner.fragment; import com.google.common.collect.HashMultiset; import com.google.common.collect.ImmutableList; -import mockit.Mocked; -import mockit.NonStrictExpectations; import org.apache.drill.categories.PlannerTest; import org.apache.drill.exec.physical.EndpointAffinity; import org.apache.drill.exec.physical.base.PhysicalOperator; @@ -37,6 +35,8 @@ import static org.apache.drill.exec.planner.fragment.HardAffinityFragmentParalle import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @Category(PlannerTest.class) public class TestHardAffinityFragmentParallelizer { @@ -50,9 +50,6 @@ public class TestHardAffinityFragmentParallelizer { private static final DrillbitEndpoint N3_EP2 = newDrillbitEndpoint("node3", 30011); private static final DrillbitEndpoint N4_EP2 = newDrillbitEndpoint("node4", 30011); - @Mocked private Fragment fragment; - @Mocked private PhysicalOperator root; - private static final DrillbitEndpoint newDrillbitEndpoint(String address, int port) { return DrillbitEndpoint.newBuilder().setAddress(address).setControlPort(port).build(); } @@ -87,11 +84,10 @@ public class TestHardAffinityFragmentParallelizer { } private final Wrapper newWrapper(double cost, int minWidth, int maxWidth, List<EndpointAffinity> epAffs) { - new NonStrictExpectations() { - { - fragment.getRoot(); result = root; - } - }; + final Fragment fragment = mock(Fragment.class); + final PhysicalOperator root = mock(PhysicalOperator.class); + + when(fragment.getRoot()).thenReturn(root); final Wrapper fragmentWrapper = new Wrapper(fragment, 1); final Stats stats = fragmentWrapper.getStats(); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java index 7f6929f84..31c25a337 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/ExpressionTreeMaterializerTest.java @@ -20,10 +20,8 @@ package org.apache.drill.exec.record; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import mockit.Injectable; -import mockit.Mock; -import mockit.MockUp; -import mockit.NonStrictExpectations; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.apache.drill.categories.VectorTest; import org.apache.drill.common.config.DrillConfig; @@ -45,7 +43,6 @@ import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.exception.SchemaChangeException; import org.apache.drill.exec.expr.ExpressionTreeMaterializer; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry; import org.junit.Test; import com.google.common.collect.ImmutableList; @@ -54,22 +51,18 @@ import org.junit.experimental.categories.Category; @Category(VectorTest.class) public class ExpressionTreeMaterializerTest extends ExecTest { - - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ExpressionTreeMaterializerTest.class); - - final MajorType boolConstant = MajorType.newBuilder().setMode(DataMode.REQUIRED).setMinorType(MinorType.BIT).build(); final MajorType bigIntType = MajorType.newBuilder().setMode(DataMode.REQUIRED).setMinorType(MinorType.BIGINT).build(); - final MajorType intType = MajorType.newBuilder().setMode(DataMode.REQUIRED).setMinorType(MinorType.INT).build(); DrillConfig c = DrillConfig.create(); FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - private MaterializedField getField(int fieldId, String name, MajorType type) { + private MaterializedField getField(String name, MajorType type) { return MaterializedField.create(name, type); } @Test - public void testMaterializingConstantTree(@Injectable RecordBatch batch) throws SchemaChangeException { + public void testMaterializingConstantTree() throws SchemaChangeException { + final RecordBatch batch = mock(RecordBatch.class); ErrorCollector ec = new ErrorCollectorImpl(); LogicalExpression expr = ExpressionTreeMaterializer.materialize(new ValueExpressions.LongExpression(1L, @@ -80,18 +73,15 @@ public class ExpressionTreeMaterializerTest extends ExecTest { } @Test - public void testMaterializingLateboundField(final @Injectable RecordBatch batch) throws SchemaChangeException { + public void testMaterializingLateboundField() throws SchemaChangeException { + final RecordBatch batch = mock(RecordBatch.class); + when(batch.getValueVectorId(new SchemaPath("test", ExpressionPosition.UNKNOWN))) + .thenReturn(new TypedFieldId(Types.required(MinorType.BIGINT), -5)); + final SchemaBuilder builder = BatchSchema.newBuilder(); - builder.addField(getField(2, "test", bigIntType)); + builder.addField(getField("test", bigIntType)); final BatchSchema schema = builder.build(); - new NonStrictExpectations() { - { - batch.getValueVectorId(new SchemaPath("test", ExpressionPosition.UNKNOWN)); - result = new TypedFieldId(Types.required(MinorType.BIGINT), -5); - } - }; - ErrorCollector ec = new ErrorCollectorImpl(); LogicalExpression expr = ExpressionTreeMaterializer.materialize(new FieldReference("test", ExpressionPosition.UNKNOWN), batch, ec, registry); @@ -100,18 +90,13 @@ public class ExpressionTreeMaterializerTest extends ExecTest { } @Test - public void testMaterializingLateboundTree(final @Injectable RecordBatch batch) throws SchemaChangeException { - new NonStrictExpectations() { - { - batch.getValueVectorId(SchemaPath.getSimplePath("test")); - result = new TypedFieldId(Types.required(MinorType.BIT), -4); - batch.getValueVectorId(SchemaPath.getSimplePath("test1")); - result = new TypedFieldId(Types.required(MinorType.BIGINT), -5); - } - }; + public void testMaterializingLateboundTree() throws SchemaChangeException { + final RecordBatch batch = mock(RecordBatch.class); - ErrorCollector ec = new ErrorCollectorImpl(); + when(batch.getValueVectorId(SchemaPath.getSimplePath("test"))).thenReturn(new TypedFieldId(Types.required(MinorType.BIT), -4)); + when(batch.getValueVectorId(SchemaPath.getSimplePath("test1"))).thenReturn(new TypedFieldId(Types.required(MinorType.BIGINT), -5)); + ErrorCollector ec = new ErrorCollectorImpl(); LogicalExpression elseExpression = new IfExpression.Builder().setElse(new ValueExpressions.LongExpression(1L, ExpressionPosition.UNKNOWN)) .setIfCondition(new IfExpression.IfCondition(new ValueExpressions.BooleanExpression("true", ExpressionPosition.UNKNOWN), @@ -125,11 +110,8 @@ public class ExpressionTreeMaterializerTest extends ExecTest { LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(expr, batch, ec, registry); assertTrue(newExpr instanceof IfExpression); IfExpression newIfExpr = (IfExpression) newExpr; - //assertEquals(1, newIfExpr.conditions.size()); IfExpression.IfCondition ifCondition = newIfExpr.ifCondition; assertTrue(newIfExpr.elseExpression instanceof IfExpression); - //assertEquals(1, newIfExpr.conditions.size()); - //ifCondition = newIfExpr.conditions.get(0); assertEquals(bigIntType, ifCondition.expression.getMajorType()); assertEquals(true, ((ValueExpressions.BooleanExpression) ((IfExpression)(newIfExpr.elseExpression)).ifCondition.condition).value); if (ec.hasErrors()) { @@ -139,7 +121,12 @@ public class ExpressionTreeMaterializerTest extends ExecTest { } @Test - public void testMaterializingLateboundTreeValidated(final @Injectable RecordBatch batch) throws SchemaChangeException { + public void testMaterializingLateboundTreeValidated() throws SchemaChangeException { + final RecordBatch batch = mock(RecordBatch.class); + + when(batch.getValueVectorId(new SchemaPath("test", ExpressionPosition.UNKNOWN))) + .thenReturn(new TypedFieldId(Types.required(MinorType.BIGINT), -5)); + ErrorCollector ec = new ErrorCollector() { int errorCount = 0; @@ -195,20 +182,6 @@ public class ExpressionTreeMaterializerTest extends ExecTest { } }; - new NonStrictExpectations() { - { - batch.getValueVectorId(new SchemaPath("test", ExpressionPosition.UNKNOWN)); - result = new TypedFieldId(Types.required(MinorType.BIGINT), -5); - } - }; - - new MockUp<RemoteFunctionRegistry>() { - @Mock - long getRegistryVersion() { - return 0L; - } - }; - LogicalExpression functionCallExpr = new FunctionCall("testFunc", ImmutableList.of((LogicalExpression) new FieldReference("test", ExpressionPosition.UNKNOWN) ), ExpressionPosition.UNKNOWN); @@ -217,5 +190,4 @@ public class ExpressionTreeMaterializerTest extends ExecTest { assertEquals(1, ec.getErrorCount()); System.out.println(ec.toErrorString()); } - } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/TestRecordIterator.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/TestRecordIterator.java index c07dbaad2..e88bb415e 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/record/TestRecordIterator.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/TestRecordIterator.java @@ -22,13 +22,12 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import com.google.common.collect.Lists; -import mockit.Injectable; import org.apache.drill.categories.VectorTest; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.util.DrillFileUtils; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.ops.OpProfileDef; import org.apache.drill.exec.ops.OperatorStats; import org.apache.drill.exec.ops.OperatorUtilities; @@ -50,18 +49,18 @@ import org.junit.Test; import com.google.common.base.Charsets; import com.google.common.io.Files; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; import java.util.List; @Category(VectorTest.class) public class TestRecordIterator extends PopUnitTestBase { - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestRecordIterator.class); DrillConfig c = DrillConfig.create(); @Test - public void testSimpleIterator(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable{ - mockDrillbitContext(bitContext); + public void testSimpleIterator() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); @@ -69,7 +68,7 @@ public class TestRecordIterator extends PopUnitTestBase { final PhysicalPlan plan = reader.readPhysicalPlan(planStr); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); final List<PhysicalOperator> operatorList = plan.getSortedOperators(false); SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) operatorList.iterator().next())); @@ -116,17 +115,16 @@ public class TestRecordIterator extends PopUnitTestBase { } @Test - public void testMarkResetIterator(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Throwable{ - mockDrillbitContext(bitContext); + public void testMarkResetIterator() throws Throwable { + final DrillbitContext bitContext = mockDrillbitContext(); + final UserClientConnection connection = Mockito.mock(UserClientConnection.class); final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c); - final String planStr = Files.toString(DrillFileUtils.getResourceAsFile("/record/test_recorditerator.json"), Charsets.UTF_8); final PhysicalPlan plan = reader.readPhysicalPlan(planStr); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); + final FragmentContextImpl context = new FragmentContextImpl(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); final List<PhysicalOperator> operatorList = plan.getSortedOperators(false); SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) operatorList.iterator().next())); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/record/TestVectorContainer.java b/exec/java-exec/src/test/java/org/apache/drill/exec/record/TestVectorContainer.java new file mode 100644 index 000000000..ef7978004 --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/record/TestVectorContainer.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.record; + +import static org.junit.Assert.*; + +import org.apache.drill.categories.VectorTest; +import org.apache.drill.common.types.TypeProtos.MinorType; +import org.apache.drill.test.DrillTest; +import org.apache.drill.test.OperatorFixture; +import org.apache.drill.test.rowSet.DirectRowSet; +import org.apache.drill.test.rowSet.RowSet; +import org.apache.drill.test.rowSet.RowSet.SingleRowSet; +import org.apache.drill.test.rowSet.RowSetComparison; +import org.apache.drill.test.rowSet.SchemaBuilder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(VectorTest.class) +public class TestVectorContainer extends DrillTest { + + // TODO: Replace the following with an extension of SubOperatorTest class + // once that is available. + + protected volatile static OperatorFixture fixture; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + fixture = OperatorFixture.standardFixture(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + fixture.close(); + } + + /** + * Test of the ability to merge two schemas and to merge + * two vector containers. The merge is "horizontal", like + * a row-by-row join. Since each container is a list of + * vectors, we just combine the two lists to create the + * merged result. + */ + @Test + public void testContainerMerge() { + + // Simulated data from a reader + + BatchSchema leftSchema = new SchemaBuilder() + .add("a", MinorType.INT) + .addNullable("b", MinorType.VARCHAR) + .build(); + SingleRowSet left = fixture.rowSetBuilder(leftSchema) + .addRow(10, "fred") + .addRow(20, "barney") + .addRow(30, "wilma") + .build(); + + // Simulated "implicit" coumns: row number and file name + + BatchSchema rightSchema = new SchemaBuilder() + .add("x", MinorType.SMALLINT) + .add("y", MinorType.VARCHAR) + .build(); + SingleRowSet right = fixture.rowSetBuilder(rightSchema) + .addRow(1, "foo.txt") + .addRow(2, "bar.txt") + .addRow(3, "dino.txt") + .build(); + + // The merge batch we expect to see + + BatchSchema expectedSchema = new SchemaBuilder() + .add("a", MinorType.INT) + .addNullable("b", MinorType.VARCHAR) + .add("x", MinorType.SMALLINT) + .add("y", MinorType.VARCHAR) + .build(); + SingleRowSet expected = fixture.rowSetBuilder(expectedSchema) + .addRow(10, "fred", 1, "foo.txt") + .addRow(20, "barney", 2, "bar.txt") + .addRow(30, "wilma", 3, "dino.txt") + .build(); + + // Merge containers without selection vector + + RowSet merged = fixture.wrap( + left.container().merge(right.container())); + + RowSetComparison comparison = new RowSetComparison(expected); + comparison.verify(merged); + + // Merge containers via row set facade + + RowSet mergedRs = DirectRowSet.fromContainer(left.container().merge(right.container())); + comparison.verifyAndClearAll(mergedRs); + + // Add a selection vector. Merging is forbidden, in the present code, + // for batches that have a selection vector. + + SingleRowSet leftIndirect = left.toIndirect(); + try { + leftIndirect.container().merge(right.container()); + fail(); + } catch (IllegalArgumentException e) { + // Expected + } + leftIndirect.clear(); + right.clear(); + } +} diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitBitKerberos.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitBitKerberos.java index 834f1084e..0b00824ff 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitBitKerberos.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitBitKerberos.java @@ -17,15 +17,13 @@ */ package org.apache.drill.exec.rpc.data; +import com.google.common.base.Preconditions; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import com.typesafe.config.Config; import com.typesafe.config.ConfigValueFactory; import io.netty.buffer.ByteBuf; -import mockit.Injectable; -import mockit.Mock; -import mockit.MockUp; -import mockit.NonStrictExpectations; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.test.BaseTestQuery; import org.apache.drill.categories.SecurityTest; import org.apache.drill.common.config.DrillConfig; @@ -60,6 +58,7 @@ import org.apache.drill.exec.server.options.SystemOptionManager; import org.apache.drill.exec.vector.Float8Vector; import org.apache.drill.exec.vector.ValueVector; import org.apache.drill.exec.work.WorkManager.WorkerBee; +import org.apache.drill.exec.work.fragment.FragmentExecutor; import org.apache.drill.exec.work.fragment.FragmentManager; import org.apache.hadoop.security.authentication.util.KerberosName; import org.apache.hadoop.security.authentication.util.KerberosUtil; @@ -68,6 +67,7 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.mockito.Mockito; import java.io.IOException; import java.lang.reflect.Field; @@ -78,12 +78,12 @@ import java.util.concurrent.atomic.AtomicLong; import static junit.framework.TestCase.fail; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @Ignore("See DRILL-5387") @Category(SecurityTest.class) public class TestBitBitKerberos extends BaseTestQuery { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestBitBitKerberos.class); - private static KerberosHelper krbHelper; private static DrillConfig newConfig; @@ -111,8 +111,7 @@ public class TestBitBitKerberos extends BaseTestQuery { .withValue(BootStrapContext.SERVICE_PRINCIPAL, ConfigValueFactory.fromAnyRef(krbHelper.SERVER_PRINCIPAL)) .withValue(BootStrapContext.SERVICE_KEYTAB_LOCATION, - ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString()))); // Ignore the compile time warning caused by the code below. @@ -134,40 +133,9 @@ public class TestBitBitKerberos extends BaseTestQuery { } private static void setupFragmentContextAndManager() { - final FragmentContext fcontext = new MockUp<FragmentContext>(){ - @SuppressWarnings("unused") - BufferAllocator getAllocator(){ - return c1.getAllocator(); - } - }.getMockInstance(); - - manager = new MockUp<FragmentManager>(){ - int v = 0; - - @Mock - boolean handle(IncomingDataBatch batch) throws FragmentSetupException, IOException { - try { - v++; - if (v % 10 == 0) { - System.out.println("sleeping."); - Thread.sleep(3000); - } - } catch (InterruptedException e) { - - } - RawFragmentBatch rfb = batch.newRawFragmentBatch(c1.getAllocator()); - rfb.sendOk(); - rfb.release(); - - return true; - } - - @SuppressWarnings("unused") - public FragmentContext getFragmentContext(){ - return fcontext; - } - - }.getMockInstance(); + final FragmentContextImpl fcontext = mock(FragmentContextImpl.class); + when(fcontext.getAllocator()).thenReturn(c1.getAllocator()); + manager = new MockFragmentManager(fcontext); } private static WritableBatch getRandomBatch(BufferAllocator allocator, int records) { @@ -222,11 +190,11 @@ public class TestBitBitKerberos extends BaseTestQuery { } @Test - public void success(@Injectable WorkerBee bee, @Injectable final WorkEventBus workBus) throws Exception { + public void success() throws Exception { + final WorkerBee bee = mock(WorkerBee.class); + final WorkEventBus workBus = mock(WorkEventBus.class); - new NonStrictExpectations() {{ - workBus.getFragmentManager( (FragmentHandle) any); result = manager; - }}; + when(workBus.getFragmentManager(Mockito.<FragmentHandle>any())).thenReturn(manager); DataConnectionConfig config = new DataConnectionConfig(c1.getAllocator(), c1, new DataServerRequestHandler(workBus, bee)); @@ -242,7 +210,6 @@ public class TestBitBitKerberos extends BaseTestQuery { tunnel.sendRecordBatch(new TimingOutcome(max), new FragmentWritableBatch(false, QueryId.getDefaultInstance(), 1, 1, 1, 1, getRandomBatch(c1.getAllocator(), 5000))); System.out.println(System.currentTimeMillis() - t1); - // System.out.println("sent."); } System.out.println(String.format("Max time: %d", max.get())); assertTrue(max.get() > 2700); @@ -250,7 +217,11 @@ public class TestBitBitKerberos extends BaseTestQuery { } @Test - public void successEncryption(@Injectable WorkerBee bee, @Injectable final WorkEventBus workBus) throws Exception { + public void successEncryption() throws Exception { + final WorkerBee bee = mock(WorkerBee.class); + final WorkEventBus workBus = mock(WorkEventBus.class); + + when(workBus.getFragmentManager(Mockito.<FragmentHandle>any())).thenReturn(manager); newConfig = new DrillConfig( config.withValue(ExecConstants.AUTHENTICATION_MECHANISMS, @@ -266,15 +237,10 @@ public class TestBitBitKerberos extends BaseTestQuery { .withValue(BootStrapContext.SERVICE_PRINCIPAL, ConfigValueFactory.fromAnyRef(krbHelper.SERVER_PRINCIPAL)) .withValue(BootStrapContext.SERVICE_KEYTAB_LOCATION, - ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString()))); updateTestCluster(1, newConfig); - new NonStrictExpectations() {{ - workBus.getFragmentManager( (FragmentHandle) any); result = manager; - }}; - DataConnectionConfig config = new DataConnectionConfig(c1.getAllocator(), c1, new DataServerRequestHandler(workBus, bee)); DataServer server = new DataServer(config); @@ -296,8 +262,14 @@ public class TestBitBitKerberos extends BaseTestQuery { } @Test - public void successEncryptionChunkMode(@Injectable WorkerBee bee, @Injectable final WorkEventBus workBus) + public void successEncryptionChunkMode() throws Exception { + + final WorkerBee bee = mock(WorkerBee.class); + final WorkEventBus workBus = mock(WorkEventBus.class); + + when(workBus.getFragmentManager(Mockito.<FragmentHandle>any())).thenReturn(manager); + newConfig = new DrillConfig( config.withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("kerberos"))) @@ -314,15 +286,10 @@ public class TestBitBitKerberos extends BaseTestQuery { .withValue(BootStrapContext.SERVICE_PRINCIPAL, ConfigValueFactory.fromAnyRef(krbHelper.SERVER_PRINCIPAL)) .withValue(BootStrapContext.SERVICE_KEYTAB_LOCATION, - ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString()))); updateTestCluster(1, newConfig); - new NonStrictExpectations() {{ - workBus.getFragmentManager( (FragmentHandle) any); result = manager; - }}; - DataConnectionConfig config = new DataConnectionConfig(c1.getAllocator(), c1, new DataServerRequestHandler(workBus, bee)); DataServer server = new DataServer(config); @@ -360,8 +327,7 @@ public class TestBitBitKerberos extends BaseTestQuery { .withValue(BootStrapContext.SERVICE_PRINCIPAL, ConfigValueFactory.fromAnyRef(krbHelper.SERVER_PRINCIPAL)) .withValue(BootStrapContext.SERVICE_KEYTAB_LOCATION, - ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString()))); updateTestCluster(1, newConfig); fail(); @@ -403,8 +369,7 @@ public class TestBitBitKerberos extends BaseTestQuery { .withValue(ExecConstants.BIT_AUTHENTICATION_MECHANISM, ConfigValueFactory.fromAnyRef("kerberos")) .withValue(ExecConstants.USE_LOGIN_PRINCIPAL, - ConfigValueFactory.fromAnyRef(false)) - ,false); + ConfigValueFactory.fromAnyRef(false))); updateTestCluster(1, newConfig, connectionProps); @@ -447,8 +412,7 @@ public class TestBitBitKerberos extends BaseTestQuery { .withValue(ExecConstants.BIT_AUTHENTICATION_MECHANISM, ConfigValueFactory.fromAnyRef("kerberos")) .withValue(ExecConstants.USE_LOGIN_PRINCIPAL, - ConfigValueFactory.fromAnyRef(false)) - ,false); + ConfigValueFactory.fromAnyRef(false))); updateTestCluster(2, newConfig, connectionProps); @@ -466,4 +430,72 @@ public class TestBitBitKerberos extends BaseTestQuery { public static void cleanTest() throws Exception { krbHelper.stopKdc(); } + + public static class MockFragmentManager implements FragmentManager + { + private int v = 0; + private final FragmentContextImpl fragmentContext; + + public MockFragmentManager(final FragmentContextImpl fragmentContext) + { + this.fragmentContext = Preconditions.checkNotNull(fragmentContext); + } + + @Override + public boolean handle(IncomingDataBatch batch) throws FragmentSetupException, IOException { + try { + v++; + if (v % 10 == 0) { + System.out.println("sleeping."); + Thread.sleep(3000); + } + } catch (InterruptedException e) { + + } + RawFragmentBatch rfb = batch.newRawFragmentBatch(c1.getAllocator()); + rfb.sendOk(); + rfb.release(); + + return true; + } + + @Override + public FragmentExecutor getRunnable() { + return null; + } + + @Override + public void cancel() { + + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public void unpause() { + + } + + @Override + public boolean isWaiting() { + return false; + } + + @Override + public FragmentHandle getHandle() { + return null; + } + + @Override + public FragmentContext getFragmentContext() { + return fragmentContext; + } + + @Override + public void receivingFragmentFinished(FragmentHandle handle) { + } + } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitRpc.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitRpc.java index 1e8318fa6..bd3e60f72 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitRpc.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitRpc.java @@ -20,10 +20,6 @@ package org.apache.drill.exec.rpc.data; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; -import mockit.Injectable; -import mockit.Mock; -import mockit.MockUp; -import mockit.NonStrictExpectations; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.scanner.ClassPathScanner; import org.apache.drill.common.types.TypeProtos.MinorType; @@ -33,6 +29,7 @@ import org.apache.drill.exec.exception.FragmentSetupException; import org.apache.drill.exec.expr.TypeHelper; import org.apache.drill.exec.memory.BufferAllocator; import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint; import org.apache.drill.exec.proto.ExecProtos.FragmentHandle; import org.apache.drill.exec.proto.GeneralRPCProtos.Ack; @@ -49,6 +46,7 @@ import org.apache.drill.exec.server.options.SystemOptionManager; import org.apache.drill.exec.vector.Float8Vector; import org.apache.drill.exec.vector.ValueVector; import org.apache.drill.exec.work.WorkManager.WorkerBee; +import org.apache.drill.exec.work.fragment.FragmentExecutor; import org.apache.drill.exec.work.fragment.FragmentManager; import org.junit.Test; @@ -58,55 +56,23 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestBitRpc extends ExecTest { - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestBitRpc.class); - @Test - public void testConnectionBackpressure(@Injectable WorkerBee bee, @Injectable final WorkEventBus workBus) throws Exception { - - DrillConfig config1 = DrillConfig.create(); + public void testConnectionBackpressure() throws Exception { + final WorkerBee bee = mock(WorkerBee.class); + final WorkEventBus workBus = mock(WorkEventBus.class); + final DrillConfig config1 = DrillConfig.create(); final BootStrapContext c = new BootStrapContext(config1, SystemOptionManager.createDefaultOptionDefinitions(), ClassPathScanner.fromPrescan(config1)); - DrillConfig config2 = DrillConfig.create(); - BootStrapContext c2 = new BootStrapContext(config2, SystemOptionManager.createDefaultOptionDefinitions(), ClassPathScanner.fromPrescan(config2)); + final FragmentContextImpl fcon = mock(FragmentContextImpl.class); + when(fcon.getAllocator()).thenReturn(c.getAllocator()); - final FragmentContext fcon = new MockUp<FragmentContext>(){ - BufferAllocator getAllocator(){ - return c.getAllocator(); - } - }.getMockInstance(); - - final FragmentManager fman = new MockUp<FragmentManager>(){ - int v = 0; - - @Mock - boolean handle(IncomingDataBatch batch) throws FragmentSetupException, IOException { - try { - v++; - if (v % 10 == 0) { - System.out.println("sleeping."); - Thread.sleep(3000); - } - } catch (InterruptedException e) { + final FragmentManager fman = new MockFragmentManager(c); - } - RawFragmentBatch rfb = batch.newRawFragmentBatch(c.getAllocator()); - rfb.sendOk(); - rfb.release(); - - return true; - } - - public FragmentContext getFragmentContext(){ - return fcon; - } - - }.getMockInstance(); - - - new NonStrictExpectations() {{ - workBus.getFragmentManager( (FragmentHandle) any); result = fman; - }}; + when(workBus.getFragmentManager(any(FragmentHandle.class))).thenReturn(fman); int port = 1234; @@ -124,7 +90,6 @@ public class TestBitRpc extends ExecTest { tunnel.sendRecordBatch(new TimingOutcome(max), new FragmentWritableBatch(false, QueryId.getDefaultInstance(), 1, 1, 1, 1, getRandomBatch(c.getAllocator(), 5000))); System.out.println(System.currentTimeMillis() - t1); - // System.out.println("sent."); } System.out.println(String.format("Max time: %d", max.get())); assertTrue(max.get() > 2700); @@ -180,4 +145,72 @@ public class TestBitRpc extends ExecTest { } } + public static class MockFragmentManager implements FragmentManager + { + private final BootStrapContext c; + private int v; + + public MockFragmentManager(BootStrapContext c) + { + this.c = c; + } + + @Override + public boolean handle(IncomingDataBatch batch) throws FragmentSetupException, IOException { + try { + v++; + if (v % 10 == 0) { + System.out.println("sleeping."); + Thread.sleep(3000); + } + } catch (InterruptedException e) { + + } + RawFragmentBatch rfb = batch.newRawFragmentBatch(c.getAllocator()); + rfb.sendOk(); + rfb.release(); + + return true; + } + + @Override + public FragmentExecutor getRunnable() { + return null; + } + + @Override + public void cancel() { + + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public void unpause() { + + } + + @Override + public boolean isWaiting() { + return false; + } + + @Override + public FragmentHandle getHandle() { + return null; + } + + @Override + public FragmentContext getFragmentContext() { + return null; + } + + @Override + public void receivingFragmentFinished(FragmentHandle handle) { + + } + } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java index 97360d3b6..1c017dca5 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestCustomUserAuthenticator.java @@ -52,8 +52,7 @@ public class TestCustomUserAuthenticator extends BaseTestQuery { .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef("true")) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, - ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), - false); + ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberos.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberos.java index 065746cdc..dbdbe3c81 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberos.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberos.java @@ -71,8 +71,7 @@ public class TestUserBitKerberos extends BaseTestQuery { .withValue(BootStrapContext.SERVICE_KEYTAB_LOCATION, ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, - ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))), - false); + ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos")))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberosEncryption.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberosEncryption.java index ac60880f1..aa26fd6ec 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberosEncryption.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberosEncryption.java @@ -77,8 +77,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)), - false); + ConfigValueFactory.fromAnyRef(true))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL); @@ -221,8 +220,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.USER_ENCRYPTION_SASL_MAX_WRAPPED_SIZE, - ConfigValueFactory.fromAnyRef(100)) - ,false); + ConfigValueFactory.fromAnyRef(100))); updateTestCluster(1, newConfig, connectionProps); @@ -259,8 +257,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)) - ,false); + ConfigValueFactory.fromAnyRef(true))); updateTestCluster(1, newConfig, connectionProps); @@ -315,8 +312,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.BIT_ENCRYPTION_SASL_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.BIT_ENCRYPTION_SASL_MAX_WRAPPED_SIZE, - ConfigValueFactory.fromAnyRef(10000)) - ,false); + ConfigValueFactory.fromAnyRef(10000))); updateTestCluster(1, newConfig, connectionProps); @@ -369,8 +365,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.USE_LOGIN_PRINCIPAL, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.BIT_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)) - ,false); + ConfigValueFactory.fromAnyRef(true))); updateTestCluster(1, newConfig, connectionProps); @@ -426,8 +421,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.USE_LOGIN_PRINCIPAL, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.BIT_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)) - ,false); + ConfigValueFactory.fromAnyRef(true))); updateTestCluster(1, newConfig, connectionProps); @@ -469,8 +463,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)), - false); + ConfigValueFactory.fromAnyRef(true))); updateTestCluster(1, newConfig, connectionProps); fail(); @@ -501,8 +494,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)), - false); + ConfigValueFactory.fromAnyRef(true))); updateTestCluster(1, newConfig, connectionProps); fail(); @@ -538,8 +530,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)), - false); + ConfigValueFactory.fromAnyRef(true))); updateTestCluster(1, newConfig, connectionProps); fail(); @@ -573,8 +564,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(BootStrapContext.SERVICE_KEYTAB_LOCATION, ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, - ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))), - false); + ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos")))); updateTestCluster(1, newConfig, connectionProps); } @@ -602,8 +592,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(BootStrapContext.SERVICE_KEYTAB_LOCATION, ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, - ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))) - , false); + ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos")))); updateTestCluster(1, newConfig, connectionProps); @@ -638,8 +627,7 @@ public class TestUserBitKerberosEncryption extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)) - , false); + ConfigValueFactory.fromAnyRef(true))); updateTestCluster(1, newConfig, connectionProps); } catch (Exception ex) { diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSSL.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSSL.java index 2fb08e301..0578d71a9 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSSL.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSSL.java @@ -76,8 +76,7 @@ public class TestUserBitSSL extends BaseTestQuery { .withValue(ExecConstants.SSL_TRUSTSTORE_PASSWORD, ConfigValueFactory.fromAnyRef("drill123")) .withValue(ExecConstants.SSL_PROTOCOL, - ConfigValueFactory.fromAnyRef("TLSv1.2")), - false); + ConfigValueFactory.fromAnyRef("TLSv1.2"))); initProps = new Properties(); initProps.setProperty(DrillProperties.ENABLE_TLS, "true"); @@ -92,7 +91,7 @@ public class TestUserBitSSL extends BaseTestQuery { @AfterClass public static void cleanTest() throws Exception { DrillConfig restoreConfig = - new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()), false); + new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())); updateTestCluster(1, restoreConfig); } @@ -253,7 +252,7 @@ public class TestUserBitSSL extends BaseTestQuery { .withValue(ExecConstants.SSL_KEYSTORE_TYPE, ConfigValueFactory.fromAnyRef("JKS")) .withValue(ExecConstants.SSL_KEYSTORE_PATH, ConfigValueFactory.fromAnyRef(keyStorePath)) .withValue(ExecConstants.SSL_KEYSTORE_PASSWORD, ConfigValueFactory.fromAnyRef("test_password")) - .withValue(ExecConstants.SSL_PROTOCOL, ConfigValueFactory.fromAnyRef("TLSv1.2")), false); + .withValue(ExecConstants.SSL_PROTOCOL, ConfigValueFactory.fromAnyRef("TLSv1.2"))); updateTestCluster(1, sslConfig, connectionProps); @@ -298,7 +297,7 @@ public class TestUserBitSSL extends BaseTestQuery { .withValue(ExecConstants.SSL_KEYSTORE_TYPE, ConfigValueFactory.fromAnyRef("JKS")) .withValue(ExecConstants.SSL_KEYSTORE_PATH, ConfigValueFactory.fromAnyRef(unknownKsPath)) .withValue(ExecConstants.SSL_KEYSTORE_PASSWORD, ConfigValueFactory.fromAnyRef("drill123")) - .withValue(ExecConstants.SSL_PROTOCOL, ConfigValueFactory.fromAnyRef("TLSv1.2")), false); + .withValue(ExecConstants.SSL_PROTOCOL, ConfigValueFactory.fromAnyRef("TLSv1.2"))); updateTestCluster(1, sslConfig, connectionProps); @@ -326,7 +325,7 @@ public class TestUserBitSSL extends BaseTestQuery { .withValue(ExecConstants.SSL_KEYSTORE_TYPE, ConfigValueFactory.fromAnyRef("JKS")) .withValue(ExecConstants.SSL_KEYSTORE_PATH, ConfigValueFactory.fromAnyRef(unknownKsPath)) .withValue(ExecConstants.SSL_KEYSTORE_PASSWORD, ConfigValueFactory.fromAnyRef("drill123")) - .withValue(ExecConstants.SSL_PROTOCOL, ConfigValueFactory.fromAnyRef("TLSv1.2")), false); + .withValue(ExecConstants.SSL_PROTOCOL, ConfigValueFactory.fromAnyRef("TLSv1.2"))); updateTestCluster(1, sslConfig, connectionProps); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSSLServer.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSSLServer.java index 470f95fa2..621309a38 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSSLServer.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSSLServer.java @@ -23,6 +23,7 @@ import org.apache.drill.test.BaseTestQuery; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.config.DrillProperties; import org.apache.drill.exec.ExecConstants; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -51,7 +52,7 @@ public class TestUserBitSSLServer extends BaseTestQuery { .withValue(ExecConstants.SSL_KEYSTORE_PATH, ConfigValueFactory.fromAnyRef(ksPath)) .withValue(ExecConstants.SSL_KEYSTORE_PASSWORD, ConfigValueFactory.fromAnyRef("drill123")) .withValue(ExecConstants.SSL_KEY_PASSWORD, ConfigValueFactory.fromAnyRef("drill123")) - .withValue(ExecConstants.SSL_PROTOCOL, ConfigValueFactory.fromAnyRef("TLSv1.2")), false); + .withValue(ExecConstants.SSL_PROTOCOL, ConfigValueFactory.fromAnyRef("TLSv1.2"))); initProps = new Properties(); initProps.setProperty(DrillProperties.ENABLE_TLS, "true"); initProps.setProperty(DrillProperties.TRUSTSTORE_PATH, tsPath); @@ -59,11 +60,17 @@ public class TestUserBitSSLServer extends BaseTestQuery { initProps.setProperty(DrillProperties.DISABLE_HOST_VERIFICATION, "true"); } + @AfterClass + public static void cleanTest() throws Exception { + DrillConfig restoreConfig = + new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())); + updateTestCluster(1, restoreConfig); + } + @Test public void testInvalidKeystorePath() throws Exception { DrillConfig testConfig = new DrillConfig(DrillConfig.create(sslConfig) - .withValue(ExecConstants.SSL_KEYSTORE_PATH, ConfigValueFactory.fromAnyRef("/bad/path")), - false); + .withValue(ExecConstants.SSL_KEYSTORE_PATH, ConfigValueFactory.fromAnyRef("/bad/path"))); // Start an SSL enabled cluster boolean failureCaught = false; @@ -78,8 +85,7 @@ public class TestUserBitSSLServer extends BaseTestQuery { @Test public void testInvalidKeystorePassword() throws Exception { DrillConfig testConfig = new DrillConfig(DrillConfig.create(sslConfig) - .withValue(ExecConstants.SSL_KEYSTORE_PASSWORD, ConfigValueFactory.fromAnyRef("badpassword")), - false); + .withValue(ExecConstants.SSL_KEYSTORE_PASSWORD, ConfigValueFactory.fromAnyRef("badpassword"))); // Start an SSL enabled cluster boolean failureCaught = false; @@ -94,8 +100,7 @@ public class TestUserBitSSLServer extends BaseTestQuery { @Test public void testInvalidKeyPassword() throws Exception { DrillConfig testConfig = new DrillConfig(DrillConfig.create(sslConfig) - .withValue(ExecConstants.SSL_KEY_PASSWORD, ConfigValueFactory.fromAnyRef("badpassword")), - false); + .withValue(ExecConstants.SSL_KEY_PASSWORD, ConfigValueFactory.fromAnyRef("badpassword"))); // Start an SSL enabled cluster boolean failureCaught = false; @@ -111,8 +116,7 @@ public class TestUserBitSSLServer extends BaseTestQuery { // Should pass because the keystore password will be used. public void testNoKeyPassword() throws Exception { DrillConfig testConfig = new DrillConfig(DrillConfig.create(sslConfig) - .withValue(ExecConstants.SSL_KEY_PASSWORD, ConfigValueFactory.fromAnyRef("")), - false); + .withValue(ExecConstants.SSL_KEY_PASSWORD, ConfigValueFactory.fromAnyRef(""))); // Start an SSL enabled cluster boolean failureCaught = false; diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSaslCompatibility.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSaslCompatibility.java index b957462ae..5a4ebf926 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSaslCompatibility.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSaslCompatibility.java @@ -52,8 +52,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(false)), - false); + ConfigValueFactory.fromAnyRef(false))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); @@ -72,8 +71,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, - ConfigValueFactory.fromAnyRef(false)), - false); + ConfigValueFactory.fromAnyRef(false))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); @@ -96,8 +94,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, - ConfigValueFactory.fromAnyRef(false)), - false); + ConfigValueFactory.fromAnyRef(false))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.AUTH_MECHANISM, "kerberos"); @@ -120,8 +117,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { public void testDisableDrillbitAuth_EnableClientEncryption() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, - ConfigValueFactory.fromAnyRef(false)), - false); + ConfigValueFactory.fromAnyRef(false))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); @@ -152,8 +148,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(false)), - false); + ConfigValueFactory.fromAnyRef(false))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); @@ -184,8 +179,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(false)), - false); + ConfigValueFactory.fromAnyRef(false))); final Properties connectionProps = new Properties(); @@ -213,8 +207,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)), - false); + ConfigValueFactory.fromAnyRef(true))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); @@ -244,8 +237,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(false)), - false); + ConfigValueFactory.fromAnyRef(false))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); @@ -274,8 +266,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, - ConfigValueFactory.fromAnyRef(true)), - false); + ConfigValueFactory.fromAnyRef(true))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); @@ -300,8 +291,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { public void testDisableDrillbitClientAuth() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, - ConfigValueFactory.fromAnyRef(false)), - false); + ConfigValueFactory.fromAnyRef(false))); final Properties connectionProps = new Properties(); @@ -325,8 +315,7 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { .withValue(ExecConstants.IMPERSONATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.IMPERSONATION_MAX_CHAINED_USER_HOPS, - ConfigValueFactory.fromAnyRef(3)), - false); + ConfigValueFactory.fromAnyRef(3))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); @@ -337,6 +326,5 @@ public class TestUserBitSaslCompatibility extends BaseTestQuery { fail(); } } - } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptionsAuthEnabled.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptionsAuthEnabled.java index 61eb85de1..733de1ff8 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptionsAuthEnabled.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestOptionsAuthEnabled.java @@ -57,8 +57,7 @@ public class TestOptionsAuthEnabled extends BaseTestQuery { final DrillConfig config = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, - ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), - false); + ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, PROCESS_USER); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/TestMainLoginPageModel.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/TestMainLoginPageModel.java index 3b36704a8..8e89e0c57 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/TestMainLoginPageModel.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/TestMainLoginPageModel.java @@ -73,7 +73,7 @@ public class TestMainLoginPageModel { public void testAuthEnabledWithNoMech() { final DrillConfig config = new DrillConfig(DrillConfig.create() .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, - ConfigValueFactory.fromAnyRef(true)), false); + ConfigValueFactory.fromAnyRef(true))); when(context.getConfig()).thenReturn(config); final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); assertTrue(model.isFormEnabled()); @@ -90,7 +90,7 @@ public class TestMainLoginPageModel { .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, - ConfigValueFactory.fromIterable(Lists.newArrayList("form"))), false); + ConfigValueFactory.fromIterable(Lists.newArrayList("form")))); when(context.getConfig()).thenReturn(config); final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); assertTrue(model.isFormEnabled()); @@ -107,7 +107,7 @@ public class TestMainLoginPageModel { .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, - ConfigValueFactory.fromIterable(Lists.newArrayList("spnego"))), false); + ConfigValueFactory.fromIterable(Lists.newArrayList("spnego")))); when(context.getConfig()).thenReturn(config); final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); assertTrue(!model.isFormEnabled()); @@ -124,7 +124,7 @@ public class TestMainLoginPageModel { .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, - ConfigValueFactory.fromIterable(Lists.newArrayList("form", "spnego"))), false); + ConfigValueFactory.fromIterable(Lists.newArrayList("form", "spnego")))); when(context.getConfig()).thenReturn(config); final MainLoginPageModel model = logInLogOutResources.new MainLoginPageModel(null); assertTrue(model.isFormEnabled()); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestDrillSpnegoAuthenticator.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestDrillSpnegoAuthenticator.java index 2b7da5622..2f078c2b1 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestDrillSpnegoAuthenticator.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestDrillSpnegoAuthenticator.java @@ -100,8 +100,7 @@ public class TestDrillSpnegoAuthenticator { .withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)) .withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, - ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString()))); // Create mock objects for optionManager and AuthConfiguration final SystemOptionManager optionManager = Mockito.mock(SystemOptionManager.class); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoAuthentication.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoAuthentication.java index 51171cd82..14253e229 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoAuthentication.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoAuthentication.java @@ -101,8 +101,7 @@ public class TestSpnegoAuthentication { .withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)) .withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, - ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString()))); final ScanResult scanResult = ClassPathScanner.fromPrescan(newConfig); final AuthenticatorProviderImpl authenticatorProvider = Mockito.mock(AuthenticatorProviderImpl.class); @@ -133,8 +132,7 @@ public class TestSpnegoAuthentication { .withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)) .withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, - ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString()))); final ScanResult scanResult = ClassPathScanner.fromPrescan(newConfig); final AuthenticatorProviderImpl authenticatorProvider = Mockito.mock(AuthenticatorProviderImpl.class); @@ -166,8 +164,7 @@ public class TestSpnegoAuthentication { .withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)) .withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, - ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString()))); final ScanResult scanResult = ClassPathScanner.fromPrescan(newConfig); final AuthenticatorProviderImpl authenticatorProvider = Mockito.mock(AuthenticatorProviderImpl.class); @@ -201,8 +198,7 @@ public class TestSpnegoAuthentication { .withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)) .withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, - ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString()))); final ScanResult scanResult = ClassPathScanner.fromPrescan(newConfig); final AuthenticatorProviderImpl authenticatorProvider = Mockito.mock(AuthenticatorProviderImpl.class); @@ -230,8 +226,7 @@ public class TestSpnegoAuthentication { final DrillConfig newConfig = new DrillConfig(DrillConfig.create() .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, - ConfigValueFactory.fromAnyRef(true)), - false); + ConfigValueFactory.fromAnyRef(true))); final ScanResult scanResult = ClassPathScanner.fromPrescan(newConfig); final AuthenticatorProviderImpl authenticatorProvider = Mockito.mock(AuthenticatorProviderImpl.class); @@ -294,8 +289,7 @@ public class TestSpnegoAuthentication { .withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)) .withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, - ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())), - false); + ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString()))); final SystemOptionManager optionManager = Mockito.mock(SystemOptionManager.class); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoConfig.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoConfig.java index 7803b9af5..d3c77c9e0 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoConfig.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoConfig.java @@ -89,8 +89,7 @@ public class TestSpnegoConfig { .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, - ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), - false); + ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))); final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig); spnegoConfig.validateSpnegoConfig(); @@ -107,7 +106,7 @@ public class TestSpnegoConfig { @Test public void testSpnegoConfigOnlyKeytab() throws Exception { try { - final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))).withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())).withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), false); + final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))).withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())).withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))); final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig); spnegoConfig.validateSpnegoConfig(); @@ -124,7 +123,7 @@ public class TestSpnegoConfig { @Test public void testSpnegoConfigOnlyPrincipal() throws Exception { try { - final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))).withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), false); + final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))).withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))); final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig); spnegoConfig.validateSpnegoConfig(); @@ -152,8 +151,7 @@ public class TestSpnegoConfig { .withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, - ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), - false); + ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))); final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig); spnegoConfig.validateSpnegoConfig(); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java index cdc316281..16348bcf4 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestAffinityCalculator.java @@ -21,7 +21,6 @@ import java.util.LinkedList; import org.apache.drill.exec.ExecTest; import org.apache.drill.exec.proto.CoordinationProtos; -import org.apache.drill.exec.store.parquet.ParquetGroupScan; import org.apache.hadoop.fs.BlockLocation; import org.junit.Test; @@ -29,10 +28,7 @@ import com.google.common.collect.ImmutableRangeMap; import com.google.common.collect.Range; public class TestAffinityCalculator extends ExecTest { - static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestAffinityCalculator.class); - - String port = "1234"; - final String path = "path"; + private final String port = "1234"; public BlockLocation[] buildBlockLocations(String[] hosts, long blockSize) { String[] names = new String[hosts.length]; @@ -50,34 +46,6 @@ public class TestAffinityCalculator extends ExecTest { return blockLocations; } - public BlockLocation[] buildBlockLocations2(String[] hosts, long blockSize) { - String[] names = new String[hosts.length]; - - for (int i = 0; i < hosts.length; i++) { - hosts[i] = "host" + i; - names[i] = "host:" + port; - } - - BlockLocation[] blockLocations = new BlockLocation[4]; - blockLocations[0] = new BlockLocation(new String[]{names[0]}, new String[]{hosts[0]}, 0, blockSize); - blockLocations[1] = new BlockLocation(new String[]{names[1]}, new String[]{hosts[1]}, blockSize, blockSize); - blockLocations[3] = new BlockLocation(new String[]{names[3]}, new String[]{hosts[3]}, blockSize*2, blockSize); - blockLocations[2] = new BlockLocation(new String[]{names[2]}, new String[]{hosts[2]}, blockSize*3, blockSize); - - return blockLocations; - } - public void buildRowGroups(LinkedList<ParquetGroupScan.RowGroupInfo> rowGroups, int numberOfBlocks, long blockSize, int numberOfRowGroups) { - long rowGroupSize = numberOfBlocks * blockSize / numberOfRowGroups; - - rowGroups.clear(); - - for (int i = 0; i < numberOfRowGroups; i++) { - // buildRowGroups method seems not be used at all. Pass -1 as rowCount. - // Maybe remove this method completely ? - rowGroups.add(new ParquetGroupScan.RowGroupInfo(path, (long)i*rowGroupSize, (long)rowGroupSize, i, -1)); - } - } - public LinkedList<CoordinationProtos.DrillbitEndpoint> buildEndpoints(int numberOfEndpoints) { LinkedList<CoordinationProtos.DrillbitEndpoint> endPoints = new LinkedList<>(); @@ -87,61 +55,6 @@ public class TestAffinityCalculator extends ExecTest { return endPoints; } -// @Test -// public void testSetEndpointBytes(@Injectable final FileSystem fs, @Injectable final FileStatus file) throws Throwable{ -// final long blockSize = 256*1024*1024; -// LinkedList<ParquetGroupScan.RowGroupInfo> rowGroups = new LinkedList<>(); -// int numberOfHosts = 4; -// int numberOfBlocks = 3; -// String port = "1234"; -// String[] hosts = new String[numberOfHosts]; -// -// final BlockLocation[] blockLocations = buildBlockLocations(hosts, blockSize); -// final LinkedList<CoordinationProtos.DrillbitEndpoint> endPoints = buildEndpoints(numberOfHosts); -// buildRowGroups(rowGroups, numberOfBlocks, blockSize, 3); -// -// new NonStrictExpectations() {{ -// fs.getFileBlockLocations(file, 0, 3*blockSize); result = blockLocations; -// fs.getFileStatus(new Path(path)); result = file; -// file.getLen(); result = 3*blockSize; -// }}; -// -// -// BlockMapBuilder ac = new BlockMapBuilder(fs, endPoints); -// for (ParquetGroupScan.RowGroupInfo rowGroup : rowGroups) { -// ac.setEndpointBytes(rowGroup); -// } -// ParquetGroupScan.RowGroupInfo rg = rowGroups.get(0); -// Long b = rg.getEndpointBytes().get(endPoints.get(0)); -// assertEquals(blockSize,b.longValue()); -// b = rg.getEndpointBytes().get(endPoints.get(3)); -// assertNull(b); -// -// buildRowGroups(rowGroups, numberOfBlocks, blockSize, 2); -// -// ac = new BlockMapBuilder(fs, endPoints); -// for (ParquetGroupScan.RowGroupInfo rowGroup : rowGroups) { -// ac.setEndpointBytes(rowGroup); -// } -// rg = rowGroups.get(0); -// b = rg.getEndpointBytes().get(endPoints.get(0)); -// assertEquals(blockSize*3/2,b.longValue()); -// b = rg.getEndpointBytes().get(endPoints.get(3)); -// assertEquals(blockSize / 2, b.longValue()); -// -// buildRowGroups(rowGroups, numberOfBlocks, blockSize, 6); -// -// ac = new BlockMapBuilder(fs, endPoints); -// for (ParquetGroupScan.RowGroupInfo rowGroup : rowGroups) { -// ac.setEndpointBytes(rowGroup); -// } -// rg = rowGroups.get(0); -// b = rg.getEndpointBytes().get(endPoints.get(0)); -// assertEquals(blockSize/2,b.longValue()); -// b = rg.getEndpointBytes().get(endPoints.get(3)); -// assertNull(b); -// } - @Test public void testBuildRangeMap() { BlockLocation[] blocks = buildBlockLocations(new String[4], 256*1024*1024); @@ -157,77 +70,4 @@ public class TestAffinityCalculator extends ExecTest { long tB = System.nanoTime(); System.out.println(String.format("Took %f ms to build range map", (tB - tA) / 1e6)); } - /* - @Test - public void testApplyAssignments(@Injectable final DrillbitContext context, @Injectable final ParquetStorageEngine engine, - @Injectable final FileSystem fs, @Injectable final FileStatus file) throws IOException { - - final long blockSize = 256*1024*1024; - LinkedList<ParquetGroupScan.RowGroupInfo> rowGroups = new LinkedList<>(); - int numberOfHosts = 4; - int numberOfBlocks = 4; - String port = "1234"; - String[] hosts = new String[numberOfHosts]; - - final BlockLocation[] blockLocations = buildBlockLocations2(hosts, blockSize); - final LinkedList<CoordinationProtos.DrillbitEndpoint> endPoints = buildEndpoints(numberOfHosts); - - new NonStrictExpectations() {{ - engine.getFileSystem(); result = fs; - engine.getContext(); result = context; - context.getBits(); result = endPoints; - fs.getFileBlockLocations(file, 0, 3*blockSize); result = blockLocations; - fs.getFileStatus(new Path(path)); result = file; - file.getLen(); result = 3*blockSize; - }}; - - buildRowGroups(rowGroups, numberOfBlocks, blockSize, 4); - ParquetGroupScan scan = new ParquetGroupScan(rowGroups, engine); - - List<EndpointAffinity> affinities = scan.getOperatorAffinity(); - - for (EndpointAffinity affinity : affinities) { - CoordinationProtos.DrillbitEndpoint db = affinity.getEndpoint(); - assertEquals((float)0.25, affinity.getAffinity(), .01); - } - - scan.applyAssignments(endPoints); - - for (int i = 0; i < endPoints.size(); i++) { - List<ParquetRowGroupScan.RowGroupReadEntry> rowGroupReadEntries = scan.getSpecificScan(i).getRowGroupReadEntries(); - assertEquals(1, rowGroupReadEntries.size()); - switch(i) { - case 0: assertEquals(0,rowGroupReadEntries.get(0).getRowGroupIndex()); - break; - case 1: assertEquals(1,rowGroupReadEntries.get(0).getRowGroupIndex()); - break; - case 2: assertEquals(3,rowGroupReadEntries.get(0).getRowGroupIndex()); - break; - case 3: assertEquals(2,rowGroupReadEntries.get(0).getRowGroupIndex()); - break; - } - } - - scan.applyAssignments(endPoints.subList(2,4)); - - List<ParquetRowGroupScan.RowGroupReadEntry> rowGroupReadEntries = scan.getSpecificScan(0).getRowGroupReadEntries(); - assertEquals(2, rowGroupReadEntries.size()); - assertEquals(3,rowGroupReadEntries.get(0).getRowGroupIndex()); - - rowGroupReadEntries = scan.getSpecificScan(1).getRowGroupReadEntries(); - assertEquals(2, rowGroupReadEntries.size()); - assertEquals(2,rowGroupReadEntries.get(0).getRowGroupIndex()); - - LinkedList<CoordinationProtos.DrillbitEndpoint> dupList = new LinkedList<>(); - dupList.add(endPoints.get(0)); - dupList.add(endPoints.get(0)); - scan.applyAssignments(dupList); - - rowGroupReadEntries = scan.getSpecificScan(0).getRowGroupReadEntries(); - assertEquals(2, rowGroupReadEntries.size()); - rowGroupReadEntries = scan.getSpecificScan(1).getRowGroupReadEntries(); - assertEquals(2, rowGroupReadEntries.size()); - } - */ - } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java index 397c512bb..b8e7750e6 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetRecordReaderTest.java @@ -21,6 +21,8 @@ import static org.apache.drill.exec.store.parquet.TestFileGenerator.populateFiel import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + import io.netty.buffer.DrillBuf; import java.io.File; @@ -30,8 +32,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -import mockit.Injectable; - +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.test.BaseTestQuery; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.expression.ExpressionPosition; @@ -42,7 +43,6 @@ import org.apache.drill.exec.exception.SchemaChangeException; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; import org.apache.drill.exec.memory.BufferAllocator; import org.apache.drill.exec.memory.RootAllocatorFactory; -import org.apache.drill.exec.ops.FragmentContext; import org.apache.drill.exec.physical.impl.OutputMutator; import org.apache.drill.exec.proto.BitControl; import org.apache.drill.exec.proto.UserBitShared.QueryType; @@ -600,23 +600,18 @@ public class ParquetRecordReaderTest extends BaseTestQuery { @Test @Ignore - public void testPerformance(@Injectable final DrillbitContext bitContext, - @Injectable UserClientConnection connection) throws Exception { + public void testPerformance() throws Exception { + final DrillbitContext bitContext = mock(DrillbitContext.class); + final UserClientConnection connection = mock(UserClientConnection.class); + final DrillConfig c = DrillConfig.create(); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); - final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); - -// new NonStrictExpectations() { -// { -// context.getAllocator(); result = BufferAllocator.getAllocator(DrillConfig.create()); -// } -// }; + final FragmentContextImpl context = new FragmentContextImpl(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry); final String fileName = "/tmp/parquet_test_performance.parquet"; final HashMap<String, FieldInfo> fields = new HashMap<>(); final ParquetTestProperties props = new ParquetTestProperties(1, 20 * 1000 * 1000, DEFAULT_BYTES_PER_PAGE, fields); populateFieldInfoMap(props); - //generateParquetFile(fileName, props); final Configuration dfsConfig = new Configuration(); final List<Footer> footers = ParquetFileReader.readFooters(dfsConfig, new Path(fileName)); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java index 85501d1ba..98e7ef237 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java @@ -21,7 +21,7 @@ package org.apache.drill.exec.store.parquet; import org.apache.commons.io.FileUtils; import org.apache.drill.PlanTestBase; import org.apache.drill.common.expression.LogicalExpression; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.planner.physical.PlannerSettings; import org.apache.drill.exec.proto.BitControl; import org.apache.hadoop.conf.Configuration; @@ -45,14 +45,14 @@ import static org.junit.Assert.assertEquals; public class TestParquetFilterPushDown extends PlanTestBase { private static final String CTAS_TABLE = "order_ctas"; - private static FragmentContext fragContext; + private static FragmentContextImpl fragContext; private static FileSystem fs; @BeforeClass public static void initFSAndCreateFragContext() throws Exception { fs = getLocalFileSystem(); - fragContext = new FragmentContext(bits[0].getContext(), + fragContext = new FragmentContextImpl(bits[0].getContext(), BitControl.PlanFragment.getDefaultInstance(), null, bits[0].getContext().getFunctionImplementationRegistry()); dirTestWatcher.copyResourceToRoot(Paths.get("parquetFilterPush")); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetMetadataCache.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetMetadataCache.java index 463021f60..f721ee4d3 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetMetadataCache.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetMetadataCache.java @@ -17,33 +17,32 @@ */ package org.apache.drill.exec.store.parquet; -import mockit.Mock; -import mockit.MockUp; import com.google.common.collect.Lists; -import mockit.integration.junit4.JMockit; +import org.apache.commons.io.filefilter.FalseFileFilter; +import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.drill.PlanTestBase; import org.apache.drill.categories.UnlikelyTest; import org.apache.commons.io.FileUtils; -import org.apache.drill.exec.store.dfs.MetadataContext; import org.apache.drill.exec.planner.physical.PlannerSettings; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.attribute.FileTime; +import java.util.Collection; import java.util.List; +import java.util.concurrent.TimeUnit; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -@RunWith(JMockit.class) public class TestParquetMetadataCache extends PlanTestBase { private static final String TABLE_NAME_1 = "parquetTable1"; private static final String TABLE_NAME_2 = "parquetTable2"; @@ -631,14 +630,7 @@ public class TestParquetMetadataCache extends PlanTestBase { File rootMetadataFile = FileUtils.getFile(dataDir, Metadata.METADATA_FILENAME); assertTrue(String.format("Metadata cache file '%s' isn't deleted", rootMetadataFile.getPath()), rootMetadataFile.delete()); - // mock Metadata tableModified method to avoid occasional metadata files updating - new MockUp<Metadata>() { - @Mock - boolean tableModified(List<String> directories, org.apache.hadoop.fs.Path metaFilePath, - org.apache.hadoop.fs.Path parentDir, MetadataContext metaContext) { - return false; - } - }; + setTimestampToZero(dataDir); String query = String.format("select dir0, dir1, o_custkey, o_orderdate from `%s` " + " where dir0=1994 or dir1='Q3'", rootMetaCorruptedTable); int expectedRowCount = 60; @@ -671,14 +663,7 @@ public class TestParquetMetadataCache extends PlanTestBase { assertTrue(String.format("Metadata cache file '%s' isn't deleted", secondInnerMetadataFile.getPath()), secondInnerMetadataFile.delete()); - // mock Metadata tableModified method to avoid occasional metadata files updating - new MockUp<Metadata>() { - @Mock - boolean tableModified(List<String> directories, org.apache.hadoop.fs.Path metaFilePath, - org.apache.hadoop.fs.Path parentDir, MetadataContext metaContext) { - return false; - } - }; + setTimestampToZero(dataDir); String query = String.format("select dir0, dir1, o_custkey, o_orderdate from `%s` " + " where dir0=1994 or dir1='Q3'", innerMetaCorruptedTable); @@ -696,6 +681,14 @@ public class TestParquetMetadataCache extends PlanTestBase { } } + private void setTimestampToZero(File dataDir) throws IOException { + Collection<File> dirs = FileUtils.listFilesAndDirs(dataDir, FalseFileFilter.INSTANCE, TrueFileFilter.INSTANCE); + + for (File dir: dirs) { + Files.setLastModifiedTime(dir.toPath(), FileTime.from(0, TimeUnit.MILLISECONDS)); + } + } + @Test // DRILL-4264 @Category(UnlikelyTest.class) public void testMetadataCacheFieldWithDots() throws Exception { diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestCountDownLatchInjection.java b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestCountDownLatchInjection.java index 6404e27ea..f904603be 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestCountDownLatchInjection.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestCountDownLatchInjection.java @@ -22,6 +22,7 @@ import static org.junit.Assert.fail; import java.util.concurrent.CountDownLatch; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.test.BaseTestQuery; import org.apache.drill.common.concurrent.ExtendedLatch; import org.apache.drill.exec.ops.QueryContext; @@ -45,7 +46,7 @@ public class TestCountDownLatchInjection extends BaseTestQuery { /** * Class whose methods we want to simulate count down latches at run-time for testing * purposes. The class must have access to {@link org.apache.drill.exec.ops.QueryContext} or - * {@link org.apache.drill.exec.ops.FragmentContext}. + * {@link FragmentContextImpl}. */ private static class DummyClass { private static final ControlsInjector injector = ControlsInjectorFactory.getInjector(DummyClass.class); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java index 571a79386..053756681 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/testing/TestPauseInjection.java @@ -22,6 +22,7 @@ import static org.junit.Assert.fail; import java.util.concurrent.CountDownLatch; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.test.BaseTestQuery; import org.apache.drill.common.concurrent.ExtendedLatch; import org.apache.drill.common.config.DrillConfig; @@ -53,7 +54,7 @@ public class TestPauseInjection extends BaseTestQuery { /** * Class whose methods we want to simulate pauses at run-time for testing * purposes. The class must have access to {@link org.apache.drill.exec.ops.QueryContext} or - * {@link org.apache.drill.exec.ops.FragmentContext}. + * {@link FragmentContextImpl}. */ private static class DummyClass { private static final Logger logger = org.slf4j.LoggerFactory.getLogger(DummyClass.class); diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java b/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java index 7a62ef336..f56df7797 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java @@ -20,9 +20,9 @@ package org.apache.drill.exec.util; import static org.junit.Assert.*; import org.apache.drill.exec.ExecConstants; +import org.apache.drill.exec.server.options.OptionManager; import org.apache.drill.test.DrillTest; import org.apache.drill.test.OperatorFixture; -import org.apache.drill.test.OperatorFixture.OperatorFixtureBuilder; import org.junit.Test; public class TestQueryMemoryAlloc extends DrillTest { @@ -32,75 +32,85 @@ public class TestQueryMemoryAlloc extends DrillTest { @Test public void testDefaultOptions() throws Exception { - OperatorFixtureBuilder builder = OperatorFixture.builder(); + OperatorFixture.Builder builder = OperatorFixture.builder(); builder.systemOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.05); builder.systemOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB); try (OperatorFixture fixture = builder.build()) { + final OptionManager optionManager = fixture.getOptionManager(); - // Out-of-box memory, use query memory per node as floor. + optionManager.setLocalOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.05); + optionManager.setLocalOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB); - long mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 8 * ONE_GB); + // Out-of-box memory, use query memory per node as floor. + long mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 8 * ONE_GB); assertEquals(2 * ONE_GB, mem); // Up to 40 GB, query memory dominates. - mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 40 * ONE_GB); + mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 40 * ONE_GB); assertEquals(2 * ONE_GB, mem); // After 40 GB, the percent dominates - mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 100 * ONE_GB); + mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 100 * ONE_GB); assertEquals(5 * ONE_GB, mem); } } @Test public void testCustomFloor() throws Exception { - OperatorFixtureBuilder builder = OperatorFixture.builder(); + OperatorFixture.Builder builder = OperatorFixture.builder(); builder.systemOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.05); builder.systemOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 3 * ONE_GB); try (OperatorFixture fixture = builder.build()) { + final OptionManager optionManager = fixture.getOptionManager(); - // Out-of-box memory, use query memory per node as floor. + optionManager.setLocalOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.05); + optionManager.setLocalOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 3 * ONE_GB); - long mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 8 * ONE_GB); + // Out-of-box memory, use query memory per node as floor. + long mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 8 * ONE_GB); assertEquals(3 * ONE_GB, mem); // Up to 60 GB, query memory dominates. - mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 60 * ONE_GB); + mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 60 * ONE_GB); assertEquals(3 * ONE_GB, mem); // After 60 GB, the percent dominates - mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 100 * ONE_GB); + mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 100 * ONE_GB); assertEquals(5 * ONE_GB, mem); } } @Test public void testCustomPercent() throws Exception { - OperatorFixtureBuilder builder = OperatorFixture.builder(); + OperatorFixture.Builder builder = OperatorFixture.builder(); builder.systemOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.10); builder.systemOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB); try (OperatorFixture fixture = builder.build()) { + final OptionManager optionManager = fixture.getOptionManager(); + + optionManager.setLocalOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.10); + optionManager.setLocalOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB); // Out-of-box memory, use query memory per node as floor. - long mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 8 * ONE_GB); + long mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 8 * ONE_GB); assertEquals(2 * ONE_GB, mem); // Up to 20 GB, query memory dominates. - mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 20 * ONE_GB); + mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 20 * ONE_GB); assertEquals(2 * ONE_GB, mem); // After 20 GB, the percent dominates - mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), fixture.options(), 30 * ONE_GB); + mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 30 * ONE_GB); assertEquals(3 * ONE_GB, mem); } } @@ -116,21 +126,26 @@ public class TestQueryMemoryAlloc extends DrillTest { @Test public void testOpMemory() throws Exception { - OperatorFixtureBuilder builder = OperatorFixture.builder(); + OperatorFixture.Builder builder = OperatorFixture.builder(); builder.systemOption(ExecConstants.CPU_LOAD_AVERAGE_KEY, 0.7); builder.systemOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 10); builder.systemOption(ExecConstants.MIN_MEMORY_PER_BUFFERED_OP_KEY, 40 * ONE_MB); try (OperatorFixture fixture = builder.build()) { + final OptionManager optionManager = fixture.getOptionManager(); + + optionManager.setLocalOption(ExecConstants.CPU_LOAD_AVERAGE_KEY, 0.7); + optionManager.setLocalOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 10); + optionManager.setLocalOption(ExecConstants.MIN_MEMORY_PER_BUFFERED_OP_KEY, 40 * ONE_MB); // Enough memory to go above configured minimum. - long opMinMem = MemoryAllocationUtilities.computeOperatorMemory(fixture.options(), 4 * ONE_GB, 2); + long opMinMem = MemoryAllocationUtilities.computeOperatorMemory(optionManager, 4 * ONE_GB, 2); assertEquals(4 * ONE_GB / 10 / 2, opMinMem); // Too little memory per operator. Use configured minimum. - opMinMem = MemoryAllocationUtilities.computeOperatorMemory(fixture.options(), ONE_GB, 100); + opMinMem = MemoryAllocationUtilities.computeOperatorMemory(optionManager, ONE_GB, 100); assertEquals(40 * ONE_MB, opMinMem); } } diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/work/fragment/FragmentStatusReporterTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/work/fragment/FragmentStatusReporterTest.java index 29cd6a2c1..7fae7a9c6 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/work/fragment/FragmentStatusReporterTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/work/fragment/FragmentStatusReporterTest.java @@ -19,12 +19,13 @@ package org.apache.drill.exec.work.fragment; import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint; +import org.apache.drill.exec.rpc.control.Controller; import org.apache.drill.exec.rpc.control.WorkEventBus; import org.junit.Before; import org.junit.Test; import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.FragmentContextImpl; import org.apache.drill.exec.ops.FragmentStats; import org.apache.drill.exec.proto.BitControl.FragmentStatus; import org.apache.drill.exec.proto.ExecProtos.FragmentHandle; @@ -47,20 +48,16 @@ import static org.apache.drill.exec.proto.UserBitShared.FragmentState.RUNNING; public class FragmentStatusReporterTest { - //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FragmentStatusReporterTest.class); - private FragmentStatusReporter statusReporter; private ControlTunnel foremanTunnel; - private FragmentContext context; + private FragmentContextImpl context; @Before public void setUp() throws Exception { - context = mock(FragmentContext.class); - when(context.getStats()).thenReturn(mock(FragmentStats.class)); - when(context.getHandle()).thenReturn(FragmentHandle.getDefaultInstance()); - when(context.getAllocator()).thenReturn(mock(BufferAllocator.class)); + context = mock(FragmentContextImpl.class); + Controller controller = mock(Controller.class); // Create 2 different endpoint such that foremanEndpoint is different than // localEndpoint @@ -68,9 +65,14 @@ public class FragmentStatusReporterTest { DrillbitEndpoint foremanEndpoint = DrillbitEndpoint.newBuilder().setAddress("10.0.0.2").build(); foremanTunnel = mock(ControlTunnel.class); + when(context.getEndpoint()).thenReturn(localEndpoint); + when(context.getController()).thenReturn(controller); + when(controller.getTunnel(foremanEndpoint)).thenReturn(foremanTunnel); + + when(context.getStats()).thenReturn(mock(FragmentStats.class)); + when(context.getHandle()).thenReturn(FragmentHandle.getDefaultInstance()); + when(context.getAllocator()).thenReturn(mock(BufferAllocator.class)); when(context.getForemanEndpoint()).thenReturn(foremanEndpoint); - when(context.getIdentity()).thenReturn(localEndpoint); - when(context.getControlTunnel(foremanEndpoint)).thenReturn(foremanTunnel); statusReporter = new FragmentStatusReporter(context); } @@ -132,7 +134,7 @@ public class FragmentStatusReporterTest { DrillbitEndpoint localEndpoint = DrillbitEndpoint.newBuilder().setAddress("10.0.0.1").build(); - when(context.getIdentity()).thenReturn(localEndpoint); + when(context.getEndpoint()).thenReturn(localEndpoint); when(context.getForemanEndpoint()).thenReturn(localEndpoint); when(context.getWorkEventbus()).thenReturn(mock(WorkEventBus.class)); @@ -153,7 +155,7 @@ public class FragmentStatusReporterTest { public void testCloseLocalForeman() throws Exception { DrillbitEndpoint localEndpoint = DrillbitEndpoint.newBuilder().setAddress("10.0.0.1").build(); - when(context.getIdentity()).thenReturn(localEndpoint); + when(context.getEndpoint()).thenReturn(localEndpoint); when(context.getForemanEndpoint()).thenReturn(localEndpoint); when(context.getWorkEventbus()).thenReturn(mock(WorkEventBus.class)); statusReporter = new FragmentStatusReporter(context); diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java index 8ee87c096..9ddcdb7e1 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java @@ -72,7 +72,6 @@ import static org.apache.drill.exec.util.StoragePluginTestUtils.TMP_SCHEMA; * creates the requested Drillbit and client. */ public class ClusterFixture extends BaseFixture implements AutoCloseable { - public static final String ENABLE_FULL_CACHE = "drill.exec.test.use-full-cache"; public static final int MAX_WIDTH_PER_NODE = 2; @SuppressWarnings("serial") diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ConfigBuilder.java b/exec/java-exec/src/test/java/org/apache/drill/test/ConfigBuilder.java index 287102089..cdb5eb075 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/ConfigBuilder.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ConfigBuilder.java @@ -21,11 +21,13 @@ import java.util.Collection; import java.util.Properties; import java.util.Map.Entry; +import com.typesafe.config.ConfigValue; import org.apache.drill.common.config.DrillConfig; import com.typesafe.config.Config; import com.typesafe.config.ConfigValueFactory; import org.apache.drill.common.map.CaseInsensitiveMap; +import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.server.options.OptionDefinition; import org.apache.drill.exec.server.options.SystemOptionManager; @@ -36,7 +38,7 @@ import org.apache.drill.exec.server.options.SystemOptionManager; public class ConfigBuilder { protected String configResource; - protected Properties configProps; + protected Properties configProps = new Properties(); protected CaseInsensitiveMap<OptionDefinition> definitions = SystemOptionManager.createDefaultOptionDefinitions(); /** @@ -45,17 +47,38 @@ public class ConfigBuilder { * @return this builder * @see {@link #put(String, Object)} */ - public ConfigBuilder configProps(Properties configProps) { if (hasResource()) { // Drill provides no constructor for this use case. throw new IllegalArgumentException( "Cannot provide both a config resource and config properties."); } + if (this.configProps == null) { - this.configProps = configProps; - } else { - this.configProps.putAll(configProps); + this.configProps = createDefaultProperties(); + } + + this.configProps.putAll(configProps); + + return this; + } + + public ConfigBuilder configProps(DrillConfig drillConfig) { + if (hasResource()) { + // Drill provides no constructor for this use case. + throw new IllegalArgumentException( "Cannot provide both a config resource and config properties."); } + + if (configProps == null) { + configProps = createDefaultProperties(); + } + + for (Entry<String, ConfigValue> entry: drillConfig.entrySet()) { + final Object key = entry.getKey(); + final Object value = entry.getValue().unwrapped(); + + configProps.put(key, value); + } + return this; } @@ -102,13 +125,25 @@ public class ConfigBuilder { // Drill provides no constructor for this use case. throw new IllegalArgumentException( "Cannot provide both a config resource and config properties."); } + if (configProps == null) { - configProps = new Properties(); + configProps = createDefaultProperties(); } + configProps.put(key, value.toString()); return this; } + private static Properties createDefaultProperties() + { + Properties properties = new Properties(); + properties.put(ExecConstants.CAST_TO_NULLABLE_NUMERIC, "false"); + properties.put(ExecConstants.USE_DYNAMIC_UDFS_KEY, "false"); + properties.put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, "false"); + + return properties; + } + public ConfigBuilder putDefinition(OptionDefinition definition) { definitions.put(definition.getValidator().getOptionName(), definition); return this; @@ -157,7 +192,7 @@ public class ConfigBuilder { ConfigValueFactory.fromAnyRef(entry.getValue())); } - return new DrillConfig(drillConfig, true); + return new DrillConfig(drillConfig); } public boolean hasResource() { diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java index 6135b1c9b..2cd5d021b 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java @@ -18,35 +18,51 @@ package org.apache.drill.test; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import com.google.common.base.Function; +import com.google.common.base.Preconditions; +import io.netty.buffer.DrillBuf; +import org.apache.calcite.schema.SchemaPlus; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.scanner.ClassPathScanner; import org.apache.drill.common.scanner.persistence.ScanResult; +import org.apache.drill.common.types.TypeProtos; import org.apache.drill.exec.ExecConstants; import org.apache.drill.exec.compile.CodeCompiler; import org.apache.drill.exec.exception.OutOfMemoryException; import org.apache.drill.exec.expr.fn.FunctionImplementationRegistry; +import org.apache.drill.exec.expr.holders.ValueHolder; import org.apache.drill.exec.memory.BufferAllocator; import org.apache.drill.exec.memory.RootAllocatorFactory; import org.apache.drill.exec.ops.BaseFragmentContext; import org.apache.drill.exec.ops.BaseOperatorContext; import org.apache.drill.exec.ops.BufferManager; import org.apache.drill.exec.ops.BufferManagerImpl; -import org.apache.drill.exec.ops.FragmentContextInterface; +import org.apache.drill.exec.ops.ContextInformation; +import org.apache.drill.exec.ops.FragmentContext; +import org.apache.drill.exec.ops.MetricDef; +import org.apache.drill.exec.ops.OpProfileDef; import org.apache.drill.exec.ops.OperatorContext; +import org.apache.drill.exec.ops.OperatorStatReceiver; import org.apache.drill.exec.ops.OperatorStats; import org.apache.drill.exec.physical.base.PhysicalOperator; +import org.apache.drill.exec.planner.PhysicalPlanReaderTestFactory; +import org.apache.drill.exec.proto.ExecProtos; import org.apache.drill.exec.record.BatchSchema; import org.apache.drill.exec.record.BatchSchema.SelectionVectorMode; import org.apache.drill.exec.record.TupleMetadata; import org.apache.drill.exec.record.TupleSchema; import org.apache.drill.exec.record.VectorContainer; import org.apache.drill.exec.record.selection.SelectionVector2; -import org.apache.drill.exec.server.DrillbitContext; import org.apache.drill.exec.server.options.OptionManager; import org.apache.drill.exec.server.options.SystemOptionManager; +import org.apache.drill.exec.store.PartitionExplorer; +import org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider; import org.apache.drill.exec.testing.ExecutionControls; import org.apache.drill.test.ClusterFixtureBuilder.RuntimeOption; import org.apache.drill.test.rowSet.DirectRowSet; @@ -83,34 +99,46 @@ import com.google.common.util.concurrent.ListenableFuture; * <li>Multiple threads of execution.</li> * </ul> */ - public class OperatorFixture extends BaseFixture implements AutoCloseable { + public OperatorContext operatorContext(PhysicalOperator config) { + return new MockOperatorContext(context, allocator(), config); + } + /** * Builds an operator fixture based on a set of config options and system/session * options. */ - - public static class OperatorFixtureBuilder + public static class Builder { - protected ConfigBuilder configBuilder = new ConfigBuilder(); - protected List<RuntimeOption> systemOptions; + protected List<RuntimeOption> systemOptions = new ArrayList<>(); protected ExecutionControls controls; + private final ConfigBuilder configBuilder = new ConfigBuilder(); + protected ExecutorService scanExecutor; + protected ExecutorService scanDecoderExecutor; + + public Builder() + { + } public ConfigBuilder configBuilder() { return configBuilder; } - public OperatorFixtureBuilder systemOption(String key, Object value) { - if (systemOptions == null) { - systemOptions = new ArrayList<>(); - } + public Builder systemOption(String key, Object value) { systemOptions.add(new RuntimeOption(key, value)); return this; } - public OperatorFixtureBuilder setControls(ExecutionControls controls) { - this.controls = controls; + public Builder setScanExecutor(final ExecutorService scanExecutor) + { + this.scanExecutor = Preconditions.checkNotNull(scanExecutor); + return this; + } + + public Builder setScanDecoderExecutor(final ExecutorService scanDecoderExecutor) + { + this.scanDecoderExecutor = Preconditions.checkNotNull(scanDecoderExecutor); return this; } @@ -124,21 +152,30 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { * uses the same code generation mechanism as the full Drill, but * provide test-specific versions of various other services. */ - - public static class TestFragmentContext extends BaseFragmentContext { - + public static class MockFragmentContext extends BaseFragmentContext { private final DrillConfig config; private final OptionManager options; private final CodeCompiler compiler; - private ExecutionControls controls; private final BufferManagerImpl bufferManager; private final BufferAllocator allocator; + private final ExecutorService scanExecutorService; + private final ExecutorService scanDecodeExecutorService; + + private ExecutorState executorState = new OperatorFixture.MockExecutorState(); + private ExecutionControls controls; - public TestFragmentContext(DrillConfig config, OptionManager options, BufferAllocator allocator) { + public MockFragmentContext(final DrillConfig config, + final OptionManager options, + final BufferAllocator allocator, + final ExecutorService scanExecutorService, + final ExecutorService scanDecodeExecutorService) { super(newFunctionRegistry(config, options)); - this.config = config; - this.options = options; - this.allocator = allocator; + this.config = Preconditions.checkNotNull(config); + this.options = Preconditions.checkNotNull(options); + this.allocator = Preconditions.checkNotNull(allocator); + this.scanExecutorService = scanExecutorService; + this.scanDecodeExecutorService = scanDecodeExecutorService; + this.controls = new ExecutionControls(options); compiler = new CodeCompiler(config, options); bufferManager = new BufferManagerImpl(allocator); } @@ -149,18 +186,14 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { return new FunctionImplementationRegistry(config, classpathScan, options); } - public void setExecutionControls(ExecutionControls controls) { - this.controls = controls; - } - @Override public OptionManager getOptions() { return options; } @Override - public boolean shouldContinue() { - return true; + public boolean isImpersonationEnabled() { + return false; } @Override @@ -174,35 +207,59 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { } @Override - public DrillbitContext getDrillbitContext() { - throw new UnsupportedOperationException("Drillbit context not available for operator unit tests"); + public ExecutorService getScanDecodeExecutor() { + return scanDecodeExecutorService; } @Override - protected CodeCompiler getCompiler() { - return compiler; + public ExecutorService getScanExecutor() { + return scanExecutorService; } @Override - protected BufferManager getBufferManager() { - return bufferManager; + public ExecutorService getExecutor() { + return null; + } + + @Override + public ExecutorState getExecutorState() { + return executorState; + } + + @Override + public BufferAllocator getNewChildAllocator(String operatorName, int operatorId, + long initialReservation, long maximumReservation) { + return allocator.newChildAllocator( + "op:" + operatorId + ":" + operatorName, + initialReservation, + maximumReservation); + } + + @Override + public ExecProtos.FragmentHandle getHandle() { + return ExecProtos.FragmentHandle.newBuilder().build(); + } + + @Override + public BufferAllocator getAllocator() { + return allocator; } @SuppressWarnings("resource") @Override public OperatorContext newOperatorContext(PhysicalOperator popConfig, - OperatorStats stats) throws OutOfMemoryException { + OperatorStats stats) throws OutOfMemoryException { BufferAllocator childAllocator = allocator.newChildAllocator( - "test:" + popConfig.getClass().getSimpleName(), - popConfig.getInitialAllocation(), - popConfig.getMaxAllocation() - ); - return new TestOperatorContext(this, childAllocator, popConfig); + "test:" + popConfig.getClass().getSimpleName(), + popConfig.getInitialAllocation(), + popConfig.getMaxAllocation() + ); + return new MockOperatorContext(this, childAllocator, popConfig); } @Override public OperatorContext newOperatorContext(PhysicalOperator popConfig) - throws OutOfMemoryException { + throws OutOfMemoryException { return newOperatorContext(popConfig, null); } @@ -210,43 +267,102 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { public String getQueryUserName() { return "fred"; } + @Override + public SchemaPlus getFullRootSchema() { + return null; + } + + @Override + public String getFragIdString() { + return null; + } + + @Override + public CodeCompiler getCompiler() { + return compiler; + } + + @Override + protected BufferManager getBufferManager() { + return bufferManager; + } + + @Override + public void close() { + bufferManager.close(); + } + + @Override + public ContextInformation getContextInformation() { + return null; + } + + @Override + public PartitionExplorer getPartitionExplorer() { + return null; + } + + @Override + public ValueHolder getConstantValueHolder(String value, TypeProtos.MinorType type, Function<DrillBuf, ValueHolder> holderInitializer) { + return null; + } } private final SystemOptionManager options; - private final TestFragmentContext context; + private final MockFragmentContext context; + private LocalPersistentStoreProvider provider; - protected OperatorFixture(OperatorFixtureBuilder builder) { + protected OperatorFixture(Builder builder) { config = builder.configBuilder().build(); allocator = RootAllocatorFactory.newRoot(config); - options = new SystemOptionManager(config); - try { - options.init(); - } catch (Exception e) { - throw new IllegalStateException("Failed to initialize the system option manager", e); - } - if (builder.systemOptions != null) { - applySystemOptions(builder.systemOptions); - } - context = new TestFragmentContext(config, options, allocator); + options = createOptionManager(); + context = new MockFragmentContext(config, options, allocator, builder.scanExecutor, builder.scanDecoderExecutor); + applySystemOptions(builder.systemOptions); } - private void applySystemOptions(List<RuntimeOption> systemOptions) { + private void applySystemOptions(List<RuntimeOption> systemOptions) { for (RuntimeOption option : systemOptions) { options.setLocalOption(option.key, option.value); } } - public SystemOptionManager options() { return options; } - public FragmentContextInterface fragmentContext() { return context; } + public OptionManager getOptionManager() + { + return options; + } + + private SystemOptionManager createOptionManager() + { + try { + provider = new LocalPersistentStoreProvider(config); + provider.start(); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + final SystemOptionManager options = new SystemOptionManager(PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(config), provider, config); + + try { + options.init(); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + return options; + } + + public FragmentContext getFragmentContext() { return context; } @Override public void close() throws Exception { + provider.close(); + context.close(); allocator.close(); options.close(); } - public static OperatorFixtureBuilder builder() { - OperatorFixtureBuilder builder = new OperatorFixtureBuilder(); + public static Builder builder() { + Builder builder = new Builder(); builder.configBuilder() // Required to avoid Dynamic UDF calls for missing or // ambiguous functions. @@ -287,19 +403,20 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { } } - public static class TestOperatorContext extends BaseOperatorContext { + public static class MockOperatorContext extends BaseOperatorContext { + private final OperatorStats operatorStats; - private final OperatorStats stats; - - public TestOperatorContext(FragmentContextInterface fragContext, - BufferAllocator allocator, - PhysicalOperator config) { + public MockOperatorContext(FragmentContext fragContext, + BufferAllocator allocator, + PhysicalOperator config) { super(fragContext, allocator, config); - stats = new OperatorStats(100, 101, 0, allocator); + this.operatorStats = new OperatorStats(new OpProfileDef(0, 0, 100), allocator); } @Override - public OperatorStats getStats() { return stats; } + public OperatorStats getStats() { + return operatorStats; + } @Override public <RESULT> ListenableFuture<RESULT> runCallableAs( @@ -308,14 +425,38 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { } } + public static class MockExecutorState implements FragmentContext.ExecutorState + { + @Override + public boolean shouldContinue() { + return true; + } + + @Override + public void fail(Throwable t) { + + } + + @Override + public boolean isFailed() { + return false; + } + + @Override + public Throwable getFailureCause() { + return null; + } + } + @SuppressWarnings("resource") public OperatorContext newOperatorContext(PhysicalOperator popConfig) { BufferAllocator childAllocator = allocator.newChildAllocator( - "test:" + popConfig.getClass().getSimpleName(), - popConfig.getInitialAllocation(), - popConfig.getMaxAllocation() - ); - return new TestOperatorContext(context, childAllocator, popConfig); + "test:" + popConfig.getClass().getSimpleName(), + popConfig.getInitialAllocation(), + popConfig.getMaxAllocation() + ); + + return new MockOperatorContext(context, childAllocator, popConfig); } public RowSet wrap(VectorContainer container, SelectionVector2 sv2) { |