public void run(HookContext hookContext) {
    SessionState ss = SessionState.get();
    Assert.assertNotNull("SessionState returned null");

    int expectedReducers = hookContext.getConf().getInt(BUCKET_CONFIG, 0);
    if (ss.getConf().get(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE.varname).equals("mr")) {
      Map<String, MapRedStats> stats = ss.getMapRedStats();
      Assert.assertEquals("Number of MapReduce jobs is incorrect", 1, stats.size());

      MapRedStats stat = stats.values().iterator().next();
      Assert.assertEquals("NumReducers is incorrect", expectedReducers, stat.getNumReduce());
    } else if (ss.getConf().get(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE.varname).equals("tez")) {
      TezProgressMonitor tezProgressMonitor = (TezProgressMonitor) ss.getProgressMonitor();
      Map<String, Progress> progressMap = tezProgressMonitor.getStatus().getVertexProgress();
      int totalReducers = 0;
      for (Map.Entry<String, Progress> entry : progressMap.entrySet()) {
        // relying on the name of vertex is fragile, but this will do for now for the tests
        if (entry.getKey().contains("Reducer")) {
          totalReducers += entry.getValue().getTotalTaskCount();
        }
      }
      Assert.assertEquals("Number of reducers is incorrect", expectedReducers, totalReducers);
    }
  }
VerifyNumReducersHook.

Provided a query involves exactly 1 map reduce job, this hook can be used to verify that the
number of reducers matches what is expected.

Use the config VerifyNumReducersHook.num.reducers to specify the expected number of reducers.
itests/util/src/main/java/org/apache/hadoop/hive/ql/hooks/VerifyNumReducersHook.java