mondrian.rolap
Class BatchTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by mondrian.test.FoodMartTestCase
              extended by mondrian.rolap.BatchTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AggregationOnDistinctCountMeasuresTest, ClearViewBase, FastBatchingCellReaderTest, FilterTest, GroupingSetQueryTest, NativeFilterMatchingTest, NativizeSetFunDefTest, NonEmptyTest, SegmentLoaderTest, SelectNotInGroupByTest, SqlQueryTest, TestAggregationManager, TestCalculatedMembers, VirtualCubeTest

public class BatchTestCase
extends FoodMartTestCase

To support all Batch related tests.

Since:
06-Jun-2007
Author:
Thiyagu

Nested Class Summary
(package private) static class BatchTestCase.Bomb
          Fake exception to interrupt the test when we see the desired query.
(package private) static class BatchTestCase.CellRequestConstraint
           
protected  class BatchTestCase.TestCase
          Runs an MDX query with a predefined resultLimit and checks the number of positions of the row axis.
(package private) static class BatchTestCase.TestListener
          Gets notified on various test events: when a matching native evaluator was found when SQL is executed when result is found in the cache
 
Field Summary
protected  String cubeNameSales
           
protected  String fieldGender
           
protected  String fieldProductDepartment
           
protected  String fieldProductFamily
           
protected  String[] fieldValueProductDepartment
           
protected  String[] fieldValuesGender
           
protected  String[] fieldValuesProductFamily
           
protected  String[] fieldValuesYear
           
protected  String fieldYear
           
protected  String measureUnitSales
           
protected  String tableCustomer
           
protected  String tableProductClass
           
protected  String tableTime
           
 
Fields inherited from class mondrian.test.FoodMartTestCase
propSaver
 
Constructor Summary
BatchTestCase()
           
BatchTestCase(String name)
           
 
Method Summary
 void assertNative(String mdx)
          Convenience method for debugging; please do not delete.
protected  void assertNoQuerySql(String mdxQuery, SqlPattern[] patterns)
          Checks that a given MDX query does not result in a particular SQL statement being generated.
 void assertNotNative(String mdx)
          Convenience method for debugging; please do not delete.
protected  void assertQuerySql(String mdxQuery, SqlPattern[] patterns)
          Checks that a given MDX query results in a particular SQL statement being generated.
protected  void assertQuerySql(String mdxQuery, SqlPattern[] patterns, boolean clearCache)
          Checks that a given MDX query results in a particular SQL statement being generated.
protected  void assertQuerySql(TestContext testContext, String mdxQuery, SqlPattern[] patterns)
          Checks that a given MDX query results in a particular SQL statement being generated.
protected  void assertQuerySqlOrNot(TestContext testContext, String mdxQuery, SqlPattern[] patterns, boolean negative, boolean bypassSchemaCache, boolean clearCache)
          During MDX query parse and execution, checks that the query results (or does not result) in a particular SQL statement being generated.
protected  void assertRequestSql(CellRequest[] requests, SqlPattern[] patterns)
          Checks that a given sequence of cell requests results in a particular SQL statement being generated.
protected  void assertRequestSql(CellRequest[] requests, SqlPattern[] patterns, boolean negative)
          Checks that a given sequence of cell requests results in a particular SQL statement being generated.
protected  void checkNative(int resultLimit, int rowCount, String mdx)
          Runs a query twice, with native crossjoin optimization enabled and disabled.
protected  void checkNative(int resultLimit, int rowCount, String mdx, String expectedResult, boolean freshConnection)
          Runs a query twice, with native crossjoin optimization enabled and disabled.
static void checkNative(String mdx, Result expectedResult)
           
protected  void checkNotNative(int rowCount, String mdx)
          Make sure the mdx runs correctly and not in native mode.
protected  void checkNotNative(int rowCount, String mdx, String expectedResult)
          Makes sure the MDX runs correctly and not in native mode.
static void checkNotNative(String mdx, Result expectedResult)
           
protected  BatchLoader.Batch createBatch(BatchLoader fbcr, String[] tableNames, String[] fieldNames, String[][] fieldValues, String cubeName, String measure)
           
protected  BatchLoader.Batch createBatch(BatchLoader fbcr, String[] tableNames, String[] fieldNames, String[][] fieldValues, String cubeName, String measure, BatchTestCase.CellRequestConstraint constraint)
           
protected  CellRequest createRequest(String cube, String measureName, String[] tables, String[] columns, String[] values)
           
protected  CellRequest createRequest(String cube, String measureName, String[] tables, String[] columns, String[] values, BatchTestCase.CellRequestConstraint aggConstraint)
           
protected  CellRequest createRequest(String cube, String measure, String table, String column, String value)
           
protected  CellRequest createRequest(String cube, String measure, String table, String column, String value, BatchTestCase.CellRequestConstraint aggConstraint)
           
