lfqueue_batch_ut.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include "lfqueue_batch.h"
  3. Y_UNIT_TEST_SUITE(TLockFreeQueueBatch) {
  4. Y_UNIT_TEST(Order1) {
  5. TLockFreeQueueBatch<unsigned> q;
  6. {
  7. TAutoPtr<TVector<unsigned>> v(new TVector<unsigned>);
  8. v->push_back(0);
  9. v->push_back(1);
  10. q.EnqueueAll(v);
  11. }
  12. TVector<unsigned> r;
  13. q.DequeueAllSingleConsumer(&r);
  14. UNIT_ASSERT_VALUES_EQUAL(2u, r.size());
  15. for (unsigned i = 0; i < 2; ++i) {
  16. UNIT_ASSERT_VALUES_EQUAL(i, r[i]);
  17. }
  18. r.clear();
  19. q.DequeueAllSingleConsumer(&r);
  20. UNIT_ASSERT_VALUES_EQUAL(0u, r.size());
  21. }
  22. Y_UNIT_TEST(Order2) {
  23. TLockFreeQueueBatch<unsigned> q;
  24. {
  25. TAutoPtr<TVector<unsigned>> v(new TVector<unsigned>);
  26. v->push_back(0);
  27. v->push_back(1);
  28. q.EnqueueAll(v);
  29. }
  30. {
  31. TAutoPtr<TVector<unsigned>> v(new TVector<unsigned>);
  32. v->push_back(2);
  33. v->push_back(3);
  34. v->push_back(4);
  35. q.EnqueueAll(v);
  36. }
  37. TVector<unsigned> r;
  38. q.DequeueAllSingleConsumer(&r);
  39. UNIT_ASSERT_VALUES_EQUAL(5u, r.size());
  40. for (unsigned i = 0; i < 5; ++i) {
  41. UNIT_ASSERT_VALUES_EQUAL(i, r[i]);
  42. }
  43. r.clear();
  44. q.DequeueAllSingleConsumer(&r);
  45. UNIT_ASSERT_VALUES_EQUAL(0u, r.size());
  46. }
  47. }