Search in sources :

Example 6 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class SqlStatementTest method setUp.

public void setUp() {
    monitor = mock(Monitor.class);
    srv = mock(MondrianServer.class);
    when(srv.getMonitor()).thenReturn(monitor);
    rolapConnection = mock(RolapConnection.class);
    when(rolapConnection.getServer()).thenReturn(srv);
    statMock = mock(StatementImpl.class);
    when(statMock.getMondrianConnection()).thenReturn(rolapConnection);
    execution = new Execution(statMock, 0);
    execution = spy(execution);
    doThrow(MondrianResource.instance().QueryCanceled.ex()).when(execution).checkCancelOrTimeout();
    locus = new Locus(execution, "component", "message");
    statement = new SqlStatement(null, "sql", null, 0, 0, locus, 0, 0, null);
    statement = spy(statement);
}
Also used : Monitor(mondrian.server.monitor.Monitor) MondrianServer(mondrian.olap.MondrianServer) Execution(mondrian.server.Execution) StatementImpl(mondrian.server.StatementImpl) Locus(mondrian.server.Locus)

Example 7 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class MemberCacheControlTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    propSaver.set(MondrianProperties.instance().EnableRolapCubeMemberCache, false);
    RolapSchemaPool.instance().clear();
    final RolapConnection conn = (RolapConnection) getConnection();
    final Statement statement = conn.getInternalStatement();
    final Execution execution = new Execution(statement, 0);
    locus = new Locus(execution, getName(), null);
    Locus.push(locus);
}
Also used : Execution(mondrian.server.Execution) Statement(mondrian.server.Statement) Locus(mondrian.server.Locus)

Example 8 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class BatchTestCase method assertRequestSql.

/**
 * Checks that a given sequence of cell requests results in a
 * particular SQL statement being generated.
 *
 * <p>Always clears the cache before running the requests.
 *
 * <p>Runs the requests once for each SQL pattern in the current
 * dialect. If there are multiple patterns, runs the MDX query multiple
 * times, and expects to see each SQL statement appear. If there are no
 * patterns in this dialect, the test trivially succeeds.
 *
 * @param requests Sequence of cell requests
 * @param patterns Set of patterns
 * @param negative Set to false in order to 'expect' a query or
 * true to 'forbid' a query.
 */
protected void assertRequestSql(CellRequest[] requests, SqlPattern[] patterns, boolean negative) {
    final RolapStar star = requests[0].getMeasure().getStar();
    final String cubeName = requests[0].getMeasure().getCubeName();
    final RolapCube cube = lookupCube(cubeName);
    final Dialect sqlDialect = star.getSqlQueryDialect();
    Dialect.DatabaseProduct d = sqlDialect.getDatabaseProduct();
    SqlPattern sqlPattern = SqlPattern.getPattern(d, patterns);
    if (d == Dialect.DatabaseProduct.UNKNOWN) {
        // test. We do not print any warning message.
        return;
    }
    boolean patternFound = false;
    for (SqlPattern pattern : patterns) {
        if (!pattern.hasDatabaseProduct(d)) {
            continue;
        }
        patternFound = true;
        clearCache(cube);
        String sql = sqlPattern.getSql();
        String trigger = sqlPattern.getTriggerSql();
        switch(d) {
            case ORACLE:
                sql = sql.replaceAll(" =as= ", " ");
                trigger = trigger.replaceAll(" =as= ", " ");
                break;
            case TERADATA:
                sql = sql.replaceAll(" =as= ", " as ");
                trigger = trigger.replaceAll(" =as= ", " as ");
                break;
        }
        // Create a dummy DataSource which will throw a 'bomb' if it is
        // asked to execute a particular SQL statement, but will otherwise
        // behave exactly the same as the current DataSource.
        RolapUtil.setHook(new TriggerHook(trigger));
        Bomb bomb;
        final Execution execution = new Execution(((RolapConnection) getConnection()).getInternalStatement(), 1000);
        final AggregationManager aggMgr = execution.getMondrianStatement().getMondrianConnection().getServer().getAggregationManager();
        final Locus locus = new Locus(execution, "BatchTestCase", "BatchTestCase");
        try {
            FastBatchingCellReader fbcr = new FastBatchingCellReader(execution, getCube(cubeName), aggMgr);
            for (CellRequest request : requests) {
                fbcr.recordCellRequest(request);
            }
            // The FBCR will presume there is a current Locus in the stack,
            // so let's create a mock one.
            Locus.push(locus);
            fbcr.loadAggregations();
            bomb = null;
        } catch (Bomb e) {
            bomb = e;
        } catch (RuntimeException e) {
            // Walk up the exception tree and see if the root cause
            // was a SQL bomb.
            bomb = Util.getMatchingCause(e, Bomb.class);
            if (bomb == null) {
                throw e;
            }
        } finally {
            RolapUtil.setHook(null);
            Locus.pop(locus);
        }
        if (!negative && bomb == null) {
            fail("expected query [" + sql + "] did not occur");
        } else if (negative && bomb != null) {
            fail("forbidden query [" + sql + "] detected");
        }
        TestContext.assertEqualsVerbose(replaceQuotes(sql), replaceQuotes(bomb.sql));
    }
    // dialect.
    if (!patternFound) {
        String warnDialect = MondrianProperties.instance().WarnIfNoPatternForDialect.get();
        if (warnDialect.equals(d.toString())) {
            System.out.println("[No expected SQL statements found for dialect \"" + sqlDialect.toString() + "\" and test not run]");
        }
    }
}
Also used : Execution(mondrian.server.Execution) SqlPattern(mondrian.test.SqlPattern) Dialect(mondrian.spi.Dialect) Locus(mondrian.server.Locus)

