|
| 1 | +// Copyright 2023 PingCAP, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package gluetidb |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/pingcap/tidb/br/pkg/glue" |
| 22 | + "github.com/pingcap/tidb/parser/model" |
| 23 | + "github.com/pingcap/tidb/testkit" |
| 24 | + "github.com/pingcap/tidb/types" |
| 25 | + "github.com/stretchr/testify/require" |
| 26 | +) |
| 27 | + |
| 28 | +func TestTheSessionIsoation(t *testing.T) { |
| 29 | + req := require.New(t) |
| 30 | + store, _, clean := testkit.CreateMockStoreAndDomain(t) |
| 31 | + defer clean() |
| 32 | + ctx := context.Background() |
| 33 | + |
| 34 | + g := Glue{} |
| 35 | + session, err := g.CreateSession(store) |
| 36 | + req.NoError(err) |
| 37 | + |
| 38 | + req.NoError(session.ExecuteInternal(ctx, "use test;")) |
| 39 | + infos := []*model.TableInfo{} |
| 40 | + infos = append(infos, &model.TableInfo{ |
| 41 | + Name: model.NewCIStr("tables_1"), |
| 42 | + Columns: []*model.ColumnInfo{ |
| 43 | + {Name: model.NewCIStr("foo"), FieldType: *types.NewFieldType(types.KindBinaryLiteral), State: model.StatePublic}, |
| 44 | + }, |
| 45 | + }) |
| 46 | + infos = append(infos, &model.TableInfo{ |
| 47 | + Name: model.NewCIStr("tables_2"), |
| 48 | + PlacementPolicyRef: &model.PolicyRefInfo{ |
| 49 | + Name: model.NewCIStr("threereplication"), |
| 50 | + }, |
| 51 | + Columns: []*model.ColumnInfo{ |
| 52 | + {Name: model.NewCIStr("foo"), FieldType: *types.NewFieldType(types.KindBinaryLiteral), State: model.StatePublic}, |
| 53 | + }, |
| 54 | + }) |
| 55 | + infos = append(infos, &model.TableInfo{ |
| 56 | + Name: model.NewCIStr("tables_3"), |
| 57 | + PlacementPolicyRef: &model.PolicyRefInfo{ |
| 58 | + Name: model.NewCIStr("fivereplication"), |
| 59 | + }, |
| 60 | + Columns: []*model.ColumnInfo{ |
| 61 | + {Name: model.NewCIStr("foo"), FieldType: *types.NewFieldType(types.KindBinaryLiteral), State: model.StatePublic}, |
| 62 | + }, |
| 63 | + }) |
| 64 | + polices := []*model.PolicyInfo{ |
| 65 | + { |
| 66 | + PlacementSettings: &model.PlacementSettings{ |
| 67 | + Followers: 4, |
| 68 | + }, |
| 69 | + Name: model.NewCIStr("fivereplication"), |
| 70 | + }, |
| 71 | + { |
| 72 | + PlacementSettings: &model.PlacementSettings{ |
| 73 | + Followers: 2, |
| 74 | + }, |
| 75 | + Name: model.NewCIStr("threereplication"), |
| 76 | + }, |
| 77 | + } |
| 78 | + for _, pinfo := range polices { |
| 79 | + before := session.(*tidbSession).se.GetInfoSchema().SchemaMetaVersion() |
| 80 | + req.NoError(session.CreatePlacementPolicy(ctx, pinfo)) |
| 81 | + after := session.(*tidbSession).se.GetInfoSchema().SchemaMetaVersion() |
| 82 | + req.Greater(after, before) |
| 83 | + } |
| 84 | + req.NoError(session.(glue.BatchCreateTableSession).CreateTables(ctx, map[string][]*model.TableInfo{ |
| 85 | + "test": infos, |
| 86 | + })) |
| 87 | +} |
0 commit comments