proxygen
AtomicBatchDispatcherTesting Namespace Reference

Classes

struct  DevNullPiper
 
struct  Job
 

Typedefs

using ValueT = size_t
 
using ResultT = std::string
 
using DispatchFunctionT = folly::Function< std::vector< ResultT >(std::vector< ValueT > &&)>
 

Enumerations

enum  DispatchProblem { DispatchProblem::None, DispatchProblem::PreprocessThrows, DispatchProblem::DuplicateDispatch }
 

Functions

ResultT processSingleInput (ValueT &&input)
 
std::vector< ResultTuserDispatchFunc (std::vector< ValueT > &&inputs)
 
void createJobs (AtomicBatchDispatcher< ValueT, ResultT > &atomicBatchDispatcher, std::vector< Job > &jobs, size_t count)
 
void dispatchJobs (FiberManager &executor, std::vector< Job > &jobs, std::vector< folly::Optional< folly::Future< ResultT >>> &results, DispatchProblem dispatchProblem=DispatchProblem::None, size_t problemIndex=size_t(-1))
 
void validateResult (std::vector< folly::Optional< folly::Future< ResultT >>> &results, size_t i)
 
template<typename TException >
void validateResults (std::vector< folly::Optional< folly::Future< ResultT >>> &results, size_t expectedNumResults)
 

Variables

struct AtomicBatchDispatcherTesting::DevNullPiper devNullPiper
 

Typedef Documentation

using AtomicBatchDispatcherTesting::DispatchFunctionT = typedef folly::Function<std::vector<ResultT>(std::vector<ValueT>&&)>

Definition at line 1771 of file FibersTest.cpp.

Definition at line 1769 of file FibersTest.cpp.

using AtomicBatchDispatcherTesting::ValueT = typedef size_t

Definition at line 1768 of file FibersTest.cpp.

Enumeration Type Documentation

Function Documentation

void AtomicBatchDispatcherTesting::createJobs ( AtomicBatchDispatcher< ValueT, ResultT > &  atomicBatchDispatcher,
std::vector< Job > &  jobs,
size_t  count 
)

Definition at line 1828 of file FibersTest.cpp.

References count, folly::fibers::AtomicBatchDispatcher< InputT, ResultT >::getToken(), and i.

Referenced by TEST().

1831  {
1832  jobs.clear();
1833  for (size_t i = 0; i < count; ++i) {
1834  jobs.emplace_back(Job(atomicBatchDispatcher.getToken(), i));
1835  }
1836 }
int * count
void AtomicBatchDispatcherTesting::dispatchJobs ( FiberManager executor,
std::vector< Job > &  jobs,
std::vector< folly::Optional< folly::Future< ResultT >>> &  results,
DispatchProblem  dispatchProblem = DispatchProblem::None,
size_t  problemIndex = size_t(-1) 
)

Definition at line 1844 of file FibersTest.cpp.

References folly::fibers::FiberManager::add(), EXPECT_THROW, EXPECT_TRUE, i, AtomicBatchDispatcherTesting::Job::input, folly::gen::move, OUTPUT_TRACE, AtomicBatchDispatcherTesting::Job::preprocess(), and AtomicBatchDispatcherTesting::Job::token.

Referenced by TEST().

1849  {
1850  EXPECT_TRUE(
1851  dispatchProblem == DispatchProblem::None || problemIndex < jobs.size());
1852  results.clear();
1853  results.resize(jobs.size());
1854  for (size_t i = 0; i < jobs.size(); ++i) {
1855  executor.add(
1856  [i, &executor, &jobs, &results, dispatchProblem, problemIndex]() {
1857  try {
1858  Job job(std::move(jobs[i]));
1859 
1860  if (dispatchProblem == DispatchProblem::PreprocessThrows) {
1861  if (i == problemIndex) {
1862  EXPECT_THROW(job.preprocess(executor, true), std::logic_error);
1863  return;
1864  }
1865  }
1866 
1867  job.preprocess(executor, false);
1868  OUTPUT_TRACE << "Dispatching job #" << i << std::endl;
1869  results[i] = job.token.dispatch(job.input);
1870  OUTPUT_TRACE << "Result future filled for job #" << i << std::endl;
1871 
1872  if (dispatchProblem == DispatchProblem::DuplicateDispatch) {
1873  if (i == problemIndex) {
1874  EXPECT_THROW(job.token.dispatch(job.input), ABDUsageException);
1875  }
1876  }
1877  } catch (...) {
1878  OUTPUT_TRACE << "Preprocessing failed for job #" << i << std::endl;
1879  }
1880  });
1881  }
1882 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define OUTPUT_TRACE
void add(folly::Func f) override
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
ResultT AtomicBatchDispatcherTesting::processSingleInput ( ValueT &&  input)

Definition at line 1814 of file FibersTest.cpp.

References folly::gen::move.

Referenced by userDispatchFunc(), and validateResults().

1814  {
1815  return folly::to<ResultT>(std::move(input));
1816 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::vector<ResultT> AtomicBatchDispatcherTesting::userDispatchFunc ( std::vector< ValueT > &&  inputs)

Definition at line 1818 of file FibersTest.cpp.

References i, folly::gen::move, and processSingleInput().

Referenced by TEST().

1818  {
1819  size_t expectedCount = inputs.size();
1820  std::vector<ResultT> results;
1821  results.reserve(expectedCount);
1822  for (size_t i = 0; i < expectedCount; ++i) {
1823  results.emplace_back(processSingleInput(std::move(inputs[i])));
1824  }
1825  return results;
1826 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ResultT processSingleInput(ValueT &&input)
void AtomicBatchDispatcherTesting::validateResult ( std::vector< folly::Optional< folly::Future< ResultT >>> &  results,
size_t  i 
)

Definition at line 1884 of file FibersTest.cpp.

References i, and OUTPUT_TRACE.

Referenced by validateResults().

1886  {
1887  try {
1888  OUTPUT_TRACE << "results[" << i << "].value() : " << results[i]->value()
1889  << std::endl;
1890  } catch (std::exception& e) {
1891  OUTPUT_TRACE << "Exception : " << e.what() << std::endl;
1892  throw;
1893  }
1894 }
#define OUTPUT_TRACE
template<typename TException >
void AtomicBatchDispatcherTesting::validateResults ( std::vector< folly::Optional< folly::Future< ResultT >>> &  results,
size_t  expectedNumResults 
)

Definition at line 1897 of file FibersTest.cpp.

References EXPECT_EQ, EXPECT_NO_THROW, EXPECT_THROW, i, folly::gen::move, processSingleInput(), validateResult(), and folly::value().

Referenced by TEST().

1899  {
1900  size_t numResultsFilled = 0;
1901  for (size_t i = 0; i < results.size(); ++i) {
1902  if (!results[i]) {
1903  continue;
1904  }
1905  ++numResultsFilled;
1906  EXPECT_THROW(validateResult(results, i), TException);
1907  }
1908  EXPECT_EQ(numResultsFilled, expectedNumResults);
1909 }
void validateResult(std::vector< folly::Optional< folly::Future< ResultT >>> &results, size_t i)
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922

Variable Documentation

struct AtomicBatchDispatcherTesting::DevNullPiper AtomicBatchDispatcherTesting::devNullPiper