syncRaftLogTest2.cpp 14.0 KB
Newer Older
M
Minghao Li 已提交
1
#include <gtest/gtest.h>
2
#include "syncTest.h"
M
Minghao Li 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

void logTest() {
  sTrace("--- sync log test: trace");
  sDebug("--- sync log test: debug");
  sInfo("--- sync log test: info");
  sWarn("--- sync log test: warn");
  sError("--- sync log test: error");
  sFatal("--- sync log test: fatal");
}

SSyncNode*     pSyncNode;
SWal*          pWal;
SSyncLogStore* pLogStore;
const char*    pWalPath = "./syncLogStoreTest_wal";

M
Minghao Li 已提交
18 19 20
SyncIndex gSnapshotLastApplyIndex;
SyncIndex gSnapshotLastApplyTerm;

M
Minghao Li 已提交
21
int32_t GetSnapshotCb(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
M
Minghao Li 已提交
22 23 24 25 26 27
  pSnapshot->data = NULL;
  pSnapshot->lastApplyIndex = gSnapshotLastApplyIndex;
  pSnapshot->lastApplyTerm = gSnapshotLastApplyTerm;
  return 0;
}

M
Minghao Li 已提交
28 29
bool gAssert = true;

M
Minghao Li 已提交
30 31
void init() {
  walInit();
M
Minghao Li 已提交
32

M
Minghao Li 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  SWalCfg walCfg;
  memset(&walCfg, 0, sizeof(SWalCfg));
  walCfg.vgId = 1000;
  walCfg.fsyncPeriod = 1000;
  walCfg.retentionPeriod = 1000;
  walCfg.rollPeriod = 1000;
  walCfg.retentionSize = 1000;
  walCfg.segSize = 1000;
  walCfg.level = TAOS_WAL_FSYNC;
  pWal = walOpen(pWalPath, &walCfg);
  assert(pWal != NULL);

  pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(SSyncNode));
  memset(pSyncNode, 0, sizeof(SSyncNode));
  pSyncNode->pWal = pWal;
M
Minghao Li 已提交
48 49

  pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM));
S
Shengliang Guan 已提交
50
  // pSyncNode->pFsm->FpGetSnapshotInfo = GetSnapshotCb;
M
Minghao Li 已提交
51 52 53 54 55 56 57 58
}

void cleanup() {
  walClose(pWal);
  walCleanUp();
  taosMemoryFree(pSyncNode);
}

M
Minghao Li 已提交
59
void test1() {
M
Minghao Li 已提交
60
  taosRemoveDir(pWalPath);
M
Minghao Li 已提交
61

M
Minghao Li 已提交
62
  init();
M
Minghao Li 已提交
63 64
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
65
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
66
  logStoreLog2((char*)"\n\n\ntest1 ----- ", pLogStore);
M
Minghao Li 已提交
67 68 69 70 71 72

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 0);
    assert(pLogStore->syncLogEndIndex(pLogStore) == -1);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 0);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 0);
M
Minghao Li 已提交
73
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 1);
M
Minghao Li 已提交
74 75 76 77
    assert(pLogStore->syncLogLastIndex(pLogStore) == -1);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 0);
  }

M
Minghao Li 已提交
78
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
79
  cleanup();
M
Minghao Li 已提交
80

M
Minghao Li 已提交
81 82 83 84
  // restart
  init();
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
85
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
86
  logStoreLog2((char*)"\n\n\ntest1 restart ----- ", pLogStore);
M
Minghao Li 已提交
87 88 89 90 91 92

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 0);
    assert(pLogStore->syncLogEndIndex(pLogStore) == -1);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 0);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 0);
M
Minghao Li 已提交
93
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 1);
M
Minghao Li 已提交
94 95 96 97
    assert(pLogStore->syncLogLastIndex(pLogStore) == -1);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 0);
  }

M
Minghao Li 已提交
98
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
99 100 101 102
  cleanup();
}

void test2() {
M
Minghao Li 已提交
103
  taosRemoveDir(pWalPath);
M
Minghao Li 已提交
104

M
Minghao Li 已提交
105
  init();
M
Minghao Li 已提交
106 107
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
108
  pSyncNode->pLogStore = pLogStore;
109
  // pLogStore->syncLogSetBeginIndex(pLogStore, 5);
110
  pLogStore->syncLogRestoreFromSnapshot(pLogStore, 4);
M
Minghao Li 已提交
111
  logStoreLog2((char*)"\n\n\ntest2 ----- ", pLogStore);
M
Minghao Li 已提交
112 113 114 115 116 117

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == -1);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 0);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 5);
M
Minghao Li 已提交
118
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 1);
M
Minghao Li 已提交
119 120 121 122
    assert(pLogStore->syncLogLastIndex(pLogStore) == -1);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 0);
  }

