summaryrefslogtreecommitdiff
path: root/src/test/java/com/amazon/carbonado/qe
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/amazon/carbonado/qe')
-rw-r--r--src/test/java/com/amazon/carbonado/qe/TestIndexedQueryExecutor.java8
-rw-r--r--src/test/java/com/amazon/carbonado/qe/TestOrderingList.java110
-rw-r--r--src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java26
3 files changed, 131 insertions, 13 deletions
diff --git a/src/test/java/com/amazon/carbonado/qe/TestIndexedQueryExecutor.java b/src/test/java/com/amazon/carbonado/qe/TestIndexedQueryExecutor.java
index 3f865e6..b3eef91 100644
--- a/src/test/java/com/amazon/carbonado/qe/TestIndexedQueryExecutor.java
+++ b/src/test/java/com/amazon/carbonado/qe/TestIndexedQueryExecutor.java
@@ -21,6 +21,7 @@ package com.amazon.carbonado.qe;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -56,7 +57,8 @@ public class TestIndexedQueryExecutor extends TestCase {
return TestOrderingScore.makeIndex(type, props);
}
- static <S extends Storable> OrderedProperty<S>[] makeOrderings(Class<S> type, String... props)
+ static <S extends Storable> List<OrderedProperty<S>> makeOrderings(Class<S> type,
+ String... props)
{
return TestOrderingScore.makeOrderings(type, props);
}
@@ -679,9 +681,9 @@ public class TestIndexedQueryExecutor extends TestCase {
assertTrue(executor.mReverseOrder);
assertEquals(values.getFilter(), executor.getFilter());
- OrderedProperty<StorableTestBasic>[] expectedOrdering =
+ List<OrderedProperty<StorableTestBasic>> expectedOrdering =
makeOrderings(StorableTestBasic.class, "intProp", "-doubleProp", "stringProp");
- assertEquals(Arrays.asList(expectedOrdering), executor.getOrdering());
+ assertEquals(expectedOrdering, executor.getOrdering());
}
/**
diff --git a/src/test/java/com/amazon/carbonado/qe/TestOrderingList.java b/src/test/java/com/amazon/carbonado/qe/TestOrderingList.java
new file mode 100644
index 0000000..b696984
--- /dev/null
+++ b/src/test/java/com/amazon/carbonado/qe/TestOrderingList.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2006 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.amazon.carbonado.qe;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.amazon.carbonado.info.OrderedProperty;
+
+import com.amazon.carbonado.stored.StorableTestBasic;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+public class TestOrderingList extends TestCase {
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static TestSuite suite() {
+ return new TestSuite(TestOrderingList.class);
+ }
+
+ public TestOrderingList(String name) {
+ super(name);
+ }
+
+ public void testEmpty() throws Exception {
+ assertEquals(0, OrderingList.get(StorableTestBasic.class).size());
+ }
+
+ public void testSingle() throws Exception {
+ List<OrderedProperty<StorableTestBasic>> list_1 =
+ OrderingList.get(StorableTestBasic.class, "date");
+
+ assertEquals(1, list_1.size());
+ assertEquals("+date", list_1.get(0).toString());
+
+ List<OrderedProperty<StorableTestBasic>> list_2 =
+ OrderingList.get(StorableTestBasic.class, "+date");
+
+ assertEquals(1, list_2.size());
+ assertEquals("+date", list_2.get(0).toString());
+ assertEquals(list_1, list_2);
+ assertTrue(list_1 == list_2);
+
+ List<OrderedProperty<StorableTestBasic>> list_3 =
+ OrderingList.get(StorableTestBasic.class, "-date");
+
+ assertEquals(1, list_3.size());
+ assertEquals("-date", list_3.get(0).toString());
+ assertFalse(list_2.equals(list_3));
+ assertFalse(list_2 == list_3);
+ }
+
+ public void testDouble() throws Exception {
+ List<OrderedProperty<StorableTestBasic>> list_1 =
+ OrderingList.get(StorableTestBasic.class, "date", "intProp");
+
+ assertEquals(2, list_1.size());
+ assertEquals("+date", list_1.get(0).toString());
+ assertEquals("+intProp", list_1.get(1).toString());
+
+ List<OrderedProperty<StorableTestBasic>> list_2 =
+ OrderingList.get(StorableTestBasic.class, "+date", "+intProp");
+
+ assertEquals(2, list_2.size());
+ assertEquals("+date", list_2.get(0).toString());
+ assertEquals("+intProp", list_2.get(1).toString());
+ assertEquals(list_1, list_2);
+ assertTrue(list_1 == list_2);
+
+ List<OrderedProperty<StorableTestBasic>> list_3 =
+ OrderingList.get(StorableTestBasic.class, "-date", "-intProp");
+
+ assertEquals(2, list_3.size());
+ assertEquals("-date", list_3.get(0).toString());
+ assertEquals("-intProp", list_3.get(1).toString());
+ assertFalse(list_2.equals(list_3));
+ assertFalse(list_2 == list_3);
+ }
+
+ public void testIllegal() throws Exception {
+ try {
+ OrderingList.get(StorableTestBasic.class, "foo");
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ }
+}
diff --git a/src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java b/src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java
index 3929f59..1545b70 100644
--- a/src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java
+++ b/src/test/java/com/amazon/carbonado/qe/TestOrderingScore.java
@@ -18,6 +18,8 @@
package com.amazon.carbonado.qe;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -53,15 +55,19 @@ public class TestOrderingScore extends TestCase {
}
static <S extends Storable> StorableIndex<S> makeIndex(Class<S> type, String... props) {
- return new StorableIndex<S>(makeOrderings(type, props), UNSPECIFIED);
+ List<OrderedProperty<S>> list = makeOrderings(type, props);
+ OrderedProperty<S>[] array = list.toArray(new OrderedProperty[0]);
+
+ return new StorableIndex<S>(array, UNSPECIFIED);
}
- static <S extends Storable> OrderedProperty<S>[] makeOrderings(Class<S> type, String... props)
+ static <S extends Storable> List<OrderedProperty<S>> makeOrderings(Class<S> type,
+ String... props)
{
StorableInfo<S> info = StorableIntrospector.examine(type);
- OrderedProperty<S>[] ops = new OrderedProperty[props.length];
+ List<OrderedProperty<S>> ops = new ArrayList<OrderedProperty<S>>(props.length);
for (int i=0; i<props.length; i++) {
- ops[i] = OrderedProperty.parse(info, props[i]);
+ ops.add(OrderedProperty.parse(info, props[i]));
}
return ops;
}
@@ -82,7 +88,7 @@ public class TestOrderingScore extends TestCase {
public void testOneProp() throws Exception {
StorableIndex<StorableTestBasic> ix;
- OrderedProperty<StorableTestBasic>[] ops;
+ List<OrderedProperty<StorableTestBasic>> ops;
OrderingScore<StorableTestBasic> score;
/////////////
@@ -180,7 +186,7 @@ public class TestOrderingScore extends TestCase {
public void testMultipleProps() throws Exception {
final StorableIndex<StorableTestBasic> ix;
- OrderedProperty<StorableTestBasic>[] ops;
+ List<OrderedProperty<StorableTestBasic>> ops;
OrderingScore<StorableTestBasic> score;
ix = makeIndex(StorableTestBasic.class, "id", "intProp");
@@ -317,7 +323,7 @@ public class TestOrderingScore extends TestCase {
public void testMidGap() throws Exception {
final StorableIndex<StorableTestBasic> ix;
- OrderedProperty<StorableTestBasic>[] ops;
+ List<OrderedProperty<StorableTestBasic>> ops;
OrderingScore score;
Filter<StorableTestBasic> filter;
@@ -401,7 +407,7 @@ public class TestOrderingScore extends TestCase {
public void testComparator() throws Exception {
StorableIndex<StorableTestBasic> ix_1, ix_2;
- OrderedProperty<StorableTestBasic>[] ops;
+ List<OrderedProperty<StorableTestBasic>> ops;
OrderingScore score_1, score_2;
Filter<StorableTestBasic> filter;
Comparator<OrderingScore<?>> comp = OrderingScore.fullComparator();
@@ -466,7 +472,7 @@ public class TestOrderingScore extends TestCase {
// properties are filtered out. Thus the index is not needed.
final StorableIndex<StorableTestBasic> ix;
- OrderedProperty<StorableTestBasic>[] ops;
+ List<OrderedProperty<StorableTestBasic>> ops;
OrderingScore score;
Filter<StorableTestBasic> filter;
@@ -501,7 +507,7 @@ public class TestOrderingScore extends TestCase {
// Test a unique index which has been fully specified. Ordering is not
// needed at all.
final StorableIndex<StorableTestBasic> ix;
- OrderedProperty<StorableTestBasic>[] ops;
+ List<OrderedProperty<StorableTestBasic>> ops;
OrderingScore score;
Filter<StorableTestBasic> filter;