instance_test.go 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. package instance
  2. import (
  3. "fmt"
  4. "git.sxidc.com/service-supports/dps-sdk/client"
  5. uuid "github.com/satori/go.uuid"
  6. "math/rand"
  7. "strings"
  8. "testing"
  9. "time"
  10. )
  11. func getUUID() string {
  12. return uuid.NewV4().String()
  13. }
  14. func simpleUUID() string {
  15. return strings.ReplaceAll(getUUID(), "-", "")
  16. }
  17. var tableModelDescribe = map[string]string{
  18. "ID": "gorm:\"primary_key;type:varchar(32);comment:id;\"",
  19. "Name": "gorm:\"not null;type:varchar(128);comment:数据库名称;\"",
  20. "Time": "gorm:\"not null;type:timestamp with time zone;comment:数据库时间;\"",
  21. "TableNum": "gorm:\"not null;type:integer;comment:数据库表数量;\"",
  22. }
  23. func TestAutoMigrate(t *testing.T) {
  24. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  25. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  26. newToolKit(t).
  27. autoMigrate([]client.AutoMigrateItem{
  28. {
  29. TablePrefixWithSchema: "test." + simpleUUID()[0:8],
  30. Version: "v1",
  31. TableModelDescribe: tableModelDescribe,
  32. },
  33. })
  34. }
  35. func TestTransaction(t *testing.T) {
  36. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  37. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  38. tablePrefix := "test." + simpleUUID()[0:8]
  39. id := simpleUUID()
  40. name := simpleUUID()
  41. now := time.Now().Local()
  42. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  43. newName := simpleUUID()
  44. newNow := time.Now().Local()
  45. newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  46. var count int64
  47. resultTableRow := client.NewTableRow()
  48. newToolKit(t).
  49. autoMigrate([]client.AutoMigrateItem{
  50. {
  51. TablePrefixWithSchema: tablePrefix,
  52. Version: "v1",
  53. TableModelDescribe: tableModelDescribe,
  54. },
  55. }).
  56. transaction(func(tx client.Transaction) error {
  57. statement, err := tx.InsertTx(&client.InsertRequest{
  58. TablePrefixWithSchema: tablePrefix,
  59. Version: "v1",
  60. KeyColumns: []string{"id"},
  61. TableRow: client.NewTableRow().
  62. AddColumnValueString("id", id).
  63. AddColumnValueString("name", name).
  64. AddColumnValueTime("time", now).
  65. AddColumnValueInt("table_num", tableNum),
  66. UserID: "test",
  67. })
  68. if err != nil {
  69. return err
  70. }
  71. fmt.Println(statement)
  72. return nil
  73. }).
  74. queryByKeys(&client.QueryByKeysRequest{
  75. TablePrefixWithSchema: tablePrefix,
  76. Version: "v1",
  77. KeyValues: map[string]string{"id": id},
  78. }, resultTableRow).
  79. assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
  80. assertEqual(name, resultTableRow.ColumnValueString("name"), "名称不一致").
  81. assertEqual(now.Unix(), resultTableRow.ColumnValueTime("time").Unix(), "时间不一致").
  82. assertEqual(tableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
  83. transaction(func(tx client.Transaction) error {
  84. statement, err := tx.UpdateTx(&client.UpdateRequest{
  85. TablePrefixWithSchema: tablePrefix,
  86. Version: "v1",
  87. KeyValues: map[string]string{"id": id},
  88. NewTableRow: client.NewTableRow().
  89. AddColumnValueString("id", id).
  90. AddColumnValueString("name", newName).
  91. AddColumnValueTime("time", newNow).
  92. AddColumnValueInt("table_num", newTableNum),
  93. UserID: "test",
  94. })
  95. if err != nil {
  96. return err
  97. }
  98. fmt.Println(statement)
  99. return nil
  100. }).
  101. queryByKeys(&client.QueryByKeysRequest{
  102. TablePrefixWithSchema: tablePrefix,
  103. Version: "v1",
  104. KeyValues: map[string]string{"id": id},
  105. }, resultTableRow).
  106. assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
  107. assertEqual(newName, resultTableRow.ColumnValueString("name"), "名称不一致").
  108. assertEqual(newNow.Unix(), resultTableRow.ColumnValueTime("time").Unix(), "时间不一致").
  109. assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
  110. transaction(func(tx client.Transaction) error {
  111. statement, err := tx.UpdateTx(&client.UpdateRequest{
  112. TablePrefixWithSchema: tablePrefix,
  113. Version: "v1",
  114. KeyValues: map[string]string{"id": id},
  115. NewTableRow: client.NewTableRow().
  116. AddColumnValueString("id", id).
  117. AddColumnValueString("name", name).
  118. AddColumnValueTime("time", now).
  119. AddColumnValueInt("table_num", tableNum),
  120. UserID: "test",
  121. })
  122. if err != nil {
  123. return err
  124. }
  125. fmt.Println(statement)
  126. statement, err = tx.DeleteTx(&client.DeleteRequest{
  127. TablePrefixWithSchema: tablePrefix,
  128. Version: "v1",
  129. KeyValues: map[string]string{"id": id},
  130. UserID: "test",
  131. })
  132. if err != nil {
  133. return err
  134. }
  135. fmt.Println(statement)
  136. return nil
  137. }).
  138. countWhere(&client.CountWhereRequest{
  139. TablePrefixWithSchema: tablePrefix,
  140. Version: "v1",
  141. Where: map[string][]any{
  142. "id = ?": {id},
  143. },
  144. }, &count).
  145. assertEqual(int64(0), count, "数量不一致")
  146. }
  147. func TestTransactionBatch(t *testing.T) {
  148. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  149. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  150. tablePrefix := "test." + simpleUUID()[0:8]
  151. id1 := simpleUUID()
  152. name1 := simpleUUID()
  153. now1 := time.Now().Local()
  154. tableNum1 := rand.New(rand.NewSource(now1.Unix())).Intn(10)
  155. id2 := simpleUUID()
  156. name2 := simpleUUID()
  157. now2 := time.Now().Local()
  158. tableNum2 := rand.New(rand.NewSource(now2.Unix())).Intn(10)
  159. var count int64
  160. resultTableRow := client.NewTableRow()
  161. newToolKit(t).
  162. autoMigrate([]client.AutoMigrateItem{
  163. {
  164. TablePrefixWithSchema: tablePrefix,
  165. Version: "v1",
  166. TableModelDescribe: tableModelDescribe,
  167. },
  168. }).
  169. transaction(func(tx client.Transaction) error {
  170. statement, err := tx.InsertBatchTx(&client.InsertBatchRequest{
  171. Items: []client.InsertTableRowItem{
  172. {
  173. TablePrefixWithSchema: tablePrefix,
  174. Version: "v1",
  175. KeyColumns: []string{"id"},
  176. TableRows: []*client.TableRow{
  177. client.NewTableRow().
  178. AddColumnValueString("id", id1).
  179. AddColumnValueString("name", name1).
  180. AddColumnValueTime("time", now1).
  181. AddColumnValueInt("table_num", tableNum1),
  182. client.NewTableRow().
  183. AddColumnValueString("id", id2).
  184. AddColumnValueString("name", name2).
  185. AddColumnValueTime("time", now2).
  186. AddColumnValueInt("table_num", tableNum2),
  187. },
  188. },
  189. },
  190. })
  191. if err != nil {
  192. return err
  193. }
  194. fmt.Println(statement)
  195. return nil
  196. }).
  197. queryByKeys(&client.QueryByKeysRequest{
  198. TablePrefixWithSchema: tablePrefix,
  199. Version: "v1",
  200. KeyValues: map[string]string{"id": id1},
  201. }, resultTableRow).
  202. assertEqual(id1, resultTableRow.ColumnValueString("id"), "ID不一致").
  203. assertEqual(name1, resultTableRow.ColumnValueString("name"), "名称不一致").
  204. assertEqual(now1.Unix(), resultTableRow.ColumnValueTime("time").Unix(), "时间不一致").
  205. assertEqual(tableNum1, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
  206. queryByKeys(&client.QueryByKeysRequest{
  207. TablePrefixWithSchema: tablePrefix,
  208. Version: "v1",
  209. KeyValues: map[string]string{"id": id2},
  210. }, resultTableRow).
  211. assertEqual(id2, resultTableRow.ColumnValueString("id"), "ID不一致").
  212. assertEqual(name2, resultTableRow.ColumnValueString("name"), "名称不一致").
  213. assertEqual(now2.Unix(), resultTableRow.ColumnValueTime("time").Unix(), "时间不一致").
  214. assertEqual(tableNum2, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
  215. transaction(func(tx client.Transaction) error {
  216. statement, err := tx.DeleteBatchTx(&client.DeleteBatchRequest{
  217. Items: []client.DeleteTableRowItem{
  218. {
  219. TablePrefixWithSchema: tablePrefix,
  220. Version: "v1",
  221. KeyValues: []map[string]string{
  222. {"id": id1},
  223. {"id": id2},
  224. },
  225. },
  226. },
  227. UserID: "test",
  228. })
  229. if err != nil {
  230. return err
  231. }
  232. fmt.Println(statement)
  233. return nil
  234. }).
  235. countWhere(&client.CountWhereRequest{
  236. TablePrefixWithSchema: tablePrefix,
  237. Version: "v1",
  238. Where: map[string][]any{
  239. "id = ?": {id1},
  240. },
  241. }, &count).
  242. assertEqual(int64(0), count, "数量不一致").
  243. countWhere(&client.CountWhereRequest{
  244. TablePrefixWithSchema: tablePrefix,
  245. Version: "v1",
  246. Where: map[string][]any{
  247. "id = ?": {id2},
  248. },
  249. }, &count).
  250. assertEqual(int64(0), count, "数量不一致")
  251. }
  252. func TestInsert(t *testing.T) {
  253. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  254. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  255. tablePrefix := "test." + simpleUUID()[0:8]
  256. id := simpleUUID()
  257. name := simpleUUID()
  258. now := time.Now().Local()
  259. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  260. resultTableRow := client.NewTableRow()
  261. var exist bool
  262. newToolKit(t).
  263. autoMigrate([]client.AutoMigrateItem{
  264. {
  265. TablePrefixWithSchema: tablePrefix,
  266. Version: "v1",
  267. TableModelDescribe: tableModelDescribe,
  268. },
  269. }).
  270. insert(&client.InsertRequest{
  271. TablePrefixWithSchema: tablePrefix,
  272. Version: "v1",
  273. KeyColumns: []string{"id"},
  274. TableRow: client.NewTableRow().
  275. AddColumnValueString("id", id).
  276. AddColumnValueString("name", name).
  277. AddColumnValueTime("time", now).
  278. AddColumnValueInt("table_num", tableNum),
  279. UserID: "test",
  280. }).
  281. queryByKeys(&client.QueryByKeysRequest{
  282. TablePrefixWithSchema: tablePrefix,
  283. Version: "v1",
  284. KeyValues: map[string]string{"id": id},
  285. }, resultTableRow).
  286. assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
  287. assertEqual(name, resultTableRow.ColumnValueString("name"), "名称不一致").
  288. assertEqual(now.Unix(), resultTableRow.ColumnValueTime("time").Unix(), "时间不一致").
  289. assertEqual(tableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致").
  290. checkExistWhere(&client.CountWhereRequest{
  291. TablePrefixWithSchema: tablePrefix,
  292. Version: "v1",
  293. Where: map[string][]any{
  294. "id = ?": {id},
  295. },
  296. }, &exist).
  297. assertEqual(true, exist, "存在状态不一致").
  298. commonCheckExist(&client.CommonCountRequest{
  299. TablePrefixWithSchema: tablePrefix,
  300. Version: "v1",
  301. Where: map[string][]any{
  302. "id = ? AND name = ? AND table_num = ?": {id, name, tableNum},
  303. },
  304. }, &exist).
  305. assertEqual(true, exist, "存在状态不一致")
  306. }
  307. func TestInsertBatch(t *testing.T) {
  308. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  309. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  310. tablePrefix := "test." + simpleUUID()[0:8]
  311. id1 := simpleUUID()
  312. name1 := simpleUUID()
  313. now1 := time.Now().Local()
  314. tableNum1 := rand.New(rand.NewSource(now1.Unix())).Intn(10)
  315. id2 := simpleUUID()
  316. name2 := simpleUUID()
  317. now2 := time.Now().Local()
  318. tableNum2 := rand.New(rand.NewSource(now2.Unix())).Intn(10)
  319. resultTableRows := make([]client.TableRow, 0)
  320. var totalCount int64
  321. newToolKit(t).
  322. autoMigrate([]client.AutoMigrateItem{
  323. {
  324. TablePrefixWithSchema: tablePrefix,
  325. Version: "v1",
  326. TableModelDescribe: tableModelDescribe,
  327. },
  328. }).
  329. insertBatch(&client.InsertBatchRequest{
  330. Items: []client.InsertTableRowItem{
  331. {
  332. TablePrefixWithSchema: tablePrefix,
  333. Version: "v1",
  334. KeyColumns: []string{"id"},
  335. TableRows: []*client.TableRow{
  336. client.NewTableRow().
  337. AddColumnValueString("id", id1).
  338. AddColumnValueString("name", name1).
  339. AddColumnValueTime("time", now1).
  340. AddColumnValueInt("table_num", tableNum1),
  341. client.NewTableRow().
  342. AddColumnValueString("id", id2).
  343. AddColumnValueString("name", name2).
  344. AddColumnValueTime("time", now2).
  345. AddColumnValueInt("table_num", tableNum2),
  346. },
  347. },
  348. },
  349. }).
  350. queryByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
  351. TablePrefixWithSchema: tablePrefix,
  352. Version: "v1",
  353. Where: map[string][]any{
  354. "id = ? AND name = ? AND table_num = ?": {id1, name1, tableNum1},
  355. },
  356. PageNo: 1,
  357. PageSize: 1,
  358. }, &resultTableRows, &totalCount).
  359. assertEqual(1, int(totalCount), "总数不一致").
  360. assertEqual(id1, resultTableRows[0].ColumnValueString("id"), "ID不一致").
  361. assertEqual(name1, resultTableRows[0].ColumnValueString("name"), "名称不一致").
  362. assertEqual(now1.Unix(), resultTableRows[0].ColumnValueTime("time").Unix(), "时间不一致").
  363. assertEqual(tableNum1, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致").
  364. commonQuery(&client.CommonQueryRequest{
  365. TablePrefixWithSchema: tablePrefix,
  366. Version: "v1",
  367. Where: map[string][]any{
  368. "id = ? AND name = ? AND table_num = ?": {id2, name2, tableNum2},
  369. },
  370. PageNo: 1,
  371. PageSize: 1,
  372. }, &resultTableRows, &totalCount).
  373. assertEqual(1, int(totalCount), "总数不一致").
  374. assertEqual(id2, resultTableRows[0].ColumnValueString("id"), "ID不一致").
  375. assertEqual(name2, resultTableRows[0].ColumnValueString("name"), "名称不一致").
  376. assertEqual(now2.Unix(), resultTableRows[0].ColumnValueTime("time").Unix(), "时间不一致").
  377. assertEqual(tableNum2, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致").
  378. queryOnlyByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
  379. TablePrefixWithSchema: tablePrefix,
  380. Version: "v1",
  381. Where: map[string][]any{
  382. "id = ? AND name = ? AND table_num = ?": {id1, name1, tableNum1},
  383. },
  384. PageNo: 1,
  385. PageSize: 1,
  386. }, &resultTableRows).
  387. assertEqual(id1, resultTableRows[0].ColumnValueString("id"), "ID不一致").
  388. assertEqual(name1, resultTableRows[0].ColumnValueString("name"), "名称不一致").
  389. assertEqual(now1.Unix(), resultTableRows[0].ColumnValueTime("time").Unix(), "时间不一致").
  390. assertEqual(tableNum1, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致").
  391. commonQueryOnly(&client.CommonQueryRequest{
  392. TablePrefixWithSchema: tablePrefix,
  393. Version: "v1",
  394. Where: map[string][]any{
  395. "id = ? AND name = ? AND table_num = ?": {id2, name2, tableNum2},
  396. },
  397. PageNo: 1,
  398. PageSize: 1,
  399. }, &resultTableRows).
  400. assertEqual(id2, resultTableRows[0].ColumnValueString("id"), "ID不一致").
  401. assertEqual(name2, resultTableRows[0].ColumnValueString("name"), "名称不一致").
  402. assertEqual(now2.Unix(), resultTableRows[0].ColumnValueTime("time").Unix(), "时间不一致").
  403. assertEqual(tableNum2, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致")
  404. }
  405. func TestUpdate(t *testing.T) {
  406. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  407. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  408. tablePrefix := "test." + simpleUUID()[0:8]
  409. id := simpleUUID()
  410. name := simpleUUID()
  411. now := time.Now().Local()
  412. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  413. newName := simpleUUID()
  414. newNow := time.Now().Local()
  415. newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  416. resultTableRow := client.NewTableRow()
  417. newToolKit(t).
  418. autoMigrate([]client.AutoMigrateItem{
  419. {
  420. TablePrefixWithSchema: tablePrefix,
  421. Version: "v1",
  422. TableModelDescribe: tableModelDescribe,
  423. },
  424. }).
  425. insert(&client.InsertRequest{
  426. TablePrefixWithSchema: tablePrefix,
  427. Version: "v1",
  428. KeyColumns: []string{"id"},
  429. TableRow: client.NewTableRow().
  430. AddColumnValueString("id", id).
  431. AddColumnValueString("name", name).
  432. AddColumnValueTime("time", now).
  433. AddColumnValueInt("table_num", tableNum),
  434. UserID: "test",
  435. }).
  436. update(&client.UpdateRequest{
  437. TablePrefixWithSchema: tablePrefix,
  438. Version: "v1",
  439. KeyValues: map[string]string{"id": id},
  440. NewTableRow: client.NewTableRow().
  441. AddColumnValueString("id", id).
  442. AddColumnValueString("name", newName).
  443. AddColumnValueTime("time", newNow).
  444. AddColumnValueInt("table_num", newTableNum),
  445. UserID: "test",
  446. }).
  447. queryByKeys(&client.QueryByKeysRequest{
  448. TablePrefixWithSchema: tablePrefix,
  449. Version: "v1",
  450. KeyValues: map[string]string{"id": id},
  451. }, resultTableRow).
  452. assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
  453. assertEqual(newName, resultTableRow.ColumnValueString("name"), "名称不一致").
  454. assertEqual(newNow.Unix(), resultTableRow.ColumnValueTime("time").Unix(), "时间不一致").
  455. assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致")
  456. }
  457. func TestDelete(t *testing.T) {
  458. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  459. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  460. tablePrefix := "test." + simpleUUID()[0:8]
  461. id := simpleUUID()
  462. name := simpleUUID()
  463. now := time.Now().Local()
  464. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  465. var count int64
  466. newToolKit(t).
  467. autoMigrate([]client.AutoMigrateItem{
  468. {
  469. TablePrefixWithSchema: tablePrefix,
  470. Version: "v1",
  471. TableModelDescribe: tableModelDescribe,
  472. },
  473. }).
  474. insert(&client.InsertRequest{
  475. TablePrefixWithSchema: tablePrefix,
  476. Version: "v1",
  477. KeyColumns: []string{"id"},
  478. TableRow: client.NewTableRow().
  479. AddColumnValueString("id", id).
  480. AddColumnValueString("name", name).
  481. AddColumnValueTime("time", now).
  482. AddColumnValueInt("table_num", tableNum),
  483. UserID: "test",
  484. }).
  485. delete(&client.DeleteRequest{
  486. TablePrefixWithSchema: tablePrefix,
  487. Version: "v1",
  488. KeyValues: map[string]string{"id": id},
  489. UserID: "test",
  490. }).
  491. countWhere(&client.CountWhereRequest{
  492. TablePrefixWithSchema: tablePrefix,
  493. Version: "v1",
  494. Where: map[string][]any{
  495. "id = ?": {id},
  496. },
  497. }, &count).
  498. assertEqual(int64(0), count, "数量不一致")
  499. }
  500. func TestDeleteBatch(t *testing.T) {
  501. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  502. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  503. tablePrefix := "test." + simpleUUID()[0:8]
  504. id1 := simpleUUID()
  505. name1 := simpleUUID()
  506. now1 := time.Now().Local()
  507. tableNum1 := rand.New(rand.NewSource(now1.Unix())).Intn(10)
  508. id2 := simpleUUID()
  509. name2 := simpleUUID()
  510. now2 := time.Now().Local()
  511. tableNum2 := rand.New(rand.NewSource(now2.Unix())).Intn(10)
  512. var count int64
  513. newToolKit(t).
  514. autoMigrate([]client.AutoMigrateItem{
  515. {
  516. TablePrefixWithSchema: tablePrefix,
  517. Version: "v1",
  518. TableModelDescribe: tableModelDescribe,
  519. },
  520. }).
  521. insertBatch(&client.InsertBatchRequest{
  522. Items: []client.InsertTableRowItem{
  523. {
  524. TablePrefixWithSchema: tablePrefix,
  525. Version: "v1",
  526. KeyColumns: []string{"id"},
  527. TableRows: []*client.TableRow{
  528. client.NewTableRow().
  529. AddColumnValueString("id", id1).
  530. AddColumnValueString("name", name1).
  531. AddColumnValueTime("time", now1).
  532. AddColumnValueInt("table_num", tableNum1),
  533. client.NewTableRow().
  534. AddColumnValueString("id", id2).
  535. AddColumnValueString("name", name2).
  536. AddColumnValueTime("time", now2).
  537. AddColumnValueInt("table_num", tableNum2),
  538. },
  539. },
  540. },
  541. }).
  542. deleteBatch(&client.DeleteBatchRequest{
  543. Items: []client.DeleteTableRowItem{
  544. {
  545. TablePrefixWithSchema: tablePrefix,
  546. Version: "v1",
  547. KeyValues: []map[string]string{
  548. {"id": id1},
  549. {"id": id2},
  550. },
  551. },
  552. },
  553. UserID: "test",
  554. }).
  555. commonCount(&client.CommonCountRequest{
  556. TablePrefixWithSchema: tablePrefix,
  557. Version: "v1",
  558. }, &count).
  559. assertEqual(int64(0), count, "数量不一致")
  560. }
  561. func TestReply(t *testing.T) {
  562. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  563. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  564. tablePrefix := "test." + simpleUUID()[0:8]
  565. id := simpleUUID()
  566. name := simpleUUID()
  567. now := time.Now().Local()
  568. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  569. resultTableRow := client.NewTableRow()
  570. newToolKit(t).
  571. autoMigrate([]client.AutoMigrateItem{
  572. {
  573. TablePrefixWithSchema: tablePrefix,
  574. Version: "v1",
  575. TableModelDescribe: tableModelDescribe,
  576. },
  577. }).
  578. insert(&client.InsertRequest{
  579. TablePrefixWithSchema: tablePrefix,
  580. Version: "v1",
  581. KeyColumns: []string{"id"},
  582. TableRow: client.NewTableRow().
  583. AddColumnValueString("id", id).
  584. AddColumnValueString("name", name).
  585. AddColumnValueTime("time", now).
  586. AddColumnValueInt("table_num", tableNum),
  587. UserID: "test",
  588. }).
  589. reply(&client.ReplayRequest{
  590. TablePrefixWithSchema: tablePrefix,
  591. Version: "v1",
  592. KeyValues: map[string]string{"id": id},
  593. UserID: "test",
  594. }).
  595. queryByKeys(&client.QueryByKeysRequest{
  596. TablePrefixWithSchema: tablePrefix,
  597. Version: "v1",
  598. KeyValues: map[string]string{"id": id},
  599. }, resultTableRow).
  600. assertEqual(id, resultTableRow.ColumnValueString("id"), "ID不一致").
  601. assertEqual(name, resultTableRow.ColumnValueString("name"), "名称不一致").
  602. assertEqual(now.Unix(), resultTableRow.ColumnValueTime("time").Unix(), "时间不一致").
  603. assertEqual(tableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致")
  604. }
  605. func TestEventQuery(t *testing.T) {
  606. initClient(t, "localhost:30170", "2b78141779ee432295ca371b91c5cac7")
  607. defer destroyClient(t, "2b78141779ee432295ca371b91c5cac7")
  608. tablePrefix := "test." + simpleUUID()[0:8]
  609. id := simpleUUID()
  610. name := simpleUUID()
  611. now := time.Now().Local()
  612. tableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  613. newName := simpleUUID()
  614. newNow := time.Now().Local()
  615. newTableNum := rand.New(rand.NewSource(now.Unix())).Intn(10)
  616. var exist bool
  617. var totalCount int64
  618. eventInfos := make([]client.EventInfo, 0)
  619. newToolKit(t).
  620. autoMigrate([]client.AutoMigrateItem{
  621. {
  622. TablePrefixWithSchema: tablePrefix,
  623. Version: "v1",
  624. TableModelDescribe: tableModelDescribe,
  625. },
  626. }).
  627. insert(&client.InsertRequest{
  628. TablePrefixWithSchema: tablePrefix,
  629. Version: "v1",
  630. KeyColumns: []string{"id"},
  631. TableRow: client.NewTableRow().
  632. AddColumnValueString("id", id).
  633. AddColumnValueString("name", name).
  634. AddColumnValueTime("time", now).
  635. AddColumnValueInt("table_num", tableNum),
  636. UserID: "test",
  637. }).
  638. checkEventExistByKeys(&client.CountEventByKeysRequest{
  639. TablePrefixWithSchema: tablePrefix,
  640. KeyValues: []string{id},
  641. }, &exist).
  642. assertEqual(true, exist, "存在状态不一致").
  643. commonCheckEventExist(&client.CommonCountEventRequest{
  644. TablePrefixWithSchema: tablePrefix,
  645. KeyValues: []string{id},
  646. Version: "v1",
  647. Operation: "create",
  648. CreatorID: "test",
  649. StartCreatedTime: now.Format(time.DateTime),
  650. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  651. }, &exist).
  652. assertEqual(true, exist, "存在状态不一致").
  653. update(&client.UpdateRequest{
  654. TablePrefixWithSchema: tablePrefix,
  655. Version: "v1",
  656. KeyValues: map[string]string{"id": id},
  657. NewTableRow: client.NewTableRow().
  658. AddColumnValueString("id", id).
  659. AddColumnValueString("name", newName).
  660. AddColumnValueTime("time", newNow).
  661. AddColumnValueInt("table_num", newTableNum),
  662. UserID: "test",
  663. }).
  664. countEventByKeys(&client.CountEventByKeysRequest{
  665. TablePrefixWithSchema: tablePrefix,
  666. KeyValues: []string{id},
  667. }, &totalCount).
  668. assertEqual(2, int(totalCount), "总数不一致").
  669. commonCountEvent(&client.CommonCountEventRequest{
  670. TablePrefixWithSchema: tablePrefix,
  671. KeyValues: []string{id},
  672. Version: "v1",
  673. Operation: "create",
  674. CreatorID: "test",
  675. StartCreatedTime: now.Format(time.DateTime),
  676. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  677. }, &totalCount).
  678. assertEqual(1, int(totalCount), "总数不一致").
  679. commonCountEvent(&client.CommonCountEventRequest{
  680. TablePrefixWithSchema: tablePrefix,
  681. KeyValues: []string{id},
  682. Version: "v1",
  683. Operation: "update",
  684. CreatorID: "test",
  685. StartCreatedTime: now.Format(time.DateTime),
  686. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  687. }, &totalCount).
  688. assertEqual(1, int(totalCount), "总数不一致").
  689. eventQueryByKeys(&client.EventQueryByKeysRequest{
  690. TablePrefixWithSchema: tablePrefix,
  691. KeyValues: []string{id},
  692. PageNo: 0,
  693. PageSize: 0,
  694. }, &eventInfos, &totalCount).
  695. assertEqual(2, int(totalCount), "总数不一致").
  696. assertEqual(2, len(eventInfos), "事件数量不一致").
  697. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  698. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  699. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  700. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  701. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  702. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  703. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  704. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  705. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  706. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  707. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  708. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  709. eventQueryByKeys(&client.EventQueryByKeysRequest{
  710. TablePrefixWithSchema: tablePrefix,
  711. KeyValues: []string{id},
  712. PageNo: 1,
  713. PageSize: 1,
  714. }, &eventInfos, &totalCount).
  715. assertEqual(2, int(totalCount), "总数不一致").
  716. assertEqual(1, len(eventInfos), "事件数量不一致").
  717. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  718. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  719. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  720. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  721. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  722. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  723. commonEventQuery(&client.CommonEventQueryRequest{
  724. TablePrefixWithSchema: tablePrefix,
  725. KeyValues: []string{id},
  726. Version: "v1",
  727. Operation: "create",
  728. CreatorID: "test",
  729. StartCreatedTime: now.Format(time.DateTime),
  730. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  731. PageNo: 0,
  732. PageSize: 0,
  733. }, &eventInfos, &totalCount).
  734. assertEqual(1, int(totalCount), "总数不一致").
  735. assertEqual(1, len(eventInfos), "事件数量不一致").
  736. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  737. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  738. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  739. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  740. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  741. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  742. commonEventQuery(&client.CommonEventQueryRequest{
  743. TablePrefixWithSchema: tablePrefix,
  744. KeyValues: []string{id},
  745. Version: "v1",
  746. Operation: "update",
  747. CreatorID: "test",
  748. StartCreatedTime: now.Format(time.DateTime),
  749. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  750. PageNo: 0,
  751. PageSize: 0,
  752. }, &eventInfos, &totalCount).
  753. assertEqual(1, int(totalCount), "总数不一致").
  754. assertEqual(1, len(eventInfos), "事件数量不一致").
  755. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  756. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  757. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  758. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  759. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  760. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  761. eventQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  762. TablePrefixWithSchema: tablePrefix,
  763. KeyValues: []string{id},
  764. PageNo: 0,
  765. PageSize: 0,
  766. }, &eventInfos).
  767. assertEqual(2, len(eventInfos), "事件数量不一致").
  768. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  769. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  770. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  771. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  772. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  773. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  774. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  775. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  776. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  777. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  778. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  779. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  780. eventQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  781. TablePrefixWithSchema: tablePrefix,
  782. KeyValues: []string{id},
  783. PageNo: 1,
  784. PageSize: 1,
  785. }, &eventInfos).
  786. assertEqual(1, len(eventInfos), "事件数量不一致").
  787. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  788. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  789. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  790. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  791. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  792. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  793. commonEventQueryOnly(&client.CommonEventQueryRequest{
  794. TablePrefixWithSchema: tablePrefix,
  795. KeyValues: []string{id},
  796. Version: "v1",
  797. Operation: "create",
  798. CreatorID: "test",
  799. StartCreatedTime: now.Format(time.DateTime),
  800. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  801. PageNo: 0,
  802. PageSize: 0,
  803. }, &eventInfos).
  804. assertEqual(1, len(eventInfos), "事件数量不一致").
  805. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  806. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  807. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  808. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  809. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  810. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  811. commonEventQueryOnly(&client.CommonEventQueryRequest{
  812. TablePrefixWithSchema: tablePrefix,
  813. KeyValues: []string{id},
  814. Version: "v1",
  815. Operation: "update",
  816. CreatorID: "test",
  817. StartCreatedTime: now.Format(time.DateTime),
  818. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  819. PageNo: 0,
  820. PageSize: 0,
  821. }, &eventInfos).
  822. assertEqual(1, len(eventInfos), "事件数量不一致").
  823. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  824. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  825. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  826. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  827. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  828. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  829. delete(&client.DeleteRequest{
  830. TablePrefixWithSchema: tablePrefix,
  831. Version: "v1",
  832. KeyValues: map[string]string{"id": id},
  833. UserID: "test",
  834. }).
  835. checkEventHistoryExistByKeys(&client.CountEventByKeysRequest{
  836. TablePrefixWithSchema: tablePrefix,
  837. KeyValues: []string{id},
  838. }, &exist).
  839. assertEqual(true, exist, "存在状态不一致").
  840. commonCheckEventHistoryExist(&client.CommonCountEventRequest{
  841. TablePrefixWithSchema: tablePrefix,
  842. KeyValues: []string{id},
  843. Version: "v1",
  844. Operation: "create",
  845. CreatorID: "test",
  846. StartCreatedTime: now.Format(time.DateTime),
  847. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  848. }, &exist).
  849. assertEqual(true, exist, "存在状态不一致").
  850. countEventHistoryByKeys(&client.CountEventByKeysRequest{
  851. TablePrefixWithSchema: tablePrefix,
  852. KeyValues: []string{id},
  853. }, &totalCount).
  854. assertEqual(3, int(totalCount), "总数不一致").
  855. commonCountEventHistory(&client.CommonCountEventRequest{
  856. TablePrefixWithSchema: tablePrefix,
  857. KeyValues: []string{id},
  858. Version: "v1",
  859. Operation: "create",
  860. CreatorID: "test",
  861. StartCreatedTime: now.Format(time.DateTime),
  862. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  863. }, &totalCount).
  864. assertEqual(1, int(totalCount), "总数不一致").
  865. commonCountEventHistory(&client.CommonCountEventRequest{
  866. TablePrefixWithSchema: tablePrefix,
  867. KeyValues: []string{id},
  868. Version: "v1",
  869. Operation: "update",
  870. CreatorID: "test",
  871. StartCreatedTime: now.Format(time.DateTime),
  872. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  873. }, &totalCount).
  874. assertEqual(1, int(totalCount), "总数不一致").
  875. commonCountEventHistory(&client.CommonCountEventRequest{
  876. TablePrefixWithSchema: tablePrefix,
  877. KeyValues: []string{id},
  878. Version: "v1",
  879. Operation: "delete",
  880. CreatorID: "test",
  881. StartCreatedTime: now.Format(time.DateTime),
  882. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  883. }, &totalCount).
  884. assertEqual(1, int(totalCount), "总数不一致").
  885. eventHistoryQueryByKeys(&client.EventQueryByKeysRequest{
  886. TablePrefixWithSchema: tablePrefix,
  887. KeyValues: []string{id},
  888. PageNo: 0,
  889. PageSize: 0,
  890. }, &eventInfos, &totalCount).
  891. assertEqual(3, int(totalCount), "总数不一致").
  892. assertEqual(3, len(eventInfos), "事件数量不一致").
  893. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  894. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  895. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  896. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  897. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  898. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  899. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  900. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  901. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  902. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  903. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  904. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  905. assertEqual(id, eventInfos[2].Key, "关键字段不一致").
  906. assertEqual("v1", eventInfos[2].Version, "版本不一致").
  907. assertEqual("delete", eventInfos[2].Operation, "操作不一致").
  908. assertEqual("test", eventInfos[2].CreatorID, "创建者ID不一致").
  909. assertNotEmpty(eventInfos[2].CreateTime, "创建事件为空").
  910. assertEqual("", eventInfos[2].Value, "值为空不一致").
  911. eventHistoryQueryByKeys(&client.EventQueryByKeysRequest{
  912. TablePrefixWithSchema: tablePrefix,
  913. KeyValues: []string{id},
  914. PageNo: 1,
  915. PageSize: 1,
  916. }, &eventInfos, &totalCount).
  917. assertEqual(3, int(totalCount), "总数不一致").
  918. assertEqual(1, len(eventInfos), "事件数量不一致").
  919. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  920. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  921. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  922. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  923. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  924. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  925. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  926. TablePrefixWithSchema: tablePrefix,
  927. KeyValues: []string{id},
  928. Version: "v1",
  929. Operation: "create",
  930. CreatorID: "test",
  931. StartCreatedTime: now.Format(time.DateTime),
  932. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  933. PageNo: 0,
  934. PageSize: 0,
  935. }, &eventInfos, &totalCount).
  936. assertEqual(1, int(totalCount), "总数不一致").
  937. assertEqual(1, len(eventInfos), "事件数量不一致").
  938. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  939. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  940. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  941. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  942. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  943. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  944. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  945. TablePrefixWithSchema: tablePrefix,
  946. KeyValues: []string{id},
  947. Version: "v1",
  948. Operation: "update",
  949. CreatorID: "test",
  950. StartCreatedTime: now.Format(time.DateTime),
  951. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  952. PageNo: 0,
  953. PageSize: 0,
  954. }, &eventInfos, &totalCount).
  955. assertEqual(1, int(totalCount), "总数不一致").
  956. assertEqual(1, len(eventInfos), "事件数量不一致").
  957. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  958. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  959. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  960. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  961. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  962. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  963. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  964. TablePrefixWithSchema: tablePrefix,
  965. KeyValues: []string{id},
  966. Version: "v1",
  967. Operation: "delete",
  968. CreatorID: "test",
  969. StartCreatedTime: now.Format(time.DateTime),
  970. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  971. PageNo: 0,
  972. PageSize: 0,
  973. }, &eventInfos, &totalCount).
  974. assertEqual(1, int(totalCount), "总数不一致").
  975. assertEqual(1, len(eventInfos), "事件数量不一致").
  976. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  977. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  978. assertEqual("delete", eventInfos[0].Operation, "操作不一致").
  979. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  980. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  981. assertEqual("", eventInfos[0].Value, "值为空不一致").
  982. eventHistoryQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  983. TablePrefixWithSchema: tablePrefix,
  984. KeyValues: []string{id},
  985. PageNo: 0,
  986. PageSize: 0,
  987. }, &eventInfos).
  988. assertEqual(3, len(eventInfos), "事件数量不一致").
  989. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  990. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  991. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  992. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  993. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  994. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  995. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  996. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  997. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  998. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  999. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  1000. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  1001. assertEqual(id, eventInfos[2].Key, "关键字段不一致").
  1002. assertEqual("v1", eventInfos[2].Version, "版本不一致").
  1003. assertEqual("delete", eventInfos[2].Operation, "操作不一致").
  1004. assertEqual("test", eventInfos[2].CreatorID, "创建者ID不一致").
  1005. assertNotEmpty(eventInfos[2].CreateTime, "创建事件为空").
  1006. assertEqual("", eventInfos[2].Value, "值为空不一致").
  1007. eventHistoryQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  1008. TablePrefixWithSchema: tablePrefix,
  1009. KeyValues: []string{id},
  1010. PageNo: 1,
  1011. PageSize: 1,
  1012. }, &eventInfos).
  1013. assertEqual(1, len(eventInfos), "事件数量不一致").
  1014. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1015. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1016. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1017. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1018. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1019. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1020. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1021. TablePrefixWithSchema: tablePrefix,
  1022. KeyValues: []string{id},
  1023. Version: "v1",
  1024. Operation: "create",
  1025. CreatorID: "test",
  1026. StartCreatedTime: now.Format(time.DateTime),
  1027. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1028. PageNo: 0,
  1029. PageSize: 0,
  1030. }, &eventInfos).
  1031. assertEqual(1, len(eventInfos), "事件数量不一致").
  1032. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1033. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1034. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1035. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1036. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1037. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1038. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1039. TablePrefixWithSchema: tablePrefix,
  1040. KeyValues: []string{id},
  1041. Version: "v1",
  1042. Operation: "update",
  1043. CreatorID: "test",
  1044. StartCreatedTime: now.Format(time.DateTime),
  1045. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1046. PageNo: 0,
  1047. PageSize: 0,
  1048. }, &eventInfos).
  1049. assertEqual(1, len(eventInfos), "事件数量不一致").
  1050. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1051. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1052. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  1053. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1054. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1055. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1056. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1057. TablePrefixWithSchema: tablePrefix,
  1058. KeyValues: []string{id},
  1059. Version: "v1",
  1060. Operation: "delete",
  1061. CreatorID: "test",
  1062. StartCreatedTime: now.Format(time.DateTime),
  1063. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1064. PageNo: 0,
  1065. PageSize: 0,
  1066. }, &eventInfos).
  1067. assertEqual(1, len(eventInfos), "事件数量不一致").
  1068. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1069. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1070. assertEqual("delete", eventInfos[0].Operation, "操作不一致").
  1071. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1072. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1073. assertEqual("", eventInfos[0].Value, "值为空不一致")
  1074. }