123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package v1
- import (
- "git.sxidc.com/service-supports/dps-sdk/client"
- "sync"
- "testing"
- )
- var tableModelDescribe1 = map[string]string{
- "ID": "gorm:\"primary_key;type:varchar(32);comment:id;\"",
- "Name1": "gorm:\"not null;type:varchar(128);comment:数据库名称;\"",
- }
- var tableModelDescribe2 = map[string]string{
- "ID": "gorm:\"primary_key;type:varchar(32);comment:id;\"",
- "Name2": "gorm:\"not null;type:varchar(128);comment:数据库名称;\"",
- }
- func TestSync(t *testing.T) {
- initClient(t, "localhost:30170", "ee2d7dabe56646ce835d80873348ee0e")
- defer destroyClient(t, "ee2d7dabe56646ce835d80873348ee0e")
- tablePrefix1 := "test.test1"
- tablePrefix2 := "test.test2"
- id1 := simpleUUID()
- id2 := simpleUUID()
- name1 := "name1"
- name2 := "name2"
- toolKit := newToolKit(t).
- autoMigrate(&client.AutoMigrateRequest{
- Items: []client.AutoMigrateItem{
- {
- TablePrefixWithSchema: tablePrefix1,
- Version: "v1",
- TableModelDescribe: tableModelDescribe1,
- NoEvent: false,
- },
- {
- TablePrefixWithSchema: tablePrefix2,
- Version: "v1",
- TableModelDescribe: tableModelDescribe2,
- NoEvent: false,
- },
- },
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix1,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id1).
- AddColumnValueString("name1", name1),
- UserID: "test",
- }).
- insert(&client.InsertRequest{
- TablePrefixWithSchema: tablePrefix2,
- Version: "v1",
- KeyColumns: []string{"id"},
- TableRow: client.NewTableRow().
- AddColumnValueString("id", id2).
- AddColumnValueString("name2", name2),
- UserID: "test",
- })
- wg := sync.WaitGroup{}
- wg.Add(2)
- go func() {
- defer wg.Done()
- for i := 0; i < 100; i++ {
- toolKit.queryOnlyByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
- TablePrefixWithSchema: tablePrefix1,
- Version: "v1",
- Where: client.NewClause().Equal("id", id1).
- Equal("name1", name1),
- PageNo: 0,
- PageSize: 0,
- }, nil)
- }
- }()
- go func() {
- defer wg.Done()
- for i := 0; i < 100; i++ {
- toolKit.queryOnlyByWhereAndOrderBy(&client.QueryByWhereAndOrderByRequest{
- TablePrefixWithSchema: tablePrefix2,
- Version: "v1",
- Where: client.NewClause().Equal("id", id2).
- Equal("name2", name2),
- PageNo: 0,
- PageSize: 0,
- }, nil)
- }
- }()
- wg.Wait()
- }
|