Storage Engine API
key_string_test.cpp File Reference
#include "mongo/platform/basic.h"
#include <algorithm>
#include <cmath>
#include <limits>
#include <memory>
#include <random>
#include <typeinfo>
#include <vector>
#include "mongo/base/owned_pointer_vector.h"
#include "mongo/base/simple_string_data_comparator.h"
#include "mongo/bson/bsonobj_comparator.h"
#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/config.h"
#include "mongo/db/storage/key_string.h"
#include "mongo/platform/decimal128.h"
#include "mongo/stdx/functional.h"
#include "mongo/stdx/future.h"
#include "mongo/stdx/memory.h"
#include "mongo/unittest/death_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
#include "mongo/util/timer.h"

Classes

class  KeyStringTest
 

Macros

#define MONGO_LOG_DEFAULT_COMPONENT   ::mongo::logger::LogComponent::kStorage
 Copyright (C) 2014 MongoDB Inc. More...
 
#define ROUNDTRIP_ORDER(version, x, order)
 
#define ROUNDTRIP(version, x)
 
#define COMPARES_SAME(_v, _x, _y)
 
#define COMPARE_HELPER(LHS, RHS)   (((LHS) < (RHS)) ? -1 : (((LHS) == (RHS)) ? 0 : 1))
 

Functions

BSONObj toBson (const KeyString &ks, Ordering ord)
 
BSONObj toBsonAndCheckKeySize (const KeyString &ks, Ordering ord)
 
 TEST_F (KeyStringTest, Simple1)
 
 TEST_F (KeyStringTest, ActualBytesDouble)
 
 TEST_F (KeyStringTest, AllTypesSimple)
 
 TEST_F (KeyStringTest, Array1)
 
 TEST_F (KeyStringTest, SubDoc1)
 
 TEST_F (KeyStringTest, SubDoc2)
 
 TEST_F (KeyStringTest, Compound1)
 
 TEST_F (KeyStringTest, Undef1)
 
 TEST_F (KeyStringTest, NumberLong0)
 
 TEST_F (KeyStringTest, NumbersNearInt32Max)
 
 TEST_F (KeyStringTest, DecimalNumbers)
 
 TEST_F (KeyStringTest, LotsOfNumbers1)
 
 TEST_F (KeyStringTest, LotsOfNumbers2)
 
 TEST_F (KeyStringTest, LotsOfNumbers3)
 
 TEST_F (KeyStringTest, RecordIdOrder1)
 
 TEST_F (KeyStringTest, RecordIdOrder2)
 
 TEST_F (KeyStringTest, RecordIdOrder2Double)
 
 TEST_F (KeyStringTest, Timestamp)
 
 TEST_F (KeyStringTest, AllTypesRoundtrip)
 
const std::vector< BSONObj > & getInterestingElements (KeyString::Version version)
 
void testPermutation (KeyString::Version version, const std::vector< BSONObj > &elementsOrig, const std::vector< BSONObj > &orderings, bool debug)
 
 TEST_F (KeyStringTest, AllPermCompare)
 
 TEST_F (KeyStringTest, AllPerm2Compare)
 
int compareLongToDouble (long long lhs, double rhs)
 
int compareNumbers (const BSONElement &lhs, const BSONElement &rhs)
 
 TEST_F (KeyStringTest, NaNs)
 
 TEST_F (KeyStringTest, NumberOrderLots)
 
 TEST_F (KeyStringTest, RecordIds)
 
 TEST_F (KeyStringTest, KeyWithTooManyTypeBitsCausesUassert)
 
 TEST_F (KeyStringTest, ToBsonSafeShouldNotTerminate)
 
 TEST_F (KeyStringTest, InvalidDecimalExponent)
 
 TEST_F (KeyStringTest, InvalidDecimalZero)
 
 TEST_F (KeyStringTest, InvalidDecimalContinuation)
 
 TEST_F (KeyStringTest, RandomizedInputsForToBsonSafe)
 
 TEST_F (KeyStringTest, CommonIntPerf)
 
 TEST_F (KeyStringTest, UniformInt64Perf)
 
 TEST_F (KeyStringTest, CommonDoublePerf)
 
 TEST_F (KeyStringTest, UniformDoublePerf)
 
 TEST_F (KeyStringTest, CommonDecimalPerf)
 
 TEST_F (KeyStringTest, UniformDecimalPerf)
 
 TEST_F (KeyStringTest, DecimalFromUniformDoublePerf)
 
 DEATH_TEST (KeyStringTest, ToBsonPromotesAssertionsToTerminate, "terminate() called")
 

Variables

