コード例 #1
0
ファイル: ObjectPoolTest.cpp プロジェクト: jdiego/autowiring
TEST_F(ObjectPoolTest, MovableObjectPool) {
  ObjectPool<int> to;

  // Verify a move works correctly when an object has been checked out:
  {
    ObjectPool<int> from;
    auto original = from.Wait();
    to = std::move(from);
  }

  // Now verify that the pooled object returned home to the right place:
  ASSERT_EQ(1UL, to.GetCached()) << "Object pool move operation did not correctly relay checked out types";
}
コード例 #2
0
ファイル: ObjectPoolTest.cpp プロジェクト: jdiego/autowiring
TEST_F(ObjectPoolTest, EmptyPoolIssuance) {
  ObjectPool<int> pool;

  // Create the thread which will hold the shared pointer for awhile:
  AutoRequired<HoldsSharedPtrThenQuits> thread;
  pool(thread->m_ptr);
  std::weak_ptr<int> ptrWeak = thread->m_ptr;

  ASSERT_FALSE(ptrWeak.expired()) << "Object pool failed to issue a shared pointer as expected";

  // Verify properties now that we've zeroized the limit:
  pool.SetOutstandingLimit(0);
  EXPECT_ANY_THROW(pool.SetOutstandingLimit(1)) << "An attempt to alter a zeroized outstanding limit did not throw an exception as expected";
  EXPECT_ANY_THROW(pool.Wait()) << "An attempt to obtain an element on an empty pool did not throw an exception as expected";

  // Now see if we can delay for the thread to back out:
  m_create->Initiate();
  pool.Rundown();

  // Verify that it got released as expected:
  ASSERT_TRUE(ptrWeak.expired()) << "Not all shared pointers issued by an object pool expired in a timely fashion";
}
コード例 #3
0
ファイル: ObjectPoolTest.cpp プロジェクト: jdiego/autowiring
TEST_F(ObjectPoolTest, MovableObjectPoolAysnc) {
  static const size_t sc_count = 10000;
  ObjectPool<int> from;

  {
    // Issue a zillion objects from the from pool:
    std::vector<std::shared_ptr<int>> objs;
    for(size_t i = sc_count; i--;)
      objs.push_back(from.Wait());

    // Make a thread, let it hold these objects while we move its pool:
    *AutoRequired<CoreThread>() += [objs] {};
  }

  // Kick off threads, then immediately and asynchronously move the pool:
  AutoCurrentContext()->Initiate();
  ObjectPool<int> to = std::move(from);

  // Shutdown time:
  AutoCurrentContext()->SignalShutdown(true);

  // Verify that new pool got all of the objects:
  ASSERT_EQ(sc_count, to.GetCached()) << "Object pool move operation did not correctly relay checked out types";
}
コード例 #4
0
ファイル: ObjectPoolTest.cpp プロジェクト: jdiego/autowiring
TEST_F(ObjectPoolTest, CanRundownOneIssued) {
  // No conditions to be checked, we just know these routines should not deadlock.
  ObjectPool<int> pool;
  pool.Wait();
  pool.Rundown();
}