v1_test.go 47 KB

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