M
Minghao Li 已提交
123
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
124
  cleanup();
M
Minghao Li 已提交
125

M
Minghao Li 已提交
126 127 128 129
  // restart
  init();
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
130
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
131
  logStoreLog2((char*)"\n\n\ntest2 restart ----- ", pLogStore);
M
Minghao Li 已提交
132 133 134 135 136 137

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == -1);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 0);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 5);
M
Minghao Li 已提交
138
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 1);
M
Minghao Li 已提交
139 140 141 142
    assert(pLogStore->syncLogLastIndex(pLogStore) == -1);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 0);
  }

M
Minghao Li 已提交
143
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
144 145 146 147
  cleanup();
}

void test3() {
M
Minghao Li 已提交
148
  taosRemoveDir(pWalPath);
M
Minghao Li 已提交
149

M
Minghao Li 已提交
150
  init();
M
Minghao Li 已提交
151 152
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
153
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
154
  logStoreLog2((char*)"\n\n\ntest3 ----- ", pLogStore);
M
Minghao Li 已提交
155

M
Minghao Li 已提交
156 157 158 159 160
  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 0);
    assert(pLogStore->syncLogEndIndex(pLogStore) == -1);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 0);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 0);
M
Minghao Li 已提交
161
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 1);
M
Minghao Li 已提交
162 163 164 165
    assert(pLogStore->syncLogLastIndex(pLogStore) == -1);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 0);
  }

M
Minghao Li 已提交
166
  for (int i = 0; i <= 4; ++i) {
M
Minghao Li 已提交
167 168 169 170 171 172 173 174
    int32_t         dataLen = 10;
    SSyncRaftEntry* pEntry = syncEntryBuild(dataLen);
    assert(pEntry != NULL);
    pEntry->msgType = 1;
    pEntry->originalRpcType = 2;
    pEntry->seqNum = 3;
    pEntry->isWeak = true;
    pEntry->term = 100 + i;
M
Minghao Li 已提交
175
    pEntry->index = pLogStore->syncLogWriteIndex(pLogStore);
M
Minghao Li 已提交
176 177
    snprintf(pEntry->data, dataLen, "value%d", i);

M
Minghao Li 已提交
178
    pLogStore->syncLogAppendEntry(pLogStore, pEntry);
M
Minghao Li 已提交
179 180
    syncEntryDestory(pEntry);
  }
M
Minghao Li 已提交
181
  logStoreLog2((char*)"test3 after appendEntry", pLogStore);
M
Minghao Li 已提交
182 183 184 185 186 187

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 0);
    assert(pLogStore->syncLogEndIndex(pLogStore) == 4);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 5);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 5);
M
Minghao Li 已提交
188
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 0);
M
Minghao Li 已提交
189 190 191 192
    assert(pLogStore->syncLogLastIndex(pLogStore) == 4);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 104);
  }

M
Minghao Li 已提交
193
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
194
  cleanup();
M
Minghao Li 已提交
195

M
Minghao Li 已提交
196 197 198 199
  // restart
  init();
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
200
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
201
  logStoreLog2((char*)"\n\n\ntest3 restart ----- ", pLogStore);
M
Minghao Li 已提交
202 203 204 205 206 207

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 0);
    assert(pLogStore->syncLogEndIndex(pLogStore) == 4);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 5);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 5);
M
Minghao Li 已提交
208
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 0);
M
Minghao Li 已提交
209 210 211 212
    assert(pLogStore->syncLogLastIndex(pLogStore) == 4);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 104);
  }

M
Minghao Li 已提交
213
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
214 215 216 217
  cleanup();
}

void test4() {
M
Minghao Li 已提交
218
  taosRemoveDir(pWalPath);
M
Minghao Li 已提交
219

M
Minghao Li 已提交
220
  init();
M
Minghao Li 已提交
221 222
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
223
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
224
  logStoreLog2((char*)"\n\n\ntest4 ----- ", pLogStore);
225
  // pLogStore->syncLogSetBeginIndex(pLogStore, 5);
226
  pLogStore->syncLogRestoreFromSnapshot(pLogStore, 4);
M
Minghao Li 已提交
227

M
Minghao Li 已提交
228 229 230 231 232 233 234 235 236 237 238
  for (int i = 5; i <= 9; ++i) {
    int32_t         dataLen = 10;
    SSyncRaftEntry* pEntry = syncEntryBuild(dataLen);
    assert(pEntry != NULL);
    pEntry->msgType = 1;
    pEntry->originalRpcType = 2;
    pEntry->seqNum = 3;
    pEntry->isWeak = true;
    pEntry->term = 100 + i;
    pEntry->index = pLogStore->syncLogWriteIndex(pLogStore);
    snprintf(pEntry->data, dataLen, "value%d", i);
M
Minghao Li 已提交
239

M
Minghao Li 已提交
240 241 242 243
    pLogStore->syncLogAppendEntry(pLogStore, pEntry);
    syncEntryDestory(pEntry);
  }
  logStoreLog2((char*)"test4 after appendEntry", pLogStore);
M
Minghao Li 已提交
244 245 246 247 248 249

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == 9);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 5);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 10);
M
Minghao Li 已提交
250
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 0);
M
Minghao Li 已提交
251 252 253 254
    assert(pLogStore->syncLogLastIndex(pLogStore) == 9);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 109);
  }

