|
| 1 | +// Copyright 2026 Matrix Origin |
| 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 frontend |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "github.com/google/uuid" |
| 21 | + "github.com/stretchr/testify/require" |
| 22 | + |
| 23 | + "github.com/matrixorigin/matrixone/pkg/vm/process" |
| 24 | +) |
| 25 | + |
| 26 | +func TestBindBackExecSession(t *testing.T) { |
| 27 | + clientSessionID := uuid.New() |
| 28 | + backSessionID := uuid.New() |
| 29 | + clientSession := &Session{ |
| 30 | + feSessionImpl: feSessionImpl{uuid: clientSessionID}, |
| 31 | + tempTables: make(map[string]string), |
| 32 | + tempTablesRev: make(map[string]string), |
| 33 | + } |
| 34 | + backSes := &backSession{ |
| 35 | + feSessionImpl: feSessionImpl{ |
| 36 | + uuid: backSessionID, |
| 37 | + upstream: clientSession, |
| 38 | + }, |
| 39 | + } |
| 40 | + proc := &process.Process{Base: &process.BaseProcess{}} |
| 41 | + |
| 42 | + bindBackExecSession(proc, backSes) |
| 43 | + |
| 44 | + require.Same(t, backSes, proc.GetSession()) |
| 45 | + require.Equal(t, clientSessionID, proc.Base.SessionInfo.SessionId) |
| 46 | + proc.GetSession().AddTempTable("db1", "tmp1", "real_tmp1") |
| 47 | + realName, ok := clientSession.GetTempTable("db1", "tmp1") |
| 48 | + require.True(t, ok) |
| 49 | + require.Equal(t, "real_tmp1", realName) |
| 50 | +} |
| 51 | + |
| 52 | +func TestBindBackExecSessionWithoutUpstream(t *testing.T) { |
| 53 | + backSessionID := uuid.New() |
| 54 | + backSes := &backSession{ |
| 55 | + feSessionImpl: feSessionImpl{uuid: backSessionID}, |
| 56 | + } |
| 57 | + proc := &process.Process{Base: &process.BaseProcess{}} |
| 58 | + |
| 59 | + bindBackExecSession(proc, backSes) |
| 60 | + |
| 61 | + require.Nil(t, proc.GetSession()) |
| 62 | + require.Equal(t, uuid.Nil, proc.Base.SessionInfo.SessionId) |
| 63 | +} |
0 commit comments