Ejemplo n.º 1
0
func postFreeze(c cluster.Cluster, freeze bool, timeout time.Duration) (serverpb.ClusterFreezeResponse, error) {
	httpClient := cluster.HTTPClient
	httpClient.Timeout = timeout

	var resp serverpb.ClusterFreezeResponse
	log.Infof("requesting: freeze=%t, timeout=%s", freeze, timeout)
	cb := func(v proto.Message) {
		oldNum := resp.RangesAffected
		resp = *v.(*serverpb.ClusterFreezeResponse)
		if oldNum > resp.RangesAffected {
			resp.RangesAffected = oldNum
		}
		if (resp != serverpb.ClusterFreezeResponse{}) {
			log.Infof("%+v", &resp)
		}
	}
	err := util.StreamJSON(
		httpClient,
		c.URL(0)+"/_admin/v1/cluster/freeze",
		&serverpb.ClusterFreezeRequest{Freeze: freeze},
		&serverpb.ClusterFreezeResponse{},
		cb,
	)
	return resp, err
}
Ejemplo n.º 2
0
func TestClusterFreeze(t *testing.T) {
	defer leaktest.AfterTest(t)()
	s := StartTestServer(t)
	defer s.Stop()

	for _, freeze := range []bool{true, false} {
		req := serverpb.ClusterFreezeRequest{
			Freeze: freeze,
		}

		var resp serverpb.ClusterFreezeResponse
		cb := func(v proto.Message) {
			oldNum := resp.RangesAffected
			resp = *v.(*serverpb.ClusterFreezeResponse)
			if oldNum > resp.RangesAffected {
				resp.RangesAffected = oldNum
			}
		}

		cli, err := s.ctx.GetHTTPClient()
		if err != nil {
			t.Fatal(err)
		}
		path := s.Ctx.AdminURL() + apiEndpoint + "cluster/freeze"

		if err := util.StreamJSON(cli, path, &req, &serverpb.ClusterFreezeResponse{}, cb); err != nil {
			t.Fatal(err)
		}
		if aff := resp.RangesAffected; aff == 0 {
			t.Fatalf("expected affected ranges: %+v", resp)
		}

		if err := util.StreamJSON(cli, path, &req, &serverpb.ClusterFreezeResponse{}, cb); err != nil {
			t.Fatal(err)
		}
	}
}