v1_test.go 47 KB

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