M
Minghao Li 已提交
255
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
256
  cleanup();
M
Minghao Li 已提交
257

M
Minghao Li 已提交
258 259 260 261
  // restart
  init();
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
262
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
263
  logStoreLog2((char*)"\n\n\ntest4 restart ----- ", pLogStore);
M
Minghao Li 已提交
264 265 266 267 268 269

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == 9);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 5);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 10);
M
Minghao Li 已提交
270
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 0);
M
Minghao Li 已提交
271 272 273 274
    assert(pLogStore->syncLogLastIndex(pLogStore) == 9);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 109);
  }

M
Minghao Li 已提交
275
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
276
  cleanup();
M
Minghao Li 已提交
277 278
}

M
Minghao Li 已提交
279
void test5() {
M
Minghao Li 已提交
280
  taosRemoveDir(pWalPath);
M
Minghao Li 已提交
281

M
Minghao Li 已提交
282
  init();
M
Minghao Li 已提交
283 284
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
285
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
286
  logStoreLog2((char*)"\n\n\ntest5 ----- ", pLogStore);
287
  // pLogStore->syncLogSetBeginIndex(pLogStore, 5);
288
  pLogStore->syncLogRestoreFromSnapshot(pLogStore, 4);
M
Minghao Li 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

  for (int i = 5; i <= 9; ++i) {
    int32_t         dataLen = 10;
    SSyncRaftEntry* pEntry = syncEntryBuild(dataLen);
    assert(pEntry != NULL);
    pEntry->msgType = 1;
    pEntry->originalRpcType = 2;
    pEntry->seqNum = 3;
    pEntry->isWeak = true;
    pEntry->term = 100 + i;
    pEntry->index = pLogStore->syncLogWriteIndex(pLogStore);
    snprintf(pEntry->data, dataLen, "value%d", i);

    pLogStore->syncLogAppendEntry(pLogStore, pEntry);
    syncEntryDestory(pEntry);
  }
  logStoreLog2((char*)"test5 after appendEntry", pLogStore);

M
Minghao Li 已提交
307 308 309 310 311
  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == 9);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 5);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 10);
M
Minghao Li 已提交
312
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 0);
M
Minghao Li 已提交
313 314 315 316
    assert(pLogStore->syncLogLastIndex(pLogStore) == 9);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 109);
  }

M
Minghao Li 已提交
317 318 319
  pLogStore->syncLogTruncate(pLogStore, 7);
  logStoreLog2((char*)"after truncate 7", pLogStore);

M
Minghao Li 已提交
320 321 322 323 324
  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == 6);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 2);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 7);
M
Minghao Li 已提交
325
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 0);
M
Minghao Li 已提交
326 327 328 329
    assert(pLogStore->syncLogLastIndex(pLogStore) == 6);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 106);
  }

M
Minghao Li 已提交
330
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
331
  cleanup();
M
Minghao Li 已提交
332

M
Minghao Li 已提交
333 334 335 336
  // restart
  init();
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
337
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
338
  logStoreLog2((char*)"\n\n\ntest5 restart ----- ", pLogStore);
M
Minghao Li 已提交
339 340 341 342 343 344

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == 6);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 2);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 7);
M
Minghao Li 已提交
345
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 0);
M
Minghao Li 已提交
346 347 348 349
    assert(pLogStore->syncLogLastIndex(pLogStore) == 6);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 106);
  }

M
Minghao Li 已提交
350
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
351 352
  cleanup();
}
M
Minghao Li 已提交
353

