本文整理汇总了Golang中github.com/dingotiles/dingo-postgresql-broker/testutil.NewTestLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTestLogger函数的具体用法?Golang NewTestLogger怎么用?Golang NewTestLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTestLogger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPlan_Steps_NewCluster_Default
func TestPlan_Steps_NewCluster_Default(t *testing.T) {
t.Parallel()
testPrefix := "TestPlan_Steps_NewCluster_Default"
logger := testutil.NewTestLogger(testPrefix, t)
schedulerConfig := config.Scheduler{
Cells: []*config.Cell{
&config.Cell{GUID: "cell1"},
&config.Cell{GUID: "cell2"},
&config.Cell{GUID: "cell3"},
&config.Cell{GUID: "cell4"},
},
Etcd: testutil.LocalEtcdConfig,
}
scheduler, err := NewScheduler(schedulerConfig, new(fakes.FakePatroni), logger)
if err != nil {
t.Fatalf("NewScheduler error: %v", err)
}
clusterModel := state.NewClusterModel(&state.StateEtcd{}, structs.ClusterState{})
plan, err := scheduler.newPlan(clusterModel, structs.ClusterFeatures{NodeCount: 2})
if err != nil {
t.Fatalf("scheduler.newPlan error: %v", err)
}
expectedStepTypes := []string{"AddNode", "AddNode", "WaitForAllMembers", "WaitForLeader"}
stepTypes := plan.stepTypes()
if !reflect.DeepEqual(stepTypes, expectedStepTypes) {
t.Fatalf("plan should have steps %v, got %v", expectedStepTypes, stepTypes)
}
}
示例2: TestRouter_RemoveClusterAssignement
func TestRouter_RemoveClusterAssignement(t *testing.T) {
t.Parallel()
testPrefix := "TestRouter_RemoveClusterAssignement"
etcdApi := resetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
clusterID := structs.ClusterID("clusterID")
port := 30000
key := fmt.Sprintf("%s/routing/allocation/%s", testPrefix, clusterID)
_, err := etcdApi.Set(context.Background(), key, fmt.Sprintf("%d", port), &etcd.SetOptions{})
router, err := NewRouterWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatalf("Could not create a new router", err)
}
err = router.RemoveClusterAssignment(clusterID)
if err != nil {
t.Fatalf("Could not remove the assignment %s", err)
}
_, err = etcdApi.Get(context.Background(), fmt.Sprintf("%s/routing/allocation/%s", testPrefix, clusterID), &etcd.GetOptions{})
if err == nil {
t.Fatalf("port wasn't deleted %s", err)
}
}
示例3: TestState_LoadCluster
func TestState_LoadCluster(t *testing.T) {
t.Parallel()
testPrefix := "TestState_LoadClusterState"
testutil.ResetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
state, err := NewStateEtcdWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatalf("Could not create state", err)
}
instanceID := structs.ClusterID(uuid.New())
planID := uuid.New()
clusterState := structs.ClusterState{
InstanceID: instanceID,
OrganizationGUID: "OrganizationGUID",
PlanID: planID,
ServiceID: "ServiceID",
SpaceGUID: "SpaceGUID",
}
err = state.SaveCluster(clusterState)
if err != nil {
t.Fatalf("SaveCluster failed %s", err)
}
loadedState, err := state.LoadCluster(instanceID)
if !reflect.DeepEqual(clusterState, loadedState) {
t.Fatalf("Failed to load ClusterState")
}
}
示例4: TestScheduler_filterCellsByCellGUIDs
func TestScheduler_filterCellsByCellGUIDs(t *testing.T) {
t.Parallel()
testPrefix := "TestScheduler_filterCellsByCellGUIDs"
logger := testutil.NewTestLogger(testPrefix, t)
schedulerConfig := config.Scheduler{
Cells: []*config.Cell{
&config.Cell{GUID: "cell-guid1"},
&config.Cell{GUID: "cell-guid2"},
},
Etcd: testutil.LocalEtcdConfig,
}
scheduler, err := NewScheduler(schedulerConfig, logger)
if err != nil {
t.Fatalf("NewScheduler error: %v", err)
}
features := structs.ClusterFeatures{
CellGUIDs: []string{"cell-guid1", "unknown-cell-guid"},
}
clusterModel := state.NewClusterModel(&state.StateEtcd{}, structs.ClusterState{InstanceID: "test"})
plan, err := scheduler.newPlan(clusterModel, features)
if err != nil {
t.Fatalf("scheduler.newPlan error: %v", err)
}
if len(plan.availableCells) != 1 {
t.Fatalf("Plan should only have one filtered cell")
}
if len(plan.allCells) != 2 {
t.Fatalf("Plan should only have two cells")
}
}
示例5: TestScheduler_allCells
func TestScheduler_allCells(t *testing.T) {
t.Parallel()
testPrefix := "TestScheduler_allCells"
logger := testutil.NewTestLogger(testPrefix, t)
schedulerConfig := config.Scheduler{
Cells: []*config.Cell{
&config.Cell{GUID: "cell-guid1"},
&config.Cell{GUID: "cell-guid2"},
},
Etcd: testutil.LocalEtcdConfig,
}
scheduler, err := NewScheduler(schedulerConfig, new(fakes.FakePatroni), logger)
if err != nil {
t.Fatalf("NewScheduler error: %v", err)
}
clusterModel := state.NewClusterModel(&state.StateEtcd{}, structs.ClusterState{InstanceID: "test"})
features := structs.ClusterFeatures{}
plan, err := scheduler.newPlan(clusterModel, features)
if err != nil {
t.Fatalf("scheduler.newPlan error: %v", err)
}
if len(plan.availableCells) != 2 {
t.Fatalf("Plan should have both cell cells")
}
if len(plan.allCells) != 2 {
t.Fatalf("Plan should only have two cells")
}
}
示例6: TestScheduler_VerifyClusterFeatures
func TestScheduler_VerifyClusterFeatures(t *testing.T) {
t.Parallel()
testPrefix := "TestScheduler_VerifyClusterFeatures"
logger := testutil.NewTestLogger(testPrefix, t)
scheduler, err := NewScheduler(config.Scheduler{
Cells: []*config.Cell{
&config.Cell{GUID: "a"},
&config.Cell{GUID: "b"},
&config.Cell{GUID: "c"},
&config.Cell{GUID: "d"},
},
Etcd: testutil.LocalEtcdConfig,
}, new(fakes.FakePatroni), logger)
if err != nil {
t.Fatalf("NewScheduler error: %v", err)
}
features := structs.ClusterFeatures{
NodeCount: 3,
CellGUIDs: []string{"a", "b", "c"},
}
err = scheduler.VerifyClusterFeatures(features)
if err != nil {
t.Fatalf("Cluster features %v should be valid", features)
}
}
示例7: TestState_ClusterExists
func TestState_ClusterExists(t *testing.T) {
t.Parallel()
testPrefix := "TestState_ClusterExists"
testutil.ResetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
state, err := NewStateEtcdWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatalf("Could not create state", err)
}
clusterID := structs.ClusterID(uuid.New())
planID := uuid.New()
clusterState := structs.ClusterState{
InstanceID: clusterID,
OrganizationGUID: "OrganizationGUID",
PlanID: planID,
ServiceID: "ServiceID",
SpaceGUID: "SpaceGUID",
}
err = state.SaveCluster(clusterState)
if err != nil {
t.Fatalf("SaveCluster failed %s", err)
}
if !state.ClusterExists(clusterID) {
t.Fatalf("Cluster %s should exist", clusterID)
}
if state.ClusterExists("fakeID") {
t.Fatalf("Cluster %s should not exist", "fakeID")
}
}
示例8: TestRouter_AssignPortToCluster
func TestRouter_AssignPortToCluster(t *testing.T) {
t.Parallel()
testPrefix := "TestRouter_AssignPortToCluster"
etcdApi := resetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
router, err := NewRouterWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatalf("Could not create a new router", err)
}
clusterID := structs.ClusterID("clusterID")
port := 30000
err = router.AssignPortToCluster(clusterID, port)
if err != nil {
t.Fatalf("Assigning port failed")
}
key := fmt.Sprintf("%s/routing/allocation/%s", testPrefix, clusterID)
resp, err := etcdApi.Get(context.Background(), key, &etcd.GetOptions{})
if err != nil {
t.Fatalf("Could not read port from etcd")
}
retrievedPort, err := strconv.Atoi(resp.Node.Value)
if want, got := port, retrievedPort; want != got {
t.Fatalf("Routing was not initialized. Expected %d, got %d", want, got)
}
}
示例9: TestCallbacks_Configures
func TestCallbacks_Configures(t *testing.T) {
t.Parallel()
testPrefix := "TestCallbacks_WriteRecreationData"
logger := testutil.NewTestLogger(testPrefix, t)
callbacks := NewCallbacks(config.Callbacks{}, logger)
if want, got := false, callbacks.Configured(); want != got {
t.Fatalf("Callbacks should not be configures")
}
}
示例10: TestAddNode_PrioritizeCells_SecondNodeDiffAZ
func TestAddNode_PrioritizeCells_SecondNodeDiffAZ(t *testing.T) {
t.Parallel()
testPrefix := "TestAddNode_PrioritizeCells_SecondNodeDiffAZ"
logger := testutil.NewTestLogger(testPrefix, t)
clusterLoader := &FakeClusterLoader{
Clusters: []*structs.ClusterState{
&structs.ClusterState{
Nodes: []*structs.Node{
&structs.Node{CellGUID: "cell-n1-z1"},
&structs.Node{CellGUID: "cell-n3-z2"},
},
},
&structs.ClusterState{
Nodes: []*structs.Node{
&structs.Node{CellGUID: "cell-n1-z1"},
&structs.Node{CellGUID: "cell-n3-z2"},
},
},
&structs.ClusterState{
Nodes: []*structs.Node{
&structs.Node{CellGUID: "cell-n1-z1"},
&structs.Node{CellGUID: "cell-n2-z1"},
},
},
},
}
availableCells := cells.NewCells([]*config.Cell{
&config.Cell{GUID: "cell-n1-z1", AvailabilityZone: "z1"},
&config.Cell{GUID: "cell-n2-z1", AvailabilityZone: "z1"},
&config.Cell{GUID: "cell-n3-z2", AvailabilityZone: "z2"},
&config.Cell{GUID: "cell-n4-z2", AvailabilityZone: "z2"},
}, clusterLoader)
currentClusterNodes := []*structs.Node{
&structs.Node{ID: "node-1", CellGUID: "cell-n1-z1"},
}
step := AddNode{logger: logger, availableCells: availableCells}
cellsToTry, _ := step.prioritizeCellsToTry(currentClusterNodes)
cellIDs := []string{}
for _, cell := range cellsToTry {
cellIDs = append(cellIDs, cell.GUID)
}
// Expect all z2 AZs first, then z1 AZs as node-1 is in z1 already
expectedPriority := []string{"cell-n4-z2", "cell-n3-z2", "cell-n2-z1", "cell-n1-z1"}
if !reflect.DeepEqual(cellIDs, expectedPriority) {
t.Fatalf("Expected prioritized cells %v to be %v", cellIDs, expectedPriority)
}
}
示例11: TestCallbacks_WriteRecreationData
func TestCallbacks_WriteRecreationData(t *testing.T) {
t.Parallel()
testPrefix := "TestCallbacks_WriteRecreationData"
logger := testutil.NewTestLogger(testPrefix, t)
testDir, err := ioutil.TempDir("", testPrefix)
if err != nil {
t.Fatalf("err: %v", err)
}
defer os.Remove(testDir)
fileName := fmt.Sprintf("%s/%s", testDir, testPrefix)
config := config.Callbacks{
ClusterDataBackup: &config.CallbackCommand{
Command: "tee",
Arguments: []string{fileName},
},
}
recreationData := &structs.ClusterRecreationData{
InstanceID: "instance-id",
OrganizationGUID: "OrganizationGUID",
PlanID: "PlanID",
ServiceID: "ServiceID",
SpaceGUID: "SpaceGUID",
AdminCredentials: structs.PostgresCredentials{
Username: "pgadmin",
Password: "pw",
},
AllocatedPort: 1234,
}
callbacks := NewCallbacks(config, logger)
callbacks.WriteRecreationData(recreationData)
rawData, err := ioutil.ReadFile(fileName)
if err != nil {
t.Fatalf("Could not open file %s, Err: %s", fileName, err)
}
writtenData := &structs.ClusterRecreationData{}
json.Unmarshal(rawData, &writtenData)
if !reflect.DeepEqual(recreationData, writtenData) {
t.Fatalf("Written Data doesn't equal original. %v != %v", writtenData, recreationData)
}
}
示例12: TestPlan_Steps_NewCluster_MoveEverything
func TestPlan_Steps_NewCluster_MoveEverything(t *testing.T) {
t.Parallel()
testPrefix := "TestPlan_Steps_NewCluster_MoveEverything"
logger := testutil.NewTestLogger(testPrefix, t)
schedulerConfig := config.Scheduler{
Cells: []*config.Cell{
&config.Cell{GUID: "cell1"},
&config.Cell{GUID: "cell2"},
},
Etcd: testutil.LocalEtcdConfig,
}
patroni := new(fakes.FakePatroni)
patroni.ClusterLeaderStub = func(structs.ClusterID) (string, error) { return "a", nil }
scheduler, err := NewScheduler(schedulerConfig, patroni, logger)
if err != nil {
t.Fatalf("NewScheduler error: %v", err)
}
clusterState := structs.ClusterState{
InstanceID: "test",
Nodes: []*structs.Node{
&structs.Node{ID: "a", CellGUID: "cell-x-unavailable"},
&structs.Node{ID: "b", CellGUID: "cell-y-unavailable"},
},
}
clusterFeatures := structs.ClusterFeatures{
NodeCount: 2,
CellGUIDs: []string{"cell1", "cell2"},
}
clusterModel := state.NewClusterModel(&state.StateEtcd{}, clusterState)
plan, err := scheduler.newPlan(clusterModel, clusterFeatures)
if err != nil {
t.Fatalf("scheduler.newPlan error: %v", err)
}
expectedStepTypes := []string{"AddNode", "AddNode", "WaitForAllMembers", "RemoveNode(b)", "WaitForAllMembers", "FailoverFrom(a)", "RemoveNode(a)", "WaitForLeader"}
stepTypes := plan.stepTypes()
if !reflect.DeepEqual(stepTypes, expectedStepTypes) {
t.Fatalf("plan should have steps %v, got %v", expectedStepTypes, stepTypes)
}
}
示例13: TestState_DeleteCluster
func TestState_DeleteCluster(t *testing.T) {
t.Parallel()
testPrefix := "TestState_DeleteClusterState"
etcdApi := testutil.ResetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
state, err := NewStateEtcdWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatalf("Could not create state", err)
}
instanceID := structs.ClusterID(uuid.New())
planID := uuid.New()
clusterState := structs.ClusterState{
InstanceID: instanceID,
OrganizationGUID: "OrganizationGUID",
PlanID: planID,
ServiceID: "ServiceID",
SpaceGUID: "SpaceGUID",
}
err = state.SaveCluster(clusterState)
if err != nil {
t.Fatalf("SaveCluster failed %s", err)
}
err = state.DeleteCluster(instanceID)
if err != nil {
t.Fatalf("DeleteClusterState failed %s", err)
}
key := fmt.Sprintf("%s/service/%s/state", testPrefix, instanceID)
_, err = etcdApi.Get(context.Background(), key, &etcd.GetOptions{})
if err == nil {
t.Fatalf("Was expecting error 'Key not found'")
} else {
notFoundRegExp, _ := regexp.Compile("Key not found")
if notFoundRegExp.FindString(err.Error()) != "Key not found" {
t.Fatalf("An error other than 'Key not found' occured %s", err)
}
}
}
示例14: TestState_LoadCluster
func TestState_LoadCluster(t *testing.T) {
t.Parallel()
testPrefix := "TestState_LoadClusterState"
etcdApi := testutil.ResetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
state, err := NewStateEtcdWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatalf("Could not create state", err)
}
instanceID := structs.ClusterID(uuid.New())
planID := uuid.New()
node := structs.Node{ID: "node_id", CellGUID: "cell_guid"}
clusterState := structs.ClusterState{
InstanceID: instanceID,
OrganizationGUID: "OrganizationGUID",
PlanID: planID,
ServiceID: "ServiceID",
SpaceGUID: "SpaceGUID",
SchedulingInfo: structs.SchedulingInfo{
Status: structs.SchedulingStatusInProgress,
},
}
clusterState.Nodes = []*structs.Node{&node}
err = state.SaveCluster(clusterState)
if err != nil {
t.Fatalf("SaveCluster failed %s", err)
}
data, err := json.Marshal(node)
key := fmt.Sprintf(
"/%s/service/%s/nodes/%s", testPrefix, clusterState.InstanceID, node.ID)
etcdApi.Set(context.Background(), key, string(data), &etcd.SetOptions{})
loadedState, err := state.LoadCluster(instanceID)
if !reflect.DeepEqual(clusterState, loadedState) {
t.Fatalf("Failed to load ClusterState. Expected: %v, actual: %v", clusterState, loadedState)
}
}
示例15: TestRouter_InitialPort
func TestRouter_InitialPort(t *testing.T) {
t.Parallel()
testPrefix := "TestRouter_InitialPort"
resetEtcd(t, testPrefix)
logger := testutil.NewTestLogger(testPrefix, t)
router, err := NewRouterWithPrefix(testutil.LocalEtcdConfig, testPrefix, logger)
if err != nil {
t.Fatal("Could not create a new router", err)
}
nextPort, err := router.AllocatePort()
if err != nil {
t.Fatal("Could not allocate port", err)
}
if nextPort != initialPort {
t.Errorf("%s was not initialized in etcd", nextPortKey)
}
}