instance_test.go 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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", "ee2d7dabe56646ce835d80873348ee0e")
  28. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  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", "ee2d7dabe56646ce835d80873348ee0e")
  41. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  42. tablePrefix := "test." + simpleUUID()[0:8]
  43. id := simpleUUID()
  44. name := simpleUUID()
  45. now := time.Now().Local()
  46. tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
  47. newName := simpleUUID()
  48. newNow := time.Now().Local()
  49. newTableNum := rand.New(rand.NewSource(now.UnixMicro())).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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  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", "ee2d7dabe56646ce835d80873348ee0e")
  183. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  184. tablePrefix := "test." + simpleUUID()[0:8]
  185. id1 := simpleUUID()
  186. name1 := simpleUUID()
  187. now1 := time.Now().Local()
  188. tableNum1 := rand.New(rand.NewSource(now1.UnixMicro())).Intn(10)
  189. id2 := simpleUUID()
  190. name2 := simpleUUID()
  191. now2 := time.Now().Local()
  192. tableNum2 := rand.New(rand.NewSource(now2.UnixMicro())).Intn(10)
  193. newName := simpleUUID()
  194. newNow := time.Now().Local()
  195. newTableNum := rand.New(rand.NewSource(newNow.UnixMicro())).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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  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", "ee2d7dabe56646ce835d80873348ee0e")
  318. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  319. tablePrefix := "test." + simpleUUID()[0:8]
  320. id := simpleUUID()
  321. name := simpleUUID()
  322. now := time.Now().Local()
  323. tableNum := rand.New(rand.NewSource(now.UnixMicro())).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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  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", "ee2d7dabe56646ce835d80873348ee0e")
  373. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  374. tablePrefix := "test." + simpleUUID()[0:8]
  375. id1 := simpleUUID()
  376. name1 := simpleUUID()
  377. now1 := time.Now().Local()
  378. tableNum1 := rand.New(rand.NewSource(now1.UnixMicro())).Intn(10)
  379. id2 := simpleUUID()
  380. name2 := simpleUUID()
  381. now2 := time.Now().Local()
  382. tableNum2 := rand.New(rand.NewSource(now2.UnixMicro())).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.UnixMicro(), resultTableRows[0].ColumnValueTime("time").UnixMicro(), "时间不一致").
  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.UnixMicro(), resultTableRows[0].ColumnValueTime("time").UnixMicro(), "时间不一致").
  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.UnixMicro(), resultTableRows[0].ColumnValueTime("time").UnixMicro(), "时间不一致").
  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.UnixMicro(), resultTableRows[0].ColumnValueTime("time").UnixMicro(), "时间不一致").
  472. assertEqual(tableNum2, resultTableRows[0].ColumnValueInt("table_num"), "表数量不一致")
  473. }
  474. func TestUpdate(t *testing.T) {
  475. initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
  476. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  477. tablePrefix := "test." + simpleUUID()[0:8]
  478. id := simpleUUID()
  479. name := simpleUUID()
  480. now := time.Now().Local()
  481. tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
  482. newName := simpleUUID()
  483. newNow := time.Now().Local()
  484. newTableNum := rand.New(rand.NewSource(now.UnixMicro())).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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  525. assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致")
  526. }
  527. func TestUpdateWhere(t *testing.T) {
  528. initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
  529. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  530. tablePrefix := "test." + simpleUUID()[0:8]
  531. id := simpleUUID()
  532. name := simpleUUID()
  533. now := time.Now().Local()
  534. tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
  535. newName := simpleUUID()
  536. newNow := time.Now().Local()
  537. newTableNum := rand.New(rand.NewSource(now.UnixMicro())).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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  579. assertEqual(newTableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致")
  580. }
  581. func TestDelete(t *testing.T) {
  582. initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
  583. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  584. tablePrefix := "test." + simpleUUID()[0:8]
  585. id := simpleUUID()
  586. name := simpleUUID()
  587. now := time.Now().Local()
  588. tableNum := rand.New(rand.NewSource(now.UnixMicro())).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", "ee2d7dabe56646ce835d80873348ee0e")
  625. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  626. tablePrefix := "test." + simpleUUID()[0:8]
  627. id := simpleUUID()
  628. name := simpleUUID()
  629. now := time.Now().Local()
  630. tableNum := rand.New(rand.NewSource(now.UnixMicro())).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", "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.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.UnixMicro(), resultTableRow.ColumnValueTime("time").UnixMicro(), "时间不一致").
  709. assertEqual(tableNum, resultTableRow.ColumnValueInt("table_num"), "表数量不一致")
  710. }
  711. func TestEventQuery(t *testing.T) {
  712. if noEvent {
  713. return
  714. }
  715. initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
  716. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  717. tablePrefix := "test." + simpleUUID()[0:8]
  718. id := simpleUUID()
  719. name := simpleUUID()
  720. now := time.Now().Local()
  721. tableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
  722. newName := simpleUUID()
  723. newNow := time.Now().Local()
  724. newTableNum := rand.New(rand.NewSource(now.UnixMicro())).Intn(10)
  725. var exist bool
  726. var totalCount int64
  727. eventInfos := make([]client.EventInfo, 0)
  728. newToolKit(t).
  729. autoMigrate([]client.AutoMigrateItem{
  730. {
  731. TablePrefixWithSchema: tablePrefix,
  732. Version: "v1",
  733. TableModelDescribe: tableModelDescribe,
  734. NoEvent: noEvent,
  735. },
  736. }).
  737. insert(&client.InsertRequest{
  738. TablePrefixWithSchema: tablePrefix,
  739. Version: "v1",
  740. KeyColumns: []string{"id"},
  741. TableRow: client.NewTableRow().
  742. AddColumnValueString("id", id).
  743. AddColumnValueString("name", name).
  744. AddColumnValueTime("time", now).
  745. AddColumnValueInt("table_num", tableNum),
  746. UserID: "test",
  747. }).
  748. checkEventExistByKeys(&client.CountEventByKeysRequest{
  749. TablePrefixWithSchema: tablePrefix,
  750. KeyValues: []string{id},
  751. }, &exist).
  752. assertEqual(true, exist, "存在状态不一致").
  753. commonCheckEventExist(&client.CommonCountEventRequest{
  754. TablePrefixWithSchema: tablePrefix,
  755. KeyValues: []string{id},
  756. Version: "v1",
  757. Operation: "create",
  758. CreatorID: "test",
  759. StartCreatedTime: now.Format(time.DateTime),
  760. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  761. }, &exist).
  762. assertEqual(true, exist, "存在状态不一致").
  763. update(&client.UpdateRequest{
  764. TablePrefixWithSchema: tablePrefix,
  765. Version: "v1",
  766. KeyValues: client.NewKeyValue().Add("id", id),
  767. NewTableRow: client.NewTableRow().
  768. AddColumnValueString("id", id).
  769. AddColumnValueString("name", newName).
  770. AddColumnValueTime("time", newNow).
  771. AddColumnValueInt("table_num", newTableNum),
  772. UserID: "test",
  773. }).
  774. countEventByKeys(&client.CountEventByKeysRequest{
  775. TablePrefixWithSchema: tablePrefix,
  776. KeyValues: []string{id},
  777. }, &totalCount).
  778. assertEqual(2, int(totalCount), "总数不一致").
  779. commonCountEvent(&client.CommonCountEventRequest{
  780. TablePrefixWithSchema: tablePrefix,
  781. KeyValues: []string{id},
  782. Version: "v1",
  783. Operation: "create",
  784. CreatorID: "test",
  785. StartCreatedTime: now.Format(time.DateTime),
  786. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  787. }, &totalCount).
  788. assertEqual(1, int(totalCount), "总数不一致").
  789. commonCountEvent(&client.CommonCountEventRequest{
  790. TablePrefixWithSchema: tablePrefix,
  791. KeyValues: []string{id},
  792. Version: "v1",
  793. Operation: "update",
  794. CreatorID: "test",
  795. StartCreatedTime: now.Format(time.DateTime),
  796. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  797. }, &totalCount).
  798. assertEqual(1, int(totalCount), "总数不一致").
  799. eventQueryByKeys(&client.EventQueryByKeysRequest{
  800. TablePrefixWithSchema: tablePrefix,
  801. KeyValues: []string{id},
  802. PageNo: 0,
  803. PageSize: 0,
  804. }, &eventInfos, &totalCount).
  805. assertEqual(2, int(totalCount), "总数不一致").
  806. assertEqual(2, len(eventInfos), "事件数量不一致").
  807. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  808. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  809. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  810. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  811. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  812. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  813. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  814. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  815. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  816. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  817. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  818. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  819. eventQueryByKeys(&client.EventQueryByKeysRequest{
  820. TablePrefixWithSchema: tablePrefix,
  821. KeyValues: []string{id},
  822. PageNo: 1,
  823. PageSize: 1,
  824. }, &eventInfos, &totalCount).
  825. assertEqual(2, int(totalCount), "总数不一致").
  826. assertEqual(1, len(eventInfos), "事件数量不一致").
  827. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  828. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  829. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  830. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  831. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  832. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  833. commonEventQuery(&client.CommonEventQueryRequest{
  834. TablePrefixWithSchema: tablePrefix,
  835. KeyValues: []string{id},
  836. Version: "v1",
  837. Operation: "create",
  838. CreatorID: "test",
  839. StartCreatedTime: now.Format(time.DateTime),
  840. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  841. PageNo: 0,
  842. PageSize: 0,
  843. }, &eventInfos, &totalCount).
  844. assertEqual(1, int(totalCount), "总数不一致").
  845. assertEqual(1, len(eventInfos), "事件数量不一致").
  846. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  847. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  848. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  849. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  850. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  851. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  852. commonEventQuery(&client.CommonEventQueryRequest{
  853. TablePrefixWithSchema: tablePrefix,
  854. KeyValues: []string{id},
  855. Version: "v1",
  856. Operation: "update",
  857. CreatorID: "test",
  858. StartCreatedTime: now.Format(time.DateTime),
  859. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  860. PageNo: 0,
  861. PageSize: 0,
  862. }, &eventInfos, &totalCount).
  863. assertEqual(1, int(totalCount), "总数不一致").
  864. assertEqual(1, len(eventInfos), "事件数量不一致").
  865. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  866. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  867. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  868. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  869. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  870. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  871. eventQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  872. TablePrefixWithSchema: tablePrefix,
  873. KeyValues: []string{id},
  874. PageNo: 0,
  875. PageSize: 0,
  876. }, &eventInfos).
  877. assertEqual(2, len(eventInfos), "事件数量不一致").
  878. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  879. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  880. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  881. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  882. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  883. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  884. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  885. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  886. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  887. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  888. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  889. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  890. eventQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  891. TablePrefixWithSchema: tablePrefix,
  892. KeyValues: []string{id},
  893. PageNo: 1,
  894. PageSize: 1,
  895. }, &eventInfos).
  896. assertEqual(1, len(eventInfos), "事件数量不一致").
  897. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  898. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  899. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  900. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  901. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  902. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  903. commonEventQueryOnly(&client.CommonEventQueryRequest{
  904. TablePrefixWithSchema: tablePrefix,
  905. KeyValues: []string{id},
  906. Version: "v1",
  907. Operation: "create",
  908. CreatorID: "test",
  909. StartCreatedTime: now.Format(time.DateTime),
  910. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  911. PageNo: 0,
  912. PageSize: 0,
  913. }, &eventInfos).
  914. assertEqual(1, len(eventInfos), "事件数量不一致").
  915. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  916. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  917. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  918. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  919. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  920. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  921. commonEventQueryOnly(&client.CommonEventQueryRequest{
  922. TablePrefixWithSchema: tablePrefix,
  923. KeyValues: []string{id},
  924. Version: "v1",
  925. Operation: "update",
  926. CreatorID: "test",
  927. StartCreatedTime: now.Format(time.DateTime),
  928. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  929. PageNo: 0,
  930. PageSize: 0,
  931. }, &eventInfos).
  932. assertEqual(1, len(eventInfos), "事件数量不一致").
  933. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  934. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  935. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  936. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  937. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  938. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  939. delete(&client.DeleteRequest{
  940. TablePrefixWithSchema: tablePrefix,
  941. Version: "v1",
  942. KeyValues: client.NewKeyValue().Add("id", id),
  943. UserID: "test",
  944. }).
  945. checkEventHistoryExistByKeys(&client.CountEventByKeysRequest{
  946. TablePrefixWithSchema: tablePrefix,
  947. KeyValues: []string{id},
  948. }, &exist).
  949. assertEqual(true, exist, "存在状态不一致").
  950. commonCheckEventHistoryExist(&client.CommonCountEventRequest{
  951. TablePrefixWithSchema: tablePrefix,
  952. KeyValues: []string{id},
  953. Version: "v1",
  954. Operation: "create",
  955. CreatorID: "test",
  956. StartCreatedTime: now.Format(time.DateTime),
  957. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  958. }, &exist).
  959. assertEqual(true, exist, "存在状态不一致").
  960. countEventHistoryByKeys(&client.CountEventByKeysRequest{
  961. TablePrefixWithSchema: tablePrefix,
  962. KeyValues: []string{id},
  963. }, &totalCount).
  964. assertEqual(3, int(totalCount), "总数不一致").
  965. commonCountEventHistory(&client.CommonCountEventRequest{
  966. TablePrefixWithSchema: tablePrefix,
  967. KeyValues: []string{id},
  968. Version: "v1",
  969. Operation: "create",
  970. CreatorID: "test",
  971. StartCreatedTime: now.Format(time.DateTime),
  972. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  973. }, &totalCount).
  974. assertEqual(1, int(totalCount), "总数不一致").
  975. commonCountEventHistory(&client.CommonCountEventRequest{
  976. TablePrefixWithSchema: tablePrefix,
  977. KeyValues: []string{id},
  978. Version: "v1",
  979. Operation: "update",
  980. CreatorID: "test",
  981. StartCreatedTime: now.Format(time.DateTime),
  982. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  983. }, &totalCount).
  984. assertEqual(1, int(totalCount), "总数不一致").
  985. commonCountEventHistory(&client.CommonCountEventRequest{
  986. TablePrefixWithSchema: tablePrefix,
  987. KeyValues: []string{id},
  988. Version: "v1",
  989. Operation: "delete",
  990. CreatorID: "test",
  991. StartCreatedTime: now.Format(time.DateTime),
  992. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  993. }, &totalCount).
  994. assertEqual(1, int(totalCount), "总数不一致").
  995. eventHistoryQueryByKeys(&client.EventQueryByKeysRequest{
  996. TablePrefixWithSchema: tablePrefix,
  997. KeyValues: []string{id},
  998. PageNo: 0,
  999. PageSize: 0,
  1000. }, &eventInfos, &totalCount).
  1001. assertEqual(3, int(totalCount), "总数不一致").
  1002. assertEqual(3, len(eventInfos), "事件数量不一致").
  1003. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1004. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1005. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1006. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1007. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1008. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1009. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  1010. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  1011. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  1012. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  1013. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  1014. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  1015. assertEqual(id, eventInfos[2].Key, "关键字段不一致").
  1016. assertEqual("v1", eventInfos[2].Version, "版本不一致").
  1017. assertEqual("delete", eventInfos[2].Operation, "操作不一致").
  1018. assertEqual("test", eventInfos[2].CreatorID, "创建者ID不一致").
  1019. assertNotEmpty(eventInfos[2].CreateTime, "创建事件为空").
  1020. assertEqual("", eventInfos[2].Value, "值为空不一致").
  1021. eventHistoryQueryByKeys(&client.EventQueryByKeysRequest{
  1022. TablePrefixWithSchema: tablePrefix,
  1023. KeyValues: []string{id},
  1024. PageNo: 1,
  1025. PageSize: 1,
  1026. }, &eventInfos, &totalCount).
  1027. assertEqual(3, int(totalCount), "总数不一致").
  1028. assertEqual(1, len(eventInfos), "事件数量不一致").
  1029. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1030. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1031. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1032. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1033. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1034. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1035. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  1036. TablePrefixWithSchema: tablePrefix,
  1037. KeyValues: []string{id},
  1038. Version: "v1",
  1039. Operation: "create",
  1040. CreatorID: "test",
  1041. StartCreatedTime: now.Format(time.DateTime),
  1042. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1043. PageNo: 0,
  1044. PageSize: 0,
  1045. }, &eventInfos, &totalCount).
  1046. assertEqual(1, int(totalCount), "总数不一致").
  1047. assertEqual(1, len(eventInfos), "事件数量不一致").
  1048. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1049. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1050. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1051. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1052. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1053. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1054. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  1055. TablePrefixWithSchema: tablePrefix,
  1056. KeyValues: []string{id},
  1057. Version: "v1",
  1058. Operation: "update",
  1059. CreatorID: "test",
  1060. StartCreatedTime: now.Format(time.DateTime),
  1061. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1062. PageNo: 0,
  1063. PageSize: 0,
  1064. }, &eventInfos, &totalCount).
  1065. assertEqual(1, int(totalCount), "总数不一致").
  1066. assertEqual(1, len(eventInfos), "事件数量不一致").
  1067. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1068. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1069. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  1070. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1071. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1072. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1073. commonEventHistoryQuery(&client.CommonEventQueryRequest{
  1074. TablePrefixWithSchema: tablePrefix,
  1075. KeyValues: []string{id},
  1076. Version: "v1",
  1077. Operation: "delete",
  1078. CreatorID: "test",
  1079. StartCreatedTime: now.Format(time.DateTime),
  1080. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1081. PageNo: 0,
  1082. PageSize: 0,
  1083. }, &eventInfos, &totalCount).
  1084. assertEqual(1, int(totalCount), "总数不一致").
  1085. assertEqual(1, len(eventInfos), "事件数量不一致").
  1086. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1087. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1088. assertEqual("delete", eventInfos[0].Operation, "操作不一致").
  1089. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1090. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1091. assertEqual("", eventInfos[0].Value, "值为空不一致").
  1092. eventHistoryQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  1093. TablePrefixWithSchema: tablePrefix,
  1094. KeyValues: []string{id},
  1095. PageNo: 0,
  1096. PageSize: 0,
  1097. }, &eventInfos).
  1098. assertEqual(3, len(eventInfos), "事件数量不一致").
  1099. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1100. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1101. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1102. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1103. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1104. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1105. assertEqual(id, eventInfos[1].Key, "关键字段不一致").
  1106. assertEqual("v1", eventInfos[1].Version, "版本不一致").
  1107. assertEqual("update", eventInfos[1].Operation, "操作不一致").
  1108. assertEqual("test", eventInfos[1].CreatorID, "创建者ID不一致").
  1109. assertNotEmpty(eventInfos[1].CreateTime, "创建事件为空").
  1110. assertNotEmpty(eventInfos[1].Value, "值为空不一致").
  1111. assertEqual(id, eventInfos[2].Key, "关键字段不一致").
  1112. assertEqual("v1", eventInfos[2].Version, "版本不一致").
  1113. assertEqual("delete", eventInfos[2].Operation, "操作不一致").
  1114. assertEqual("test", eventInfos[2].CreatorID, "创建者ID不一致").
  1115. assertNotEmpty(eventInfos[2].CreateTime, "创建事件为空").
  1116. assertEqual("", eventInfos[2].Value, "值为空不一致").
  1117. eventHistoryQueryOnlyByKeys(&client.EventQueryByKeysRequest{
  1118. TablePrefixWithSchema: tablePrefix,
  1119. KeyValues: []string{id},
  1120. PageNo: 1,
  1121. PageSize: 1,
  1122. }, &eventInfos).
  1123. assertEqual(1, len(eventInfos), "事件数量不一致").
  1124. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1125. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1126. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1127. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1128. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1129. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1130. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1131. TablePrefixWithSchema: tablePrefix,
  1132. KeyValues: []string{id},
  1133. Version: "v1",
  1134. Operation: "create",
  1135. CreatorID: "test",
  1136. StartCreatedTime: now.Format(time.DateTime),
  1137. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1138. PageNo: 0,
  1139. PageSize: 0,
  1140. }, &eventInfos).
  1141. assertEqual(1, len(eventInfos), "事件数量不一致").
  1142. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1143. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1144. assertEqual("create", eventInfos[0].Operation, "操作不一致").
  1145. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1146. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1147. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1148. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1149. TablePrefixWithSchema: tablePrefix,
  1150. KeyValues: []string{id},
  1151. Version: "v1",
  1152. Operation: "update",
  1153. CreatorID: "test",
  1154. StartCreatedTime: now.Format(time.DateTime),
  1155. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1156. PageNo: 0,
  1157. PageSize: 0,
  1158. }, &eventInfos).
  1159. assertEqual(1, len(eventInfos), "事件数量不一致").
  1160. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1161. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1162. assertEqual("update", eventInfos[0].Operation, "操作不一致").
  1163. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1164. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1165. assertNotEmpty(eventInfos[0].Value, "值为空不一致").
  1166. commonEventHistoryQueryOnly(&client.CommonEventQueryRequest{
  1167. TablePrefixWithSchema: tablePrefix,
  1168. KeyValues: []string{id},
  1169. Version: "v1",
  1170. Operation: "delete",
  1171. CreatorID: "test",
  1172. StartCreatedTime: now.Format(time.DateTime),
  1173. EndCreatedTime: now.Add(time.Second).Format(time.DateTime),
  1174. PageNo: 0,
  1175. PageSize: 0,
  1176. }, &eventInfos).
  1177. assertEqual(1, len(eventInfos), "事件数量不一致").
  1178. assertEqual(id, eventInfos[0].Key, "关键字段不一致").
  1179. assertEqual("v1", eventInfos[0].Version, "版本不一致").
  1180. assertEqual("delete", eventInfos[0].Operation, "操作不一致").
  1181. assertEqual("test", eventInfos[0].CreatorID, "创建者ID不一致").
  1182. assertNotEmpty(eventInfos[0].CreateTime, "创建事件为空").
  1183. assertEqual("", eventInfos[0].Value, "值为空不一致")
  1184. }