protected  String dialectize(Dialect.DatabaseProduct d, String sql)
           
protected  Result executeQuery(String mdx, Connection connection)
           
protected  RolapCube getCube(String cube)
           
protected  Connection getFoodMartConnection()
           
protected  GroupingSet getGroupingSet(String[] tableNames, String[] fieldNames, String[][] fieldValues, String cubeName, String measure)
           
protected  RolapStar.Measure getMeasure(String cube, String measureName)
           
(package private)  RolapNativeRegistry getRegistry(Connection connection)
           
(package private) static BatchTestCase.CellRequestConstraint makeConstraintCountryState(List<String[]> values)
           
(package private) static BatchTestCase.CellRequestConstraint makeConstraintProductFamilyDepartment(List<String[]> values)
           
(package private) static BatchTestCase.CellRequestConstraint makeConstraintYearQuarterMonth(List<String[]> values)
           
 
Methods inherited from class mondrian.test.FoodMartTestCase
allMember, assertAxisReturns, assertAxisThrows, assertBooleanExprReturns, assertExprReturns, assertExprThrows, assertQueriesReturnSimilarResults, assertQueryReturns, assertQueryThrows, assertSize, cubeByName, execute, executeExpr, executeQuery, executeSingletonAxis, genderMembersIncludingAll, getConnection, getDimensionWithName, getTestContext, isDefaultNullMemberRepresentation, isGroupingSetsSupported, member, productMembersPotScrubbersPotsAndPans, storeMembersCAAndOR, storeMembersUsaAndCanada, tearDown, warehouseMembersCanadaMexicoUsa
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tableTime

protected final String tableTime
See Also:
Constant Field Values

tableProductClass

protected final String tableProductClass
See Also:
Constant Field Values

tableCustomer

protected final String tableCustomer
See Also:
Constant Field Values

fieldYear

protected final String fieldYear
See Also:
Constant Field Values

fieldProductFamily

protected final String fieldProductFamily
See Also:
Constant Field Values

fieldProductDepartment

protected final String fieldProductDepartment
See Also:
Constant Field Values

fieldValuesYear

protected final String[] fieldValuesYear

fieldValuesProductFamily

protected final String[] fieldValuesProductFamily

fieldValueProductDepartment

protected final String[] fieldValueProductDepartment

fieldValuesGender

protected final String[] fieldValuesGender

cubeNameSales

protected final String cubeNameSales
See Also:
Constant Field Values

measureUnitSales

protected final String measureUnitSales
See Also:
Constant Field Values

fieldGender

protected String fieldGender
Constructor Detail

BatchTestCase

public BatchTestCase(String name)

BatchTestCase

public BatchTestCase()
Method Detail

createBatch

protected BatchLoader.Batch createBatch(BatchLoader fbcr,
                                        String[] tableNames,
                                        String[] fieldNames,
                                        String[][] fieldValues,
                                        String cubeName,
                                        String measure)

createBatch

protected BatchLoader.Batch createBatch(BatchLoader fbcr,
                                        String[] tableNames,
                                        String[] fieldNames,
                                        String[][] fieldValues,
                                        String cubeName,
                                        String measure,
                                        BatchTestCase.CellRequestConstraint constraint)

getGroupingSet

protected GroupingSet getGroupingSet(String[] tableNames,
                                     String[] fieldNames,
                                     String[][] fieldValues,
                                     String cubeName,
                                     String measure)

assertRequestSql

protected void assertRequestSql(CellRequest[] requests,
                                SqlPattern[] patterns)
Checks that a given sequence of cell requests results in a particular SQL statement being generated.

Always clears the cache before running the requests.

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.

Parameters:
requests - Sequence of cell requests
patterns - Set of patterns

assertRequestSql

protected void assertRequestSql(CellRequest[] requests,
                                SqlPattern[] patterns,
                                boolean negative)
Checks that a given sequence of cell requests results in a particular SQL statement being generated.

Always clears the cache before running the requests.

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.

Parameters:
requests - Sequence of cell requests
patterns - Set of patterns
negative - Set to false in order to 'expect' a query or true to 'forbid' a query.

assertQuerySql

protected void assertQuerySql(String mdxQuery,
                              SqlPattern[] patterns)
Checks that a given MDX query results in a particular SQL statement being generated.

Parameters:
mdxQuery - MDX query
patterns - Set of patterns for expected SQL statements

assertQuerySql

protected void assertQuerySql(TestContext testContext,
                              String mdxQuery,
                              SqlPattern[] patterns)
Checks that a given MDX query results in a particular SQL statement being generated.

Parameters:
testContext - non-default test context if required
mdxQuery - MDX query
patterns - Set of patterns for expected SQL statements

assertNoQuerySql

protected void assertNoQuerySql(String mdxQuery,
                                SqlPattern[] patterns)
