示例#1
0
  /**
   * Makes sure the MDX runs correctly and not in native mode.
   *
   * @param rowCount Number of rows returned
   * @param mdx Query
   * @param expectedResult Expected result string
   */
  protected void checkNotNative(int rowCount, String mdx, String expectedResult) {
    getConnection().getCacheControl(null).flushSchemaCache();
    Connection con = getTestContext().withSchemaPool(false).getConnection();
    RolapNativeRegistry reg = getRegistry(con);
    reg.setListener(
        new Listener() {
          public void foundEvaluator(NativeEvent e) {
            fail("should not be executed native");
          }

          public void foundInCache(TupleEvent e) {}

          public void executingSql(TupleEvent e) {}
        });

    TestCase c = new TestCase(con, 0, rowCount, mdx);
    Result result = c.run();

    if (expectedResult != null) {
      String nonNativeResult = TestContext.toString(result);
      if (!nonNativeResult.equals(expectedResult)) {
        TestContext.assertEqualsVerbose(
            expectedResult,
            nonNativeResult,
            false,
            "Non Native implementation returned different result than " + "expected; MDX=" + mdx);
      }
    }
  }
示例#2
0
  /**
   * Runs a query twice, with native crossjoin optimization enabled and disabled. If both results
   * are equal,and both aggree with the expected result, it is considered correct.
   *
   * <p>Optionally the query can be run with fresh connection. This is useful if the test case sets
   * its certain mondrian properties, e.g. native properties like: mondrian.native.filter.enable
   *
   * @param resultLimit Maximum result size of all the MDX operations in this query. This might be
   *     hard to estimate as it is usually larger than the rowCount of the final result. Setting it
   *     to 0 will cause this limit to be ignored.
   * @param rowCount Number of rows returned. (That is, the number of positions on the last axis of
   *     the query.)
   * @param mdx Query
   * @param expectedResult Expected result string
   * @param freshConnection Whether fresh connection is required
   */
  protected void checkNative(
      int resultLimit, int rowCount, String mdx, String expectedResult, boolean freshConnection) {
    // Don't run the test if we're testing expression dependencies.
    // Expression dependencies cause spurious interval calls to
    // 'level.getMembers()' which create false negatives in this test.
    if (MondrianProperties.instance().TestExpDependencies.get() > 0) {
      return;
    }

    getConnection().getCacheControl(null).flushSchemaCache();
    try {
      Logger.getLogger(getClass()).debug("*** Native: " + mdx);
      boolean reuseConnection = !freshConnection;
      Connection con = getTestContext().withSchemaPool(reuseConnection).getConnection();
      RolapNativeRegistry reg = getRegistry(con);
      reg.useHardCache(true);
      TestListener listener = new TestListener();
      reg.setListener(listener);
      reg.setEnabled(true);
      TestCase c = new TestCase(con, resultLimit, rowCount, mdx);
      Result result = c.run();
      String nativeResult = TestContext.toString(result);
      if (!listener.isFoundEvaluator()) {
        fail("expected native execution of " + mdx);
      }
      if (!listener.isExecuteSql()) {
        fail("cache is empty: expected SQL query to be executed");
      }
      if (MondrianProperties.instance().EnableRolapCubeMemberCache.get()) {
        // run once more to make sure that the result comes from cache
        // now
        listener.setExecuteSql(false);
        c.run();
        if (listener.isExecuteSql()) {
          fail("expected result from cache when query runs twice");
        }
      }
      con.close();

      Logger.getLogger(getClass()).debug("*** Interpreter: " + mdx);

      getConnection().getCacheControl(null).flushSchemaCache();
      con = getTestContext().withSchemaPool(false).getConnection();
      reg = getRegistry(con);
      listener.setFoundEvaluator(false);
      reg.setListener(listener);
      // disable RolapNativeSet
      reg.setEnabled(false);
      result = executeQuery(mdx, con);
      String interpretedResult = TestContext.toString(result);
      if (listener.isFoundEvaluator()) {
        fail("did not expect native executions of " + mdx);
      }

      if (expectedResult != null) {
        TestContext.assertEqualsVerbose(
            expectedResult,
            nativeResult,
            false,
            "Native implementation returned different result than " + "expected; MDX=" + mdx);
        TestContext.assertEqualsVerbose(
            expectedResult,
            interpretedResult,
            false,
            "Interpreter implementation returned different result than " + "expected; MDX=" + mdx);
      }

      if (!nativeResult.equals(interpretedResult)) {
        TestContext.assertEqualsVerbose(
            interpretedResult,
            nativeResult,
            false,
            "Native implementation returned different result than " + "interpreter; MDX=" + mdx);
      }
    } finally {
      Connection con = getConnection();
      RolapNativeRegistry reg = getRegistry(con);
      reg.setEnabled(true);
      reg.useHardCache(false);
    }
  }