func (th *TestHandler) SessionInc(s *Session) {
}
SessionInc implements the interface.
package driver
import (
	"fmt"
	"math/rand"
	"regexp"
	"strconv"
	"strings"
	"sync"
	"time"
	"github.com/xelabs/go-mysqlstack/sqldb"
	"github.com/xelabs/go-mysqlstack/xlog"
	querypb "github.com/xelabs/go-mysqlstack/sqlparser/depends/query"
	"github.com/xelabs/go-mysqlstack/sqlparser/depends/sqltypes"
)
func randomPort(min int, max int) int {
	rand := rand.New(rand.NewSource(time.Now().UnixNano()))
	d, delta := min, (max - min)
	if delta > 0 {
		d += rand.Intn(int(delta))
	}
	return d
}
type exprResult struct {
	expr   *regexp.Regexp
	result *sqltypes.Result
	err    error
}
type CondType int
const (
	COND_NORMAL CondType = iota
	COND_DELAY
	COND_ERROR
	COND_PANIC
	COND_STREAM
)
type Cond struct {
	Type CondType
	Query string
	Result *sqltypes.Result
	Panic bool
	Error error
	Delay int
}
type CondList struct {
	len   int
	idx   int
	conds []Cond
}
type SessionTuple struct {
	session *Session
	closed  bool
	killed  chan bool
}
type TestHandler struct {
	log      *xlog.Log
	mu       sync.RWMutex
	conds    map[string]*Cond
	condList map[string]*CondList
	ss       map[uint32]*SessionTuple
	patterns      []exprResult
	patternErrors []exprResult
	queryCalled map[string]int
}
func NewTestHandler(log *xlog.Log) *TestHandler {
	return &TestHandler{
		log:         log,
		ss:          make(map[uint32]*SessionTuple),
		conds:       make(map[string]*Cond),
		queryCalled: make(map[string]int),
		condList:    make(map[string]*CondList),
	}
}
func (th *TestHandler) setCond(cond *Cond) {
	th.mu.Lock()
	defer th.mu.Unlock()
	th.conds[strings.ToLower(cond.Query)] = cond
	th.queryCalled[strings.ToLower(cond.Query)] = 0
}
func (th *TestHandler) ResetAll() {
	th.mu.Lock()
	defer th.mu.Unlock()
	for k := range th.conds {
		delete(th.conds, k)
	}
	th.patterns = make([]exprResult, 0, 4)
	th.patternErrors = make([]exprResult, 0, 4)
}
func (th *TestHandler) ResetPatternErrors() {
	th.patternErrors = make([]exprResult, 0, 4)
}
func (th *TestHandler) ResetErrors() {
	for k, v := range th.conds {
		if v.Type == COND_ERROR {
			delete(th.conds, k)
		}
	}
}
func (th *TestHandler) SessionCheck(s *Session) error {
	return nil
}
func (th *TestHandler) AuthCheck(s *Session) error {
	user := s.User()
	if user != "mock" {
		return sqldb.NewSQLErrorf(sqldb.ER_ACCESS_DENIED_ERROR, "Access denied for user '%v'", user)
	}
	return nil
}
func (th *TestHandler) ServerVersion() string {
	return "FakeDB"
}
func (th *TestHandler) SetServerVersion() {
	return
}
func (th *TestHandler) NewSession(s *Session) {
	th.mu.Lock()
	defer th.mu.Unlock()
	st := &SessionTuple{
		session: s,
		killed:  make(chan bool, 2),
	}
	th.ss[s.ID()] = st
}