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(context.Background(), "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(context.Background(), "%+v", &resp) } } err := httputil.StreamJSON( httpClient, c.URL(0)+"/_admin/v1/cluster/freeze", &serverpb.ClusterFreezeRequest{Freeze: freeze}, &serverpb.ClusterFreezeResponse{}, cb, ) return resp, err }
func TestClusterFreeze(t *testing.T) { defer leaktest.AfterTest(t)() s, _, _ := serverutils.StartServer(t, base.TestServerArgs{}) defer s.Stopper().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.GetHTTPClient() if err != nil { t.Fatal(err) } path := s.AdminURL() + adminPrefix + "cluster/freeze" if err := httputil.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 := httputil.StreamJSON(cli, path, &req, &serverpb.ClusterFreezeResponse{}, cb); err != nil { t.Fatal(err) } } }