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);
}
Aggregations