Proxy slice(int f_begin, int f_length, int s_begin, int s_length) const { ASSERT_GTE(f_length, 0); ASSERT_GTE(s_length, 0); Proxy result(source_); result.f_begin_ = map_f_to_src(f_begin); result.f_length_ = f_length; result.f_ori_ = f_ori_; result.s_begin_ = map_s_to_src(s_begin); result.s_length_ = s_length; result.s_ori_ = s_ori_; return result; }
TEST(RandomTest, NextInt64InRange) { PseudoRandom a(11); for (int i = 0; i < 1000; i++) { auto res = a.nextInt64(10); ASSERT_GTE(res, 0); ASSERT_LT(res, 10); } }
virtual void parse(T_arg_list args, bool call_super = true) { if (call_super) { super::parse(args); } tx_redundancy = get_arg("kodo::tx_redundancy", tx_redundancy, args).d; ASSERT_GTE(tx_redundancy, 1); tx_gen_size = get_arg("kodo::tx_gen_size", tx_gen_size, args).u32; uint32_t symbol_size = tx_symbol_size - sizeof(T_zeropad); tx_symbol_size = get_arg("kodo::tx_symbol_size", symbol_size, args).u32 + sizeof(T_zeropad); }
// Insert multiple keys and try to iterate through all of them // using a reverse cursor while calling savePosition() and // restorePosition() in succession. TEST( SortedDataInterface, SaveAndRestorePositionWhileIterateCursorReversed ) { const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() ); const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) ); { const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } int nToInsert = 10; for ( int i = 0; i < nToInsert; i++ ) { const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); BSONObj key = BSON( "" << i ); RecordId loc( 42, i * 2 ); ASSERT_OK( sorted->insert( opCtx.get(), key, loc, true ) ); uow.commit(); } } { const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( nToInsert, sorted->numEntries( opCtx.get() ) ); } { const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() ); const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get(), false) ); int i = nToInsert - 1; for (auto entry = cursor->seek(maxKey, true); entry; i--, entry = cursor->next()) { ASSERT_GTE(i, 0); ASSERT_EQ(entry, IndexKeyEntry(BSON( "" << i), RecordId(42, i * 2))); cursor->savePositioned(); cursor->restore( opCtx.get() ); } ASSERT( !cursor->next() ); ASSERT_EQ(i, -1); } }
void ClusterCommandTestFixture::testSnapshotReadConcernWithAfterClusterTime( BSONObj targetedCmd, BSONObj scatterGatherCmd) { auto containsAtClusterTimeNoAfterClusterTime = [&](const executor::RemoteCommandRequest& request) { ASSERT(!request.cmdObj["readConcern"]["atClusterTime"].eoo()); ASSERT(request.cmdObj["readConcern"]["afterClusterTime"].eoo()); // The chosen atClusterTime should be greater than or equal to the request's // afterClusterTime. ASSERT_GTE(LogicalTime(request.cmdObj["readConcern"]["atClusterTime"].timestamp()), LogicalTime(kAfterClusterTime)); }; // Target one shard. runCommandInspectRequests( _makeCmd(targetedCmd, true), containsAtClusterTimeNoAfterClusterTime, true); // Target all shards. if (!scatterGatherCmd.isEmpty()) { runCommandInspectRequests( _makeCmd(scatterGatherCmd, true), containsAtClusterTimeNoAfterClusterTime, false); } }
TEST(KVEngineTestHarness, AllCommittedTimestamp) { unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create()); KVEngine* engine = helper->getEngine(); if (!engine->supportsDocLocking()) return; unique_ptr<RecordStore> rs; { MyOperationContext opCtx(engine); WriteUnitOfWork uow(&opCtx); CollectionOptions options; options.capped = true; options.cappedSize = 10240; options.cappedMaxDocs = -1; NamespaceString oplogNss("local.oplog.rs"); ASSERT_OK(engine->createRecordStore(&opCtx, oplogNss.ns(), "ident", options)); rs = engine->getRecordStore(&opCtx, oplogNss.ns(), "ident", options); ASSERT(rs); } { Timestamp t11(1, 1); Timestamp t12(1, 2); Timestamp t21(2, 1); auto t11Doc = BSON("ts" << t11); auto t12Doc = BSON("ts" << t12); auto t21Doc = BSON("ts" << t21); Timestamp allCommitted = engine->getAllCommittedTimestamp(); MyOperationContext opCtx1(engine); WriteUnitOfWork uow1(&opCtx1); ASSERT_EQ(invariant(rs->insertRecord( &opCtx1, t11Doc.objdata(), t11Doc.objsize(), Timestamp::min())), RecordId(1, 1)); Timestamp lastAllCommitted = allCommitted; allCommitted = engine->getAllCommittedTimestamp(); ASSERT_GTE(allCommitted, lastAllCommitted); ASSERT_LT(allCommitted, t11); MyOperationContext opCtx2(engine); WriteUnitOfWork uow2(&opCtx2); ASSERT_EQ(invariant(rs->insertRecord( &opCtx2, t21Doc.objdata(), t21Doc.objsize(), Timestamp::min())), RecordId(2, 1)); uow2.commit(); lastAllCommitted = allCommitted; allCommitted = engine->getAllCommittedTimestamp(); ASSERT_GTE(allCommitted, lastAllCommitted); ASSERT_LT(allCommitted, t11); ASSERT_EQ(invariant(rs->insertRecord( &opCtx1, t12Doc.objdata(), t12Doc.objsize(), Timestamp::min())), RecordId(1, 2)); lastAllCommitted = allCommitted; allCommitted = engine->getAllCommittedTimestamp(); ASSERT_GTE(allCommitted, lastAllCommitted); ASSERT_LT(allCommitted, t11); uow1.commit(); lastAllCommitted = allCommitted; allCommitted = engine->getAllCommittedTimestamp(); ASSERT_GTE(allCommitted, lastAllCommitted); ASSERT_LTE(allCommitted, t21); } }