use of mondrian.olap.CacheControl in project pentaho-platform by pentaho.
the class MondrianFlushCacheComponent method executeAction.
public boolean executeAction() {
MDXLookupRule mdxLookupRule = getLookupRule();
Connection conn = ((MDXConnection) mdxLookupRule.shareConnection()).getConnection();
CacheControl cacheControl = conn.getCacheControl(null);
Cube[] cubes = conn.getSchema().getCubes();
for (Cube cube : cubes) {
cacheControl.flush(cacheControl.createMeasuresRegion(cube));
}
cacheControl.flushSchema(conn.getSchema());
return true;
}
use of mondrian.olap.CacheControl in project mondrian by pentaho.
the class SegmentCacheTest method testSegmentCacheEvents.
public void testSegmentCacheEvents() throws Exception {
SegmentCache mockCache = new MockSegmentCache();
SegmentCacheWorker testWorker = new SegmentCacheWorker(mockCache, null);
// Flush the cache before we start. Wait a second for the cache
// flush to propagate.
final CacheControl cc = getTestContext().getConnection().getCacheControl(null);
Cube salesCube = getCube("Sales");
cc.flush(cc.createMeasuresRegion(salesCube));
Thread.sleep(1000);
MondrianServer.forConnection(getTestContext().getConnection()).getAggregationManager().cacheMgr.segmentCacheWorkers.add(testWorker);
final List<SegmentHeader> createdHeaders = new ArrayList<SegmentHeader>();
final List<SegmentHeader> deletedHeaders = new ArrayList<SegmentHeader>();
final SegmentCache.SegmentCacheListener listener = new SegmentCache.SegmentCacheListener() {
public void handle(SegmentCacheEvent e) {
switch(e.getEventType()) {
case ENTRY_CREATED:
createdHeaders.add(e.getSource());
break;
case ENTRY_DELETED:
deletedHeaders.add(e.getSource());
break;
default:
throw new UnsupportedOperationException();
}
}
};
try {
// Register our custom listener.
((CompositeSegmentCache) MondrianServer.forConnection(getTestContext().getConnection()).getAggregationManager().cacheMgr.compositeCache).addListener(listener);
// Now execute a query and check the events
executeQuery("select {[Measures].[Unit Sales]} on columns from [Sales]");
// Wait for propagation.
Thread.sleep(2000);
assertEquals(2, createdHeaders.size());
assertEquals(0, deletedHeaders.size());
assertEquals("Sales", createdHeaders.get(0).cubeName);
assertEquals("FoodMart", createdHeaders.get(0).schemaName);
assertEquals("Unit Sales", createdHeaders.get(0).measureName);
createdHeaders.clear();
deletedHeaders.clear();
// Now flush the segment and check the events.
cc.flush(cc.createMeasuresRegion(salesCube));
// Wait for propagation.
Thread.sleep(2000);
assertEquals(0, createdHeaders.size());
assertEquals(2, deletedHeaders.size());
assertEquals("Sales", deletedHeaders.get(0).cubeName);
assertEquals("FoodMart", deletedHeaders.get(0).schemaName);
assertEquals("Unit Sales", deletedHeaders.get(0).measureName);
} finally {
((CompositeSegmentCache) MondrianServer.forConnection(getTestContext().getConnection()).getAggregationManager().cacheMgr.compositeCache).removeListener(listener);
MondrianServer.forConnection(getTestContext().getConnection()).getAggregationManager().cacheMgr.segmentCacheWorkers.remove(testWorker);
}
}
use of mondrian.olap.CacheControl in project mondrian by pentaho.
the class BatchTestCase method clearCache.
private void clearCache(RolapCube cube) {
// Clear the cache for the Sales cube, so the query runs as if
// for the first time. (TODO: Cleaner way to do this.)
final Cube salesCube = getConnection().getSchema().lookupCube("Sales", true);
RolapHierarchy hierarchy = (RolapHierarchy) salesCube.lookupHierarchy(new Id.NameSegment("Store", Id.Quoting.UNQUOTED), false);
SmartMemberReader memberReader = (SmartMemberReader) hierarchy.getMemberReader();
MemberCacheHelper cacheHelper = memberReader.cacheHelper;
cacheHelper.mapLevelToMembers.cache.clear();
cacheHelper.mapMemberToChildren.cache.clear();
// Flush the cache, to ensure that the query gets executed.
cube.clearCachedAggregations(true);
CacheControl cacheControl = getConnection().getCacheControl(null);
final CacheControl.CellRegion measuresRegion = cacheControl.createMeasuresRegion(cube);
cacheControl.flush(measuresRegion);
waitForFlush(cacheControl, measuresRegion, cube.getName());
}
use of mondrian.olap.CacheControl in project mondrian by pentaho.
the class NativeSetEvaluationTest method testNativeSetsCacheClearing.
/**
* tests if cache associated with Native Sets is flushed.
*
* @see <a href="http://jira.pentaho.com/browse/MONDRIAN-2366">Jira issue</a>
*/
public void testNativeSetsCacheClearing() {
if (MondrianProperties.instance().ReadAggregates.get() && MondrianProperties.instance().UseAggregates.get()) {
return;
}
final String mdx = "select filter( gender.gender.members, measures.[Unit Sales] > 0) on 0 from sales ";
final String query = "select\n" + " `customer`.`gender` as `c0`\n" + "from\n" + " `customer` as `customer`,\n" + " `sales_fact_1997` as `sales_fact_1997`,\n" + " `time_by_day` as `time_by_day`\n" + "where\n" + " `sales_fact_1997`.`customer_id` = `customer`.`customer_id`\n" + "and\n" + " `sales_fact_1997`.`time_id` = `time_by_day`.`time_id`\n" + "and\n" + " `time_by_day`.`the_year` = 1997\n" + "group by\n" + " `customer`.`gender`\n" + "having\n" + " (sum(`sales_fact_1997`.`unit_sales`) > 0)\n" + "order by\n" + (TestContext.instance().getDialect().requiresOrderByAlias() ? " ISNULL(`c0`) ASC, `c0` ASC" : " ISNULL(`customer`.`gender`) ASC, `customer`.`gender` ASC");
propSaver.set(propSaver.properties.GenerateFormattedSql, true);
SqlPattern mysqlPattern = new SqlPattern(DatabaseProduct.MYSQL, query, null);
mondrian.olap.Result rest = executeQuery(mdx);
RolapCube cube = (RolapCube) rest.getQuery().getCube();
RolapConnection con = (RolapConnection) rest.getQuery().getConnection();
CacheControl cacheControl = con.getCacheControl(null);
for (RolapHierarchy hier : cube.getHierarchies()) {
if (hier.hasAll()) {
cacheControl.flush(cacheControl.createMemberSet(hier.getAllMember(), true));
}
}
SqlPattern[] patterns = new SqlPattern[] { mysqlPattern };
if (propSaver.properties.EnableNativeFilter.get()) {
assertQuerySqlOrNot(getTestContext(), mdx, patterns, false, false, false);
}
}
Aggregations