本文整理汇总了C++中Token::GetSerialNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ Token::GetSerialNumber方法的具体用法?C++ Token::GetSerialNumber怎么用?C++ Token::GetSerialNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token::GetSerialNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(TokenManager, Basic)
{
TokenManager tokenManager;
{
const Token token1 = tokenManager.RequestToken();
ASSERT_EQ(token1.GetSerialNumber(), 0u);
const Token token2 = tokenManager.RequestToken();
ASSERT_EQ(token2.GetSerialNumber(), 1u);
}
}
示例2: tokenDistributor
// Test which verifies distribution of tokens and starting/stopping
// token trackers.
TEST(TokenManager, WithTrackersTest)
{
static const unsigned c_threadCount = 16;
// static const unsigned c_testDuration = 5 * 1000; TODO
TokenManager tokenManager;
std::unique_ptr<Logging::ILogger> logger(new Logging::ConsoleLogger());
Logging::RegisterLogger(logger.get());
TokenThreadHolder tokenDistributor(c_threadCount, tokenManager);
std::atomic<bool> isRunning(true);
// Add a thread that periodically starts tracking tokens.
TokenTrackerThread * trackerThread = new TokenTrackerThread(tokenManager, isRunning);
tokenDistributor.AddThread(trackerThread);
tokenDistributor.Start();
// DESIGN NOTE: this test used to have random sleeps in the methods
// and a 5 second sleep here. All the sleeps were reduced because we
// still get some randomness in ordering and this test shouldn't
// take 5+ seconds to run. However, it's possible that's too extreme
// and we should larger sleeps.
// This test, with the reduced sleeps, found a threading bug that
// was triggered every 10s to 100s of executions. With the old version
// of this test, that would have taken an unreasonably long time, so
// even if this test is sacrificing some "randomness" by having
// a shorter duration, I believe it makes up for it by the increased
// number of executions possible per unit time, and that we should
// really have a seperate test that's designed for overnight use
// that can be more comprehensive.
// 5 is an arbitrary number that's > 2x 2.
std::this_thread::sleep_for(std::chrono::milliseconds(5));
isRunning = false;
tokenDistributor.Stop();
{
const Token lastToken = tokenManager.RequestToken();
// Sanity check that some tokens have actually been issued.
ASSERT_TRUE(lastToken.GetSerialNumber() > 0);
LogB(Logging::Info,
"TokenManagerWithTrackersTest",
"Last serial num: %u",
lastToken.GetSerialNumber());
}
}