Ordering ALL_ASCENDING = Ordering::make(BSONObj())
 
Ordering ONE_ASCENDING = Ordering::make(BSON("a" << 1))
 
Ordering ONE_DESCENDING = Ordering::make(BSON("a" << -1))
 

Macro Definition Documentation

◆ COMPARE_HELPER

#define COMPARE_HELPER (   LHS,
  RHS 
)    (((LHS) < (RHS)) ? -1 : (((LHS) == (RHS)) ? 0 : 1))

◆ COMPARES_SAME

#define COMPARES_SAME (   _v,
  _x,
  _y 
)
Value:
do { \
KeyString _xKS(_v, _x, ONE_ASCENDING); \
KeyString _yKS(_v, _y, ONE_ASCENDING); \
if (SimpleBSONObjComparator::kInstance.evaluate(_x == _y)) { \
ASSERT_EQUALS(_xKS, _yKS); \
} else if (SimpleBSONObjComparator::kInstance.evaluate(_x < _y)) { \
ASSERT_LESS_THAN(_xKS, _yKS); \
} else { \
ASSERT_LESS_THAN(_yKS, _xKS); \
} \
\
_xKS.resetToKey(_x, ONE_DESCENDING); \
_yKS.resetToKey(_y, ONE_DESCENDING); \
if (SimpleBSONObjComparator::kInstance.evaluate(_x == _y)) { \
ASSERT_EQUALS(_xKS, _yKS); \
} else if (SimpleBSONObjComparator::kInstance.evaluate(_x < _y)) { \
ASSERT_GREATER_THAN(_xKS, _yKS); \
} else { \
ASSERT_GREATER_THAN(_yKS, _xKS); \
} \
} while (0)
Ordering ONE_DESCENDING
Definition: key_string_test.cpp:77
Ordering ONE_ASCENDING
Definition: key_string_test.cpp:76

◆ MONGO_LOG_DEFAULT_COMPONENT

#define MONGO_LOG_DEFAULT_COMPONENT   ::mongo::logger::LogComponent::kStorage

Copyright (C) 2014 MongoDB Inc.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

As a special exception, the copyright holders give permission to link the code of portions of this program with the OpenSSL library under certain conditions as described in each individual source file and distribute linked combinations including the program with the OpenSSL library. You must comply with the GNU Affero General Public License in all respects for all of the code used other than as permitted herein. If you modify file(s) with this exception, you may extend this exception to your version of the file(s), but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. If you delete this exception statement from all source files in the program, then also delete it in the license file.

◆ ROUNDTRIP

#define ROUNDTRIP (   version,
 
)
Value:
do { \
ROUNDTRIP_ORDER(version, x, ALL_ASCENDING); \
ROUNDTRIP_ORDER(version, x, ONE_DESCENDING); \
} while (0)
Ordering ONE_DESCENDING
Definition: key_string_test.cpp:77
Ordering ALL_ASCENDING
Definition: key_string_test.cpp:75

◆ ROUNDTRIP_ORDER

#define ROUNDTRIP_ORDER (   version,
  x,
  order 
)
Value:
do { \
const BSONObj _orig = x; \
const KeyString _ks(version, _orig, order); \
const BSONObj _converted = toBsonAndCheckKeySize(_ks, order); \
ASSERT_BSONOBJ_EQ(_converted, _orig); \
ASSERT(_converted.binaryEqual(_orig)); \
} while (0)
Definition: key_string.h:47
BSONObj toBsonAndCheckKeySize(const KeyString &ks, Ordering ord)
Definition: key_string_test.cpp:66

Function Documentation

◆ compareLongToDouble()

int compareLongToDouble ( long long  lhs,
double  rhs 
)

◆ compareNumbers()

int compareNumbers ( const BSONElement &  lhs,
const BSONElement &  rhs 
)

◆ DEATH_TEST()

DEATH_TEST ( KeyStringTest  ,
ToBsonPromotesAssertionsToTerminate  ,
"terminate() called"   
)

◆ getInterestingElements()

const std::vector<BSONObj>& getInterestingElements ( KeyString::Version  version)

◆ TEST_F() [1/37]

TEST_F ( KeyStringTest  ,
Simple1   
)

◆ TEST_F() [2/37]

TEST_F ( KeyStringTest  ,
ActualBytesDouble   
)

◆ TEST_F() [3/37]

TEST_F ( KeyStringTest  ,
AllTypesSimple   
)

◆ TEST_F() [4/37]

TEST_F ( KeyStringTest  ,
Array1   
)

◆ TEST_F() [5/37]

