instance_test.go 46 KB

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