tstreamUpdateTest.cpp 4.4 KB
Newer Older
R
root 已提交
1 2 3 4 5 6
#include <gtest/gtest.h>

#include "tstreamUpdate.h"
#include "ttime.h"

using namespace std;
5
54liuyao 已提交
7
#define MAX_NUM_SCALABLE_BF    100000
R
root 已提交
8 9 10 11 12

TEST(TD_STREAM_UPDATE_TEST, update) {
  int64_t interval = 20 * 1000;
  int64_t watermark = 10 * 60 * 1000;
  SUpdateInfo *pSU = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark);
5
54liuyao 已提交
13 14
  GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,1, 0), true);
  GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,1, -1), true);
R
root 已提交
15 16

  for(int i=0; i < 1024; i++) {
5
54liuyao 已提交
17
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 1), false);
R
root 已提交
18 19
  }
  for(int i=0; i < 1024; i++) {
5
54liuyao 已提交
20
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 1), true);
R
root 已提交
21 22 23
  }

  for(int i=0; i < 1024; i++) {
5
54liuyao 已提交
24
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 2), false);
R
root 已提交
25 26
  }
  for(int i=0; i < 1024; i++) {
5
54liuyao 已提交
27
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 2), true);
R
root 已提交
28 29 30
  }

  for(int i=0; i < 1024; i++) {
5
54liuyao 已提交
31
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,i, 1), true);
R
root 已提交
32 33 34
  }

  for(int i=3; i < 1024; i++) {
5
54liuyao 已提交
35
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,0, i), false);
R
root 已提交
36 37 38 39
  }
  GTEST_ASSERT_EQ(*(int64_t*)taosArrayGet(pSU->pTsBuckets,0), 1023);

  for(int i=3; i < 1024; i++) {
5
54liuyao 已提交
40
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU,0, i), true);
R
root 已提交
41 42 43 44 45
  }
  GTEST_ASSERT_EQ(*(int64_t*)taosArrayGet(pSU->pTsBuckets,0), 1023);

  SUpdateInfo *pSU1 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark);
  for(int i=1; i <= watermark / interval; i++) {
5
54liuyao 已提交
46
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU1, 1, i * interval + 5), false);
R
root 已提交
47 48 49 50 51 52 53 54 55 56
    GTEST_ASSERT_EQ(pSU1->minTS, interval);
    GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval);
  }
  for(int i=0; i < pSU1->numSBFs; i++) {
    SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU1->pTsSBFs, i);
    SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0);
    GTEST_ASSERT_EQ(pBF->size, 1);
  }

  for(int i= watermark / interval + 1, j = 2 ; i <= watermark / interval + 10; i++,j++) {
5
54liuyao 已提交
57
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU1, 1, i * interval + 5), false);
R
root 已提交
58 59 60 61 62 63 64 65
    GTEST_ASSERT_EQ(pSU1->minTS, interval*j);
    GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval);
    SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU1->pTsSBFs, pSU1->numSBFs - 1);
    SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0);
    GTEST_ASSERT_EQ(pBF->size, 1);
  }
  
  for(int i= watermark / interval * 100, j = 0; j < 10; i+= (watermark / interval * 2), j++) {
5
54liuyao 已提交
66
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU1, 1, i * interval + 5), false);
R
root 已提交
67 68 69 70 71
    GTEST_ASSERT_EQ(pSU1->minTS, (i-(pSU1->numSBFs-1))*interval);
    GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval);
  }

  SUpdateInfo *pSU2 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark);
5
54liuyao 已提交
72
  GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU2, 1, 1 * interval + 5), false);
R
root 已提交
73 74
  GTEST_ASSERT_EQ(pSU2->minTS, interval);
  for(int i= watermark / interval * 100, j = 0; j < 10; i+= (watermark / interval * 10), j++) {
5
54liuyao 已提交
75
    GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU2, 1, i * interval + 5), false);
R
root 已提交
76 77 78 79 80 81 82 83
    GTEST_ASSERT_EQ(pSU2->minTS, (i-(pSU2->numSBFs-1))*interval);
    GTEST_ASSERT_EQ(pSU2->numSBFs, watermark / interval);
    GTEST_ASSERT_EQ(*(int64_t*)taosArrayGet(pSU2->pTsBuckets,1), i * interval + 5);
  }
  
  SUpdateInfo *pSU3 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark);
  for(int j = 1; j < 100; j++) {
    for(int i = 0; i < pSU3->numSBFs; i++) {
5
54liuyao 已提交
84
      GTEST_ASSERT_EQ(updateInfoIsUpdated(pSU3, i, i * interval + 5 * j), false);
R
root 已提交
85 86 87 88 89 90 91 92 93
      GTEST_ASSERT_EQ(pSU3->minTS, 0);
      GTEST_ASSERT_EQ(pSU3->numSBFs, watermark / interval);
      GTEST_ASSERT_EQ(*(int64_t*)taosArrayGet(pSU3->pTsBuckets, i), i * interval + 5 * j);
      SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU3->pTsSBFs, i);
      SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0);
      GTEST_ASSERT_EQ(pBF->size, j);
    }
  }

5
54liuyao 已提交
94
  SUpdateInfo *pSU4 = updateInfoInit(-1, TSDB_TIME_PRECISION_MILLI, -1);
5
54liuyao 已提交
95
  GTEST_ASSERT_EQ(pSU4->watermark, MAX_NUM_SCALABLE_BF * pSU4->interval);
5
54liuyao 已提交
96 97 98
  GTEST_ASSERT_EQ(pSU4->interval, MILLISECOND_PER_MINUTE);

  SUpdateInfo *pSU5 = updateInfoInit(0, TSDB_TIME_PRECISION_MILLI, 0);
5
54liuyao 已提交
99
  GTEST_ASSERT_EQ(pSU5->watermark, MAX_NUM_SCALABLE_BF * pSU4->interval);
5
54liuyao 已提交
100 101
  GTEST_ASSERT_EQ(pSU5->interval, MILLISECOND_PER_MINUTE);

R
root 已提交
102 103 104 105 106

  updateInfoDestroy(pSU);
  updateInfoDestroy(pSU1);
  updateInfoDestroy(pSU2);
  updateInfoDestroy(pSU3);
5
54liuyao 已提交
107 108
  updateInfoDestroy(pSU4);
  updateInfoDestroy(pSU5);
R
root 已提交
109 110 111 112 113 114
}

int main(int argc, char* argv[]) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}