v1_test.go 47 KB

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