log_ut.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "log.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. using namespace NLWTrace;
  4. namespace
  5. {
  6. struct TData
  7. {
  8. ui32 Val = 0;
  9. void Clear()
  10. {
  11. }
  12. };
  13. struct TReader
  14. {
  15. ui32 NumSeen = 0;
  16. void Reset()
  17. {
  18. NumSeen = 0;
  19. }
  20. void Push(TThread::TId tid, const TData& val)
  21. {
  22. Y_UNUSED(tid);
  23. Y_UNUSED(val);
  24. ++NumSeen;
  25. }
  26. };
  27. }
  28. Y_UNIT_TEST_SUITE(LWTraceLog) {
  29. Y_UNIT_TEST(ShouldAccumulateTracesViaReadItems) {
  30. TCyclicLogImpl<TData> log(100);
  31. {
  32. TCyclicLogImpl<TData>::TAccessor acc1(log);
  33. TCyclicLogImpl<TData>::TAccessor acc2(log);
  34. TCyclicLogImpl<TData>::TAccessor acc3(log);
  35. acc1.Add()->Val = 1;
  36. acc2.Add()->Val = 2;
  37. acc3.Add()->Val = 3;
  38. }
  39. TReader reader;
  40. log.ReadItems(reader);
  41. UNIT_ASSERT_VALUES_EQUAL(3, reader.NumSeen);
  42. {
  43. TCyclicLogImpl<TData>::TAccessor acc1(log);
  44. TCyclicLogImpl<TData>::TAccessor acc2(log);
  45. TCyclicLogImpl<TData>::TAccessor acc3(log);
  46. acc1.Add()->Val = 4;
  47. acc2.Add()->Val = 5;
  48. acc3.Add()->Val = 6;
  49. }
  50. reader.Reset();
  51. log.ReadItems(reader);
  52. UNIT_ASSERT_VALUES_EQUAL(6, reader.NumSeen);
  53. }
  54. Y_UNIT_TEST(ShouldNotReturnProcessedItemsViaMoveItems) {
  55. struct TData
  56. {
  57. ui32 Val = 0;
  58. void Clear()
  59. {
  60. }
  61. };
  62. struct TReader
  63. {
  64. ui32 NumSeen = 0;
  65. void Reset()
  66. {
  67. NumSeen = 0;
  68. }
  69. void Push(TThread::TId tid, const TData& val)
  70. {
  71. Y_UNUSED(tid);
  72. Y_UNUSED(val);
  73. ++NumSeen;
  74. }
  75. };
  76. TCyclicLogImpl<TData> log(100);
  77. {
  78. TCyclicLogImpl<TData>::TAccessor acc1(log);
  79. TCyclicLogImpl<TData>::TAccessor acc2(log);
  80. TCyclicLogImpl<TData>::TAccessor acc3(log);
  81. acc1.Add()->Val = 1;
  82. acc2.Add()->Val = 2;
  83. acc3.Add()->Val = 3;
  84. }
  85. TReader reader;
  86. log.ExtractItems(reader);
  87. UNIT_ASSERT_VALUES_EQUAL(3, reader.NumSeen);
  88. {
  89. TCyclicLogImpl<TData>::TAccessor acc1(log);
  90. TCyclicLogImpl<TData>::TAccessor acc2(log);
  91. TCyclicLogImpl<TData>::TAccessor acc3(log);
  92. acc1.Add()->Val = 4;
  93. acc2.Add()->Val = 5;
  94. acc3.Add()->Val = 6;
  95. }
  96. reader.Reset();
  97. log.ExtractItems(reader);
  98. UNIT_ASSERT_VALUES_EQUAL(3, reader.NumSeen);
  99. }
  100. }