TEST_F ( KeyStringTest  ,
SubDoc1   
)

◆ TEST_F() [6/37]

TEST_F ( KeyStringTest  ,
SubDoc2   
)

◆ TEST_F() [7/37]

TEST_F ( KeyStringTest  ,
Compound1   
)

◆ TEST_F() [8/37]

TEST_F ( KeyStringTest  ,
Undef1   
)

◆ TEST_F() [9/37]

TEST_F ( KeyStringTest  ,
NumberLong0   
)

◆ TEST_F() [10/37]

TEST_F ( KeyStringTest  ,
NumbersNearInt32Max   
)

◆ TEST_F() [11/37]

TEST_F ( KeyStringTest  ,
DecimalNumbers   
)

◆ TEST_F() [12/37]

TEST_F ( KeyStringTest  ,
LotsOfNumbers1   
)

◆ TEST_F() [13/37]

TEST_F ( KeyStringTest  ,
LotsOfNumbers2   
)

◆ TEST_F() [14/37]

TEST_F ( KeyStringTest  ,
LotsOfNumbers3   
)

◆ TEST_F() [15/37]

TEST_F ( KeyStringTest  ,
RecordIdOrder1   
)

◆ TEST_F() [16/37]

TEST_F ( KeyStringTest  ,
RecordIdOrder2   
)

◆ TEST_F() [17/37]

TEST_F ( KeyStringTest  ,
RecordIdOrder2Double   
)

◆ TEST_F() [18/37]

TEST_F ( KeyStringTest  ,
Timestamp   
)

◆ TEST_F() [19/37]

TEST_F ( KeyStringTest  ,
AllTypesRoundtrip   
)

◆ TEST_F() [20/37]

TEST_F ( KeyStringTest  ,
AllPermCompare   
)

◆ TEST_F() [21/37]

TEST_F ( KeyStringTest  ,
AllPerm2Compare   
)

◆ TEST_F() [22/37]

TEST_F ( KeyStringTest  ,
NaNs   
)

◆ TEST_F() [23/37]

TEST_F ( KeyStringTest  ,
NumberOrderLots   
)

◆ TEST_F() [24/37]

TEST_F ( KeyStringTest  ,
RecordIds   
)

◆ TEST_F() [25/37]

TEST_F ( KeyStringTest  ,
KeyWithTooManyTypeBitsCausesUassert   
)

◆ TEST_F() [26/37]

TEST_F ( KeyStringTest  ,
ToBsonSafeShouldNotTerminate   
)

◆ TEST_F() [27/37]

TEST_F ( KeyStringTest  ,
InvalidDecimalExponent   
)

◆ TEST_F() [28/37]

TEST_F ( KeyStringTest  ,
InvalidDecimalZero   
)

◆ TEST_F() [29/37]

TEST_F ( KeyStringTest  ,
InvalidDecimalContinuation   
)

◆ TEST_F() [30/37]

TEST_F ( KeyStringTest  ,
RandomizedInputsForToBsonSafe   
)

◆ TEST_F() [31/37]

TEST_F ( KeyStringTest  ,
CommonIntPerf   
)

◆ TEST_F() [32/37]

TEST_F ( KeyStringTest  ,
UniformInt64Perf   
)

◆ TEST_F() [33/37]

TEST_F ( KeyStringTest  ,
CommonDoublePerf   
)

◆ TEST_F() [34/37]

TEST_F ( KeyStringTest  ,
UniformDoublePerf   
)

◆ TEST_F() [35/37]

TEST_F ( KeyStringTest  ,
CommonDecimalPerf   
)

◆ TEST_F() [36/37]

TEST_F ( KeyStringTest  ,
UniformDecimalPerf   
)

◆ TEST_F() [37/37]

TEST_F ( KeyStringTest  ,
DecimalFromUniformDoublePerf   
)

◆ testPermutation()

void testPermutation ( KeyString::Version  version,
const std::vector< BSONObj > &  elementsOrig,
const std::vector< BSONObj > &  orderings,
bool  debug 
)

◆ toBson()

BSONObj toBson ( const KeyString ks,
Ordering  ord 
)

◆ toBsonAndCheckKeySize()

BSONObj toBsonAndCheckKeySize ( const KeyString ks,
Ordering  ord 
)

Variable Documentation

◆ ALL_ASCENDING

Ordering ALL_ASCENDING = Ordering::make(BSONObj())

◆ ONE_ASCENDING

Ordering ONE_ASCENDING = Ordering::make(BSON("a" << 1))

◆ ONE_DESCENDING

Ordering ONE_DESCENDING = Ordering::make(BSON("a" << -1))