sync_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package v1
  2. import (
  3. "git.sxidc.com/service-supports/dps-sdk/client"
  4. "sync"
  5. "testing"
  6. )
  7. var tableModelDescribe1 = map[string]string{
  8. "ID": "gorm:\"primary_key;type:varchar(32);comment:id;\"",
  9. "Name1": "gorm:\"not null;type:varchar(128);comment:数据库名称;\"",
  10. }
  11. var tableModelDescribe2 = map[string]string{
  12. "ID": "gorm:\"primary_key;type:varchar(32);comment:id;\"",
  13. "Name2": "gorm:\"not null;type:varchar(128);comment:数据库名称;\"",
  14. }
  15. func TestSync(t *testing.T) {
  16. initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
  17. defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
  18. tablePrefix1 := "test.test1"
  19. tablePrefix2 := "test.test2"
  20. id1 := simpleUUID()
  21. id2 := simpleUUID()
  22. name1 := "name1"
  23. name2 := "name2"
  24. toolKit := newToolKit(t).
  25. autoMigrate(&client.AutoMigrateRequest{
  26. Items: []client.AutoMigrateItem{
  27. {
  28. TablePrefixWithSchema: tablePrefix1,
  29. Version: "v1",
  30. TableModelDescribe: tableModelDescribe1,
  31. NoEvent: false,
  32. },
  33. {
  34. TablePrefixWithSchema: tablePrefix2,
  35. Version: "v1",
  36. TableModelDescribe: tableModelDescribe2,
  37. NoEvent: false,
  38. },
  39. },
  40. }).
  41. insert(&client.InsertRequest{
  42. TablePrefixWithSchema: tablePrefix1,
  43. Version: "v1",
  44. KeyColumns: []string{"id"},
  45. TableRow: client.NewTableRow().
  46. AddColumnValueString("id", id1).
  47. AddColumnValueString("name1", name1),
  48. UserID: "test",
  49. }).
  50. insert(&client.InsertRequest{
  51. TablePrefixWithSchema: tablePrefix2,
  52. Version: "v1",
  53. KeyColumns: []string{"id"},
  54. TableRow: client.NewTableRow().
  55. AddColumnValueString("id", id2).
  56. AddColumnValueString("name2", name2),
  57. UserID: "test",
  58. })
  59. wg := sync.WaitGroup{}
  60. wg.Add(2)
  61. go func() {
  62. defer wg.Done()
  63. for i := 0; i < 100; i++ {
  64. toolKit.queryOnlyByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
  65. TablePrefixWithSchema: tablePrefix1,
  66. Version: "v1",
  67. Where: client.NewClause().Equal("id", id1).
  68. Equal("name1", name1),
  69. PageNo: 0,
  70. PageSize: 0,
  71. }, nil)
  72. }
  73. }()
  74. go func() {
  75. defer wg.Done()
  76. for i := 0; i < 100; i++ {
  77. toolKit.queryOnlyByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
  78. TablePrefixWithSchema: tablePrefix2,
  79. Version: "v1",
  80. Where: client.NewClause().Equal("id", id2).
  81. Equal("name2", name2),
  82. PageNo: 0,
  83. PageSize: 0,
  84. }, nil)
  85. }
  86. }()
  87. wg.Wait()
  88. }