Skip to content

Commit

Permalink
Dispatcher: Expose configured outbounds (#1498)
Browse files Browse the repository at this point in the history
This pull request creates an `Dispatcher.Outbounds` method that is
symmetrical to `Dispatcher.Inbounds()`.  It allows reading off all of
the configured outbounds in one shot.

The intention behind this is to make it somewhat easier to read off a
YARPC configuration, rather than trying to recreate it by hand when
created via our internal wrapper around YARPC.
  • Loading branch information
ztstewart authored and zmt committed Jul 5, 2018
1 parent 4b098da commit cd7ae27
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added `Outbounds()` on `Dispatcher` to provide access to the configured outbounds.

### Changed
- TChannel inbounds will blackhole requests when handlers return resource
exhausted errors.
Expand Down
9 changes: 9 additions & 0 deletions dispatcher.go
Expand Up @@ -224,6 +224,15 @@ func (d *Dispatcher) Inbounds() Inbounds {
return inbounds
}

// Outbounds returns a copy of the list of outbounds for this RPC object.
func (d *Dispatcher) Outbounds() Outbounds {
outbounds := make(Outbounds, len(d.outbounds))
for k, v := range d.outbounds {
outbounds[k] = v
}
return outbounds
}

// ClientConfig provides the configuration needed to talk to the given
// service through an outboundKey. This configuration may be directly
// passed into encoding-specific RPC clients.
Expand Down
24 changes: 24 additions & 0 deletions dispatcher_test.go
Expand Up @@ -157,6 +157,30 @@ func TestInboundsOrderAfterStart(t *testing.T) {
assert.NotNil(t, httpInbound.Addr(), "expected an HTTP addr")
}

func TestOutboundsReturnsACopy(t *testing.T) {
testService := "my-test-service"
d := NewDispatcher(Config{
Name: "test",
Outbounds: Outbounds{
testService: {
Unary: http.NewTransport().NewSingleOutbound("http://127.0.0.1:1234"),
},
},
})

outbounds := d.Outbounds()
require.Len(t, outbounds, 1, "expected one outbound")
assert.Contains(t, outbounds, testService, "must contain my-test-service")

// Mutate the map and verify that the next call still returns non-nil
// results.
delete(outbounds, "my-test-service")

outbounds = d.Outbounds()
require.Len(t, outbounds, 1, "expected one outbound")
assert.Contains(t, outbounds, testService, "must contain my-test-service")
}

func TestStartStopFailures(t *testing.T) {
tests := []struct {
desc string
Expand Down

0 comments on commit cd7ae27

Please sign in to comment.