예제 #1
0
func NewDecider(me, other, monitor state.State, performer Performer) Looper {
	decider := decider{
		me:        me,
		other:     other,
		monitor:   monitor,
		performer: performer,
	}
	for {
		// Really we only have to wait for a quorum, 2 out of 3 will allow everything to be ok.
		// But in certain conditions, this node was a backup that was down, and the current active
		// if offline, we need to wait for all 3 nodes.
		// So really we are going to wait for all 3 nodes to make it simple
		// me is already Ready. no need to call it
		config.Log.Info("waiting for cluster to be ready")
		other.Ready()
		monitor.Ready()
		config.Log.Info("cluster is ready")

		err := decider.reCheck()
		switch err {
		case ClusterUnaviable: // we try again.
		case nil: // the cluster was successfully rechecked
			return decider
		default:
			config.Log.Fatal("Another kind of error occured: %v", err)
			os.Exit(1)
		}
	}
}
예제 #2
0
func testState(client state.State, store *mock_state.MockStore, test *testing.T) {
	role, err := client.GetRole()
	if err != nil {
		test.Log(err)
		test.FailNow()
	}
	if role != "something" {
		test.Logf("wrong role was returned '%v'", role)
		test.Fail()
	}

	dbRole, err := client.GetDBRole()
	if err != nil {
		test.Log(err)
		test.FailNow()
	}
	if dbRole != "initialized" {
		test.Logf("wrong dbrole was returned '%v'", dbRole)
		test.Fail()
	}

	synced, err := client.HasSynced()
	if err != nil {
		test.Log(err)
		test.FailNow()
	}

	if synced {
		test.Log("it should not have been in sync")
		test.Fail()
	}

	err = client.SetSynced(true)
	if err != nil {
		test.Log(err)
		test.FailNow()
	}

	synced, err = client.HasSynced()
	if err != nil {
		test.Log(err)
		test.FailNow()
	}

	if !synced {
		test.Log("it should have been in sync")
		test.Fail()
	}

	dir, err := client.GetDataDir()
	if err != nil {
		test.Log(err)
		test.FailNow()
	}

	if dir != "//here" {
		test.Logf("got wrong data dir '%v'", dir)
		test.Fail()
	}

	// really doesn't do anything...
	client.Ready()
}