Instantiating Components

There are a few techniques for creating instances classes in unit tests:

  • Use a mocking library. (Depracated)
  • Provide a simple impementation of an interface
  • Build a real instance of class using the class's builders / constructors
  • Use the ClusterFixture or OperatorFixture classes to create instances of objects.

Mocking Libraries (Deprecated)

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.

Instantiating Contexts

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:

Creating An Instance of QueryId

UserBitShared.QueryId queryId = UserBitShared.QueryId.newBuilder()
  .setPart1(1L)
  .setPart2(2L)
  .build();

Creating FragmentHandle

ExecProtos.FragmentHandle fragmentHandle = ExecProtos.FragmentHandle.newBuilder()
  .setQueryId(queryId)
  .setMinorFragmentId(1)
  .setMajorFragmentId(2)
  .build();

Creating A DrillConfig

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.

Creating A SpillSet

  1. Create a PhysicalOperator.
    HashJoinPOP pop = new HashJoinPOP(null, null, null, JoinRelType.FULL);
    
  2. Create a DrillConfig.
  3. Create a FragmentHandle as described above.
  4. Create a SpillSet.
    SpillSet spillSet = new SpillSet(config, fragmentHandle, pop);
    

Creating A PersistentStoreProvider

LocalPersistentStoreProvider provider = new LocalPersistentStoreProvider(drillConfig);
provider.start();

Creating A LogicalPlanPersistence

LogicalPlanPersistence logicalPlanPersistence = PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(drillConfig);

Creating An Instance Of An Option Manager

You can create an instance of the SystemOptionManager by leveraging the OperatorFixture.

  1. Create an OperatorFixture.
  2. Retrieve the SystemOptionManager.
    operatorFixture.getOptionManager();