Exemplo n.º 1
0
static int
reportLastHistoryCheckpoint(Config const& cfg, std::string const& outputFile)
{
    VirtualClock clock(VirtualClock::REAL_TIME);
    Application::pointer app = Application::create(clock, cfg, false);

    if (!checkInitialized(app))
    {
        return 1;
    }

    auto state = HistoryArchiveState{};
    auto& wm = app->getWorkManager();
    auto getHistoryArchiveStateWork =
        wm.executeWork<GetHistoryArchiveStateWork>(
            true, "get-history-archive-state-work", state);

    auto ok = getHistoryArchiveStateWork->getState() == Work::WORK_SUCCESS;
    if (ok)
    {
        std::string filename = outputFile.empty() ? "-" : outputFile;

        if (filename == "-")
        {
            LOG(INFO) << "*";
            LOG(INFO) << "* Last history checkpoint " << state.toString();
            LOG(INFO) << "*";
        }
        else
        {
            state.save(filename);
            LOG(INFO) << "*";
            LOG(INFO) << "* Wrote last history checkpoint " << filename;
            LOG(INFO) << "*";
        }
    }
    else
    {
        LOG(INFO) << "*";
        LOG(INFO) << "* Fetching last history checkpoint failed.";
        LOG(INFO) << "*";
    }

    app->gracefulStop();
    while (clock.crank(true))
        ;

    return ok ? 0 : 1;
}
Exemplo n.º 2
0
        mDidRun = true;
    }

    bool
    didRun() const
    {
        return mDidRun;
    }
};

TEST_CASE("work manager", "[work]")
{
    VirtualClock clock;
    Config const& cfg = getTestConfig();
    Application::pointer appPtr = createTestApplication(clock, cfg);
    auto& wm = appPtr->getWorkManager();

    auto w = wm.addWork<CallCmdWork>("hostname");
    w->addWork<CallCmdWork>("date");
    w->addWork<CallCmdWork>("uname");
    wm.advanceChildren();
    while (!wm.allChildrenSuccessful())
    {
        clock.crank();
    }
}

TEST_CASE("work propagates process failure", "[work]")
{
    VirtualClock clock;
    Config const& cfg = getTestConfig();