зеркало из https://github.com/github/vitess-gh.git
add unit test for ConsolveEventHandler
This commit is contained in:
Родитель
ed9c969815
Коммит
82a0a18ac1
|
@ -26,7 +26,7 @@ func (handler *ConsoleEventHandler) OnDataSourcerReadSuccess(sql []string) error
|
|||
// OnDataSourcerReadFail is called when schemamanager fails to read all sql statements.
|
||||
func (handler *ConsoleEventHandler) OnDataSourcerReadFail(err error) error {
|
||||
fmt.Printf("Failed to read schema changes, error: %v\n", err)
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// OnValidationSuccess is called when schemamanager successfully validates all sql statements.
|
||||
|
@ -38,7 +38,7 @@ func (handler *ConsoleEventHandler) OnValidationSuccess([]string) error {
|
|||
// OnValidationFail is called when schemamanager fails to validate sql statements.
|
||||
func (handler *ConsoleEventHandler) OnValidationFail(err error) error {
|
||||
fmt.Printf("Failed to validate sqls, error: %v\n", err)
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// OnExecutorComplete is called when schemamanager finishes applying schema changes.
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2015, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package schemamanager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConsoleEventHandler(t *testing.T) {
|
||||
sqls := []string{"CREATE TABLE test_table (pk int)"}
|
||||
handler := NewConsoleEventHandler()
|
||||
err := handler.OnDataSourcerReadSuccess(sqls)
|
||||
if err != nil {
|
||||
t.Fatalf("OnDataSourcerReadSuccess should succeed")
|
||||
}
|
||||
|
||||
errReadFail := fmt.Errorf("read fail")
|
||||
err = handler.OnDataSourcerReadFail(errReadFail)
|
||||
if err != errReadFail {
|
||||
t.Fatalf("should get error:%v, but get: %v", errReadFail, err)
|
||||
}
|
||||
|
||||
err = handler.OnValidationSuccess(sqls)
|
||||
if err != nil {
|
||||
t.Fatalf("OnValidationSuccess should succeed")
|
||||
}
|
||||
|
||||
errValidationFail := fmt.Errorf("validation fail")
|
||||
err = handler.OnValidationFail(errValidationFail)
|
||||
if err != errValidationFail {
|
||||
t.Fatalf("should get error:%v, but get: %v", errValidationFail, err)
|
||||
}
|
||||
|
||||
err = handler.OnExecutorComplete(&ExecuteResult{})
|
||||
if err != nil {
|
||||
t.Fatalf("OnExecutorComplete should succeed")
|
||||
}
|
||||
}
|
|
@ -69,7 +69,8 @@ func Run(sourcer DataSourcer,
|
|||
sqls, err := sourcer.Read()
|
||||
if err != nil {
|
||||
log.Errorf("failed to read data from data sourcer: %v", err)
|
||||
return handler.OnDataSourcerReadFail(err)
|
||||
handler.OnDataSourcerReadFail(err)
|
||||
return err
|
||||
}
|
||||
handler.OnDataSourcerReadSuccess(sqls)
|
||||
if err := exec.Open(); err != nil {
|
||||
|
@ -79,7 +80,8 @@ func Run(sourcer DataSourcer,
|
|||
defer exec.Close()
|
||||
if err := exec.Validate(sqls); err != nil {
|
||||
log.Errorf("validation fail: %v", err)
|
||||
return handler.OnValidationFail(err)
|
||||
handler.OnValidationFail(err)
|
||||
return err
|
||||
}
|
||||
handler.OnValidationSuccess(sqls)
|
||||
result := exec.Execute(sqls)
|
||||
|
|
|
@ -71,6 +71,19 @@ func TestRunSchemaChangesExecutorOpenFail(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRunSchemaChangesExecutorExecuteFail(t *testing.T) {
|
||||
dataSourcer := newFakeDataSourcer([]string{"create table test_table (pk int);"}, false, false, false)
|
||||
handler := newFakeHandler()
|
||||
exec := NewTabletExecutor(
|
||||
newFakeTabletManagerClient(),
|
||||
newFakeTopo(),
|
||||
"test_keyspace")
|
||||
err := Run(dataSourcer, exec, handler)
|
||||
if err == nil {
|
||||
t.Fatalf("run schema change should fail due to executor.Execute fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunSchemaChanges(t *testing.T) {
|
||||
sql := "create table test_table (pk int)"
|
||||
dataSourcer := NewSimpleDataSourcer(sql)
|
||||
|
|
Загрузка…
Ссылка в новой задаче