diff --git a/mondrian/src/test/java/mondrian/olap/fun/CrossJoinTest.java b/mondrian/src/test/java/mondrian/olap/fun/CrossJoinTest.java index 92d0c749e9..c41aa2952c 100644 --- a/mondrian/src/test/java/mondrian/olap/fun/CrossJoinTest.java +++ b/mondrian/src/test/java/mondrian/olap/fun/CrossJoinTest.java @@ -13,29 +13,25 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.io.PrintWriter; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Optional; import org.eclipse.daanse.mdx.model.api.expression.operation.FunctionOperationAtom; import org.eclipse.daanse.mdx.model.api.expression.operation.OperationAtom; -import org.eclipse.daanse.olap.api.connection.Connection; +import org.eclipse.daanse.olap.api.CatalogReader; import org.eclipse.daanse.olap.api.Context; import org.eclipse.daanse.olap.api.DataType; -import org.eclipse.daanse.olap.api.CatalogReader; -import org.eclipse.daanse.olap.api.ConfigConstants; -import org.eclipse.daanse.olap.api.Statement; import org.eclipse.daanse.olap.api.Validator; import org.eclipse.daanse.olap.api.calc.Calc; import org.eclipse.daanse.olap.api.calc.compiler.ExpressionCompiler; import org.eclipse.daanse.olap.api.calc.todo.TupleCursor; import org.eclipse.daanse.olap.api.calc.todo.TupleIterable; import org.eclipse.daanse.olap.api.calc.todo.TupleList; +import org.eclipse.daanse.olap.api.connection.Connection; import org.eclipse.daanse.olap.api.element.Member; import org.eclipse.daanse.olap.api.function.FunctionDefinition; import org.eclipse.daanse.olap.api.function.FunctionMetaData; @@ -48,29 +44,23 @@ import org.eclipse.daanse.olap.api.type.SetType; import org.eclipse.daanse.olap.api.type.TupleType; import org.eclipse.daanse.olap.api.type.Type; -import org.eclipse.daanse.olap.calc.base.type.tuplebase.ArrayTupleList; import org.eclipse.daanse.olap.calc.base.type.tuplebase.UnaryTupleList; import org.eclipse.daanse.olap.common.SystemWideProperties; -import org.eclipse.daanse.olap.common.Util; import org.eclipse.daanse.olap.function.core.FunctionParameterR; -import org.eclipse.daanse.olap.function.def.crossjoin.BaseListCalc; import org.eclipse.daanse.olap.function.def.crossjoin.CrossJoinFunDef; import org.eclipse.daanse.olap.function.def.crossjoin.CrossJoinIterCalc; -import org.eclipse.daanse.olap.function.def.crossjoin.ImmutableListCalc; -import org.eclipse.daanse.olap.function.def.crossjoin.MutableListCalc; import org.eclipse.daanse.olap.query.component.ResolvedFunCallImpl; +import org.eclipse.daanse.olap.server.ExecutionImpl; +import org.eclipse.daanse.olap.server.LocusImpl; +import org.eclipse.daanse.rolap.element.RolapCube; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.opencube.junit5.ContextSource; import org.opencube.junit5.TestUtil; import org.opencube.junit5.context.TestContextImpl; import org.opencube.junit5.dataloader.FastFoodmardDataLoader; import org.opencube.junit5.propupdator.AppandFoodMartCatalog; -import org.eclipse.daanse.olap.server.ExecutionImpl; -import org.eclipse.daanse.olap.server.LocusImpl; -import org.eclipse.daanse.rolap.element.RolapCube; /** @@ -131,46 +121,7 @@ protected void afterEach() throws Exception { // Iterable //////////////////////////////////////////////////////////////////////// - @Test - void testListTupleListTupleIterCalc() { - Statement statement = mock(Statement.class); - Connection rolapConnection = mock(Connection.class); - Context context = mock(Context.class); - when(context.getConfigValue(ConfigConstants.CHECK_CANCEL_OR_TIMEOUT_INTERVAL, ConfigConstants.CHECK_CANCEL_OR_TIMEOUT_INTERVAL_DEFAULT_VALUE, Integer.class)).thenReturn(0); - when(rolapConnection.getContext()).thenReturn(context); - when(statement.getMondrianConnection()).thenReturn(rolapConnection); - when(excMock.getMondrianStatement()).thenReturn(statement); - CrossJoinIterCalc calc = - new CrossJoinIterCalc( getResolvedFunCall(), null, crossJoinFunDef.getCtag() ); - - doTupleTupleIterTest( calc, excMock ); - } - private void doTupleTupleIterTest( - CrossJoinIterCalc calc, ExecutionImpl execution ) { - TupleList l4 = makeListTuple( m4 ); - String s4 = toString( l4 ); - String e4 = "{[U, V], [W, X], [Y, Z]}"; - assertEquals( e4, s4 ); - - TupleList l3 = makeListTuple( m3 ); - String s3 = toString( l3 ); - String e3 = "{[k, l], [m, n]}"; - assertEquals( e3, s3 ); - - String s = LocusImpl.execute( - execution, "CrossJoinTest", new LocusImpl.Action() { - @Override - public String execute() { - TupleIterable iterable = calc.makeIterable( l4, l3 ); - return CrossJoinTest.this.toString( iterable ); - } - } ); - String e = - "{[U, V, k, l], [U, V, m, n], [W, X, k, l], " - + "[W, X, m, n], [Y, Z, k, l], [Y, Z, m, n]}"; - assertEquals( e, s ); - } // The test to verify that cancellation/timeout is checked // in CrossJoinFunDef$CrossJoinIterCalc$1$1.forward() @@ -237,147 +188,6 @@ public Integer execute() { } ); } - //////////////////////////////////////////////////////////////////////// - // Immutable List - //////////////////////////////////////////////////////////////////////// - - @Test - void testImmutableListTupleListTupleListCalc() { - ImmutableListCalc calc = - new ImmutableListCalc( - getResolvedFunCall(), null, crossJoinFunDef.getCtag() ); - - doTupleTupleListTest( calc ); - } - - protected void doTupleTupleListTest( - BaseListCalc calc ) { - TupleList l4 = makeListTuple( m4 ); - String s4 = toString( l4 ); - String e4 = "{[U, V], [W, X], [Y, Z]}"; - assertEquals( e4, s4 ); - - TupleList l3 = makeListTuple( m3 ); - String s3 = toString( l3 ); - String e3 = "{[k, l], [m, n]}"; - assertEquals( e3, s3 ); - - TupleList list = calc.makeList( l4, l3 ); - String s = toString( list ); - String e = - "{[U, V, k, l], [U, V, m, n], [W, X, k, l], " - + "[W, X, m, n], [Y, Z, k, l], [Y, Z, m, n]}"; - assertEquals( e, s ); - - TupleList subList = list.subList( 0, 6 ); - s = toString( subList ); - assertEquals( 6, subList.size() ); - assertEquals( e, s ); - - subList = subList.subList( 0, 6 ); - s = toString( subList ); - assertEquals( 6, subList.size() ); - assertEquals( e, s ); - - subList = subList.subList( 1, 5 ); - s = toString( subList ); - e = "{[U, V, m, n], [W, X, k, l], [W, X, m, n], [Y, Z, k, l]}"; - assertEquals( 4, subList.size() ); - assertEquals( e, s ); - - subList = subList.subList( 2, 4 ); - s = toString( subList ); - e = "{[W, X, m, n], [Y, Z, k, l]}"; - assertEquals( 2, subList.size() ); - assertEquals( e, s ); - - subList = subList.subList( 1, 2 ); - s = toString( subList ); - e = "{[Y, Z, k, l]}"; - assertEquals( 1, subList.size() ); - assertEquals( e, s ); - - subList = list.subList( 1, 4 ); - s = toString( subList ); - e = "{[U, V, m, n], [W, X, k, l], [W, X, m, n]}"; - assertEquals( 3, subList.size() ); - assertEquals( e, s ); - - subList = list.subList( 2, 4 ); - s = toString( subList ); - e = "{[W, X, k, l], [W, X, m, n]}"; - assertEquals( 2, subList.size() ); - assertEquals( e, s ); - - subList = list.subList( 2, 3 ); - s = toString( subList ); - e = "{[W, X, k, l]}"; - assertEquals( 1, subList.size() ); - assertEquals( e, s ); - - subList = list.subList( 4, 4 ); - s = toString( subList ); - e = "{}"; - assertEquals( 0, subList.size() ); - assertEquals( e, s ); - } - - - //////////////////////////////////////////////////////////////////////// - // Mutable List - //////////////////////////////////////////////////////////////////////// - @Test - void testMutableListTupleListTupleListCalc() { - MutableListCalc calc = - new MutableListCalc( - getResolvedFunCall(), null, crossJoinFunDef.getCtag() ); - - doMTupleTupleListTest( calc ); - } - - protected void doMTupleTupleListTest( - BaseListCalc calc ) { - TupleList l1 = makeListTuple( m3 ); - String s1 = toString( l1 ); - String e1 = "{[k, l], [m, n]}"; - assertEquals( e1, s1 ); - - TupleList l2 = makeListTuple( m4 ); - String s2 = toString( l2 ); - String e2 = "{[U, V], [W, X], [Y, Z]}"; - assertEquals( e2, s2 ); - - TupleList list = calc.makeList( l1, l2 ); - String s = toString( list ); - String e = "{[k, l, U, V], [k, l, W, X], [k, l, Y, Z], " - + "[m, n, U, V], [m, n, W, X], [m, n, Y, Z]}"; - assertEquals( e, s ); - - if ( false ) { - // Cannot apply Collections.reverse to TupleList - // because TupleList.set always returns null. - // (This is a violation of the List contract, but it is inefficient - // to construct a list to return.) - Collections.reverse( list ); - s = toString( list ); - e = "{[m, n, Y, Z], [m, n, W, X], [m, n, U, V], " - + "[k, l, Y, Z], [k, l, W, X], [k, l, U, V]}"; - assertEquals( e, s ); - } - - // sort - Collections.sort( list, memberComparator ); - s = toString( list ); - e = "{[k, l, U, V], [k, l, W, X], [k, l, Y, Z], " - + "[m, n, U, V], [m, n, W, X], [m, n, Y, Z]}"; - assertEquals( e, s ); - - List members = list.remove( 1 ); - s = toString( list ); - e = "{[k, l, U, V], [k, l, Y, Z], [m, n, U, V], " - + "[m, n, W, X], [m, n, Y, Z]}"; - assertEquals( e, s ); - } @ParameterizedTest @ContextSource(propertyUpdater = AppandFoodMartCatalog.class, dataloader = FastFoodmardDataLoader.class ) @@ -395,30 +205,6 @@ void testResultLimitWithinCrossjoin(Context foodMartContext) { "result (1,539) exceeded limit (1,000)","Sales" ); } - //////////////////////////////////////////////////////////////////////// - // Helper methods - //////////////////////////////////////////////////////////////////////// - protected String toString( TupleIterable l ) { - StringBuffer buf = new StringBuffer( 100 ); - buf.append( '{' ); - int j = 0; - for ( List o : l ) { - if ( j++ > 0 ) { - buf.append( ", " ); - } - buf.append( o ); - } - buf.append( '}' ); - return buf.toString(); - } - - protected TupleList makeListTuple( List> ms ) { - final TupleList list = new ArrayTupleList( ms.get( 0 ).size() ); - for ( List m : ms ) { - list.add( m ); - } - return list; - } protected ResolvedFunCallImpl getResolvedFunCall() { FunctionDefinition funDef = new TestFunDef(); diff --git a/mondrian/src/test/java/mondrian/olap/fun/SortTest.java b/mondrian/src/test/java/mondrian/olap/fun/SortTest.java index 14dcdb6908..68fbeb3916 100644 --- a/mondrian/src/test/java/mondrian/olap/fun/SortTest.java +++ b/mondrian/src/test/java/mondrian/olap/fun/SortTest.java @@ -9,15 +9,12 @@ package mondrian.olap.fun; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opencube.junit5.TestUtil.assertAxisReturns; import static org.opencube.junit5.TestUtil.assertQueryReturns; import org.eclipse.daanse.olap.api.Context; import org.eclipse.daanse.olap.common.SystemWideProperties; -import org.eclipse.daanse.olap.fun.FunUtil; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.opencube.junit5.ContextSource; import org.opencube.junit5.context.TestContextImpl; @@ -43,36 +40,6 @@ public void afterEach() { SystemWideProperties.instance().populateInitial(); } - @Test - void testFoo() { - // Check that each value compares according to its position in the total - // order. For example, NaN compares greater than - // Double.NEGATIVE_INFINITY, -34.5, -0.001, 0, 0.00000567, 1, 3.14; - // equal to NaN; and less than Double.POSITIVE_INFINITY. - double[] values = { - Double.NEGATIVE_INFINITY, - FunUtil.DOUBLE_NULL, - -34.5, - -0.001, - 0, - 0.00000567, - 1, - 3.14, - Double.NaN, - Double.POSITIVE_INFINITY, - }; - for ( int i = 0; i < values.length; i++ ) { - for ( int j = 0; j < values.length; j++ ) { - int expected = Integer.compare( i, j ); - assertEquals( - expected, - FunUtil.compareValues( values[ i ], values[ j ] ), - "values[" + i + "]=" + values[ i ] + ", values[" + j - + "]=" + values[ j ]); - } - } - } - @ParameterizedTest @ContextSource(propertyUpdater = AppandFoodMartCatalog.class, dataloader = FastFoodmardDataLoader.class) void testOrderDesc(Context context) { diff --git a/mondrian/src/test/java/mondrian/olap/fun/UnionFunDefTest.java b/mondrian/src/test/java/mondrian/olap/fun/UnionFunDefTest.java index 3e12ec7a22..8b3ea48939 100644 --- a/mondrian/src/test/java/mondrian/olap/fun/UnionFunDefTest.java +++ b/mondrian/src/test/java/mondrian/olap/fun/UnionFunDefTest.java @@ -8,35 +8,11 @@ */ package mondrian.olap.fun; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.Mockito.doCallRealMethod; -import static org.mockito.Mockito.mock; import static org.opencube.junit5.TestUtil.assertAxisReturns; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.daanse.olap.api.connection.Connection; import org.eclipse.daanse.olap.api.Context; -import org.eclipse.daanse.olap.api.calc.Calc; -import org.eclipse.daanse.olap.api.calc.todo.TupleList; -import org.eclipse.daanse.olap.api.element.Member; -import org.eclipse.daanse.olap.api.function.FunctionDefinition; -import org.eclipse.daanse.olap.api.query.component.Expression; -import org.eclipse.daanse.olap.api.type.SetType; -import org.eclipse.daanse.olap.calc.base.type.tuplebase.ArrayTupleList; -import org.eclipse.daanse.olap.calc.base.type.tuplebase.UnaryTupleList; -import org.eclipse.daanse.olap.function.def.crossjoin.CrossJoinFunDef; -import org.eclipse.daanse.olap.function.def.crossjoin.ImmutableListCalc; -import org.eclipse.daanse.olap.function.def.union.UnionCalc; -import org.eclipse.daanse.olap.query.component.ResolvedFunCallImpl; -import org.eclipse.daanse.rolap.element.RolapMemberBase; -import org.junit.jupiter.api.Test; +import org.eclipse.daanse.olap.api.connection.Connection; import org.junit.jupiter.params.ParameterizedTest; -import org.mockito.Mockito; import org.opencube.junit5.ContextSource; import org.opencube.junit5.dataloader.FastFoodmardDataLoader; import org.opencube.junit5.propupdator.AppandFoodMartCatalog; @@ -48,86 +24,6 @@ */ class UnionFunDefTest { - /** - * Test for MONDRIAN-2250 issue. - * Tests that the result is independent on the hashCode. - * For this purpose MemberForTest with rewritten hashCode is used. - * - * Tuples are gotten from customer attachments. - */ - @Test - void testMondrian2250() { - Member[] dates = new Member[4]; - for (int i = 25; i < 29; i++) { - dates[i - 25] = - new MemberForTest("[Consumption Date.Calendar].[2014-07-" + i + "]"); - } - List list = Arrays.asList(dates); - UnaryTupleList unaryTupleList = new UnaryTupleList(list); - - Member consumptionMethod = - new MemberForTest("[Consumption Method].[PVR]"); - Member measuresAverageTimeshift = - new MemberForTest("[Measures].[Average Timeshift]"); - String[] hours = { "00", "14", "15", "16", "23" }; - Member[] times = new Member[5]; - for (int i = 0; i < hours.length; i++) { - times[i] = - new MemberForTest("[Consumption Time.Time].[" + hours[i] + ":00]"); - } - - int arity = 3; - ArrayTupleList arrayTupleList = new ArrayTupleList(arity); - for (Member time : times) { - List currentList = new ArrayList(3); - currentList.add(consumptionMethod); - currentList.add(measuresAverageTimeshift); - currentList.add(time); - arrayTupleList.add(currentList); - } - - CrossJoinFunDef crossJoinFunDef = - new CrossJoinFunDef(new CrossJoinTest.NullFunDef().getFunctionMetaData()); - Expression[] expMock = new Expression[1]; - expMock[0] = mock(Expression.class); - ResolvedFunCallImpl resolvedFunCall = - new ResolvedFunCallImpl(mock(FunctionDefinition.class), expMock, mock(SetType.class)); - Calc[] calcs = new Calc[1]; - calcs[0] = Mockito.mock(Calc.class); - ImmutableListCalc immutableListCalc = - new ImmutableListCalc( - resolvedFunCall, calcs, crossJoinFunDef.getCtag()); - - TupleList listForUnion1 = - immutableListCalc.makeList(unaryTupleList, arrayTupleList); - - List list2 = Arrays.asList(dates); - UnaryTupleList unaryTupleList2 = new UnaryTupleList(list2); - - Member measuresTotalViewingTime = - new MemberForTest("[Measures].[Total Viewing Time]"); - ArrayTupleList arrayTupleList2 = new ArrayTupleList(arity); - for (Member time : times) { - List currentList = new ArrayList(3); - currentList.add(consumptionMethod); - currentList.add(measuresTotalViewingTime); - currentList.add(time); - arrayTupleList2.add(currentList); - } - - TupleList listForUnion2 = - immutableListCalc.makeList(unaryTupleList2, arrayTupleList2); - - UnionCalc unionFunDefMock = mock(UnionCalc.class); - doCallRealMethod().when(unionFunDefMock).union( - any(), any(), anyBoolean()); - - TupleList tupleList = - unionFunDefMock.union(listForUnion1, listForUnion2, false); - System.out.println(tupleList); - assertEquals(40, tupleList.size()); - } - @ParameterizedTest @ContextSource(propertyUpdater = AppandFoodMartCatalog.class, dataloader = FastFoodmardDataLoader.class) void testArity4TupleUnion(Context context) { @@ -260,21 +156,4 @@ void testArity6TupleUnionAll(Context context) { tupleSet1Expected + "\n" + tupleSet2Expected); } - private class MemberForTest extends RolapMemberBase { - private String identifer; - - public MemberForTest(String identifer) { - this.identifer = identifer; - } - - @Override - public String getUniqueName() { - return identifer; - } - - @Override - public int hashCode() { - return 31; - } - } } diff --git a/mondrian/src/test/java/mondrian/olap/fun/VisualTotalsTest.java b/mondrian/src/test/java/mondrian/olap/fun/VisualTotalsTest.java index d8d28bbcdb..6b745b946d 100644 --- a/mondrian/src/test/java/mondrian/olap/fun/VisualTotalsTest.java +++ b/mondrian/src/test/java/mondrian/olap/fun/VisualTotalsTest.java @@ -33,15 +33,14 @@ import java.util.Arrays; import java.util.List; -import org.eclipse.daanse.olap.api.connection.Connection; import org.eclipse.daanse.olap.api.Context; +import org.eclipse.daanse.olap.api.connection.Connection; import org.eclipse.daanse.olap.api.element.Member; import org.eclipse.daanse.olap.api.result.Cell; import org.eclipse.daanse.olap.api.result.CellSet; import org.eclipse.daanse.olap.api.result.Position; -import org.eclipse.daanse.rolap.function.def.visualtotals.VisualTotalsCalc; import org.eclipse.daanse.olap.impl.CellImpl; -import org.junit.jupiter.api.Test; +import org.eclipse.daanse.rolap.function.def.visualtotals.VisualTotalsFunDef; import org.junit.jupiter.params.ParameterizedTest; import org.opencube.junit5.ContextSource; import org.opencube.junit5.TestUtil; @@ -55,52 +54,6 @@ * @author efine */ class VisualTotalsTest { - @Test - void testSubstituteEmpty() { - final String actual = VisualTotalsCalc.substitute("", "anything"); - final String expected = ""; - assertEquals(expected, actual); - } - - @Test - void testSubstituteOneStarOnly() { - final String actual = VisualTotalsCalc.substitute("*", "anything"); - final String expected = "anything"; - assertEquals(expected, actual); - } - - @Test - void testSubstituteOneStarBegin() { - final String actual = - VisualTotalsCalc.substitute("* is the word.", "Grease"); - final String expected = "Grease is the word."; - assertEquals(expected, actual); - } - - @Test - void testSubstituteOneStarEnd() { - final String actual = - VisualTotalsCalc.substitute( - "Lies, damned lies, and *!", "statistics"); - final String expected = "Lies, damned lies, and statistics!"; - assertEquals(expected, actual); - } - - @Test - void testSubstituteTwoStars() { - final String actual = VisualTotalsCalc.substitute("**", "anything"); - final String expected = "*"; - assertEquals(expected, actual); - } - - @Test - void testSubstituteCombined() { - final String actual = - VisualTotalsCalc.substitute( - "*: see small print**** for *", "disclaimer"); - final String expected = "disclaimer: see small print** for disclaimer"; - assertEquals(expected, actual); - } /** * Test case for bug diff --git a/mondrian/src/test/java/mondrian/rolap/RolapStarTest.java b/mondrian/src/test/java/mondrian/rolap/RolapStarTest.java index ef94c84424..bafe4232ee 100644 --- a/mondrian/src/test/java/mondrian/rolap/RolapStarTest.java +++ b/mondrian/src/test/java/mondrian/rolap/RolapStarTest.java @@ -11,19 +11,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import java.util.List; - -import org.eclipse.daanse.olap.api.connection.Connection; import org.eclipse.daanse.olap.api.Context; -import org.eclipse.daanse.rolap.element.RolapCatalog; -import org.eclipse.daanse.rolap.element.RolapCube; +import org.eclipse.daanse.olap.api.connection.Connection; import org.eclipse.daanse.rolap.common.RolapStar; -import org.eclipse.daanse.rolap.common.RolapStar.Column; import org.eclipse.daanse.rolap.common.util.RelationUtil; +import org.eclipse.daanse.rolap.element.RolapCatalog; +import org.eclipse.daanse.rolap.element.RolapCube; import org.eclipse.daanse.rolap.mapping.model.DatabaseSchema; import org.eclipse.daanse.rolap.mapping.model.PhysicalTable; import org.eclipse.daanse.rolap.mapping.model.Query; @@ -31,7 +25,6 @@ import org.eclipse.daanse.rolap.mapping.model.RolapMappingFactory; import org.eclipse.daanse.rolap.mapping.model.SqlStatement; import org.eclipse.daanse.rolap.mapping.model.TableQuery; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.opencube.junit5.ContextSource; import org.opencube.junit5.dataloader.FastFoodmardDataLoader; @@ -108,46 +101,4 @@ void testCloneRelationWithFilteredTable(Context context) { assertEquals("NewAlias.clicked = 'true'", cloned.getSqlWhereExpression().getSql()); } - //Below there are tests for mondrian.rolap.RolapStar.ColumnComparator - @Test - void testTwoColumnsWithDifferentNamesNotEquals() { - RolapStar.ColumnComparator colComparator = - RolapStar.ColumnComparator.instance; - Column column1 = getColumnMock("Column1", "Table1"); - Column column2 = getColumnMock("Column2", "Table1"); - assertNotSame(column1, column2); - assertEquals(-1, colComparator.compare(column1, column2)); - } - - @Test - void testTwoColumnsWithEqualsNamesButDifferentTablesNotEquals() { - RolapStar.ColumnComparator colComparator = - RolapStar.ColumnComparator.instance; - Column column1 = getColumnMock("Column1", "Table1"); - Column column2 = getColumnMock("Column1", "Table2"); - assertNotSame(column1, column2); - assertEquals(-1, colComparator.compare(column1, column2)); - } - - @Test - void testTwoColumnsEquals() { - RolapStar.ColumnComparator colComparator = - RolapStar.ColumnComparator.instance; - Column column1 = getColumnMock("Column1", "Table1"); - Column column2 = getColumnMock("Column1", "Table1"); - assertNotSame(column1, column2); - assertEquals(0, colComparator.compare(column1, column2)); - } - - private static Column getColumnMock( - String columnName, - String tableName) - { - Column colMock = mock(Column.class); - RolapStar.Table tableMock = mock(RolapStar.Table.class); - when(colMock.getName()).thenReturn(columnName); - when(colMock.getTable()).thenReturn(tableMock); - when(tableMock.getAlias()).thenReturn(tableName); - return colMock; - } } diff --git a/mondrian/src/test/java/mondrian/rolap/SqlStatementTest.java b/mondrian/src/test/java/mondrian/rolap/SqlStatementTest.java deleted file mode 100644 index cb722e99f6..0000000000 --- a/mondrian/src/test/java/mondrian/rolap/SqlStatementTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* -// 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. -// You must accept the terms of that agreement to use this software. -// -// Copyright (C) 2015-2017 Hitachi Vantara and others -// All Rights Reserved. -*/ -package mondrian.rolap; - -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.time.Duration; -import java.util.Optional; - -import org.eclipse.daanse.olap.api.Context; -import org.eclipse.daanse.olap.api.connection.Connection; -import org.eclipse.daanse.olap.api.monitor.EventBus; -import org.eclipse.daanse.olap.common.QueryCanceledException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.eclipse.daanse.olap.server.ExecutionImpl; -import org.eclipse.daanse.olap.server.LocusImpl; -import org.eclipse.daanse.olap.server.StatementImpl; -import org.eclipse.daanse.rolap.common.SqlStatement; - -/** - * @author Andrey Khayrutdinov - */ -class SqlStatementTest { - - private EventBus monitor; - private Context context; - private Connection rolapConnection; - private StatementImpl statMock; - private ExecutionImpl execution; - private LocusImpl locus; - private SqlStatement statement; - - @BeforeEach - public void beforeEach() { - monitor = mock(EventBus.class); - - context = mock(Context.class); - when(context.getMonitor()).thenReturn(monitor); - - rolapConnection = mock(Connection.class); - when(rolapConnection.getContext()).thenReturn(context); - - statMock = mock(StatementImpl.class); - when(statMock.getMondrianConnection()).thenReturn(rolapConnection); - - execution = new ExecutionImpl(statMock, Optional.empty()); - execution = spy(execution); - doThrow(new QueryCanceledException()) - .when(execution).checkCancelOrTimeout(); - - locus = new LocusImpl(execution, "component", "message"); - - statement = new SqlStatement(null, "sql", null, 0, 0, locus, 0, 0, null); - statement = spy(statement); - } - - @Test - void testPrintingNilDurationIfCancelledBeforeStart() throws Exception { - try { - statement.execute(); - } catch (Exception e) { - Throwable cause = e.getCause(); - if (!(cause instanceof QueryCanceledException)) { - String message = "Expected QueryCanceledException but caught " - + ((cause == null) ? null : cause.getClass().getSimpleName()); - fail(message); - } - } - - verify(statement).formatTimingStatus(eq(Duration.ZERO), anyInt()); - } - -} diff --git a/mondrian/src/test/java/mondrian/rolap/agg/DenseDoubleSegmentBodyTest.java b/mondrian/src/test/java/mondrian/rolap/agg/DenseDoubleSegmentBodyTest.java deleted file mode 100644 index 1259a7f9bb..0000000000 --- a/mondrian/src/test/java/mondrian/rolap/agg/DenseDoubleSegmentBodyTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -// 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. -// You must accept the terms of that agreement to use this software. -// -// Copyright (c) 2015-2017 Hitachi Vantara.. All rights reserved. -*/ -package mondrian.rolap.agg; - -import java.util.BitSet; -import java.util.List; -import java.util.SortedSet; - -import org.eclipse.daanse.olap.util.Pair; -import org.eclipse.daanse.rolap.common.agg.DenseDoubleSegmentBody; - -/** - * @author Andrey Khayrutdinov - */ -class DenseDoubleSegmentBodyTest extends - DenseSegmentBodyTestBase -{ - - @Override - Double createNullValue() { - return 0d; - } - - @Override - Double createNonNullValue() { - return 1d; - } - - @Override - boolean isNull(Double value) { - return (value == null) || (value == 0); - } - - @Override - DenseDoubleSegmentBody createSegmentBody( - BitSet nullValues, - Object array, - List, Boolean>> axes) - { - Object[] doubles = (Object[]) array; - double[] values = new double[doubles.length]; - for (int i = 0; i < doubles.length; i++) { - values[i] = (Double)doubles[i]; - } - return new DenseDoubleSegmentBody(nullValues, values, axes); - } -} diff --git a/mondrian/src/test/java/mondrian/rolap/agg/DenseIntSegmentBodyTest.java b/mondrian/src/test/java/mondrian/rolap/agg/DenseIntSegmentBodyTest.java deleted file mode 100644 index 0fc3cdbd81..0000000000 --- a/mondrian/src/test/java/mondrian/rolap/agg/DenseIntSegmentBodyTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -// 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. -// You must accept the terms of that agreement to use this software. -// -// Copyright (c) 2015-2017 Hitachi Vantara.. All rights reserved. -*/ -package mondrian.rolap.agg; - -import java.util.BitSet; -import java.util.List; -import java.util.SortedSet; - -import org.eclipse.daanse.olap.util.Pair; -import org.eclipse.daanse.rolap.common.agg.DenseIntSegmentBody; - -/** - * @author Andrey Khayrutdinov - */ -class DenseIntSegmentBodyTest extends - DenseSegmentBodyTestBase -{ - - @Override - Integer createNullValue() { - return 0; - } - - @Override - Integer createNonNullValue() { - return 1; - } - - @Override - boolean isNull(Integer value) { - return (value == null) || (value == 0); - } - - @Override - DenseIntSegmentBody createSegmentBody( - BitSet nullValues, - Object array, - List, Boolean>> axes) - { - Object[] integers = (Object[]) array; - int[] values = new int[integers.length]; - for (int i = 0; i < integers.length; i++) { - values[i] = (Integer)integers[i]; - } - return new DenseIntSegmentBody(nullValues, values, axes); - } -} diff --git a/mondrian/src/test/java/mondrian/rolap/agg/DenseSegmentBodyTestBase.java b/mondrian/src/test/java/mondrian/rolap/agg/DenseSegmentBodyTestBase.java deleted file mode 100644 index 5851e2e514..0000000000 --- a/mondrian/src/test/java/mondrian/rolap/agg/DenseSegmentBodyTestBase.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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. - * You must accept the terms of that agreement to use this software. - * - * Copyright (c) 2015-2017 Hitachi Vantara.. All rights reserved. - * ---- All changes after Fork in 2023 ------------------------ - * - * Project: Eclipse daanse - * - * Copyright (c) 2023 Contributors to the Eclipse Foundation. - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors after Fork in 2023: - * SmartCity Jena - initial - */ - -package mondrian.rolap.agg; - -import static java.util.Arrays.asList; -import static org.eclipse.daanse.olap.util.Pair.of; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.BitSet; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.junit.jupiter.api.Test; -import org.eclipse.daanse.olap.util.Pair; -import org.eclipse.daanse.olap.key.CellKey; -import org.eclipse.daanse.rolap.common.agg.AbstractSegmentBody; - -/** - * This is a base class for two heirs. It provides several template methods - * for testing - * @author Andrey Khayrutdinov - */ -abstract class DenseSegmentBodyTestBase -{ - - final V nonNull = createNonNullValue(); - final V nullValue = createNullValue(); - - @Test - public void testGetObject_NonNull() { - T body = withOutAxes(nonNull); - assertEquals(nonNull, body.getObject(0)); - } - - @Test - public void testGetObject_Null() { - T body = withOutAxes(nullValue); - assertNull(body.getObject(0)); - } - - @Test - public void testGetSize_NoNulls() { - T body = withOutAxes(nonNull, nonNull, nonNull); - assertEquals(body.getSize(), body.getEffectiveSize()); - } - - @Test - public void testGetSize_HasNulls() { - T body = withOutAxes(nonNull, nullValue, nonNull); - assertEquals(3, body.getSize()); - assertEquals(2, body.getEffectiveSize()); - } - - @Test - public void testGetSize_OnlyNulls() { - T body = withOutAxes(nullValue, nullValue, nullValue); - assertEquals(3, body.getSize()); - assertEquals(0, body.getEffectiveSize()); - } - - @Test - public void testGetValueMap_NoNullCells_NoNullAxes() { - SortedSet axis1 = new TreeSet<>(asList(1, 2)); - SortedSet axis2 = new TreeSet<>(asList(3)); - List, Boolean>> axes = asList( - of(axis1, false), of(axis2, false)); - T body = withAxes(axes, nonNull, nonNull, nonNull); - assertValuesMapIsCorrect(body, 3); - } - - @Test - public void testGetValueMap_NoNullCells_HasNullAxes() { - SortedSet axis1 = new TreeSet<>(asList(1, 2)); - SortedSet axis2 = new TreeSet<>(asList(3)); - List, Boolean>> axes = asList( - of(axis1, false), of(axis2, true)); - T body = withAxes(axes, nonNull, nonNull, nonNull, nonNull); - assertValuesMapIsCorrect(body, 4); - } - - @Test - public void testGetValueMap_HasNullCells_NoNullAxes() { - SortedSet axis1 = new TreeSet<>(asList(1, 2)); - SortedSet axis2 = new TreeSet<>(asList(3)); - List, Boolean>> axes = asList( - of(axis1, false), of(axis2, false)); - T body = withAxes(axes, nonNull, nullValue, nonNull, nullValue, nonNull); - assertValuesMapIsCorrect(body, 3); - } - - @Test - public void testGetValueMap_HasNullCells_HasNullAxes() { - SortedSet axis1 = new TreeSet<>(asList(1, 2)); - SortedSet axis2 = new TreeSet<>(asList(3)); - List, Boolean>> axes = asList( - of(axis1, false), of(axis2, true)); - T body = withAxes( - axes, nonNull, nullValue, nonNull, nullValue, nonNull, nonNull); - assertValuesMapIsCorrect(body, 4); - } - - @Test - public void testGetValueMap_OnlyNullCells_NoNullAxes() { - SortedSet axis1 = new TreeSet<>(asList(1, 2)); - SortedSet axis2 = new TreeSet<>(asList(3)); - List, Boolean>> axes = asList( - of(axis1, false), of(axis2, false)); - T body = withAxes(axes, nullValue, nullValue); - assertValuesMapIsCorrect(body, 0); - } - - @Test - public void testGetValueMap_OnlyNullCells_HasNullAxes() { - SortedSet axis1 = new TreeSet<>(asList(1, 2)); - SortedSet axis2 = new TreeSet<>(asList(3)); - List, Boolean>> axes = asList( - of(axis1, false), of(axis2, true)); - T body = withAxes(axes, nullValue, nullValue); - assertValuesMapIsCorrect(body, 0); - } - - private void assertValuesMapIsCorrect(T body, int expectedSize) { - Map valueMap = body.getValueMap(); - - assertEquals(expectedSize, valueMap.size()); - assertEquals(expectedSize, valueMap.keySet().size()); - assertEquals(expectedSize, valueMap.values().size()); - assertEquals(expectedSize, valueMap.entrySet().size()); - - int i = 0; - Iterator> it = valueMap.entrySet().iterator(); - while (i < expectedSize) { - assertTrue(it.hasNext(), Integer.toString(i)); - assertNotNull(it.next()); - i++; - } - assertFalse(it.hasNext()); - } - - abstract V createNullValue(); - abstract V createNonNullValue(); - abstract boolean isNull(V value); - - abstract T createSegmentBody( - BitSet nullValues, Object array, - List, Boolean>> axes); - - T withOutAxes(V... values) { - return withAxes( - Collections., Boolean>>emptyList(), - values); - } - - T withAxes(List, Boolean>> axes, V... values) { - BitSet nullValues = new BitSet(); - for (int i = 0; i < values.length; i++) { - if (isNull(values[i])) { - nullValues.set(i); - } - } - return createSegmentBody(nullValues, values, axes); - } -} diff --git a/mondrian/src/test/java/mondrian/rolap/agg/GroupingSetsListTest.java b/mondrian/src/test/java/mondrian/rolap/agg/GroupingSetsListTest.java deleted file mode 100644 index 6646b38e4a..0000000000 --- a/mondrian/src/test/java/mondrian/rolap/agg/GroupingSetsListTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* -// 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. -// You must accept the terms of that agreement to use this software. -// -// Copyright (C) 2005-2005 Julian Hyde -// Copyright (C) 2005-2018 Hitachi Vantara -// All Rights Reserved. -*/ -package mondrian.rolap.agg; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.daanse.olap.key.BitKey; -import org.eclipse.daanse.rolap.element.RolapCatalog; -import org.eclipse.daanse.rolap.common.RolapStar; -import org.eclipse.daanse.rolap.common.StarColumnPredicate; -import org.eclipse.daanse.rolap.common.StarPredicate; -import org.eclipse.daanse.rolap.common.agg.GroupingSet; -import org.eclipse.daanse.rolap.common.agg.GroupingSetsList; -import org.eclipse.daanse.rolap.common.agg.Segment; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import org.eclipse.daanse.olap.util.ByteString; - -class GroupingSetsListTest { - - private static List groupingSetList; - private static GroupingSetsList testObject; - private static BitKey bitkeyMock = mock(BitKey.class); - - private static RolapStar starMock; - private static RolapStar.Measure measureMock = mock(RolapStar.Measure.class); - - private static RolapStar.Column col1, col2, col3, col4; - private static RolapStar.Column[] columns; - - @BeforeAll - public static void beforeAll() throws Exception { - //Get star mock - just to allow creating Segment - starMock = getStarMock(); - //Columns mocks - col1 = getColumnMock("LV1_ID", "Table1"); - col2 = getColumnMock("LV1_ID", "Table2"); - col3 = getColumnMock("LV1_ID", "Table3"); - col4 = getColumnMock("LV1_ID", "Table4"); - columns = new RolapStar.Column[] {col1, col2, col3, col4 }; - - groupingSetList = createGroupingSetList(); - } - - @Test - void testNewGroupingSetsList_RollupColumnsFoundCorrectly() { - testObject = new GroupingSetsList(groupingSetList); - assertNotNull(testObject); - assertSame(groupingSetList, testObject.getGroupingSets()); - assertTrue(testObject.useGroupingSets()); - // verify count of grouping sets for columns - assertEquals( - expectedGroupingSetsColumns().size(), - testObject.getGroupingSetsColumns().size()); - // verify columns in each of groups - for (int i = 0; i < expectedGroupingSetsColumns().size(); i++) { - assertEquals( - expectedGroupingSetsColumns().get(i).length, - testObject.getGroupingSetsColumns().get(i).length); - for (int j = 0; j < expectedGroupingSetsColumns().get(i).length; j++) { - assertEquals( - expectedGroupingSetsColumns().get(i)[j], - testObject.getGroupingSetsColumns().get(i)[j]); - } - } - assertEquals(2, testObject.getRollupColumns().size()); - assertEquals(Arrays.asList(col3, col4), testObject.getRollupColumns()); - assertEquals(5, testObject.getGroupingBitKeyIndex()); - } - - private List expectedGroupingSetsColumns() { - List ls = new ArrayList<>(); - ls.add(columns); - ls.add(new RolapStar.Column[] {col1, col2, col3}); - ls.add(new RolapStar.Column[] {col1, col2}); - return ls; - } - private static List createGroupingSetList() { - List grList = new ArrayList<>(); - //We have 3 grouping sets for testing - //detailed grouping set - all columns used - grList.add(createGroupingSet(4)); - //rolled-up grouping sets - grList.add(createGroupingSet(3)); - grList.add(createGroupingSet(2)); - return grList; - } - private static GroupingSet createGroupingSet(int columnCount) { - StarColumnPredicate[] predicates = new StarColumnPredicate[] {}; - List compPredicates = new ArrayList<>(); - RolapStar.Column[] c = new RolapStar.Column[columnCount]; - //Every grouping set will contain different count of columns - for (int i = 0; i < columnCount; i++) { - c[i] = columns[i]; - } - Segment segment = - new Segment( - starMock, bitkeyMock, c, measureMock, - predicates, null, compPredicates); - GroupingSet grSet = - new GroupingSet( - Arrays.asList(segment), bitkeyMock, - bitkeyMock, predicates, c); - return grSet; - } - - private static RolapStar.Column getColumnMock( - String columnName, - String tableName) - { - RolapStar.Column colMock = mock(RolapStar.Column.class); - RolapStar.Table tableMock = mock(RolapStar.Table.class); - when(colMock.getName()).thenReturn(columnName); - when(colMock.getTable()).thenReturn(tableMock); - when(tableMock.getAlias()).thenReturn(tableName); - return colMock; - } - - private static RolapStar getStarMock() { - RolapStar mock = mock(RolapStar.class); - - RolapStar.Table tableMock = mock(RolapStar.Table.class); - RolapCatalog schemaMock = mock(RolapCatalog.class); - ByteString md5 = new ByteString("test schema".getBytes()); - when(mock.getCatalog()).thenReturn(schemaMock); - when(schemaMock.getChecksum()).thenReturn(md5); - when(mock.getFactTable()).thenReturn(tableMock); - when(tableMock.getAlias()).thenReturn("Table Mock"); - return mock; - } - -} diff --git a/mondrian/src/test/java/mondrian/rolap/agg/SegmentBuilderTest.java b/mondrian/src/test/java/mondrian/rolap/agg/SegmentBuilderTest.java index d549a11a52..f4e90549f2 100644 --- a/mondrian/src/test/java/mondrian/rolap/agg/SegmentBuilderTest.java +++ b/mondrian/src/test/java/mondrian/rolap/agg/SegmentBuilderTest.java @@ -9,13 +9,9 @@ package mondrian.rolap.agg; import static java.util.Arrays.asList; -import static java.util.Collections.singleton; -import static java.util.Collections.singletonMap; import static mondrian.enums.DatabaseProduct.getDatabaseProduct; -import static org.eclipse.daanse.olap.util.Pair.of; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opencube.junit5.TestUtil.assertQueryReturns; import static org.opencube.junit5.TestUtil.executeQuery; import static org.opencube.junit5.TestUtil.flushSchemaCache; @@ -36,13 +32,13 @@ import java.util.TreeSet; import org.eclipse.daanse.jdbc.db.dialect.api.Datatype; -import org.eclipse.daanse.olap.api.connection.Connection; import org.eclipse.daanse.olap.api.Context; import org.eclipse.daanse.olap.api.ISegmentCacheManager; +import org.eclipse.daanse.olap.api.connection.Connection; import org.eclipse.daanse.olap.api.result.Result; -import org.eclipse.daanse.olap.key.BitKey; import org.eclipse.daanse.olap.common.SystemWideProperties; import org.eclipse.daanse.olap.core.AbstractBasicContext; +import org.eclipse.daanse.olap.key.BitKey; import org.eclipse.daanse.olap.spi.SegmentBody; import org.eclipse.daanse.olap.spi.SegmentCache; import org.eclipse.daanse.olap.spi.SegmentColumn; @@ -51,15 +47,11 @@ import org.eclipse.daanse.olap.util.Pair; import org.eclipse.daanse.rolap.aggregator.SumAggregator; import org.eclipse.daanse.rolap.common.RolapUtil; -import org.eclipse.daanse.rolap.common.agg.DenseDoubleSegmentBody; -import org.eclipse.daanse.rolap.common.agg.DenseIntSegmentBody; import org.eclipse.daanse.rolap.common.agg.DenseObjectSegmentBody; import org.eclipse.daanse.rolap.common.agg.SegmentBuilder; import org.eclipse.daanse.rolap.common.agg.SegmentCacheManager; -import org.eclipse.daanse.rolap.common.agg.SparseSegmentBody; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.opencube.junit5.ContextSource; import org.opencube.junit5.TestUtil; @@ -172,35 +164,6 @@ void testNullMemberOffset2ColRollup(Context context) { + "Row #0: 1,907\n"); } - @Test - void testSegmentBodyIterator() { - // checks that cell key coordinates are generated correctly - // when a null member is present. - List, Boolean>> axes = - new ArrayList<>(); - axes.add(new Pair, Boolean>( - new TreeSet( - Arrays.asList("foo1", "bar1")), true)); // nullAxisFlag=T - axes.add(new Pair, Boolean>( - new TreeSet( - Arrays.asList("foo2", "bar2", "baz3")), false)); - SegmentBody testBody = new DenseIntSegmentBody( - new BitSet(), new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, - axes); - Map valueMap = testBody.getValueMap(); - assertEquals( - "{(0, 0)=1, " - + "(0, 1)=2, " - + "(0, 2)=3, " - + "(1, 0)=4, " - + "(1, 1)=5, " - + "(1, 2)=6, " - + "(2, 0)=7, " - + "(2, 1)=8, " - + "(2, 2)=9}", - valueMap.toString()); - } - @ParameterizedTest @ContextSource(propertyUpdater = AppandFoodMartCatalog.class, dataloader = FastFoodmardDataLoader.class) void testSparseRollup(Context context) { @@ -234,127 +197,6 @@ void testSparseRollup(Context context) { } } - @Test - void testRollupWithIntOverflowPossibility() { - // rolling up a segment that would cause int overflow if - // rolled up to a dense segment - // MONDRIAN-1377 - - // make a source segment w/ 3 cols, 47K vals each, - // target segment has 2 of the 3 cols. - // count of possible values will exceed Integer.MAX_VALUE - Pair rollup = - SegmentBuilder.rollup( - makeSegmentMap( - new String[] {"col1", "col2", "col3"}, - null, 47000, 4, false, null), - new HashSet<>(Arrays.asList("col1", "col2")), - null, SumAggregator.INSTANCE, Datatype.NUMERIC, - 1000, 0.5); - assertTrue(rollup.right instanceof SparseSegmentBody); - } - - @Test - void testRollupWithOOMPossibility() { - // rolling up a segment that would cause OOM if - // rolled up to a dense segment - // MONDRIAN-1377 - - // make a source segment w/ 3 cols, 44K vals each, - // target segment has 2 of the 3 cols. - Pair rollup = - SegmentBuilder.rollup( - makeSegmentMap( - new String[] {"col1", "col2", "col3"}, - null, 44000, 4, false, null), - new HashSet<>(Arrays.asList("col1", "col2")), - null, SumAggregator.INSTANCE, Datatype.NUMERIC, - 1000, 0.5); - assertTrue(rollup.right instanceof SparseSegmentBody); - } - - @Test - void testRollupShouldBeDense() { - // Fewer than 1000 column values in rolled up segment. - Pair rollup = - SegmentBuilder.rollup( - makeSegmentMap( - new String[] {"col1", "col2", "col3"}, - null, 10, 15, false, null), - new HashSet<>(Arrays.asList("col1", "col2")), - null, SumAggregator.INSTANCE, Datatype.NUMERIC, - 1000, 0.5); - assertTrue(rollup.right instanceof DenseDoubleSegmentBody); - - // greater than 1K col vals, above density ratio - rollup = - SegmentBuilder.rollup( - makeSegmentMap( - new String[] {"col1", "col2", "col3", "col4"}, - null, 11, 10000, false, null), - // 1331 possible intersections (11*3) - new HashSet<>(Arrays.asList("col1", "col2", "col3")), - null, SumAggregator.INSTANCE, Datatype.NUMERIC, - 1000, 0.5); - assertTrue(rollup.right instanceof DenseDoubleSegmentBody); - } - - @Test - void testRollupWithDenseIntBody() { - // - // We have the following data: - // - // 1 _ _ - // col2 1 2 _ - // 1 _ 1 - // col1 - // So, after rolling it up with the SUM function, we expect to get - // - // 3 2 1 - // col1 - // - String[][] colValues = dummyColumnValues(2, 3); - int[] values = {1, 1, 1, 0, 2, 0, 1}; - - BitSet nulls = new BitSet(); - for (int i = 0; i < values.length; i++) { - if (values[i] == 0) { - nulls.set(i); - } - } - - List, Boolean>> axes = - new ArrayList<>(); - List segmentColumns = new ArrayList<>(); - for (int i = 0; i < colValues.length; i++) { - axes.add(of(toSortedSet(colValues[i]), false)); - segmentColumns.add(new SegmentColumn( - "col" + (i + 1), - colValues[i].length, - toSortedSet(colValues[i]))); - } - SegmentHeader header = makeDummySegmentHeader(segmentColumns); - SegmentBody body = new DenseIntSegmentBody(nulls, values, axes); - Map segmentsMap = singletonMap(header, body); - - Pair rollup = - SegmentBuilder.rollup( - segmentsMap, singleton("col1"), - null, SumAggregator.INSTANCE, Datatype.NUMERIC, - 1000, 0.5); - - double[] result = (double[])rollup.right.getValueArray(); - double[] expected = {3, 2, 1}; - assertEquals(expected.length, result.length); - for (int i = 0; i < expected.length; i++) { - double exp = expected[i]; - double act = result[i]; - assertTrue( - Math.abs(exp - act) < 1e-6, - String.format("%d %f %f", i, exp, act)); - } - } - @Disabled //TODO need investigate @ParameterizedTest @ContextSource(propertyUpdater = AppandFoodMartCatalog.class, dataloader = FastFoodmardDataLoader.class) diff --git a/mondrian/src/test/java/mondrian/test/I18nTest.java b/mondrian/src/test/java/mondrian/test/I18nTest.java index 89eeb40608..069304f7b5 100644 --- a/mondrian/src/test/java/mondrian/test/I18nTest.java +++ b/mondrian/src/test/java/mondrian/test/I18nTest.java @@ -9,13 +9,10 @@ package mondrian.test; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opencube.junit5.TestUtil.assertEqualsVerbose; import java.time.Duration; -import java.util.Calendar; import java.util.List; -import java.util.Locale; import java.util.Optional; import org.apache.commons.lang3.LocaleUtils; @@ -24,8 +21,6 @@ import org.eclipse.daanse.olap.api.connection.ConnectionProps; import org.eclipse.daanse.olap.api.query.component.Query; import org.eclipse.daanse.olap.api.result.Result; -import org.eclipse.daanse.olap.util.Format; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.opencube.junit5.ContextSource; import org.opencube.junit5.TestUtil; @@ -46,39 +41,6 @@ class I18nTest { public static final char EA = '\u00e9'; // e acute public static final char UC = '\u00FB'; // u circumflex - @Test - void testFormat() { - // Make sure Util is loaded, so that the LocaleFormatFactory gets - // registered. -// discard(Util.NL); - - Locale spanish = new Locale("es", "ES"); - Locale german = new Locale("de", "DE"); - - // Thousands and decimal separators are different in Spain - Format numFormat = new Format("#,000.00", spanish); - assertEquals(numFormat.format(new Double(123456.789)), "123.456,79"); - - // Currency too - Format currencyFormat = new Format("Currency", spanish); - assertEquals( - "1.234.567,79 €", - currencyFormat.format(new Double(1234567.789))); - - // Dates - Format dateFormat = new Format("Medium Date", spanish); - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, 2005); - calendar.set(Calendar.MONTH, 0); // January, 0-based - calendar.set(Calendar.DATE, 22); - java.util.Date date = calendar.getTime(); - assertEquals("22-ene-05", dateFormat.format(date)); - - // Dates in German - dateFormat = new Format("Long Date", german); - assertEquals("Samstag, Januar 22, 2005", dateFormat.format(date)); - } - @ParameterizedTest @ContextSource(propertyUpdater = AppandFoodMartCatalog.class, dataloader = FastFoodmardDataLoader.class ) void testAutoFrench(Context context) { diff --git a/mondrian/src/test/java/mondrian/test/TupleListTest.java b/mondrian/src/test/java/mondrian/test/TupleListTest.java index a2d125cb19..b91afe8392 100644 --- a/mondrian/src/test/java/mondrian/test/TupleListTest.java +++ b/mondrian/src/test/java/mondrian/test/TupleListTest.java @@ -23,10 +23,11 @@ import java.util.Collections; import java.util.List; -import org.eclipse.daanse.olap.api.connection.Connection; +import org.eclipse.daanse.olap.api.CatalogReader; import org.eclipse.daanse.olap.api.Context; import org.eclipse.daanse.olap.api.calc.todo.TupleList; -import org.eclipse.daanse.olap.api.CatalogReader; +import org.eclipse.daanse.olap.api.connection.Connection; +import org.eclipse.daanse.olap.api.element.Catalog; import org.eclipse.daanse.olap.api.element.Cube; import org.eclipse.daanse.olap.api.element.Member; import org.eclipse.daanse.olap.calc.base.type.tuplebase.ArrayTupleList; @@ -34,13 +35,11 @@ import org.eclipse.daanse.olap.calc.base.type.tuplebase.TupleCollections; import org.eclipse.daanse.olap.calc.base.type.tuplebase.UnaryTupleList; import org.eclipse.daanse.olap.common.Util; -import org.eclipse.daanse.olap.api.element.Catalog; -import org.junit.jupiter.api.Test; +import org.eclipse.daanse.olap.server.LocusImpl; import org.junit.jupiter.params.ParameterizedTest; import org.opencube.junit5.ContextSource; import org.opencube.junit5.dataloader.FastFoodmardDataLoader; import org.opencube.junit5.propupdator.AppandFoodMartCatalog; -import org.eclipse.daanse.olap.server.LocusImpl; /** * Unit test for {@link TupleList} and common implementations. @@ -49,12 +48,6 @@ */ class TupleListTest { - @Test - void testTupleList() { - assertTrue(TupleCollections.createList(1) instanceof UnaryTupleList); - assertTrue(TupleCollections.createList(2) instanceof ArrayTupleList); - } - @ParameterizedTest @ContextSource(propertyUpdater = AppandFoodMartCatalog.class, dataloader = FastFoodmardDataLoader.class) void testUnaryTupleList(Context context) { diff --git a/mondrian/src/test/java/mondrian/util/FilteredIterableTest.java b/mondrian/src/test/java/mondrian/util/FilteredIterableTest.java deleted file mode 100644 index 12693633c7..0000000000 --- a/mondrian/src/test/java/mondrian/util/FilteredIterableTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* -* 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. -* You must accept the terms of that agreement to use this software. -* -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. -*/ - -package mondrian.util; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.fail; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Predicate; - -import org.eclipse.daanse.rolap.util.FilteredIterableList; -import org.junit.jupiter.api.Test; - -/** - * Unit-test for FilteredIterable - * - * @author jlopez, lcanals, Stefan Bischof - * @since May, 2008 - */ -class FilteredIterableTest{ - public FilteredIterableTest() { - } - - @Test - void testEmptyList() throws Exception { - final List base = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - base.add(i); - } - - final List empty = - new FilteredIterableList<>( - base, - new Predicate() { - @Override - public boolean test(final Integer i) { - return false; - } - }); - for (final Integer x : empty) { - fail("All elements should have been filtered"); - } - } - - @Test - void testGetter() throws Exception { - final List base = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - base.add(i); - } - - final List empty = - new FilteredIterableList<>( - base, - new Predicate() { - @Override - public boolean test(final Integer i) { - return i < 2; - } - }); - for (int i = 0; i < 2; i++) { - assertEquals(Integer.valueOf(i), empty.get(i)); - } - } - - @Test - void test2Elements() throws Exception { - final List base = new ArrayList<>(); - for (int i = 0; i < 2; i++) { - base.add(i); - } - - final List identical = - new FilteredIterableList<>( - base, - new Predicate() { - @Override - public boolean test (final Integer i) { - return true; - } - }); - assertFalse(identical.isEmpty()); - assertNotNull(identical.get(0)); - int k = 0; - for (final Integer i : identical) { - assertEquals(i, identical.get(k)); - k++; - } - } -} diff --git a/mondrian/src/test/java/mondrian/util/MemoryMonitorTest.java b/mondrian/src/test/java/mondrian/util/MemoryMonitorTest.java index fd04d13428..b69813e484 100644 --- a/mondrian/src/test/java/mondrian/util/MemoryMonitorTest.java +++ b/mondrian/src/test/java/mondrian/util/MemoryMonitorTest.java @@ -121,48 +121,6 @@ public void memoryUsageNotification(long used, long max) { } } */ - @Test - void testDeltaUsage() throws Exception { - if (!enabled) { - return; - } - class Listener implements MemoryMonitor.Listener { - boolean wasNotified = false; - Listener() { - } - @Override - public void memoryUsageNotification(long used, long max) { - wasNotified = true; - } - } - Listener listener = new Listener(); - MemoryMonitor mm = new NotificationMemoryMonitor(); - // we will set a percentage slightly above the current - // used level, and then allocate some objects that will - // force a notification. - long maxMemory = mm.getMaxMemory(); - long usedMemory = mm.getUsedMemory(); - int currentPercentage = - convertThresholdToPercentage(usedMemory, maxMemory); - int delta = (int) (maxMemory - usedMemory) / 10; - int percentage = convertThresholdToPercentage(delta, maxMemory); - try { - byte[][] bytes = new byte[10][]; - mm.addListener(listener, percentage + currentPercentage); - for (int i = 0; i < bytes.length; i++) { - bytes[i] = new byte[delta]; - if (listener.wasNotified) { - bytes = null; - break; - } - } - if (! listener.wasNotified) { - Assertions.fail("Listener callback not called"); - } - } finally { - mm.removeListener(listener); - } - } /* Does not work without the notify on add feature. void testUpdatePercent() throws Exception { diff --git a/mondrian/src/test/java/mondrian/util/ObjectPoolTest.java b/mondrian/src/test/java/mondrian/util/ObjectPoolTest.java deleted file mode 100644 index 0d2e78e942..0000000000 --- a/mondrian/src/test/java/mondrian/util/ObjectPoolTest.java +++ /dev/null @@ -1,287 +0,0 @@ -/* -* 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. -* You must accept the terms of that agreement to use this software. -* -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. -*/ - -package mondrian.util; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -import org.eclipse.daanse.rolap.util.ObjectPool; -import org.junit.jupiter.api.Test; - -/** - * Test case for {@link ObjectPool}. - * - * @author Richard Emberson, Stefan Bischof - */ -class ObjectPoolTest{ - - static class KeyValue { - long key; - Object value; - KeyValue(long key, Object value) { - this.key = key; - this.value = value; - } - @Override - public int hashCode() { - return (int)(key ^ (key >>> 32)); - } - @Override - public boolean equals(Object o) { - return (o instanceof KeyValue) - ? (((KeyValue) o).key == this.key) - : false; - } - @Override - public String toString() { - return value.toString(); - } - } - - @Test - void testString() throws Exception { - ObjectPool strings = new ObjectPool<>(); - int nos = 100000; - String[] ss1 = genStringsArray(nos); - for (int i = 0; i < nos; i++) { - strings.add(ss1[i]); - } - assertEquals(nos, strings.size(),"size not equal"); - - // second array of strings, same as the first but different objects - String[] ss2 = genStringsArray(nos); - for (int i = 0; i < nos; i++) { - String s = strings.add(ss2[i]); - assertEquals(s, ss2[i],"string not equal: " + s); - // REVIEW jvs 16-Jan-2008: This failed for me when - // I ran with a 1GB JVM heap size on JDK 1.5, probably - // because of interning (I tried changing genStringsList to add a - // gratuitous String constructor call, but that did not help). If - // there's a reason this test is on strings explicitly, then - // this needs to stay disabled; if the datatype can be changed - // to something which doesn't have any magic interning, then - // it can be re-enabled. This probably explains the - // Util.PreJdk15 "unknown reasons" above. - /* - assertFalse("same object", (s == ss2[i])); - */ - } - - strings.clear(); - assertEquals(0, strings.size(),"size not equal"); - - nos = 25; - ss1 = genStringsArray(nos); - for (int i = 0; i < nos; i++) { - strings.add(ss1[i]); - } - assertEquals(nos, strings.size(),"size not equal"); - - List l = genStringsList(nos); - Iterator it = strings.iterator(); - while (it.hasNext()) { - String s = it.next(); - l.remove(s); - } - assertTrue(l.isEmpty(),"list not empty"); - } - - @Test - void testKeyValue() throws Exception { - ObjectPool op = new ObjectPool<>(); - int nos = 100000; - KeyValue[] kv1 = genKeyValueArray(nos); - for (int i = 0; i < nos; i++) { - op.add(kv1[i]); - } - assertEquals(nos, op.size(),"size not equal"); - - // second array of KeyValues, same as the first but different objects - KeyValue[] kv2 = genKeyValueArray(nos); - for (int i = 0; i < nos; i++) { - KeyValue kv = op.add(kv2[i]); - assertEquals(kv, kv2[i],"KeyValue not equal: " + kv); - assertFalse((kv == kv2[i]),"same object"); - } - - op.clear(); - assertEquals(0, op.size(),"size not equal"); - - nos = 25; - kv1 = genKeyValueArray(nos); - for (int i = 0; i < nos; i++) { - op.add(kv1[i]); - } - assertEquals(nos, op.size(),"size not equal"); - - List l = genKeyValueList(nos); - Iterator it = op.iterator(); - while (it.hasNext()) { - KeyValue kv = it.next(); - l.remove(kv); - } - assertTrue(l.isEmpty(),"list not empty"); - } - - /** - * Tests ObjectPools containing large numbers of integer and string keys, - * and makes sure they return the same results as HashSet. Optionally - * measures performance. - */ - @Test - void testLarge() { - // Some typical results (2.4 GHz Intel dual-core). - - // Key type: Integer String - // Implementation: ObjectPool HashSet ObjectPool HashSet - // ========== ========== ========== ========== - // With density=0.01, 298,477 distinct entries, 7,068 hits - // 300,000 adds 221 ms 252 ms 293 ms 1013 ms - // 700,000 gets 164 ms 148 ms 224 ms 746 ms - // - // With density=0.5, 236,022 distinct entries, 275,117 hits - // 300,000 adds 175 ms 250 ms 116 ms 596 ms - // 700,000 gets 147 ms 176 ms 190 ms 757 ms - // - // With density=0.999, 189,850 distinct entries, 442,618 hits - // 300,000 adds 128 ms 185 ms 99 ms 614 ms - // 700,000 gets 133 ms 184 ms 130 ms 830 ms - - checkLargeMulti(300000, 0.01, 700000, 298477, 7068); - checkLargeMulti(300000, 0.5, 700000, 236022, 275117); - checkLargeMulti(300000, 0.999, 700000, 189850, 442618); - } - - private static void checkLargeMulti( - int entryCount, - double density, - int retrieveCount, - int expectedDistinct, - int expectedHits) - { - checkLarge( - true, true, entryCount, density, retrieveCount, - expectedDistinct, expectedHits); - checkLarge( - false, true, entryCount, density, retrieveCount, - expectedDistinct, expectedHits); - checkLarge( - false, true, entryCount, density, retrieveCount, - expectedDistinct, expectedHits); - checkLarge( - false, false, entryCount, density, retrieveCount, - expectedDistinct, expectedHits); - } - - private static void checkLarge( - boolean usePool, - boolean intKey, - int entryCount, - double density, - int retrieveCount, - int expectedDistinct, - int expectedHits) - { - final boolean print = false; - final long t1 = System.currentTimeMillis(); - assert density > 0 && density <= 1; - int space = (int) (entryCount / density); - ObjectPool objectPool = new ObjectPool<>(); - HashSet set = new HashSet<>(); - Random random = new Random(1234); - int distinctCount = 0; - final String longString = - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyy"; - for (int i = 0; i < entryCount; i++) { - final Object key = intKey - ? random.nextInt(space) - : longString + random.nextInt(space); - if (usePool) { - if (objectPool.add(key) != null) { - ++distinctCount; - } - } else { - if (set.add(key)) { - ++distinctCount; - } - } - } - final long t2 = System.currentTimeMillis(); - int hitCount = 0; - for (int i = 0; i < retrieveCount; i++) { - final Object key = intKey - ? random.nextInt(space) - : longString + random.nextInt(space); - if (usePool) { - if (objectPool.contains(key)) { - ++hitCount; - } - } else { - if (set.contains(key)) { - ++hitCount; - } - } - } - final long t3 = System.currentTimeMillis(); - if (usePool) { -// todo: assertEquals(expectedDistinct, objectPool.size()); - distinctCount = objectPool.size(); - } else { - assertEquals(expectedDistinct, set.size()); - } - if (print) { - System.out.println( - "Using " + (usePool ? "ObjectPool" : "HashSet") - + ", density=" + density - + ", " + distinctCount + " distinct entries, " - + hitCount + " hits"); - System.out.println( - entryCount + " adds took " + (t2 - t1) + " milliseconds"); - System.out.println( - retrieveCount + " gets took " + (t3 - t2) + " milliseconds"); - } - assertEquals(expectedDistinct, distinctCount); - assertEquals(expectedHits, hitCount); - } - - ///////////////////////////////////////////////////////////////////////// - // helpers - ///////////////////////////////////////////////////////////////////////// - private static String[] genStringsArray(int nos) { - List l = genStringsList(nos); - return l.toArray(new String[l.size()]); - } - private static List genStringsList(int nos) { - List l = new ArrayList<>(nos); - for (int i = 0; i < nos; i++) { - l.add(Integer.valueOf(i).toString()); - } - return l; - } - private static KeyValue[] genKeyValueArray(int nos) { - List l = genKeyValueList(nos); - return l.toArray(new KeyValue[l.size()]); - } - private static List genKeyValueList(int nos) { - List l = new ArrayList<>(nos); - for (int i = 0; i < nos; i++) { - l.add(new KeyValue(i, Integer.valueOf(i))); - } - return l; - } - -} diff --git a/mondrian/src/test/java/mondrian/util/PartiallyOrderedSetTest.java b/mondrian/src/test/java/mondrian/util/PartiallyOrderedSetTest.java deleted file mode 100644 index e687e9ef3e..0000000000 --- a/mondrian/src/test/java/mondrian/util/PartiallyOrderedSetTest.java +++ /dev/null @@ -1,441 +0,0 @@ -/* -* 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. -* You must accept the terms of that agreement to use this software. -* -* Copyright (c) 2002-2019 Hitachi Vantara.. All rights reserved. -*/ - -package mondrian.util; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.AbstractList; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.TreeSet; - -import org.eclipse.daanse.rolap.util.PartiallyOrderedSet; -import org.junit.jupiter.api.Test; - -/** - * Unit test for {@link PartiallyOrderedSet}. - */ -class PartiallyOrderedSetTest { - private static final boolean debug = false; - private final int SCALE = 250; // 100, 1000, 3000 are also reasonable values - final long seed = new Random().nextLong(); - final Random random = new Random(seed); - - static final PartiallyOrderedSet.Ordering stringSubsetOrdering = - new PartiallyOrderedSet.Ordering<>() { - @Override - public boolean lessThan(String e1, String e2) { - // e1 < e2 if every char in e1 is also in e2 - for (int i = 0; i < e1.length(); i++) { - if (e2.indexOf(e1.charAt(i)) < 0) { - return false; - } - } - return true; - } - }; - - // Integers, ordered by division. Top is 1, its children are primes, - // etc. - static final PartiallyOrderedSet.Ordering isDivisor = - new PartiallyOrderedSet.Ordering<>() { - @Override - public boolean lessThan(Integer e1, Integer e2) { - return e2 % e1 == 0; - } - }; - - // Bottom is 1, parents are primes, etc. - static final PartiallyOrderedSet.Ordering isDivisorInverse = - new PartiallyOrderedSet.Ordering<>() { - @Override - public boolean lessThan(Integer e1, Integer e2) { - return e1 % e2 == 0; - } - }; - - static final PartiallyOrderedSet.Ordering isDivisorWithNulls = - new PartiallyOrderedSet.Ordering<>() { - @Override - public boolean lessThan(Integer e1, Integer e2) { - if (e1 == null || e2 == null) { - return true; - } - return e2 % e1 == 0; - } - }; - - // Ordered by bit inclusion. E.g. the children of 14 (1110) are - // 12 (1100), 10 (1010) and 6 (0110). - static final PartiallyOrderedSet.Ordering isBitSubset = - new PartiallyOrderedSet.Ordering<>() { - @Override - public boolean lessThan(Integer e1, Integer e2) { - return (e2 & e1) == e2; - } - }; - - // Ordered by bit inclusion. E.g. the children of 14 (1110) are - // 12 (1100), 10 (1010) and 6 (0110). - static final PartiallyOrderedSet.Ordering isBitSuperset = - new PartiallyOrderedSet.Ordering<>() { - @Override - public boolean lessThan(Integer e1, Integer e2) { - return (e2 & e1) == e1; - } - }; - - @Test - void testPoset() { - String empty = "''"; - String abcd = "'abcd'"; - PartiallyOrderedSet poset = - new PartiallyOrderedSet<>(stringSubsetOrdering); - assertEquals(0, poset.size()); - - final StringBuilder buf = new StringBuilder(); - poset.out(buf); - assertEquals( - "PartiallyOrderedSet size: 0 elements: {\n" - + "}", - buf.toString()); - - poset.add("a"); - printValidate(poset); - poset.add("b"); - printValidate(poset); - - poset.clear(); - assertEquals(0, poset.size()); - poset.add(empty); - printValidate(poset); - poset.add(abcd); - printValidate(poset); - assertEquals(2, poset.size()); - assertEquals("['abcd']", poset.getNonChildren().toString()); - assertEquals("['']", poset.getNonParents().toString()); - - final String ab = "'ab'"; - poset.add(ab); - printValidate(poset); - assertEquals(3, poset.size()); - assertEquals("[]", poset.getChildren(empty).toString()); - assertEquals("['ab']", poset.getParents(empty).toString()); - assertEquals("['ab']", poset.getChildren(abcd).toString()); - assertEquals("[]", poset.getParents(abcd).toString()); - assertEquals("['']", poset.getChildren(ab).toString()); - assertEquals("['abcd']", poset.getParents(ab).toString()); - - // "bcd" is child of "abcd" and parent of "" - final String bcd = "'bcd'"; - poset.add(bcd); - printValidate(poset); - assertTrue(poset.isValid(false)); - assertEquals("['']", poset.getChildren(bcd).toString()); - assertEquals("['abcd']", poset.getParents(bcd).toString()); - assertEquals("['ab', 'bcd']", poset.getChildren(abcd).toString()); - - buf.setLength(0); - poset.out(buf); - assertEquals( - "PartiallyOrderedSet size: 4 elements: {\n" - + " 'abcd' parents: [] children: ['ab', 'bcd']\n" - + " 'ab' parents: ['abcd'] children: ['']\n" - + " 'bcd' parents: ['abcd'] children: ['']\n" - + " '' parents: ['ab', 'bcd'] children: []\n" - + "}", - buf.toString()); - - final String b = "'b'"; - - // ancestors of an element not in the set - assertEqualsList("['ab', 'abcd', 'bcd']", poset.getAncestors(b)); - - poset.add(b); - printValidate(poset); - assertEquals("['abcd']", poset.getNonChildren().toString()); - assertEquals("['']", poset.getNonParents().toString()); - assertEquals("['']", poset.getChildren(b).toString()); - assertEqualsList("['ab', 'bcd']", poset.getParents(b)); - assertEquals("['']", poset.getChildren(b).toString()); - assertEquals("['ab', 'bcd']", poset.getChildren(abcd).toString()); - assertEquals("['b']", poset.getChildren(bcd).toString()); - assertEquals("['b']", poset.getChildren(ab).toString()); - assertEqualsList("['ab', 'abcd', 'bcd']", poset.getAncestors(b)); - - // descendants and ancestors of an element with no descendants - assertEquals("[]", poset.getDescendants(empty).toString()); - assertEqualsList( - "['ab', 'abcd', 'b', 'bcd']", - poset.getAncestors(empty)); - - // some more ancestors of missing elements - assertEqualsList("['abcd']", poset.getAncestors("'ac'")); - assertEqualsList("[]", poset.getAncestors("'z'")); - assertEqualsList("['ab', 'abcd']", poset.getAncestors("'a'")); - } - @Test - void testPosetTricky() { - PartiallyOrderedSet poset = - new PartiallyOrderedSet<>(stringSubsetOrdering); - - // A tricky little poset with 4 elements: - // {a <= ab and ac, b < ab, ab, ac} - poset.clear(); - poset.add("'a'"); - printValidate(poset); - poset.add("'b'"); - printValidate(poset); - poset.add("'ac'"); - printValidate(poset); - poset.add("'ab'"); - printValidate(poset); - } - @Test - void testPosetBits() { - final PartiallyOrderedSet poset = - new PartiallyOrderedSet<>(isBitSuperset); - poset.add(2112); // {6, 11} i.e. 64 + 2048 - poset.add(2240); // {6, 7, 11} i.e. 64 + 128 + 2048 - poset.add(2496); // {6, 7, 8, 11} i.e. 64 + 128 + 256 + 2048 - printValidate(poset); - poset.remove(2240); - printValidate(poset); - poset.add(2240); // {6, 7, 11} i.e. 64 + 128 + 2048 - printValidate(poset); - } - - @Test - void testPosetBitsRemoveParent() { - final PartiallyOrderedSet poset = - new PartiallyOrderedSet<>(isBitSuperset); - poset.add(66); // {bit 2, bit 6} - poset.add(68); // {bit 3, bit 6} - poset.add(72); // {bit 4, bit 6} - poset.add(64); // {bit 6} - printValidate(poset); - poset.remove(64); // {bit 6} - printValidate(poset); - } - - @Test - void testMondrian2628() { - PartiallyOrderedSet integers = - new PartiallyOrderedSet<>(isDivisorWithNulls, - range(1, 1000)); - // Null elements can't be added to the poset. - assertFalse(integers.add(null)); - // Ancestors list cannot have null elements. - for (int i = 1; i < 1000; i++) { - assertFalse(integers.getAncestors(i).contains(null), - "Ancestor list of " + i + " has null elements."); - } - } - - @Test - void testDivisorPoset() { - PartiallyOrderedSet integers = - new PartiallyOrderedSet<>(isDivisor, range(1, 1000)); - assertEquals( - "[1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60]", - new TreeSet<>(integers.getDescendants(120)).toString()); - assertEquals( - "[240, 360, 480, 600, 720, 840, 960]", - new TreeSet<>(integers.getAncestors(120)).toString()); - assertTrue(integers.getDescendants(1).isEmpty()); - assertEquals( - 998, - integers.getAncestors(1).size()); - assertTrue(integers.isValid(true)); - } - - @Test - void testDivisorSeries() { - checkPoset(isDivisor, debug, range(1, SCALE * 3), false); - } - - @Test - void testDivisorRandom() { - boolean ok = false; - try { - checkPoset( - isDivisor, debug, random(random, SCALE, SCALE * 3), false); - ok = true; - } finally { - if (!ok) { - System.out.println("Random seed: " + seed); - } - } - } - - @Test - void testDivisorRandomWithRemoval() { - boolean ok = false; - try { - checkPoset( - isDivisor, debug, random(random, SCALE, SCALE * 3), true); - ok = true; - } finally { - if (!ok) { - System.out.println("Random seed: " + seed); - } - } - } - - @Test - void testDivisorInverseSeries() { - checkPoset(isDivisorInverse, debug, range(1, SCALE * 3), false); - } - - @Test - void testDivisorInverseRandom() { - boolean ok = false; - try { - checkPoset( - isDivisorInverse, debug, random(random, SCALE, SCALE * 3), - false); - ok = true; - } finally { - if (!ok) { - System.out.println("Random seed: " + seed); - } - } - } - - @Test - void testDivisorInverseRandomWithRemoval() { - boolean ok = false; - try { - checkPoset( - isDivisorInverse, debug, random(random, SCALE, SCALE * 3), - true); - ok = true; - } finally { - if (!ok) { - System.out.println("Random seed: " + seed); - } - } - } - - @Test - void testSubsetSeries() { - checkPoset(isBitSubset, debug, range(1, SCALE / 2), false); - } - - @Test - void testSubsetRandom() { - boolean ok = false; - try { - checkPoset( - isBitSubset, debug, random(random, SCALE / 4, SCALE), false); - ok = true; - } finally { - if (!ok) { - System.out.println("Random seed: " + seed); - } - } - } - - private void printValidate(PartiallyOrderedSet poset) { - if (debug) { - dump(poset); - } - assertTrue(poset.isValid(debug)); - } - - public void checkPoset( - PartiallyOrderedSet.Ordering ordering, - boolean debug, - Iterable generator, - boolean remove) - { - final PartiallyOrderedSet poset = - new PartiallyOrderedSet<>(ordering); - int n = 0; - int z = 0; - if (debug) { - dump(poset); - } - for (int i : generator) { - if (remove && z++ % 2 == 0) { - if (debug) { - System.out.println("remove " + i); - } - poset.remove(i); - if (debug) { - dump(poset); - } - continue; - } - if (debug) { - System.out.println("add " + i); - } - poset.add(i); - if (debug) { - dump(poset); - } - assertEquals(++n, poset.size()); - if (i < 100) { - if (!poset.isValid(false)) { - dump(poset); - } - assertTrue(poset.isValid(true)); - } - } - assertTrue(poset.isValid(true)); - - final StringBuilder buf = new StringBuilder(); - poset.out(buf); - assertTrue(buf.length() > 0); - } - - private void dump(PartiallyOrderedSet poset) { - final StringBuilder buf = new StringBuilder(); - poset.out(buf); - System.out.println(buf); - } - - private static Collection range( - final int start, final int end) - { - return new AbstractList<>() { - @Override - public Integer get(int index) { - return start + index; - } - - @Override - public int size() { - return end - start; - } - }; - } - - private static Iterable random( - Random random, final int size, final int max) - { - final Set set = new LinkedHashSet<>(); - while (set.size() < size) { - set.add(random.nextInt(max) + 1); - } - return set; - } - - private static void assertEqualsList(String expected, List ss) { - assertEquals( - expected, - new TreeSet<>(ss).toString()); - } -} diff --git a/mondrian/src/test/java/mondrian/util/PrimeFinderTest.java b/mondrian/src/test/java/mondrian/util/PrimeFinderTest.java deleted file mode 100644 index 16c40b9ba3..0000000000 --- a/mondrian/src/test/java/mondrian/util/PrimeFinderTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* -* 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. -* You must accept the terms of that agreement to use this software. -* -* Copyright (c) 2002-2017 Hitachi Vantara.. All rights reserved. -*/ - -package mondrian.util; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.eclipse.daanse.rolap.util.PrimeFinder; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -/** - * Testcase for {@link org.eclipse.daanse.rolap.util.PrimeFinder}. - * - * @author jhyde, Stefan Bischof - * @since Feb 4, 2007 - */ -class PrimeFinderTest{ - - private void assertStatistics(int from, int to, String expected) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - PrimeFinder.statistics(from, to, pw); - pw.flush(); - assertEquals(expected, sw.toString()); - } - - @Test - void testOne() { - assertStatistics( - 1000, - 1000, - "new maxdev @1000@dev=0.039\n" - + "Statistics for [1000,1000] are as follows\n" - + "meanDeviation = 3.9 %\n" - + "maxDeviation = 3.9 %\n"); - } - - @Test - void testTwo() { - assertStatistics( - 200, - 1000, - "new maxdev @200@dev=0.385\n" - + "Statistics for [200,1000] are as follows\n" - + "meanDeviation = 6.589286 %\n" - + "maxDeviation = 38.5 %\n"); - } - - @Test - void testThree() { - assertStatistics( - 16, - 1000, - "new maxdev @16@dev=0.0625\n" - + "new maxdev @18@dev=0.2777777777777778\n" - + "new maxdev @24@dev=0.2916666666666667\n" - + "new maxdev @48@dev=0.3958333333333333\n" - + "new maxdev @98@dev=0.3979591836734694\n" - + "new maxdev @198@dev=0.398989898989899\n" - + "Statistics for [16,1000] are as follows\n" - + "meanDeviation = 7.374975 %\n" - + "maxDeviation = 39.898987 %\n"); - } - - // disabled because it takes a LONG time - @Test - @Disabled - void testFour() { - assertStatistics(1000, Integer.MAX_VALUE, ""); - } -}