Beispiel #1
0
TEST_F(ParseNsOrUUID, FailInvalidDbName) {
    auto cmd = BSON("query"
                    << "coll");
    ASSERT_THROWS_CODE(CommandHelpers::parseNsOrUUID(opCtx, "test.coll", cmd),
                       DBException,
                       ErrorCodes::InvalidNamespace);
}
TEST(ParticipantList, ReceiveParticipantListMissingParticipantThatAlreadyVotedCommitThrows) {
    ParticipantList participantList;
    participantList.recordVoteCommit(ShardId("shard0000"), dummyTimestamp);
    ASSERT_THROWS_CODE(participantList.recordFullList({ShardId("shard0001")}),
                       AssertionException,
                       ErrorCodes::InternalError);
}
TEST(ParticipantList, ReceiveConflictingParticipantListsFirstListIsSupersetOfSecondThrows) {
    ParticipantList participantList;
    participantList.recordFullList({ShardId("shard0000"), ShardId("shard0001")});
    ASSERT_THROWS_CODE(participantList.recordFullList({ShardId("shard0000")}),
                       AssertionException,
                       ErrorCodes::InternalError);
}
TEST(ParticipantList, ReceiveVoteCommitFromParticipantNotInListThrows) {
    ParticipantList participantList;
    participantList.recordFullList({ShardId("shard0000")});
    ASSERT_THROWS_CODE(participantList.recordVoteCommit(ShardId("shard0001"), dummyTimestamp),
                       AssertionException,
                       ErrorCodes::InternalError);
}
TEST(ParticipantList, ReceiveConflictingParticipantListsNoOverlapThrows) {
    ParticipantList participantList;
    participantList.recordFullList({ShardId("shard0000"), ShardId("shard0001")});
    ASSERT_THROWS_CODE(participantList.recordFullList({ShardId("shard0002"), ShardId("shard0003")}),
                       AssertionException,
                       ErrorCodes::InternalError);
}
TEST(ParticipantList, ParticipantChangesPrepareTimestampThrows) {
    ParticipantList participantList;
    participantList.recordVoteCommit(ShardId("shard0000"), Timestamp::min());
    ASSERT_THROWS_CODE(participantList.recordVoteCommit(ShardId("shard0000"), Timestamp::max()),
                       AssertionException,
                       ErrorCodes::InternalError);
}
TEST(ParticipantList, ParticipantChangesVoteFromCommitToAbortThrows) {
    ParticipantList participantList;
    participantList.recordVoteCommit(ShardId("shard0000"), dummyTimestamp);
    ASSERT_THROWS_CODE(participantList.recordVoteAbort(ShardId("shard0000")),
                       AssertionException,
                       ErrorCodes::InternalError);
}
Beispiel #8
0
TEST_F(SyncTailTest, MultiInitialSyncApplyPassesThroughShouldSyncTailRetryError) {
    SyncTail syncTail(nullptr, SyncTail::MultiSyncApplyFunc(), nullptr);
    NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName());
    auto op = makeUpdateDocumentOplogEntry(
        {Timestamp(Seconds(1), 0), 1LL}, nss, BSON("_id" << 0), BSON("_id" << 0 << "x" << 2));
    ASSERT_THROWS_CODE(
        syncTail.shouldRetry(_txn.get(), op.raw), mongo::UserException, ErrorCodes::FailedToParse);
    MultiApplier::OperationPtrs ops = {&op};
    ASSERT_EQUALS(ErrorCodes::FailedToParse,
                  multiInitialSyncApply_noAbort(_txn.get(), &ops, &syncTail));
}
Beispiel #9
0
 void run() {
     auto opCtx = cc().makeOperationContext();
     DBDirectClient client(opCtx.get());
     client.dropCollection(_ns);
     client.insert(_ns, BSON("a" << BSON_ARRAY(99 << BSONSymbol("mySymbol"))));
     ASSERT_EQUALS(client.count(_ns), 1U);
     IndexSpec indexSpec;
     indexSpec.addKey("a").addOptions(BSON("collation" << BSON("locale"
                                                               << "fr")));
     ASSERT_THROWS_CODE(client.createIndex(_ns, indexSpec),
                        AssertionException,
                        ErrorCodes::CannotBuildIndexKeys);
 }
TEST_F(SnapshotManagerTests, FailsAfterDropAllSnapshotsWhileYielded) {
    if (!snapshotManager)
        return;  // This test is only for engines that DO support SnapshotMangers.

    auto op = makeOperation();

    // Start an operation using a committed snapshot.
    auto name = prepareAndCreateSnapshot();
    snapshotManager->setCommittedSnapshot(name);
    ASSERT_OK(op->recoveryUnit()->setReadFromMajorityCommittedSnapshot());
    ASSERT_EQ(itCountOn(op), 0);  // acquires a snapshot.

    // Everything still works until we abandon our snapshot.
    snapshotManager->dropAllSnapshots();
    ASSERT_EQ(itCountOn(op), 0);

    // Now it doesn't.
    op->recoveryUnit()->abandonSnapshot();
    ASSERT_THROWS_CODE(
        itCountOn(op), UserException, ErrorCodes::ReadConcernMajorityNotAvailableYet);
}
Beispiel #11
0
TEST_F(ParseNsOrUUID, ParseUnknownUUID) {
    auto cmd = BSON("query" << UUID::gen());
    ASSERT_THROWS_CODE(CommandHelpers::parseNsOrUUID(opCtx, "test.coll", cmd),
                       DBException,
                       ErrorCodes::NamespaceNotFound);
}
Beispiel #12
0
TEST_F(ParseNsOrUUID, FailWrongType) {
    auto cmd = BSON("query" << BSON("a" << BSON("$gte" << 11)));
    ASSERT_THROWS_CODE(
        CommandHelpers::parseNsOrUUID(opCtx, "db", cmd), DBException, ErrorCodes::InvalidNamespace);
}