summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/index_bounds_builder_test.cpp
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2014-02-14 11:58:42 -0500
committerMatt Kangas <matt.kangas@mongodb.com>2014-02-14 14:22:26 -0500
commitde8cdc77791f8145e26dafca6c6499c8c4023f60 (patch)
treefe28ee86425c2446cb40bc56dee27a563cd119d5 /src/mongo/db/query/index_bounds_builder_test.cpp
parent8b10468dcb91a856fbaa5e062cf67464127aa2b7 (diff)
downloadmongo-de8cdc77791f8145e26dafca6c6499c8c4023f60.tar.gz
SERVER-12460 Relocate fast count code for 2.6, port old tests over for new version.
Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Diffstat (limited to 'src/mongo/db/query/index_bounds_builder_test.cpp')
-rw-r--r--src/mongo/db/query/index_bounds_builder_test.cpp201
1 files changed, 201 insertions, 0 deletions
diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp
index 83ab037bac8..7712daad4e5 100644
--- a/src/mongo/db/query/index_bounds_builder_test.cpp
+++ b/src/mongo/db/query/index_bounds_builder_test.cpp
@@ -137,6 +137,21 @@ namespace {
}
}
+ /**
+ * run isSingleInterval and return the result to calling test.
+ */
+ bool testSingleInterval(IndexBounds bounds) {
+ BSONObj startKey;
+ bool startKeyIn;
+ BSONObj endKey;
+ bool endKeyIn;
+ return IndexBoundsBuilder::isSingleInterval( bounds,
+ &startKey,
+ &startKeyIn,
+ &endKey,
+ &endKeyIn );
+ }
+
//
// $elemMatch value
// Example: {a: {$elemMatch: {$gt: 2}}}
@@ -788,4 +803,190 @@ namespace {
ASSERT(tightness == IndexBoundsBuilder::EXACT);
}
+ //
+ // isSingleInterval
+ //
+
+ TEST(IndexBoundsBuilderTest, SingleFieldEqualityInterval) {
+ // Equality on a single field is a single interval.
+ OrderedIntervalList oil("a");
+ IndexBounds bounds;
+ oil.intervals.push_back(Interval(BSON("" << 5 << "" << 5), true, true));
+ bounds.fields.push_back(oil);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, SingleIntervalSingleFieldInterval) {
+ // Single interval on a single field is a single interval.
+ OrderedIntervalList oil("a");
+ IndexBounds bounds;
+ oil.intervals.push_back(Interval(fromjson("{ '':5, '':Infinity }"), true, true));
+ bounds.fields.push_back(oil);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, MultipleIntervalsSingleFieldInterval) {
+ // Multiple intervals on a single field is not a single interval.
+ OrderedIntervalList oil("a");
+ IndexBounds bounds;
+ oil.intervals.push_back(Interval(fromjson( "{ '':4, '':5 }" ), true, true));
+ oil.intervals.push_back(Interval(fromjson( "{ '':7, '':Infinity }" ), true, true));
+ bounds.fields.push_back(oil);
+ ASSERT(!testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, EqualityTwoFieldsInterval) {
+ // Equality on two fields is a compound single interval.
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(BSON("" << 5 << "" << 5), true, true));
+ oil_b.intervals.push_back(Interval(BSON("" << 6 << "" << 6), true, true));
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, EqualityFirstFieldSingleIntervalSecondFieldInterval) {
+ // Equality on first field and single interval on second field
+ // is a compound single interval.
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(BSON("" << 5 << "" << 5), true, true));
+ oil_b.intervals.push_back(Interval(fromjson( "{ '':6, '':Infinity }" ), true, true));
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, SingleIntervalFirstAndSecondFieldsInterval) {
+ // Single interval on first field and single interval on second field is
+ // not a compound single interval.
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(fromjson( "{ '':-Infinity, '':5 }" ), true, true));
+ oil_b.intervals.push_back(Interval(fromjson( "{ '':6, '':Infinity }" ), true, true));
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ ASSERT(!testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, MultipleIntervalsTwoFieldsInterval) {
+ // Multiple intervals on two fields is not a compound single interval.
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(BSON( "" << 4 << "" << 4 ), true, true));
+ oil_a.intervals.push_back(Interval(BSON( "" << 5 << "" << 5 ), true, true));
+ oil_b.intervals.push_back(Interval(BSON( "" << 7 << "" << 7 ), true, true));
+ oil_b.intervals.push_back(Interval(BSON( "" << 8 << "" << 8 ), true, true));
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ ASSERT(!testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, MissingSecondFieldInterval) {
+ // when second field is not specified, still a compound single interval
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(BSON( "" << 5 << "" << 5 ), true, true));
+ oil_b.intervals.push_back(IndexBoundsBuilder::allValues());
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, EqualityTwoFieldsIntervalThirdInterval) {
+ // Equality on first two fields and single interval on third is a
+ // compound single interval.
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ OrderedIntervalList oil_c("c");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(BSON( "" << 5 << "" << 5 ), true, true));
+ oil_b.intervals.push_back(Interval(BSON( "" << 6 << "" << 6 ), true, true));
+ oil_c.intervals.push_back(Interval(fromjson( "{ '':7, '':Infinity }" ), true, true));
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ bounds.fields.push_back(oil_c);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, EqualitySingleIntervalMissingInterval) {
+ // Equality, then Single Interval, then missing is a compound single interval
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ OrderedIntervalList oil_c("c");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(BSON( "" << 5 << "" << 5 ), true, true));
+ oil_b.intervals.push_back(Interval(fromjson( "{ '':7, '':Infinity }" ), true, true));
+ oil_c.intervals.push_back(IndexBoundsBuilder::allValues());
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ bounds.fields.push_back(oil_c);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, EqualitySingleMissingMissingInterval) {
+ // Equality, then single interval, then missing, then missing,
+ // is a compound single interval
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ OrderedIntervalList oil_c("c");
+ OrderedIntervalList oil_d("d");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(BSON( "" << 5 << "" << 5 ), true, true));
+ oil_b.intervals.push_back(Interval(fromjson( "{ '':7, '':Infinity }" ), true, true));
+ oil_c.intervals.push_back(IndexBoundsBuilder::allValues());
+ oil_d.intervals.push_back(IndexBoundsBuilder::allValues());
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ bounds.fields.push_back(oil_c);
+ bounds.fields.push_back(oil_d);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, EqualitySingleMissingMissingMixedInterval) {
+ // Equality, then single interval, then missing, then missing, with mixed order
+ // fields is a compound single interval.
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ OrderedIntervalList oil_c("c");
+ OrderedIntervalList oil_d("d");
+ IndexBounds bounds;
+ Interval allValues = IndexBoundsBuilder::allValues();
+ oil_a.intervals.push_back(Interval(BSON( "" << 5 << "" << 5 ), true, true));
+ oil_b.intervals.push_back(Interval(fromjson( "{ '':7, '':Infinity }" ), true, true));
+ oil_c.intervals.push_back(allValues);
+ IndexBoundsBuilder::reverseInterval(&allValues);
+ oil_d.intervals.push_back(allValues);
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ bounds.fields.push_back(oil_c);
+ bounds.fields.push_back(oil_d);
+ ASSERT(testSingleInterval(bounds));
+ }
+
+ TEST(IndexBoundsBuilderTest, EqualitySingleMissingSingleInterval) {
+ // Equality, then single interval, then missing, then single interval is not
+ // a compound single interval.
+ OrderedIntervalList oil_a("a");
+ OrderedIntervalList oil_b("b");
+ OrderedIntervalList oil_c("c");
+ OrderedIntervalList oil_d("d");
+ IndexBounds bounds;
+ oil_a.intervals.push_back(Interval(BSON( "" << 5 << "" << 5 ), true, true));
+ oil_b.intervals.push_back(Interval(fromjson( "{ '':7, '':Infinity }" ), true, true));
+ oil_c.intervals.push_back(IndexBoundsBuilder::allValues());
+ oil_d.intervals.push_back(Interval(fromjson( "{ '':1, '':Infinity }" ), true, true));
+ bounds.fields.push_back(oil_a);
+ bounds.fields.push_back(oil_b);
+ bounds.fields.push_back(oil_c);
+ bounds.fields.push_back(oil_d);
+ ASSERT(!testSingleInterval(bounds));
+ }
+
} // namespace