Skip to content

Commit

Permalink
MONDRIAN: Clear thread-local cache at start and end of statement exec…
Browse files Browse the repository at this point in the history
…ution.

    Nullify pointers in TestCase.tearDown, to allow gc to happen sooner.
    'ant all' now also compiles tests.

[git-p4: depot-paths = "//open/mondrian/": change = 14878]
  • Loading branch information
julianhyde committed Jan 8, 2012
1 parent 5bd3292 commit 4e0c790
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -468,6 +468,7 @@ demo/access/MondrianFoodMart.mdb"/>

<target name="all" depends="
compile,
compile.tests,
unzip-databases"/>

<target name="unzip-databases" depends="
Expand Down
2 changes: 2 additions & 0 deletions src/main/mondrian/rolap/RolapConnection.java
Expand Up @@ -666,6 +666,7 @@ public void memoryUsageNotification(long used, long max) {
Result result;
try {
statement.start(execution);
((RolapCube) query.getCube()).clearCachedAggregations(true);
result = new RolapResult(execution, true);
int i = 0;
for (QueryAxis axis : query.getAxes()) {
Expand All @@ -676,6 +677,7 @@ public void memoryUsageNotification(long used, long max) {
}
} finally {
Locus.pop(locus);
((RolapCube) query.getCube()).clearCachedAggregations(true);
}
statement.end(execution);
return result;
Expand Down
10 changes: 6 additions & 4 deletions src/main/mondrian/rolap/RolapStar.java
Expand Up @@ -20,7 +20,6 @@
import mondrian.server.Locus;
import mondrian.spi.*;
import mondrian.util.Bug;
import mondrian.util.Pair;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -189,7 +188,8 @@ private Object getCellFromExternalCache(CellRequest request) {
}

public void register(SegmentWithData segment) {
localBars.get().segmentRefs.add(
final Bar bar = localBars.get();
bar.segmentRefs.add(
new SoftReference<SegmentWithData>(segment));
}

Expand Down Expand Up @@ -546,8 +546,10 @@ void clearCachedAggregations(boolean forced) {
LOGGER.debug(buf.toString());
}

// Clear aggregation cache for the currect thread context.
localBars.get().aggregations.clear();
// Clear aggregation cache for the current thread context.
final Bar bar = localBars.get();
bar.aggregations.clear();
bar.segmentRefs.clear();
}
}

Expand Down
17 changes: 8 additions & 9 deletions testsrc/main/mondrian/olap/type/TypeTest.java
Expand Up @@ -2,7 +2,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2008-2011 Julian Hyde
// Copyright (C) 2008-2012 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand All @@ -26,14 +26,9 @@
*/

public class TypeTest extends TestCase {
TestContext testContext = null;

protected void setUp() throws Exception {
testContext = TestContext.instance();
}

public void testConversions() {
final Connection connection = testContext.getConnection();
final Connection connection = getTestContext().getConnection();
Cube salesCube =
getCubeWithName("Sales", connection.getSchema().getCubes());
assertTrue(salesCube != null);
Expand Down Expand Up @@ -161,6 +156,10 @@ public void testConversions() {
}
}

protected TestContext getTestContext() {
return TestContext.instance();
}

public void testCommonTypeWhenSetTypeHavingMemberTypeAndTupleType() {
MemberType measureMemberType =
getMemberTypeHavingMeasureInIt(getUnitSalesMeasure());
Expand Down Expand Up @@ -299,11 +298,11 @@ private SchemaReader getSalesCubeSchemaReader() {
"Sales",
getSchemaReader().getCubes());
return salesCube.getSchemaReader(
testContext.getConnection().getRole()).withLocus();
getTestContext().getConnection().getRole()).withLocus();
}

private SchemaReader getSchemaReader() {
return testContext.getConnection().getSchemaReader().withLocus();
return getTestContext().getConnection().getSchemaReader().withLocus();
}

private Cube getCubeWithName(String cubeName, Cube[] cubes) {
Expand Down
8 changes: 7 additions & 1 deletion testsrc/main/mondrian/rolap/NonEmptyTest.java
Expand Up @@ -4,7 +4,7 @@
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2004-2005 TONBELLER AG
// Copyright (C) 2005-2011 Julian Hyde and others
// Copyright (C) 2005-2012 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -71,6 +71,12 @@ protected void setUp() throws Exception {
MondrianProperties.instance().EnableNativeNonEmpty, true);
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
localTestContext = null; // allow gc
}

@Override
public TestContext getTestContext() {
return localTestContext != null
Expand Down
6 changes: 6 additions & 0 deletions testsrc/main/mondrian/rolap/TestAggregationManager.java
Expand Up @@ -58,6 +58,12 @@ protected void setUp() throws Exception {
@Override
protected void tearDown() throws Exception {
Locus.pop(locus);

// allow gc
locus = null;
execution = null;
aggMgr = null;

super.tearDown();
}

Expand Down
22 changes: 17 additions & 5 deletions testsrc/main/mondrian/test/UdfTest.java
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2005-2011 Julian Hyde
// Copyright (C) 2005-2012 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -50,10 +50,22 @@ public UdfTest(String name) {
* Test context which uses the local FoodMart schema, and adds a "PlusOne"
* user-defined function.
*/
private final TestContext tc = udfTestContext(
"<UserDefinedFunction name=\"PlusOne\" className=\""
+ PlusOneUdf.class.getName()
+ "\"/>\n");
private TestContext tc;

@Override
protected void setUp() throws Exception {
super.setUp();
tc = udfTestContext(
"<UserDefinedFunction name=\"PlusOne\" className=\""
+ PlusOneUdf.class.getName()
+ "\"/>\n");
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
tc = null; // allow gc
}

public TestContext getTestContext() {
return tc;
Expand Down
4 changes: 3 additions & 1 deletion testsrc/main/mondrian/test/loader/CsvDBTestCase.java
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2005-2011 Julian Hyde and others
// Copyright (C) 2005-2012 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -107,6 +107,8 @@ protected void tearDown() throws Exception {
// ignore
}

testContext = null; // allow gc

super.tearDown();
}

Expand Down

0 comments on commit 4e0c790

Please sign in to comment.