summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-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
-rw-r--r--src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java17
4 files changed, 141 insertions, 20 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;
diff --git a/src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java b/src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java
index dd29e4b..01f9fbf 100644
--- a/src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java
+++ b/src/test/java/com/amazon/carbonado/repo/toy/ToyStorage.java
@@ -48,10 +48,11 @@ import com.amazon.carbonado.filter.FilterValues;
import com.amazon.carbonado.info.OrderedProperty;
import com.amazon.carbonado.info.StorableIntrospector;
+import com.amazon.carbonado.qe.ArraySortedQueryExecutor;
import com.amazon.carbonado.qe.FilteredQueryExecutor;
import com.amazon.carbonado.qe.IterableQueryExecutor;
+import com.amazon.carbonado.qe.OrderingList;
import com.amazon.carbonado.qe.QueryExecutor;
-import com.amazon.carbonado.qe.SortedQueryExecutor;
import com.amazon.carbonado.qe.StandardQuery;
/**
@@ -89,7 +90,7 @@ public class ToyStorage<S extends Storable> implements Storage<S>, MasterSupport
}
public Query<S> query() throws FetchException {
- return new ToyQuery(null);
+ return new ToyQuery(null, null);
}
public Query<S> query(String filter) throws FetchException {
@@ -97,7 +98,7 @@ public class ToyStorage<S extends Storable> implements Storage<S>, MasterSupport
}
public Query<S> query(Filter<S> filter) throws FetchException {
- return new ToyQuery(filter.initialFilterValues());
+ return new ToyQuery(filter.initialFilterValues(), null);
}
public boolean addTrigger(Trigger<? super S> trigger) {
@@ -211,7 +212,7 @@ public class ToyStorage<S extends Storable> implements Storage<S>, MasterSupport
}
private class ToyQuery extends StandardQuery<S> {
- ToyQuery(FilterValues<S> values, String... orderings) {
+ ToyQuery(FilterValues<S> values, OrderingList<S> orderings) {
super(values, orderings);
}
@@ -223,19 +224,21 @@ public class ToyStorage<S extends Storable> implements Storage<S>, MasterSupport
return mRepo.enterTransaction(level);
}
- protected QueryExecutor<S> getExecutor(FilterValues<S> values, String... orderings) {
+ protected QueryExecutor<S> getExecutor(FilterValues<S> values, OrderingList<S> orderings) {
QueryExecutor<S> executor = new IterableQueryExecutor<S>(mType, mData, mDataLock);
if (values != null) {
executor = new FilteredQueryExecutor<S>(executor, values.getFilter());
}
- // FIXME: sorting
+ if (orderings.size() > 0) {
+ executor = new ArraySortedQueryExecutor<S>(executor, null, orderings);
+ }
return executor;
}
- protected StandardQuery<S> newInstance(FilterValues<S> values, String... orderings) {
+ protected StandardQuery<S> newInstance(FilterValues<S> values, OrderingList<S> orderings) {
return new ToyQuery(values, orderings);
}
}