Skip to content

Commit

Permalink
Queries: Improve unit test coverage for all filters
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//dev/coherence-ce/main/": change = 107249]
  • Loading branch information
aseovic committed Mar 4, 2024
1 parent a71e0b5 commit fe019d2
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,33 @@ public String toStringValue()
public int calculateEffectiveness(Map mapIndexes, Set setKeys)
{
MapIndex index = (MapIndex) mapIndexes.get(getValueExtractor());
return index == null ? calculateIteratorEffectiveness(setKeys.size())
: ((Collection) getValue()).size();
if (index == null)
{
// there is no relevant index
return -1;
}
else
{
// calculating the exact number of keys retained is too expensive;
// ignore the fact that there may be duplicates and simply return
// the worst possible number of keys retained, as if they were unique

Collection colValues = getValue();
Map mapContents = index.getIndexContents();
int cMatch = 0;

for (Object oValue : colValues)
{
Set setEQ = (Set) mapContents.get(oValue);

if (setEQ != null)
{
cMatch += setEQ.size();
}
}

return Math.min(cMatch, setKeys.size());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -41,7 +41,7 @@ public AllFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -86,6 +86,8 @@ public void testApplyIndex()
}

// begin test
assertEquals(3, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals("Two keys should remain in the set of keys.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/
package com.tangosol.util.filter;

Expand Down Expand Up @@ -39,7 +39,7 @@ public AndFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -93,6 +93,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(3, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals("Two keys should remain in the set of keys.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -39,7 +39,7 @@ public AnyFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -93,6 +93,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(2, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals("Two keys should remain in the set of keys.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/

package com.tangosol.util.filter;
Expand Down Expand Up @@ -39,7 +39,7 @@ public ContainsAllFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -94,6 +94,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(2, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals(2, setKeys.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/

package com.tangosol.util.filter;
Expand Down Expand Up @@ -39,7 +39,7 @@ public ContainsAnyFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -94,6 +94,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(6, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals(4, setKeys.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/

package com.tangosol.util.filter;
Expand Down Expand Up @@ -39,7 +39,7 @@ public ContainsFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -94,6 +94,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(3, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals(3, setKeys.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -47,7 +47,7 @@ public EqualsFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -99,6 +99,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(1, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals("One key should remain in the set of keys.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -43,7 +43,7 @@ public InFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -93,6 +93,8 @@ public void testApplyIndex()

// begin test
Set<String> setKeys = new HashSet<>(map.keySet());
assertEquals(4, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals(4, setKeys.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/
package com.tangosol.util.filter;

Expand Down Expand Up @@ -38,7 +38,7 @@ public KeyFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -90,6 +90,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(2, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals("Two keys should remain in the set of keys.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/
package com.tangosol.util.filter;

Expand Down Expand Up @@ -39,7 +39,7 @@ public LikeFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -106,6 +106,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(2, filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals("Two keys should remain in the set of keys.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
* https://oss.oracle.com/licenses/upl.
*/
package com.tangosol.util.filter;

Expand Down Expand Up @@ -38,7 +38,7 @@ public NotEqualsFilterTest(boolean fOrdered, boolean fPartial)
m_fPartial = fPartial;
}

@Parameterized.Parameters
@Parameterized.Parameters(name ="ordered={0} partial={1}")
public static Collection data() {
Object[][] data = new Object[][]
{ new Object[] {Boolean.FALSE, Boolean.FALSE},
Expand Down Expand Up @@ -89,6 +89,8 @@ public void testApplyIndex()
when(index.getIndexContents()).thenReturn(mapInverse);

// begin test
assertEquals(3 + (m_fPartial ? 4 : 0), filter.calculateEffectiveness(mapIndexes, setKeys));

filter.applyIndex(mapIndexes, setKeys);

assertEquals("One key should have been removed from the set of keys.",
Expand Down

0 comments on commit fe019d2

Please sign in to comment.