instance_test.go 43 KB

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