Exemplo n.º 1
0
// New returns a mock Hyperbahn server that can be used for testing.
func New() (*Mock, error) {
	ch, err := tchannel.NewChannel("hyperbahn", nil)
	if err != nil {
		return nil, err
	}

	mh := &Mock{
		ch:              ch,
		respCh:          make(chan int),
		discoverResults: make(map[string][]string),
	}
	if err := json.Register(ch, json.Handlers{"ad": mh.adHandler}, nil); err != nil {
		return nil, err
	}

	thriftServer := thrift.NewServer(ch)
	thriftServer.Register(hthrift.NewTChanHyperbahnServer(mh))

	return mh, ch.ListenAndServe("127.0.0.1:0")
}
Exemplo n.º 2
0
// New returns a mock Hyperbahn server that can be used for testing.
func New() (*Mock, error) {
	table := &mockTable{}
	ch, err := tchannel.NewChannel("hyperbahn", &tchannel.ChannelOptions{
		RelayHosts:         table,
		RelayLocalHandlers: []string{"hyperbahn"},
	})
	if err != nil {
		return nil, err
	}
	table.ch = ch
	mh := &Mock{
		ch:              ch,
		respCh:          make(chan int),
		discoverResults: make(map[string][]string),
	}
	if err := json.Register(ch, json.Handlers{"ad": mh.adHandler}, nil); err != nil {
		return nil, err
	}

	thriftServer := thrift.NewServer(ch)
	thriftServer.Register(hthrift.NewTChanHyperbahnServer(mh))

	return mh, ch.ListenAndServe("127.0.0.1:0")
}