Ejemplo n.º 1
0
func (suite *errorSetSuite) SetupTest() {
	suite.rawErrs = map[string]*terrors.Error{}
	suite.errs = nil

	err := terrors.InternalService("", "uid1", nil)
	err.Params[errUidField] = "uid1"
	err.Params[errServiceField] = "service.uid1"
	err.Params[errEndpointField] = "uid1"
	suite.errs = append(suite.errs, err)
	suite.rawErrs["uid1"] = err

	err = terrors.InternalService("", "uid2", nil)
	err.Params[errUidField] = "uid2"
	err.Params[errServiceField] = "service.uid2"
	err.Params[errEndpointField] = "uid2"
	suite.errs = append(suite.errs, err)
	suite.rawErrs["uid2"] = err

	err = terrors.InternalService("", "uid3", nil)
	err.Params[errUidField] = "uid3"
	err.Params[errServiceField] = "service.uid2" // Same service as uid2
	err.Params[errEndpointField] = "uid3"
	suite.errs = append(suite.errs, err)
	suite.rawErrs["uid3"] = err
}
Ejemplo n.º 2
0
// exec actually executes the requests; called by Go() within a sync.Once.
func (c *client) exec() {
	defer close(c.doneC)

	c.RLock()
	timeout := c.timeout
	calls := c.calls // We don't need to make a copy as calls cannot be mutated once execution begins
	trans := c.transport()
	middleware := c.middleware
	c.RUnlock()

	completedCallsC := make(chan clientCall, len(calls))
	for _, call := range calls {
		if call.err != nil {
			completedCallsC <- call
			continue
		} else if trans == nil {
			call.err = terrors.InternalService("no_transport", "Client has no transport", nil)
			completedCallsC <- call
			continue
		}
		go c.performCall(call, middleware, trans, timeout, completedCallsC)
	}

	// Collect completed calls into a new map
	completedCalls := make(map[string]clientCall, cap(completedCallsC))
	for i := 0; i < cap(completedCallsC); i++ {
		call := <-completedCallsC
		completedCalls[call.uid] = call
	}
	close(completedCallsC)

	c.Lock()
	defer c.Unlock()
	c.calls = completedCalls
}
Ejemplo n.º 3
0
func (suite *errorSetSuite) TestMultiErrorPriority() {
	br := terrors.BadRequest("missing_param", "foo bar", nil)
	is := terrors.InternalService("something_broke", "hello world", nil)
	suite.Assert().True(higherPriority(is.Code, br.Code))
	se := terrors.New("something_else", "baz", nil)
	suite.Assert().True(higherPriority(is.Code, se.Code))
	suite.Assert().True(higherPriority(br.Code, se.Code))

	es := ErrorSet{se, is, br}
	suite.Assert().Equal(is.Code, es.Combined().(*terrors.Error).Code)
}
Ejemplo n.º 4
0
	"github.com/mondough/terrors"
	tmsg "github.com/mondough/typhon/message"
	ttrans "github.com/mondough/typhon/transport"
	"golang.org/x/net/context"
	"gopkg.in/tomb.v2"

	"github.com/mondough/mercury"
	"github.com/mondough/mercury/transport"
)

const (
	connectTimeout = 30 * time.Second
)

var (
	ErrAlreadyRunning   error = terrors.InternalService("", "Server is already running", nil) // empty dotted code so impl details don't leak outside
	ErrTransportClosed  error = terrors.InternalService("", "Transport closed", nil)
	errEndpointNotFound       = terrors.BadRequest("endpoint_not_found", "Endpoint not found", nil)
	defaultMiddleware   []ServerMiddleware
	defaultMiddlewareM  sync.RWMutex
)

func NewServer(name string) Server {
	defaultMiddlewareM.RLock()
	middleware := defaultMiddleware
	defaultMiddlewareM.RUnlock()

	return &server{
		name:       name,
		middleware: middleware,
	}