Skip to content

Commit

Permalink
Fixes memory leaks in the test suite.
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@497 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
lucboudreau committed Jan 30, 2012
1 parent 4180611 commit cbc6665
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
4 changes: 2 additions & 2 deletions testsrc/org/olap4j/CellSetFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
* @version $Id$
*/
public class CellSetFormatterTest extends TestCase {
private final TestContext testContext = TestContext.instance();
private final TestContext.Tester tester = testContext.getTester();

private static final String query1 =
"select\n"
Expand All @@ -67,6 +65,8 @@ private void assertFormat(
Format format,
String expected) throws SQLException
{
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
Connection connection = null;
try {
connection = tester.createConnection();
Expand Down
6 changes: 4 additions & 2 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
* @version $Id$
*/
public class ConnectionTest extends TestCase {
private final TestContext testContext = TestContext.instance();
private final TestContext.Tester tester = testContext.getTester();
private TestContext testContext = TestContext.instance();
private TestContext.Tester tester = testContext.getTester();

private static final boolean IS_JDK_16 =
System.getProperty("java.version").startsWith("1.6.");
Expand All @@ -72,6 +72,8 @@ protected void tearDown() throws Exception {
connection.close();
connection = null;
}
testContext = null;
tester = null;
}

/**
Expand Down
26 changes: 24 additions & 2 deletions testsrc/org/olap4j/MetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.olap4j.impl.Olap4jUtil;
import org.olap4j.metadata.*;
import org.olap4j.test.TestContext;
import org.olap4j.test.TestContext.Tester;

import junit.framework.TestCase;

Expand All @@ -36,8 +37,6 @@
public class MetadataTest extends TestCase {
private static final String NL = System.getProperty("line.separator");

private final TestContext testContext = TestContext.instance();
private final TestContext.Tester tester = testContext.getTester();
private Connection connection;
private String catalogName;
private OlapConnection olapConnection;
Expand Down Expand Up @@ -115,6 +114,8 @@ public MetadataTest() throws SQLException {
}

protected void setUp() throws SQLException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
connection = tester.createConnection();
catalogName = connection.getCatalog();
olapConnection =
Expand All @@ -127,6 +128,9 @@ protected void tearDown() throws Exception {
connection.close();
connection = null;
}
connection = null;
olapConnection = null;
olapDatabaseMetaData = null;
}

// ~ Helper methods ----------
Expand Down Expand Up @@ -186,6 +190,8 @@ private int linecount(String s) {
// ~ Tests follow -------------

public void testDatabaseMetaData() throws SQLException {
final TestContext context = TestContext.instance();
final Tester tester = context.getTester();
assertEquals("" + catalogName + "", catalogName);

DatabaseMetaData databaseMetaData = connection.getMetaData();
Expand Down Expand Up @@ -242,6 +248,8 @@ public void testDatabaseMetaData() throws SQLException {
}

public void testSchemas() throws OlapException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
// check schema auto detection
final Schema schema1 = olapConnection.getOlapSchema();
assertEquals(
Expand Down Expand Up @@ -282,6 +290,8 @@ public void testSchemas() throws OlapException {
}

public void testCatalogs() throws SQLException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
final Catalog catalog = olapConnection.getOlapCatalog();
assertEquals(
"Failed to auto detect the catalog.",
Expand Down Expand Up @@ -323,6 +333,8 @@ public void testCatalogs() throws SQLException {

public void testDatabases() throws SQLException {
final Database database = olapConnection.getOlapDatabase();
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
assertTrue(
"Failed to auto detect the database.",
database.getName()
Expand Down Expand Up @@ -391,6 +403,8 @@ public void testDatabaseMetaDataGetActions() throws SQLException {
}

public void testDatabaseMetaDataGetDatasources() throws SQLException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
String s = checkResultSet(
olapDatabaseMetaData.getDatabases(),
DATASOURCES_COLUMN_NAMES);
Expand Down Expand Up @@ -424,6 +438,8 @@ public void testDatabaseMetaDataGetDatasources() throws SQLException {
}

public void testDatabaseMetaDataGetCatalogs() throws SQLException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
String s = checkResultSet(
olapDatabaseMetaData.getCatalogs(),
CATALOGS_COLUMN_NAMES);
Expand All @@ -445,6 +461,8 @@ public void testDatabaseMetaDataGetCatalogs() throws SQLException {
}

public void testDatabaseMetaDataGetSchemas() throws SQLException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
String s = checkResultSet(
olapDatabaseMetaData.getSchemas(),
SCHEMAS_COLUMN_NAMES);
Expand Down Expand Up @@ -517,6 +535,8 @@ public void testDatabaseMetaDataGetMdxKeywords() throws SQLException {
}

public void testDatabaseMetaDataGetCubes() throws SQLException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
String s = checkResultSet(
olapDatabaseMetaData.getCubes(
catalogName,
Expand Down Expand Up @@ -700,6 +720,8 @@ public void testDatabaseMetaDataGetMeasures() throws SQLException {
}

public void testDatabaseMetaDataGetMembers() throws SQLException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
String s = checkResultSet(
olapDatabaseMetaData.getMembers(
catalogName, "FoodMart", "Sales", null, "[Gender]", null, null,
Expand Down
5 changes: 4 additions & 1 deletion testsrc/org/olap4j/OlapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
* @version $Id$
*/
public class OlapTest extends TestCase {
final TestContext.Tester tester = TestContext.instance().getTester();
private Connection connection;

public OlapTest() {
Expand All @@ -61,6 +60,8 @@ protected void tearDown() throws Exception {
}

public Cube getFoodmartCube(String cubeName) throws Exception {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
connection = tester.createConnection();
OlapConnection olapConnection =
tester.getWrapper().unwrap(connection, OlapConnection.class);
Expand All @@ -86,6 +87,8 @@ public Cube getFoodmartCube(String cubeName) throws Exception {
}

public void testModel() throws Exception {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
if (false) {
// define the connection information
String schemaUri = "file:/open/mondrian/demo/FoodMart.xml";
Expand Down
13 changes: 6 additions & 7 deletions testsrc/org/olap4j/XmlaConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class XmlaConnectionTest extends TestCase {

public static final String DRIVER_CLASS_NAME =
"org.olap4j.driver.xmla.XmlaOlap4jDriver";
private final TestContext testContext = TestContext.instance();

static class XmlaOlap4jProxyMock implements XmlaOlap4jProxy {
public byte[] get(
Expand Down Expand Up @@ -235,6 +234,8 @@ public void testNoNonTrivalCallsOnConnect() throws Exception {
}

public void testDbSchemaSchemata() throws Exception {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
if (!testContext.getTester().getFlavor()
.equals(Tester.Flavor.XMLA))
{
Expand Down Expand Up @@ -273,8 +274,6 @@ public byte[] get(
Proxy.class.getName());
DoubleSubmissionTestProxy.setProxyClassName(oldValue);
try {
final TestContext.Tester tester =
testContext.getTester();
Connection connection = tester.createConnection();
OlapConnection oConn =
tester.getWrapper().unwrap(connection, OlapConnection.class);
Expand All @@ -295,6 +294,8 @@ public byte[] get(
* @throws Exception If the test fails.
*/
public void testNoDoubleQuerySubmission() throws Exception {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
if (!testContext.getTester().getFlavor()
.equals(Tester.Flavor.XMLA)
&& !testContext.getTester().getFlavor()
Expand All @@ -307,8 +308,6 @@ public void testNoDoubleQuerySubmission() throws Exception {
DoubleSubmissionTestProxy.class.getName());
DoubleSubmissionTestProxy.setProxyClassName(oldValue);
try {
final TestContext.Tester tester =
testContext.getTester();
Connection connection = tester.createConnection();
Statement statement = connection.createStatement();
final OlapStatement olapStatement =
Expand Down Expand Up @@ -343,6 +342,8 @@ public void testNoDoubleQuerySubmission() throws Exception {
* not be sent to the server.
*/
public void testPropertyList() throws Exception {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
if (!testContext.getTester().getFlavor()
.equals(Tester.Flavor.XMLA)
&& !testContext.getTester().getFlavor()
Expand All @@ -358,8 +359,6 @@ public void testPropertyList() throws Exception {
try {
XmlaTester.setProxyClassName(
PropertyListTestProxy.class.getName());
final TestContext.Tester tester =
testContext.getTester();

OlapConnection connection =
tester.getWrapper().unwrap(
Expand Down
3 changes: 2 additions & 1 deletion testsrc/org/olap4j/transform/TransformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
* @since Jul 28, 2008
*/
public class TransformTest extends TestCase {
final TestContext.Tester tester = TestContext.instance().getTester();
private Connection connection = null;

public TransformTest() {
Expand All @@ -61,6 +60,8 @@ protected void tearDown() throws Exception {
}

protected OlapConnection getConnection() throws SQLException {
final TestContext testContext = TestContext.instance();
final TestContext.Tester tester = testContext.getTester();
if (connection == null) {
connection = tester.createConnection();
}
Expand Down

0 comments on commit cbc6665

Please sign in to comment.