18 using namespace folly;
22 using std::unique_ptr;
45 virtual void onA() = 0;
48 virtual void setCallback(
Callback* cb) = 0;
49 virtual void doA() = 0;
68 TesterInterface::Callback,
69 &TesterInterface::setCallback,
82 Owned>(calls, callbacks) {}
85 this->setCallbackInternal(cb);
123 return std::make_unique<MockTester>();
144 Owned>>(getTester<Owned>());
146 actor_ = CHECK_NOTNULL(static_cast<MockTester*>(chain_->call()));
154 template<
typename FilterT>
156 return new FilterT();
159 template<
typename FilterT>
161 return std::make_unique<FilterT>();
164 template<
typename FilterT>
166 auto f = getFilter<FilterT>();
172 std::deque<TestFilter<Owned>*> filters;
174 for (
unsigned i = 0;
i < num; ++
i) {
177 addFilterToChain<TestFilter<Owned>>(filters);
179 addFilterToChain<TestFilterNoCall<Owned>>(filters);
181 addFilterToChain<TestFilterNoCallback<Owned>>(filters);
183 addFilterToChain<TestFilterNoCallbackNoCall<Owned>>(filters);
191 unique_ptr<
FilterChain<TesterInterface, TesterInterface::Callback,
207 CHECK_NOTNULL(actor_->cb_);
214 for (
auto f: filters) {
224 CHECK_NOTNULL(actor_->cb_);
227 for (
auto f: filters) {
228 if (
f->kWantsCalls_) {
233 if (
f->kWantsCallbacks_) {
249 auto filterUnique = std::make_unique<TestFilter<true>>();
250 auto filter = filterUnique.get();
251 chain().addFilters(
std::move(filterUnique));
260 auto f1 = std::make_unique<TestFilter<true>>();
261 auto f2 = std::make_unique<TestFilter<true>>();
262 auto f3 = std::make_unique<TestFilter<true>>();
277 std::deque<TestFilter<true>*> filters;
278 for (
unsigned i = 0;
i < 10; ++
i) {
279 auto filter = std::make_unique<TestFilter<true>>();
280 filters.push_back(
filter.get());
284 for (
auto filter: filters) {
291 auto f1 = std::make_unique<TestFilter<true>>();
292 auto f2 = std::make_unique<TestFilterNoCallback<true>>();
293 auto f3 = std::make_unique<TestFilterNoCall<true>>();
294 auto f4 = std::make_unique<TestFilterNoCallbackNoCall<true>>();
316 auto f1 = std::make_unique<TestFilterNoCallback<true>>();
317 auto f2 = std::make_unique<TestFilterNoCall<true>>();
338 const unsigned NUM_FILTERS = 5000;
339 auto filters = getRandomFilters(NUM_FILTERS);
342 for (
unsigned i = 0;
i < NUM_FILTERS; ++
i) {
344 if (
f->kWantsCalls_) {
349 if (
f->kWantsCallbacks_) {
360 auto f = std::make_unique<TestFilterNoCallback<true>>();
370 chain().setCallback(&callback2);
379 const unsigned NUM_FILTERS = 5000;
380 auto filters = getRandomFilters(NUM_FILTERS);
383 for (
auto f: filters) {
384 if (
f->kWantsCalls_) {
389 if (
f->kWantsCallbacks_) {
403 auto filters = getRandomFilters(100);
404 chain().setCallback(
nullptr);
405 CHECK(
nullptr == actor_->cb_);
407 testFilters(filters,
nullptr);
410 chain().setCallback(&head);
412 testFilters(filters, &head);
415 for (
auto f: filters) {
416 if (
f->kWantsCallbacks_) {
430 deletions_(CHECK_NOTNULL(deletions)) {}
437 }
else if (times_++) {
450 for (
unsigned i = 0;
i < 4; ++
i) {
454 for (
unsigned i = 0;
i < 2; ++
i) {
465 template<
bool Owned=false>
469 deletions_(CHECK_NOTNULL(deletions)) {}
476 }
else if (times_++) {
489 for (
unsigned i = 0;
i < 4; ++
i) {
493 for (
unsigned i = 0;
i < 2; ++
i) {
507 const unsigned NUM_FILTERS = 1000;
509 for (
unsigned i = 0;
i < NUM_FILTERS; ++
i) {
518 for (
unsigned i = 1;
i < 100; ++
i) {
519 auto filters = getRandomFilters(
i);
520 EXPECT_EQ(actor_, &chain().getChainEnd());
525 auto filters = getRandomFilters(20);
528 auto tester2 = getTester<true>();
529 actor_ = tester2.get();
530 auto oldTester = chain().setDestination(
std::move(tester2));
536 auto filters = getRandomFilters(20);
541 std::default_delete<TesterInterface> >*
filter) {
void addFilterToChain(std::deque< TestFilter< Owned > * > &refs)
std::enable_if<!Owned, FilterT * >::type getFilter()
std::deque< TestFilter< Owned > * > getRandomFilters(unsigned num)
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
#define ASSERT_EQ(val1, val2)
FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > & chain()
std::enable_if< Owned, unique_ptr< MockTester > >::type getTester()
#define EXPECT_EQ(val1, val2)
virtual void setCallback(Callback *cb)=0
constexpr detail::Map< Move > move
TestFilterOddDeleteOn(int *deletions)
unique_ptr< FilterChain< TesterInterface, TesterInterface::Callback, TestFilter< Owned >,&TesterInterface::setCallback, Owned > > chain_
std::unordered_map< std::string, IValidator * > refs
—— Concurrent Priority Queue Implementation ——
MockTesterCallback callback_
~TestFilterOddDeleteDo() override
std::enable_if< Owned, unique_ptr< FilterT > >::type getFilter()
std::unique_ptr< AsyncFizzServer::HandshakeCallback > cb_
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
void setCallback(TesterInterface::Callback *cb) override
~TestFilterOddDeleteOn() override
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
void testFilters(const std::deque< TestFilter< Owned > * > &filters, MockTesterCallback *expectedCb)
TestFilterNoCallbackNoCall()
const Value * get_pointer(const Expected< Value, Error > &ex) noexcept
static uint32_t idCounter_
void setCallback(Callback *cb) override
#define EXPECT_CALL(obj, call)
folly::Function< void()> callback_
TestFilterOddDeleteDo(int *deletions)
TestFilter(bool calls, bool callbacks)
Future< bool > call(int depth, Executor *executor)
T * get_pointer(const unique_ptr< T > &ptr)
virtual ~TesterInterface()
#define MOCK_METHOD0(m,...)