| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- ============================================================
- TsDB2 全功能综合测试
- 涵盖: 表/索引/CRUD/事务/WAL/BufferPool/提交策略/恢复
- ============================================================
- ================================================== 1. 数据库配置与打开
- ✅ OpenDB
- ✅ 配置: BufferPool=200页, DirtyThreshold=50页, Debounce=500ms, Preset=online
- ================================================== 2. 表创建 (泛型 UseTable)
- ✅ UseTable[User] (自动建表+主键索引)
- ✅ UseTable[Order] (自动建表+主键索引)
- ✅ 重复 UseTable[User] 自动同步 schema
- ================================================== 3. 二级索引创建 (标签自动创建)
- ✅ 索引已通过标签自动创建
- ================================================== 4. 基础 CRUD
- ✅ Insert 20 行 (ID=1~20)
- ✅ Find(5): Name=User005 Age=25 Score=65 Dept=D0
- ✅ Update(5) Score=999
- ✅ 验证更新: Score=999
- ✅ Delete(10)
- ✅ 验证删除: ID=10 不存在
- ================================================== 5. 条件查询
- ✅ WHERE Age=25: 0 行
- ✅ WHERE Age>=20 AND Age<=25: 4 行
- ✅ WHERE Age>40: 0 行
- ✅ WHERE Name LIKE 'User%': 18 行
- ✅ WHERE Age!=25: 19 行
- ================================================== 6. 排序 + 分页
- ✅ ORDER BY Age DESC LIMIT 5:
- [1] Name=User020 Age=40 Score=110
- [2] Name=User019 Age=39 Score=107
- [3] Name=User018 Age=38 Score=104
- [4] Name=User017 Age=37 Score=101
- [5] Name=User016 Age=36 Score=98
- ✅ ORDER BY Age ASC OFFSET 5 LIMIT 5:
- [1] Name=User006 Age=26 Score=68
- [2] Name=User007 Age=27 Score=71
- [3] Name=User008 Age=28 Score=74
- [4] Name=User009 Age=29 Score=77
- [5] Name=User011 Age=31 Score=83
- ================================================== 7. 聚合查询
- ✅ COUNT(*): 19
- ✅ COUNT WHERE Age=25: 0
- ================================================== 8. Scan 流式遍历
- ✅ Scan LIMIT 10: 遍历 10 行
- ================================================== 9. 事务 - 提交
- ✅ 事务内插入 10 行 (ID=21~30)
- ✅ 事务内 Update(21) Score=8888
- ✅ 事务内 Delete(25)
- ✅ Transaction.Commit()
- ✅ 提交后验证: ID=21 Score=8888
- ✅ 提交后验证: ID=25 已删除
- ================================================== 10. 事务 - 回滚
- ✅ 事务内插入 10 行 (ID=31~40)
- ✅ Transaction.Rollback()
- ⏳ 回滚后数据验证将在重开后进行
- ================================================== 11. WAL + Commit 持久化
- ✅ DB.Commit() (WAL 写入)
- ================================================== 12. 多表操作
- ✅ orders 表插入 10 行
- ✅ orders WHERE Status=0: 3 行
- ================================================== 13. DropTable
- ✅ DropTable orders
- ✅ orders 表已不存在
- ✅ users 表不受影响
- ================================================== 14. 关闭 + 重开验证持久化
- ✅ DB.Close()
- ✅ 重新打开数据库
- ✅ 重开后 Find(1): Name=User001 Age=21
- ✅ 重开后 Find(5): Score=999 (更新持久化)
- ✅ 重开后 ID=10 (已删除) 不存在
- ✅ 重开后 Find(21) (事务提交+更新): Score=8888
- ✅ 重开后 ID=25 (事务内删除) 不存在
- ✅ 重开后 ID=31 (回滚) 不存在
- ================================================== 15. 防抖自动提交
- ✅ 插入 10 行, 等待防抖自动提交 (500ms)...
- ✅ 防抖自动提交后重开: ID=5 存在 (Name=Auto005)
- ================================================== 16. LockTable 机制
- ✅ LockWrites() 成功
- ✅ UnlockWrites() 成功
- ================================================== 17. 提交策略预设
- ✅ Preset 'batch' 设置成功
- ✅ Preset 'online' 设置成功
- ✅ Preset 'safe' 设置成功
- ================================================== 18. 批量插入 (BatchInsert)
- ✅ BatchInsert 10 行
- ================================================== 19. First 查询
- ✅ First(): Name=Auto001 Age=25
- ================================================== 20. FindAll
- ✅ FindAll(): 20 行
- ============================================================
- 测试结果: 53 通过, 0 失败
- 🎉 全部通过!
- ============================================================
|