github.com/matrixorigin/matrixone@v1.2.0/pkg/tests/txn/types.go (about) 1 // Copyright 2021 - 2022 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 txn 16 17 import ( 18 "database/sql" 19 20 "github.com/matrixorigin/matrixone/pkg/tests/service" 21 "github.com/matrixorigin/matrixone/pkg/txn/client" 22 "go.uber.org/zap" 23 ) 24 25 // Cluster txn testing cluster 26 type Cluster interface { 27 // Start start the cluster, block until all service started and all DNShard created 28 Start() 29 // Stop stop the cluster 30 Stop() 31 // Env return the test cluster env 32 Env() service.Cluster 33 // NewClient create a test txn client 34 NewClient() Client 35 // GetLogger returns the logger 36 GetLogger() *zap.Logger 37 } 38 39 // Client used to execute read and write. 40 type Client interface { 41 // NewTxn create a txn to execute read and write command 42 NewTxn(options ...client.TxnOption) (Txn, error) 43 } 44 45 // Txn txn operation handler 46 type Txn interface { 47 // Commit commit the txn 48 Commit() error 49 // Rollback rollback the txn 50 Rollback() error 51 // Read read by key 52 Read(key string) (string, error) 53 // Write write key 54 Write(key, value string) error 55 } 56 57 // SQLBasedTxn support exec raw sql Txn 58 type SQLBasedTxn interface { 59 Txn 60 // ExecSQL exec sql, ddl/insert/update/delete 61 ExecSQL(sql string) (sql.Result, error) 62 // ExecSQLQuery exec query 63 ExecSQLQuery(sql string) (*sql.Rows, error) 64 }