Beispiel #1
0
func TestRetry(t *testing.T) {
	th := test.NewServiceHost(t)

	state := &host.ExampleServiceDocument{}
	stateURI := th.StartMock(state)

	client.DefaultTransport.DisableKeepAlives = true

	get := func(retry int) error {
		ctx := context.Background()
		op := operation.NewGet(ctx, stateURI)
		op.SetRetryCount(retry)
		return client.Send(op).Wait()
	}

	if err := get(0); err != nil {
		t.Fatal(err)
	}

	client.DefaultTransport.CloseIdleConnections()
	if err := th.Stop(); err != nil {
		t.Fatal(err)
	}

	if err := get(1); err == nil {
		t.Fatal("expected error")
	}
}
Beispiel #2
0
func GetAuthCredentialsServiceState(ctx context.Context, a *AuthCredentialsServiceState, u uri.URI) error {
	op := operation.NewGet(ctx, u)
	err := client.Send(op).Wait()
	if err != nil {
		return err
	}

	if err := op.DecodeBody(a); err != nil {
		return err
	}

	return nil
}
Beispiel #3
0
func WaitForNonEmptyBody(ctx context.Context, u uri.URI) error {
	return poll(ctx, func() (bool, error) {
		op := operation.NewGet(ctx, u)
		if err := client.Send(op).Wait(); err != nil {
			return false, fmt.Errorf("Error issuing GET: %s", err)
		}

		var m map[string]interface{}
		if err := op.DecodeBody(&m); err != nil {
			return false, fmt.Errorf("Error decoding body: %s", err)
		}

		return len(m) > 0, nil
	})
}
Beispiel #4
0
// GetServiceHostManagementState returns the local node's NodeState
func GetServiceHostManagementState(ctx context.Context) (*common.ServiceHostState, error) {
	u := uri.Extend(uri.Local(), common.Management)
	p := operation.NewGet(ctx, u)
	client.Send(p)
	if err := p.Wait(); err != nil {
		return nil, err
	}

	var state common.ServiceHostState
	err := p.DecodeBody(&state)
	if err != nil {
		return nil, err
	}
	return &state, nil
}
Beispiel #5
0
func (s *pingService) HandlePatch(ctx context.Context, op *operation.Operation) {
	req := &pingRequest{}
	err := op.DecodeBody(req)
	if err != nil {
		op.Fail(err)
		return
	}

	op.SetStatusCode(http.StatusCreated)
	op.Complete()

	// Ping specified URL
	pingOp := operation.NewPatch(ctx, req.URI, nil)
	pingOp.SetBody(req)
	client.Send(pingOp)
}