Checks that a given MDX query does not result in a particular SQL statement being generated.

Parameters:
mdxQuery - MDX query
patterns - Set of patterns for expected SQL statements

assertQuerySql

protected void assertQuerySql(String mdxQuery,
                              SqlPattern[] patterns,
                              boolean clearCache)
Checks that a given MDX query results in a particular SQL statement being generated.

Parameters:
mdxQuery - MDX query
patterns - Set of patterns, one for each dialect.
clearCache - whether to clear cache before running the query

assertQuerySqlOrNot

protected void assertQuerySqlOrNot(TestContext testContext,
                                   String mdxQuery,
                                   SqlPattern[] patterns,
                                   boolean negative,
                                   boolean bypassSchemaCache,
                                   boolean clearCache)
During MDX query parse and execution, checks that the query results (or does not result) in a particular SQL statement being generated.

Parses and executes the MDX query 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.

Parameters:
testContext - non-default test context if required
mdxQuery - MDX query
patterns - Set of patterns
negative - false to assert if SQL is generated; true to assert if SQL is NOT generated
bypassSchemaCache - whether to grab a new connection and bypass the schema cache before parsing the MDX query
clearCache - whether to clear cache before executing the MDX query

dialectize

protected String dialectize(Dialect.DatabaseProduct d,
                            String sql)

createRequest

protected CellRequest createRequest(String cube,
                                    String measure,
                                    String table,
                                    String column,
                                    String value)

createRequest

protected CellRequest createRequest(String cube,
                                    String measureName,
                                    String[] tables,
                                    String[] columns,
                                    String[] values)

createRequest

protected CellRequest createRequest(String cube,
                                    String measure,
                                    String table,
                                    String column,
                                    String value,
                                    BatchTestCase.CellRequestConstraint aggConstraint)

createRequest

protected CellRequest createRequest(String cube,
                                    String measureName,
                                    String[] tables,
                                    String[] columns,
                                    String[] values,
                                    BatchTestCase.CellRequestConstraint aggConstraint)

makeConstraintYearQuarterMonth

static BatchTestCase.CellRequestConstraint makeConstraintYearQuarterMonth(List<String[]> values)

makeConstraintCountryState

static BatchTestCase.CellRequestConstraint makeConstraintCountryState(List<String[]> values)

makeConstraintProductFamilyDepartment

static BatchTestCase.CellRequestConstraint makeConstraintProductFamilyDepartment(List<String[]> values)

getMeasure

protected RolapStar.Measure getMeasure(String cube,
                                       String measureName)

getFoodMartConnection

protected Connection getFoodMartConnection()

getCube

protected RolapCube getCube(String cube)

checkNotNative

protected void checkNotNative(int rowCount,
                              String mdx)
Make sure the mdx runs correctly and not in native mode.

Parameters:
rowCount - number of rows returned
mdx - query

checkNotNative

protected void checkNotNative(int rowCount,
                              String mdx,
                              String expectedResult)
Makes sure the MDX runs correctly and not in native mode.

Parameters:
rowCount - Number of rows returned
mdx - Query
expectedResult - Expected result string

getRegistry

RolapNativeRegistry getRegistry(Connection connection)

checkNative

protected void checkNative(int resultLimit,
                           int rowCount,
                           String mdx)
Runs a query twice, with native crossjoin optimization enabled and disabled. If both results are equal, its considered correct.

Parameters:
resultLimit - Maximum result size of all the MDX operations in this query. This might be hard to estimate as it is usually larger than the rowCount of the final result. Setting it to 0 will cause this limit to be ignored.
rowCount - Number of rows returned
mdx - Query

checkNative

protected void checkNative(int resultLimit,
                           int rowCount,
                           String mdx,
                           String expectedResult,
                           boolean freshConnection)
Runs a query twice, with native crossjoin optimization enabled and disabled. If both results are equal,and both aggree with the expected result, it is considered correct.

Optionally the query can be run with fresh connection. This is useful if the test case sets its certain mondrian properties, e.g. native properties like: mondrian.native.filter.enable

Parameters:
resultLimit - Maximum result size of all the MDX operations in this query. This might be hard to estimate as it is usually larger than the rowCount of the final result. Setting it to 0 will cause this limit to be ignored.
rowCount - Number of rows returned. (That is, the number of positions on the last axis of the query.)
mdx - Query
expectedResult - Expected result string
freshConnection - Whether fresh connection is required

checkNotNative

public static void checkNotNative(String mdx,
                                  Result expectedResult)

checkNative

public static void checkNative(String mdx,
                               Result expectedResult)

executeQuery

protected Result executeQuery(String mdx,
                              Connection connection)

assertNotNative

public void assertNotNative(String mdx)
Convenience method for debugging; please do not delete.


assertNative

public void assertNative(String mdx)
Convenience method for debugging; please do not delete.


Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads