instance_test.go 48 KB

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