Search in sources :

Example 1 with NativeEvaluationUnsupportedException

use of mondrian.olap.NativeEvaluationUnsupportedException in project mondrian by pentaho.

the class NonEmptyTest method testNotNativeVirtualCubeCrossJoinUnsupported.

public void testNotNativeVirtualCubeCrossJoinUnsupported() {
    switch(getTestContext().getDialect().getDatabaseProduct()) {
        case INFOBRIGHT:
            // Hits same Infobright bug as NamedSetTest.testNamedSetOnMember.
            return;
    }
    final BooleanProperty enableProperty = MondrianProperties.instance().EnableNativeCrossJoin;
    final StringProperty alertProperty = MondrianProperties.instance().AlertNativeEvaluationUnsupported;
    if (!enableProperty.get()) {
        // are supposed to be raised.
        return;
    }
    String mdx = "select " + "{[Measures].AllMembers} on columns, " + "NonEmptyCrossJoin([Product].[All Products].children, " + "[Store].[All Stores].children) on rows " + "from [Warehouse and Sales]";
    final List<LoggingEvent> events = new ArrayList<LoggingEvent>();
    // set up log4j listener to detect alerts
    Appender alertListener = new AppenderSkeleton() {

        protected void append(LoggingEvent event) {
            events.add(event);
        }

        public void close() {
        }

        public boolean requiresLayout() {
            return false;
        }
    };
    final Logger rolapUtilLogger = Logger.getLogger(RolapUtil.class);
    propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
    rolapUtilLogger.addAppender(alertListener);
    String expectedMessage = "Unable to use native SQL evaluation for 'NonEmptyCrossJoin'";
    // verify that exception is thrown if alerting is set to ERROR
    propSaver.set(alertProperty, org.apache.log4j.Level.ERROR.toString());
    try {
        checkNotNative(3, mdx);
        fail("Expected NativeEvaluationUnsupportedException");
    } catch (Exception ex) {
        Throwable t = ex;
        while (t.getCause() != null && t != t.getCause()) {
            t = t.getCause();
        }
        if (!(t instanceof NativeEvaluationUnsupportedException)) {
            fail();
        }
    // Expected
    } finally {
        propSaver.reset();
        propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
    }
    // should have gotten one ERROR
    int nEvents = countFilteredEvents(events, org.apache.log4j.Level.ERROR, expectedMessage);
    assertEquals("logged error count check", 1, nEvents);
    events.clear();
    // verify that exactly one warning is posted but execution succeeds
    // if alerting is set to WARN
    propSaver.set(alertProperty, org.apache.log4j.Level.WARN.toString());
    try {
        checkNotNative(3, mdx);
    } finally {
        propSaver.reset();
        propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
    }
    // should have gotten one WARN
    nEvents = countFilteredEvents(events, org.apache.log4j.Level.WARN, expectedMessage);
    assertEquals("logged warning count check", 1, nEvents);
    events.clear();
    // verify that no warning is posted if native evaluation is
    // explicitly disabled
    propSaver.set(alertProperty, org.apache.log4j.Level.WARN.toString());
    propSaver.set(enableProperty, false);
    try {
        checkNotNative(3, mdx);
    } finally {
        propSaver.reset();
        propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
    }
    // should have gotten no WARN
    nEvents = countFilteredEvents(events, org.apache.log4j.Level.WARN, expectedMessage);
    assertEquals("logged warning count check", 0, nEvents);
    events.clear();
    // no biggie if we don't get here for some reason; just being
    // half-heartedly clean
    rolapUtilLogger.removeAppender(alertListener);
}
Also used : Appender(org.apache.log4j.Appender) AppenderSkeleton(org.apache.log4j.AppenderSkeleton) BooleanProperty(org.eigenbase.util.property.BooleanProperty) ArrayList(java.util.ArrayList) StringProperty(org.eigenbase.util.property.StringProperty) Logger(org.apache.log4j.Logger) NativeEvaluationUnsupportedException(mondrian.olap.NativeEvaluationUnsupportedException) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) LoggingEvent(org.apache.log4j.spi.LoggingEvent) NativeEvaluationUnsupportedException(mondrian.olap.NativeEvaluationUnsupportedException)

Aggregations

ArrayList (java.util.ArrayList)1 NativeEvaluationUnsupportedException (mondrian.olap.NativeEvaluationUnsupportedException)1 MemberChildrenConstraint (mondrian.rolap.sql.MemberChildrenConstraint)1 TupleConstraint (mondrian.rolap.sql.TupleConstraint)1 Appender (org.apache.log4j.Appender)1 AppenderSkeleton (org.apache.log4j.AppenderSkeleton)1 Logger (org.apache.log4j.Logger)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 BooleanProperty (org.eigenbase.util.property.BooleanProperty)1 StringProperty (org.eigenbase.util.property.StringProperty)1