M
Minghao Li 已提交
354
void test6() {
M
Minghao Li 已提交
355
  taosRemoveDir(pWalPath);
M
Minghao Li 已提交
356

M
Minghao Li 已提交
357
  init();
M
Minghao Li 已提交
358 359
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
360
  pSyncNode->pLogStore = pLogStore;
M
Minghao Li 已提交
361
  logStoreLog2((char*)"\n\n\ntest6 ----- ", pLogStore);
362 363
  // pLogStore->syncLogSetBeginIndex(pLogStore, 5);
  pLogStore->syncLogRestoreFromSnapshot(pLogStore, 4);
M
Minghao Li 已提交
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381

  for (int i = 5; i <= 9; ++i) {
    int32_t         dataLen = 10;
    SSyncRaftEntry* pEntry = syncEntryBuild(dataLen);
    assert(pEntry != NULL);
    pEntry->msgType = 1;
    pEntry->originalRpcType = 2;
    pEntry->seqNum = 3;
    pEntry->isWeak = true;
    pEntry->term = 100 + i;
    pEntry->index = pLogStore->syncLogWriteIndex(pLogStore);
    snprintf(pEntry->data, dataLen, "value%d", i);

    pLogStore->syncLogAppendEntry(pLogStore, pEntry);
    syncEntryDestory(pEntry);
  }
  logStoreLog2((char*)"test6 after appendEntry", pLogStore);

M
Minghao Li 已提交
382 383 384 385 386
  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == 9);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 5);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 10);
M
Minghao Li 已提交
387
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 0);
M
Minghao Li 已提交
388 389 390 391
    assert(pLogStore->syncLogLastIndex(pLogStore) == 9);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 109);
  }

M
Minghao Li 已提交
392 393 394
  pLogStore->syncLogTruncate(pLogStore, 5);
  logStoreLog2((char*)"after truncate 5", pLogStore);

M
Minghao Li 已提交
395 396 397 398 399
  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == -1);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 0);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 5);
M
Minghao Li 已提交
400
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 1);
M
Minghao Li 已提交
401 402 403 404
    assert(pLogStore->syncLogLastIndex(pLogStore) == -1);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 0);
  }

405 406 407
  do {
    SyncIndex firstVer = walGetFirstVer(pWal);
    SyncIndex lastVer = walGetLastVer(pWal);
408
    bool      isEmpty = walIsEmpty(pWal);
S
Shengliang Guan 已提交
409
    printf("before -------- firstVer:%" PRId64 " lastVer:%" PRId64 " isEmpty:%d \n", firstVer, lastVer, isEmpty);
410 411
  } while (0);

M
Minghao Li 已提交
412
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
413
  cleanup();
M
Minghao Li 已提交
414

M
Minghao Li 已提交
415 416 417 418
  // restart
  init();
  pLogStore = logStoreCreate(pSyncNode);
  assert(pLogStore);
419
  pSyncNode->pLogStore = pLogStore;
420 421 422 423

  do {
    SyncIndex firstVer = walGetFirstVer(pWal);
    SyncIndex lastVer = walGetLastVer(pWal);
424
    bool      isEmpty = walIsEmpty(pWal);
S
Shengliang Guan 已提交
425
    printf("after -------- firstVer:%" PRId64 " lastVer:%" PRId64 " isEmpty:%d \n", firstVer, lastVer, isEmpty);
426 427
  } while (0);

M
Minghao Li 已提交
428
  logStoreLog2((char*)"\n\n\ntest6 restart ----- ", pLogStore);
M
Minghao Li 已提交
429 430 431 432 433 434

  if (gAssert) {
    assert(pLogStore->syncLogBeginIndex(pLogStore) == 5);
    assert(pLogStore->syncLogEndIndex(pLogStore) == -1);
    assert(pLogStore->syncLogEntryCount(pLogStore) == 0);
    assert(pLogStore->syncLogWriteIndex(pLogStore) == 5);
M
Minghao Li 已提交
435
    assert(pLogStore->syncLogIsEmpty(pLogStore) == 1);
M
Minghao Li 已提交
436 437 438 439
    assert(pLogStore->syncLogLastIndex(pLogStore) == -1);
    assert(pLogStore->syncLogLastTerm(pLogStore) == 0);
  }

M
Minghao Li 已提交
440
  logStoreDestory(pLogStore);
M
Minghao Li 已提交
441
  cleanup();
M
Minghao Li 已提交
442 443 444 445 446
}

int main(int argc, char** argv) {
  tsAsyncLog = 0;
  sDebugFlag = DEBUG_TRACE + DEBUG_INFO + DEBUG_SCREEN + DEBUG_FILE;
447
  gRaftDetailLog = true;
M
Minghao Li 已提交
448

M
Minghao Li 已提交
449 450 451 452 453
  if (argc == 2) {
    gAssert = atoi(argv[1]);
  }
  sTrace("gAssert : %d", gAssert);

454 455 456 457 458 459 460
  /*
    test1();
    test2();
    test3();
    test4();
    test5();
  */
M
Minghao Li 已提交
461
  test6();
M
Minghao Li 已提交
462 463 464

  return 0;
}