TEST_F(SnapshotManagerTests, FailsWithNoCommittedSnapshot) {
    if (!snapshotManager)
        return;  // This test is only for engines that DO support SnapshotMangers.

    auto op = makeOperation();
    auto ru = op->recoveryUnit();

    // Before first snapshot is created.
    ASSERT_EQ(ru->setReadFromMajorityCommittedSnapshot(),
              ErrorCodes::ReadConcernMajorityNotAvailableYet);

    // There is a snapshot but it isn't committed.
    auto name = prepareAndCreateSnapshot();
    ASSERT_EQ(ru->setReadFromMajorityCommittedSnapshot(),
              ErrorCodes::ReadConcernMajorityNotAvailableYet);

    // Now there is a committed snapshot.
    snapshotManager->setCommittedSnapshot(name);
    ASSERT_OK(ru->setReadFromMajorityCommittedSnapshot());

    // Not anymore!
    snapshotManager->dropAllSnapshots();
    ASSERT_EQ(ru->setReadFromMajorityCommittedSnapshot(),
              ErrorCodes::ReadConcernMajorityNotAvailableYet);
}
Esempio n. 2
0
Boolean::Ptr Expression::makeOperation(const std::string& expression) {
  static const std::string seporators = " \n";
  static const std::string singleTokens = "()&|";
  static const std::string multipleTokens = "01";
  Tokenizer tokenizer(expression, seporators, singleTokens, multipleTokens);
  return makeOperation(tokenizer);
}
Esempio n. 3
0
Numeric::Ptr Expression::makeOperation(const std::string& expression) {
  static const std::string seporators = " \n";
  static const std::string singleTokens = "()+-*/";
  static const std::string multipleTokens = "0.123456789";
  Tokenizer tokenizer(expression, seporators, singleTokens, multipleTokens);
  return makeOperation(tokenizer);
}
int StringCalculator::calculateExpression(char string[])
{
        StackInterface* stackObject = new PointerStack();
        makePolish(string, stackObject);
        //printf("%s\n", string);
        int i = 0;
        int length = strlen(string) + 1;
        int argument1 = 1;
        int argument2 = 1;
        int tmpResult = 0;
        for (i = 0; i < length; i++)
        {
            if (isNumber(string[i]))
                stackObject->push(convertToInt(string[i]));
            if (isSign(string[i]))
            {
                argument2 = stackObject->pop();
                argument1 = stackObject->pop();
                tmpResult = makeOperation(string[i], argument1, argument2);
                stackObject->push(tmpResult);
            }
        }
        int result = stackObject->pop();
        delete stackObject;
        return result;
}
Esempio n. 5
0
int main()
{
	pst head = NULL;
	printf("vvedyte vyrazhenye\n");
	char s[60];
	scanf("%s", s);
	int length = strlen(s);
	for(int i = 0; i < length; i++)
	{
		if (!isSymbol(s[i]))
			push(head, s[i] - '0');
		else 
			if (isSymbol(s[i]))
			{
				int a = front(head);
				pop(head);
				int b = front(head);
				pop(head);
				push(head, makeOperation(s[i], a, b));
			}
	}
	printf("result = ");
	printf("%d\n",front(head));
	deleteStack(head);
	return 0;
}
int calculateSubtree(TreeNode* &node)
{
	if(isSign(node->value))
	{
		return makeOperation(calculateSubtree(node->left),calculateSubtree(node->right),node->value);
	}
	else
		return node->value;
}
Esempio n. 7
0
TEST_F(SnapshotManagerTests, ConsistentIfNotSupported) {
    if (snapshotManager)
        return;  // This test is only for engines that DON'T support SnapshotMangers.

    auto op = makeOperation();
    auto ru = op->recoveryUnit();
    ASSERT(!ru->isReadingFromMajorityCommittedSnapshot());
    ASSERT(!ru->getMajorityCommittedSnapshot());
}
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);
}
TEST_F(SnapshotManagerTests, BasicFunctionality) {
    if (!snapshotManager)
        return;  // This test is only for engines that DO support SnapshotMangers.

    // Snapshot variables are named according to the size of the RecordStore at the time of the
    // snapshot.
    auto snap0 = prepareAndCreateSnapshot();

    insertRecordAndCommit();
    auto snap1 = prepareAndCreateSnapshot();

    insertRecordAndCommit();
    prepareSnapshot();
    insertRecordAndCommit();
    auto snap2 = createSnapshot();

    {
        auto op = makeOperation();
        WriteUnitOfWork wuow(op);
        insertRecord(op);

        prepareSnapshot();  // insert should still be invisible.
        ASSERT_EQ(itCountOn(snapshotOperation), 3);

        wuow.commit();
    }
    auto snap3 = createSnapshot();

    {
        auto op = makeOperation();
        WriteUnitOfWork wuow(op);
        insertRecord(op);
        // rolling back wuow
    }
    auto snap4 = prepareAndCreateSnapshot();

    // If these fail, everything is busted.
    snapshotManager->setCommittedSnapshot(snap0);
    ASSERT_EQ(itCountCommitted(), 0);
    snapshotManager->setCommittedSnapshot(snap1);
    ASSERT_EQ(itCountCommitted(), 1);

    // If this fails, the snapshot is from the 'create' time rather than the 'prepare' time.
    snapshotManager->setCommittedSnapshot(snap2);
    ASSERT_EQ(itCountCommitted(), 2);

    // If this fails, the snapshot contains writes that weren't yet committed.
    snapshotManager->setCommittedSnapshot(snap3);
    ASSERT_EQ(itCountCommitted(), 3);

    // This op should keep its original snapshot until abandoned.
    auto longOp = makeOperation();
    ASSERT_OK(longOp->recoveryUnit()->setReadFromMajorityCommittedSnapshot());
    ASSERT_EQ(itCountOn(longOp), 3);

    // If this fails, the snapshot contains writes that were rolled back.
    snapshotManager->setCommittedSnapshot(snap4);
    ASSERT_EQ(itCountCommitted(), 4);

    // If this fails, longOp changed snapshots at an illegal time.
    ASSERT_EQ(itCountOn(longOp), 3);

    // If this fails, snapshots aren't preserved while in use.
    snapshotManager->cleanupUnneededSnapshots();
    ASSERT_EQ(itCountOn(longOp), 3);

    // If this fails, longOp didn't get a new snapshot when it should have.
    longOp->recoveryUnit()->abandonSnapshot();
    ASSERT_EQ(itCountOn(longOp), 4);
}