From 84a22c3b1003a29344859b8af286e37bbe4c7b21 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 5 Sep 2006 01:31:18 +0000 Subject: Added support to get free and unused orderings. --- .../com/amazon/carbonado/qe/TestOrderingScore.java | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'src/test/java/com/amazon/carbonado/qe') diff --git a/src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java b/src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java index 83b2364..02f7808 100644 --- a/src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java +++ b/src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java @@ -596,4 +596,88 @@ public class TestOrderingScore extends TestCase { assertEquals("-intProp", score.getHandledOrderings().get(1).toString()); assertEquals("~longProp", score.getRemainderOrderings().get(0).toString()); } + + public void testFreeOrderings() throws Exception { + final StorableIndex ix; + List> ops; + OrderingScore score; + Filter filter = null; + + ix = makeIndex(StorableTestBasic.class, "id", "intProp", "doubleProp"); + ops = makeOrderings(StorableTestBasic.class, "~id"); + + score = OrderingScore.evaluate(ix, filter, ops); + assertEquals(1, score.getHandledCount()); + assertEquals(0, score.getRemainderCount()); + assertEquals(false, score.shouldReverseOrder()); + assertEquals(2, score.getFreeOrderings().size()); + assertEquals("~intProp", score.getFreeOrderings().get(0).toString()); + assertEquals("~doubleProp", score.getFreeOrderings().get(1).toString()); + assertEquals(0, score.getUnusedOrderings().size()); + + ops = makeOrderings(StorableTestBasic.class, "~id", "-intProp"); + + score = OrderingScore.evaluate(ix, filter, ops); + assertEquals(2, score.getHandledCount()); + assertEquals(0, score.getRemainderCount()); + assertEquals(true, score.shouldReverseOrder()); + assertEquals(1, score.getFreeOrderings().size()); + assertEquals("-doubleProp", score.getFreeOrderings().get(0).toString()); + assertEquals(0, score.getUnusedOrderings().size()); + + ops = makeOrderings(StorableTestBasic.class, "~id", "-intProp", "+doubleProp"); + + score = OrderingScore.evaluate(ix, filter, ops); + assertEquals(2, score.getHandledCount()); + assertEquals(1, score.getRemainderCount()); + assertEquals("+doubleProp", score.getRemainderOrderings().get(0).toString()); + assertEquals(true, score.shouldReverseOrder()); + assertEquals(1, score.getFreeOrderings().size()); + assertEquals("-doubleProp", score.getFreeOrderings().get(0).toString()); + assertEquals(0, score.getUnusedOrderings().size()); + } + + public void testFreeAndUnusedOrderings() throws Exception { + final StorableIndex ix; + List> ops; + OrderingScore score; + Filter filter; + + ix = makeIndex(StorableTestBasic.class, "stringProp", "id", "intProp", "doubleProp"); + ops = makeOrderings(StorableTestBasic.class, "~id"); + filter = Filter.filterFor(StorableTestBasic.class, "stringProp = ?"); + + score = OrderingScore.evaluate(ix, filter, ops); + assertEquals(1, score.getHandledCount()); + assertEquals(0, score.getRemainderCount()); + assertEquals(false, score.shouldReverseOrder()); + assertEquals(2, score.getFreeOrderings().size()); + assertEquals("~intProp", score.getFreeOrderings().get(0).toString()); + assertEquals("~doubleProp", score.getFreeOrderings().get(1).toString()); + assertEquals(1, score.getUnusedOrderings().size()); + assertEquals("~stringProp", score.getUnusedOrderings().get(0).toString()); + + ops = makeOrderings(StorableTestBasic.class, "~id", "-intProp"); + + score = OrderingScore.evaluate(ix, filter, ops); + assertEquals(2, score.getHandledCount()); + assertEquals(0, score.getRemainderCount()); + assertEquals(true, score.shouldReverseOrder()); + assertEquals(1, score.getFreeOrderings().size()); + assertEquals("-doubleProp", score.getFreeOrderings().get(0).toString()); + assertEquals(1, score.getUnusedOrderings().size()); + assertEquals("~stringProp", score.getUnusedOrderings().get(0).toString()); + + ops = makeOrderings(StorableTestBasic.class, "~id", "-intProp", "+doubleProp"); + + score = OrderingScore.evaluate(ix, filter, ops); + assertEquals(2, score.getHandledCount()); + assertEquals(1, score.getRemainderCount()); + assertEquals("+doubleProp", score.getRemainderOrderings().get(0).toString()); + assertEquals(true, score.shouldReverseOrder()); + assertEquals(1, score.getFreeOrderings().size()); + assertEquals("-doubleProp", score.getFreeOrderings().get(0).toString()); + assertEquals(1, score.getUnusedOrderings().size()); + assertEquals("~stringProp", score.getUnusedOrderings().get(0).toString()); + } } -- cgit v1.2.3