instance_test.go 48 KB

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