Search in sources :

Example 1 with CodeCompiler

use of org.apache.drill.exec.compile.CodeCompiler in project drill by apache.

the class PhysicalOpUnitTestBase method mockFragmentContext.

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;
            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();
            try {
                CodeGenerator<?> cg = CodeGenerator.get(templateClassDefinition, funcReg);
                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, funcReg).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);
            }
        }
    };
}
Also used : ClassTransformationException(org.apache.drill.exec.exception.ClassTransformationException) CodeCompiler(org.apache.drill.exec.compile.CodeCompiler) IOException(java.io.IOException) NonStrictExpectations(mockit.NonStrictExpectations)

Aggregations

IOException (java.io.IOException)1 NonStrictExpectations (mockit.NonStrictExpectations)1 CodeCompiler (org.apache.drill.exec.compile.CodeCompiler)1 ClassTransformationException (org.apache.drill.exec.exception.ClassTransformationException)1