Example 9 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class SegmentCacheManager method loadFailed.

/**
 * Informs cache manager that a segment load failed.
 *
 * <p>Called when a SQL statement receives an error while loading a
 * segment.</p>
 *
 * @param header segment header
 * @param throwable Error
 */
public void loadFailed(RolapStar star, SegmentHeader header, Throwable throwable) {
    final Locus locus = Locus.peek();
    ACTOR.event(handler, new SegmentLoadFailedEvent(System.currentTimeMillis(), locus.getServer().getMonitor(), locus.getServer().getId(), locus.execution.getMondrianStatement().getMondrianConnection().getId(), locus.execution.getMondrianStatement().getId(), locus.execution.getId(), star, header, throwable));
}
Also used : Locus(mondrian.server.Locus)

Example 10 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class SegmentCacheManager method remove.

/**
 * Removes a segment from segment index.
 *
 * <p>Call is asynchronous. It comes back immediately.</p>
 *
 * <p>Does not remove it from the external cache.</p>
 *
 * @param header segment header
 */
public void remove(RolapStar star, SegmentHeader header) {
    final Locus locus = Locus.peek();
    ACTOR.event(handler, new SegmentRemoveEvent(System.currentTimeMillis(), locus.getServer().getMonitor(), locus.getServer().getId(), locus.execution.getMondrianStatement().getMondrianConnection().getId(), locus.execution.getMondrianStatement().getId(), locus.execution.getId(), this, star, header));
}
Also used : Locus(mondrian.server.Locus)

Aggregations

Locus (mondrian.server.Locus)14 Execution (mondrian.server.Execution)4 SqlStatement (mondrian.rolap.SqlStatement)3 SegmentCacheIndex (mondrian.rolap.cache.SegmentCacheIndex)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Future (java.util.concurrent.Future)1 MondrianException (mondrian.olap.MondrianException)1 MondrianServer (mondrian.olap.MondrianServer)1 Util (mondrian.olap.Util)1 AbortException (mondrian.rolap.agg.SegmentCacheManager.AbortException)1 Statement (mondrian.server.Statement)1 StatementImpl (mondrian.server.StatementImpl)1 Monitor (mondrian.server.monitor.Monitor)1 Dialect (mondrian.spi.Dialect)1 SqlPattern (mondrian.test.SqlPattern)1 BooleanProperty (org.eigenbase.util.property.BooleanProperty)1