v1_test.go 47 KB

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