From c16716f2d8e15f6539995c656ad05e4e8f799a21 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 20 Sep 2006 03:00:40 +0000 Subject: More tests and fixes. --- .../carbonado/info/StorableIntrospector.java | 4 +- .../amazon/carbonado/qe/UnionQueryAnalyzer.java | 10 +- .../java/com/amazon/carbonado/TestQueryLogic.java | 835 +++++++++++++++++++++ .../carbonado/qe/TestUnionQueryAnalyzer.java | 20 +- .../amazon/carbonado/spi/raw/TestDataEncoding.java | 4 +- .../carbonado/spi/raw/TestEncodingStrategy.java | 6 +- .../amazon/carbonado/spi/raw/TestKeyEncoding.java | 4 +- .../carbonado/stored/StorableTestBasicIndexed.java | 37 + 8 files changed, 891 insertions(+), 29 deletions(-) create mode 100644 src/test/java/com/amazon/carbonado/TestQueryLogic.java create mode 100644 src/test/java/com/amazon/carbonado/stored/StorableTestBasicIndexed.java (limited to 'src') diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java index ac3cd24..ab60720 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java @@ -1528,8 +1528,8 @@ public class StorableIntrospector { } public int hashCode() { - return (getName().hashCode() * 31 + getType().hashCode()) * 31 - + getEnclosingType().hashCode(); + return (getName().hashCode() * 31 + getType().getName().hashCode()) * 31 + + getEnclosingType().getName().hashCode(); } public boolean equals(Object obj) { diff --git a/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java b/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java index c64e4d4..b06edba 100644 --- a/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java +++ b/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -179,7 +179,9 @@ public class UnionQueryAnalyzer implements QueryExecutorFact Map, Tally> superKey = new LinkedHashMap, Tally>(); for (Set> key : keys) { for (ChainedProperty property : key) { - superKey.put(property, new Tally(property)); + if (!superKey.containsKey(property)) { + superKey.put(property, new Tally(property)); + } } } @@ -274,7 +276,7 @@ public class UnionQueryAnalyzer implements QueryExecutorFact } int propCount = index.getPropertyCount(); - Set> props = new HashSet>(propCount); + Set> props = new LinkedHashSet>(propCount); for (int i=0; i implements QueryExecutorFact } private Set> stripOrdering(Set> orderedProps) { - Set> props = new HashSet>(orderedProps.size()); + Set> props = new LinkedHashSet>(orderedProps.size()); for (OrderedProperty ordering : orderedProps) { props.add(ordering.getChainedProperty()); } diff --git a/src/test/java/com/amazon/carbonado/TestQueryLogic.java b/src/test/java/com/amazon/carbonado/TestQueryLogic.java new file mode 100644 index 0000000..4b4e917 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/TestQueryLogic.java @@ -0,0 +1,835 @@ +/* + * 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; + +import java.util.List; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import com.amazon.carbonado.filter.Filter; + +import com.amazon.carbonado.repo.toy.ToyRepository; + +import com.amazon.carbonado.stored.StorableTestBasic; +import com.amazon.carbonado.stored.StorableTestBasicIndexed; + +/** + * + * + * @author Brian S O'Neill + */ +public class TestQueryLogic extends TestCase { + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + public static TestSuite suite() { + TestSuite suite = new TestSuite(); + suite.addTestSuite(TestQueryLogic.class); + return suite; + } + + private Repository mRepository; + + protected void setUp() throws Exception { + mRepository = new ToyRepository(); + } + + protected void tearDown() throws Exception { + if (mRepository != null) { + mRepository.close(); + mRepository = null; + } + } + + protected Repository getRepository() { + return mRepository; + } + + public TestQueryLogic(String name) { + super(name); + } + + public void test_not() throws Exception { + final int count = 10; + populate(count); + + final Storage storage = + getRepository().storageFor(StorableTestBasic.class); + + StorableTestBasic stb; + Query query; + List results; + + { + // Create query that returns nothing and verify. + query = storage.query(); + assertEquals(Filter.getOpenFilter(StorableTestBasic.class), query.getFilter()); + query = query.not(); + assertEquals(Filter.getClosedFilter(StorableTestBasic.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(0, results.size()); + + // Verify that "not" again produces everything. + query = query.not(); + results = query.fetch().toList(); + assertEquals(count, results.size()); + assertOrder(results, true); + } + + { + // Create ordered query that returns nothing and verify. + query = storage.query(); + query = query.orderBy("-intProp"); + assertEquals(Filter.getOpenFilter(StorableTestBasic.class), query.getFilter()); + query = query.not(); + assertEquals(Filter.getClosedFilter(StorableTestBasic.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(0, results.size()); + + // Verify that order is preserved when "not" again. + query = query.not(); + assertEquals(Filter.getOpenFilter(StorableTestBasic.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(count, results.size()); + assertOrder(results, false); + } + + { + // Do the ordered "not" test again, but change the sequence to build the query. + query = storage.query().not(); // do "not" before orderBy. + query = query.orderBy("-intProp"); + assertEquals(Filter.getClosedFilter(StorableTestBasic.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(0, results.size()); + + // Verify that order is preserved when "not" again. + query = query.not(); + assertEquals(Filter.getOpenFilter(StorableTestBasic.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(count, results.size()); + assertOrder(results, false); + } + } + + public void test_demorgans() throws Exception { + final int count = 10; + populate(count); + + final Storage storage = + getRepository().storageFor(StorableTestBasic.class); + + Query query; + List results; + + { + query = storage.query("intProp = ? & (stringProp >= ? | longProp < ?)"); + Filter filter1 = query.getFilter(); + query = query.not(); + Filter filter2 = query.getFilter(); + query = storage.query("intProp != ? | (stringProp < ? & longProp >= ?)"); + Filter filter3 = query.getFilter(); + + assertEquals(filter3, filter2); + } + + // Try again, making sure that values are preserved in the query. + { + query = storage.query("intProp = ? & (stringProp >= ? | longProp < ?)"); + query = query.with(5); + + results = query.with("a").with(10).fetch().toList(); + assertEquals(1, results.size()); + + query = query.not(); + results = query.with("a").with(10).fetch().toList(); + assertEquals(count - 1, results.size()); + + // Make sure record 5 is the one that's missing. + for (StorableTestBasic stb : results) { + assertFalse(5 == stb.getId()); + } + + // Should be back to the original query. + query = query.not(); + + results = query.with("a").with(10).fetch().toList(); + assertEquals(1, results.size()); + } + + // Try again, making sure that a full set of values is preserved in the query. + { + query = storage.query("intProp = ? & (stringProp >= ? | longProp < ?)"); + query = query.with(2).with("a").with(10); + + results = query.fetch().toList(); + assertEquals(1, results.size()); + + query = query.not(); + results = query.fetch().toList(); + assertEquals(count - 1, results.size()); + + // Make sure record 2 is the one that's missing. + for (StorableTestBasic stb : results) { + assertFalse(2 == stb.getId()); + } + + // Should be back to the original query. + query = query.not(); + + results = query.fetch().toList(); + assertEquals(1, results.size()); + } + } + + public void test_and() throws Exception { + final int count = 10; + populate(count, new long[] {45, 12, 34, 12, 12, 45, 0, 0, 10, 2}); + + final Storage storage = + getRepository().storageFor(StorableTestBasic.class); + + Query query; + List results; + + { + query = storage.query("longProp = ?"); + try { + query = query.and("stringProp != ?"); + fail(); + } catch (IllegalStateException e) { + // Good. Blank params exist. + } + } + + { + query = storage.query("longProp = ?").with(12); + query = query.and("stringProp != ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(2, results.size()); + assertEquals(2, results.get(0).getId()); + assertEquals(5, results.get(1).getId()); + } + + // Different value. + { + query = storage.query("longProp = ?").with(45); + query = query.and("stringProp != ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(2, results.size()); + assertEquals(1, results.get(0).getId()); + assertEquals(6, results.get(1).getId()); + } + + // Different value with ordering. + { + query = storage.query("longProp = ?").with(45); + query = query.orderBy("-intProp"); + query = query.and("stringProp != ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(2, results.size()); + assertEquals(1, results.get(1).getId()); + assertEquals(6, results.get(0).getId()); + } + + // Try again with ordering. + { + query = storage.query("longProp = ?").with(12); + query = query.orderBy("-intProp"); + query = query.and("stringProp != ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(2, results.size()); + assertEquals(2, results.get(1).getId()); + assertEquals(5, results.get(0).getId()); + } + + // Invert the selection + { + query = storage.query("longProp = ?").with(12); + query = query.and("stringProp != ?").with("str_4").not(); + + results = query.fetch().toList(); + assertEquals(count - 2, results.size()); + assertEquals(1, results.get(0).getId()); + assertEquals(3, results.get(1).getId()); + assertEquals(4, results.get(2).getId()); + assertEquals(6, results.get(3).getId()); + assertEquals(7, results.get(4).getId()); + assertEquals(8, results.get(5).getId()); + assertEquals(9, results.get(6).getId()); + assertEquals(10, results.get(7).getId()); + } + + // Invert the ordered selection + { + query = storage.query("longProp = ?").with(12); + query = query.orderBy("-intProp"); + query = query.and("stringProp != ?").with("str_4").not(); + + results = query.fetch().toList(); + assertEquals(count - 2, results.size()); + assertEquals(1, results.get(7).getId()); + assertEquals(3, results.get(6).getId()); + assertEquals(4, results.get(5).getId()); + assertEquals(6, results.get(4).getId()); + assertEquals(7, results.get(3).getId()); + assertEquals(8, results.get(2).getId()); + assertEquals(9, results.get(1).getId()); + assertEquals(10, results.get(0).getId()); + } + } + + public void test_or() throws Exception { + final int count = 10; + populate(count, new long[] {45, 12, 34, 12, 12, 45, 0, 0, 10, 2}); + + final Storage storage = + getRepository().storageFor(StorableTestBasic.class); + + Query query; + List results; + + { + query = storage.query("longProp = ?"); + try { + query = query.or("stringProp = ?"); + fail(); + } catch (IllegalStateException e) { + // Good. Blank params exist. + } + } + + { + query = storage.query("longProp = ?").with(45); + query = query.or("stringProp = ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(3, results.size()); + assertEquals(1, results.get(0).getId()); + assertEquals(4, results.get(1).getId()); + assertEquals(6, results.get(2).getId()); + } + + // Different value. + { + query = storage.query("longProp = ?").with(12); + query = query.or("stringProp = ?").with("str_3"); + + results = query.fetch().toList(); + assertEquals(4, results.size()); + assertEquals(2, results.get(0).getId()); + assertEquals(3, results.get(1).getId()); + assertEquals(4, results.get(2).getId()); + assertEquals(5, results.get(3).getId()); + } + + // Different value with ordering. + { + query = storage.query("longProp = ?").with(12); + query = query.orderBy("-intProp"); + query = query.or("stringProp = ?").with("str_3"); + + results = query.fetch().toList(); + assertEquals(4, results.size()); + assertEquals(2, results.get(3).getId()); + assertEquals(3, results.get(2).getId()); + assertEquals(4, results.get(1).getId()); + assertEquals(5, results.get(0).getId()); + } + + // Try again with ordering. + { + query = storage.query("longProp = ?").with(45); + query = query.orderBy("-intProp"); + query = query.or("stringProp = ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(3, results.size()); + assertEquals(1, results.get(2).getId()); + assertEquals(4, results.get(1).getId()); + assertEquals(6, results.get(0).getId()); + } + + // Invert the selection + { + query = storage.query("longProp = ?").with(45); + query = query.or("stringProp = ?").with("str_4").not(); + + results = query.fetch().toList(); + assertEquals(count - 3, results.size()); + assertEquals(2, results.get(0).getId()); + assertEquals(3, results.get(1).getId()); + assertEquals(5, results.get(2).getId()); + assertEquals(7, results.get(3).getId()); + assertEquals(8, results.get(4).getId()); + assertEquals(9, results.get(5).getId()); + assertEquals(10, results.get(6).getId()); + } + + // Invert the ordered selection + { + query = storage.query("longProp = ?").with(45); + query = query.orderBy("-intProp"); + query = query.or("stringProp = ?").with("str_4").not(); + + results = query.fetch().toList(); + assertEquals(count - 3, results.size()); + assertEquals(2, results.get(6).getId()); + assertEquals(3, results.get(5).getId()); + assertEquals(5, results.get(4).getId()); + assertEquals(7, results.get(3).getId()); + assertEquals(8, results.get(2).getId()); + assertEquals(9, results.get(1).getId()); + assertEquals(10, results.get(0).getId()); + } + } + + // + // Same tests again, except against an indexed storable. + // + + public void test_indexed_not() throws Exception { + final int count = 10; + populateIndexed(count); + + final Storage storage = + getRepository().storageFor(StorableTestBasicIndexed.class); + + StorableTestBasicIndexed stb; + Query query; + List results; + + { + // Create query that returns nothing and verify. + query = storage.query(); + assertEquals(Filter.getOpenFilter(StorableTestBasicIndexed.class), query.getFilter()); + query = query.not(); + assertEquals(Filter.getClosedFilter(StorableTestBasicIndexed.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(0, results.size()); + + // Verify that "not" again produces everything. + query = query.not(); + results = query.fetch().toList(); + assertEquals(count, results.size()); + assertOrderIndexed(results, true); + } + + { + // Create ordered query that returns nothing and verify. + query = storage.query(); + query = query.orderBy("-intProp"); + assertEquals(Filter.getOpenFilter(StorableTestBasicIndexed.class), query.getFilter()); + query = query.not(); + assertEquals(Filter.getClosedFilter(StorableTestBasicIndexed.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(0, results.size()); + + // Verify that order is preserved when "not" again. + query = query.not(); + assertEquals(Filter.getOpenFilter(StorableTestBasicIndexed.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(count, results.size()); + assertOrderIndexed(results, false); + } + + { + // Do the ordered "not" test again, but change the sequence to build the query. + query = storage.query().not(); // do "not" before orderBy. + query = query.orderBy("-intProp"); + assertEquals(Filter.getClosedFilter(StorableTestBasicIndexed.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(0, results.size()); + + // Verify that order is preserved when "not" again. + query = query.not(); + assertEquals(Filter.getOpenFilter(StorableTestBasicIndexed.class), query.getFilter()); + results = query.fetch().toList(); + assertEquals(count, results.size()); + assertOrderIndexed(results, false); + } + } + + public void test_indexed_demorgans() throws Exception { + final int count = 10; + populateIndexed(count); + + final Storage storage = + getRepository().storageFor(StorableTestBasicIndexed.class); + + Query query; + List results; + + { + query = storage.query("intProp = ? & (stringProp >= ? | longProp < ?)"); + Filter filter1 = query.getFilter(); + query = query.not(); + Filter filter2 = query.getFilter(); + query = storage.query("intProp != ? | (stringProp < ? & longProp >= ?)"); + Filter filter3 = query.getFilter(); + + assertEquals(filter3, filter2); + } + + // Try again, making sure that values are preserved in the query. + { + query = storage.query("intProp = ? & (stringProp >= ? | longProp < ?)"); + query = query.with(5); + + results = query.with("a").with(10).fetch().toList(); + assertEquals(1, results.size()); + + query = query.not(); + results = query.with("a").with(10).fetch().toList(); + assertEquals(count - 1, results.size()); + + // Make sure record 5 is the one that's missing. + for (StorableTestBasicIndexed stb : results) { + assertFalse(5 == stb.getId()); + } + + // Should be back to the original query. + query = query.not(); + + results = query.with("a").with(10).fetch().toList(); + assertEquals(1, results.size()); + } + + // Try again, making sure that a full set of values is preserved in the query. + { + query = storage.query("intProp = ? & (stringProp >= ? | longProp < ?)"); + query = query.with(2).with("a").with(10); + + results = query.fetch().toList(); + assertEquals(1, results.size()); + + query = query.not(); + results = query.fetch().toList(); + assertEquals(count - 1, results.size()); + + // Make sure record 2 is the one that's missing. + for (StorableTestBasicIndexed stb : results) { + assertFalse(2 == stb.getId()); + } + + // Should be back to the original query. + query = query.not(); + + results = query.fetch().toList(); + assertEquals(1, results.size()); + } + } + + public void test_indexed_and() throws Exception { + final int count = 10; + populateIndexed(count, new long[] {45, 12, 34, 12, 12, 45, 0, 0, 10, 2}); + + final Storage storage = + getRepository().storageFor(StorableTestBasicIndexed.class); + + Query query; + List results; + + { + query = storage.query("longProp = ?"); + try { + query = query.and("stringProp != ?"); + fail(); + } catch (IllegalStateException e) { + // Good. Blank params exist. + } + } + + { + query = storage.query("longProp = ?").with(12); + query = query.and("stringProp != ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(2, results.size()); + assertEquals(2, results.get(0).getId()); + assertEquals(5, results.get(1).getId()); + } + + // Different value. + { + query = storage.query("longProp = ?").with(45); + query = query.and("stringProp != ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(2, results.size()); + assertEquals(1, results.get(0).getId()); + assertEquals(6, results.get(1).getId()); + } + + // Different value with ordering. + { + query = storage.query("longProp = ?").with(45); + query = query.orderBy("-intProp"); + query = query.and("stringProp != ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(2, results.size()); + assertEquals(1, results.get(1).getId()); + assertEquals(6, results.get(0).getId()); + } + + // Try again with ordering. + { + query = storage.query("longProp = ?").with(12); + query = query.orderBy("-intProp"); + query = query.and("stringProp != ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(2, results.size()); + assertEquals(2, results.get(1).getId()); + assertEquals(5, results.get(0).getId()); + } + + // Invert the selection + { + query = storage.query("longProp = ?").with(12); + query = query.and("stringProp != ?").with("str_4").not(); + + results = query.fetch().toList(); + assertEquals(count - 2, results.size()); + assertEquals(1, results.get(0).getId()); + assertEquals(3, results.get(1).getId()); + assertEquals(4, results.get(2).getId()); + assertEquals(6, results.get(3).getId()); + assertEquals(7, results.get(4).getId()); + assertEquals(8, results.get(5).getId()); + assertEquals(9, results.get(6).getId()); + assertEquals(10, results.get(7).getId()); + } + + // Invert the ordered selection + { + query = storage.query("longProp = ?").with(12); + query = query.orderBy("-intProp"); + query = query.and("stringProp != ?").with("str_4").not(); + + results = query.fetch().toList(); + assertEquals(count - 2, results.size()); + assertEquals(1, results.get(7).getId()); + assertEquals(3, results.get(6).getId()); + assertEquals(4, results.get(5).getId()); + assertEquals(6, results.get(4).getId()); + assertEquals(7, results.get(3).getId()); + assertEquals(8, results.get(2).getId()); + assertEquals(9, results.get(1).getId()); + assertEquals(10, results.get(0).getId()); + } + } + + public void test_indexed_or() throws Exception { + final int count = 10; + populateIndexed(count, new long[] {45, 12, 34, 12, 12, 45, 0, 0, 10, 2}); + + final Storage storage = + getRepository().storageFor(StorableTestBasicIndexed.class); + + Query query; + List results; + + { + query = storage.query("longProp = ?"); + try { + query = query.or("stringProp = ?"); + fail(); + } catch (IllegalStateException e) { + // Good. Blank params exist. + } + } + + { + query = storage.query("longProp = ?").with(45); + query = query.or("stringProp = ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(3, results.size()); + assertEquals(1, results.get(0).getId()); + assertEquals(4, results.get(1).getId()); + assertEquals(6, results.get(2).getId()); + } + + // Different value. + { + query = storage.query("longProp = ?").with(12); + query = query.or("stringProp = ?").with("str_3"); + + results = query.fetch().toList(); + assertEquals(4, results.size()); + assertEquals(2, results.get(0).getId()); + assertEquals(3, results.get(1).getId()); + assertEquals(4, results.get(2).getId()); + assertEquals(5, results.get(3).getId()); + } + + // Different value with ordering. + { + query = storage.query("longProp = ?").with(12); + query = query.orderBy("-intProp"); + query = query.or("stringProp = ?").with("str_3"); + + results = query.fetch().toList(); + assertEquals(4, results.size()); + assertEquals(2, results.get(3).getId()); + assertEquals(3, results.get(2).getId()); + assertEquals(4, results.get(1).getId()); + assertEquals(5, results.get(0).getId()); + } + + // Try again with ordering. + { + query = storage.query("longProp = ?").with(45); + query = query.orderBy("-intProp"); + query = query.or("stringProp = ?").with("str_4"); + + results = query.fetch().toList(); + assertEquals(3, results.size()); + assertEquals(1, results.get(2).getId()); + assertEquals(4, results.get(1).getId()); + assertEquals(6, results.get(0).getId()); + } + + // Invert the selection + { + query = storage.query("longProp = ?").with(45); + query = query.or("stringProp = ?").with("str_4").not(); + + results = query.fetch().toList(); + assertEquals(count - 3, results.size()); + assertEquals(2, results.get(0).getId()); + assertEquals(3, results.get(1).getId()); + assertEquals(5, results.get(2).getId()); + assertEquals(7, results.get(3).getId()); + assertEquals(8, results.get(4).getId()); + assertEquals(9, results.get(5).getId()); + assertEquals(10, results.get(6).getId()); + } + + // Invert the ordered selection + { + query = storage.query("longProp = ?").with(45); + query = query.orderBy("-intProp"); + query = query.or("stringProp = ?").with("str_4").not(); + + results = query.fetch().toList(); + assertEquals(count - 3, results.size()); + assertEquals(2, results.get(6).getId()); + assertEquals(3, results.get(5).getId()); + assertEquals(5, results.get(4).getId()); + assertEquals(7, results.get(3).getId()); + assertEquals(8, results.get(2).getId()); + assertEquals(9, results.get(1).getId()); + assertEquals(10, results.get(0).getId()); + } + } + + private void populate(int count) throws Exception { + populate(count, null); + } + + private void populate(int count, long[] longValues) throws Exception { + final Storage storage = + getRepository().storageFor(StorableTestBasic.class); + + StorableTestBasic stb; + + // Insert some test data + for (int i=1; i<=count; i++) { + stb = storage.prepare(); + stb.initBasicProperties(); + stb.setId(i); + stb.setIntProp(i); + stb.setStringProp("str_" + i); + if (longValues != null && i <= longValues.length) { + stb.setLongProp(longValues[i - 1]); + } + stb.insert(); + } + } + + private void populateIndexed(int count) throws Exception { + populateIndexed(count, null); + } + + private void populateIndexed(int count, long[] longValues) throws Exception { + final Storage storage = + getRepository().storageFor(StorableTestBasicIndexed.class); + + StorableTestBasicIndexed stb; + + // Insert some test data + for (int i=1; i<=count; i++) { + stb = storage.prepare(); + stb.initBasicProperties(); + stb.setId(i); + stb.setIntProp(i); + stb.setStringProp("str_" + i); + if (longValues != null && i <= longValues.length) { + stb.setLongProp(longValues[i - 1]); + } + stb.insert(); + } + } + + private void assertOrder(List list, boolean ascending) throws Exception { + StorableTestBasic last = null; + for (StorableTestBasic stb : list) { + if (last != null) { + if (ascending) { + if (stb.getIntProp() <= last.getIntProp()) { + fail(); + } + } else { + if (stb.getIntProp() >= last.getIntProp()) { + fail(); + } + } + } + last = stb; + } + } + + private void assertOrderIndexed(List list, boolean ascending) + throws Exception + { + StorableTestBasicIndexed last = null; + for (StorableTestBasicIndexed stb : list) { + if (last != null) { + if (ascending) { + if (stb.getIntProp() <= last.getIntProp()) { + fail(); + } + } else { + if (stb.getIntProp() >= last.getIntProp()) { + fail(); + } + } + } + last = stb; + } + } +} diff --git a/src/test/java/com/amazon/carbonado/qe/TestUnionQueryAnalyzer.java b/src/test/java/com/amazon/carbonado/qe/TestUnionQueryAnalyzer.java index 3d99c84..e9cc8f9 100644 --- a/src/test/java/com/amazon/carbonado/qe/TestUnionQueryAnalyzer.java +++ b/src/test/java/com/amazon/carbonado/qe/TestUnionQueryAnalyzer.java @@ -447,24 +447,12 @@ public class TestUnionQueryAnalyzer extends TestCase { (StorableTestBasic.class, "stringProp = ? | stringProp = ?"); filter = filter.bind(); UnionQueryAnalyzer.Result result = uqa.analyze(filter, null); - - boolean a = result.getTotalOrdering() == - OrderingList.get(StorableTestBasic.class, "+doubleProp", "+stringProp"); - boolean b = result.getTotalOrdering() == - OrderingList.get(StorableTestBasic.class, "+stringProp", "+doubleProp"); - - assertTrue(a || b); + assertEquals(OrderingList.get(StorableTestBasic.class, "+stringProp", "+doubleProp"), + result.getTotalOrdering()); QueryExecutor exec = result.createExecutor(); - - assertEquals(filter, exec.getFilter()); - - a = exec.getOrdering() == - OrderingList.get(StorableTestBasic.class, "+doubleProp", "+stringProp"); - b = exec.getOrdering() == - OrderingList.get(StorableTestBasic.class, "+stringProp", "+doubleProp"); - - assertTrue(a || b); + assertEquals(OrderingList.get(StorableTestBasic.class, "+stringProp", "+doubleProp"), + exec.getOrdering()); List.Result> subResults = result.getSubResults(); diff --git a/src/test/java/com/amazon/carbonado/spi/raw/TestDataEncoding.java b/src/test/java/com/amazon/carbonado/spi/raw/TestDataEncoding.java index a65ab21..783a71e 100644 --- a/src/test/java/com/amazon/carbonado/spi/raw/TestDataEncoding.java +++ b/src/test/java/com/amazon/carbonado/spi/raw/TestDataEncoding.java @@ -34,8 +34,8 @@ import junit.framework.TestSuite; */ public class TestDataEncoding extends TestCase { private static final int SHORT_TEST = 100; - private static final int MEDIUM_TEST = 1000; - private static final int LONG_TEST = 10000; + private static final int MEDIUM_TEST = 500; + private static final int LONG_TEST = 1000; public static void main(String[] args) { junit.textui.TestRunner.run(suite()); diff --git a/src/test/java/com/amazon/carbonado/spi/raw/TestEncodingStrategy.java b/src/test/java/com/amazon/carbonado/spi/raw/TestEncodingStrategy.java index 29572f0..514df34 100644 --- a/src/test/java/com/amazon/carbonado/spi/raw/TestEncodingStrategy.java +++ b/src/test/java/com/amazon/carbonado/spi/raw/TestEncodingStrategy.java @@ -41,9 +41,9 @@ import com.amazon.carbonado.spi.*; * @author Brian S O'Neill */ public class TestEncodingStrategy extends TestCase { - private static final int SHORT_TEST = 100; - private static final int MEDIUM_TEST = 1000; - private static final int LONG_TEST = 10000; + private static final int SHORT_TEST = 100; + private static final int MEDIUM_TEST = 500; + private static final int LONG_TEST = 1000; private static final int ENCODE_OBJECT_ARRAY = 0; private static final int DECODE_OBJECT_ARRAY = 1; diff --git a/src/test/java/com/amazon/carbonado/spi/raw/TestKeyEncoding.java b/src/test/java/com/amazon/carbonado/spi/raw/TestKeyEncoding.java index 246e6fe..ae09c92 100644 --- a/src/test/java/com/amazon/carbonado/spi/raw/TestKeyEncoding.java +++ b/src/test/java/com/amazon/carbonado/spi/raw/TestKeyEncoding.java @@ -34,8 +34,8 @@ import junit.framework.TestSuite; */ public class TestKeyEncoding extends TestCase { private static final int SHORT_TEST = 100; - private static final int MEDIUM_TEST = 1000; - private static final int LONG_TEST = 10000; + private static final int MEDIUM_TEST = 500; + private static final int LONG_TEST = 1000; public static void main(String[] args) { junit.textui.TestRunner.run(suite()); diff --git a/src/test/java/com/amazon/carbonado/stored/StorableTestBasicIndexed.java b/src/test/java/com/amazon/carbonado/stored/StorableTestBasicIndexed.java new file mode 100644 index 0000000..c9de396 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/stored/StorableTestBasicIndexed.java @@ -0,0 +1,37 @@ +/* + * 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.stored; + +import com.amazon.carbonado.Index; +import com.amazon.carbonado.Indexes; +import com.amazon.carbonado.PrimaryKey; + +/** + * StorableTestBasicIndexed + * + * @author Brian S O'Neill + */ +@Indexes({ + @Index("stringProp"), + @Index("intProp"), + @Index("longProp"), + @Index("doubleProp") +}) +@PrimaryKey("id") +public abstract class StorableTestBasicIndexed extends StorableTestBasic { +} -- cgit v1.2.3