There are a few techniques for creating instances classes in unit tests:
Drill uses two mocking libraries in order to mock classes.
These libraries were originally used to work around the lack of well defined interfaces and adequate testing tools. Drill has made significant improvements in these areas so using mocking libraries are no longer required. Existing tests that use these libraries will be refactored to remove them, and new tests should NOT use these libraries.
There are several contexts used throughout Drill, for a complete description of each and how they are used please see FragmentContextImpl.
When doing tests you can use the following mock contexts:
FragmentContext context = operatorFixture.getFragmentContext();
UserBitShared.QueryId queryId = UserBitShared.QueryId.newBuilder() .setPart1(1L) .setPart2(2L) .build();
ExecProtos.FragmentHandle fragmentHandle = ExecProtos.FragmentHandle.newBuilder() .setQueryId(queryId) .setMinorFragmentId(1) .setMajorFragmentId(2) .build();
There are a few ways to create a DrillConfig. The simplest way is to create a ClusterFixture or OperatorFixture and then do the following:
DrillConfig drillConfig = clusterFixture.config();
or
DrillConfig drillConfig = operatorFixture.config();
If you need a DrillConfig and don't want all the extra things provided by ClusterFixture and OperatorFixture, you can use ConfigBuilder.
HashJoinPOP pop = new HashJoinPOP(null, null, null, JoinRelType.FULL);
SpillSet spillSet = new SpillSet(config, fragmentHandle, pop);
LocalPersistentStoreProvider provider = new LocalPersistentStoreProvider(drillConfig); provider.start();
LogicalPlanPersistence logicalPlanPersistence = PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(drillConfig);
You can create an instance of the SystemOptionManager by leveraging the OperatorFixture.
operatorFixture.getOptionManager();