Skip to content

Commit

Permalink
integration: grpc on etcd peer ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Aug 18, 2017
1 parent 98f7f4e commit 115ae3a
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"testing"
"time"

"github.com/cockroachdb/cmux"
"golang.org/x/net/context"
"google.golang.org/grpc"

Expand Down Expand Up @@ -649,11 +650,29 @@ func (m *member) Launch() error {
m.s.SyncTicker = time.NewTicker(500 * time.Millisecond)
m.s.Start()

if m.grpcListener != nil {
var (
tlscfg *tls.Config
)
if m.ClientTLSInfo != nil && !m.ClientTLSInfo.Empty() {
tlscfg, err = m.ClientTLSInfo.ServerConfig()
if err != nil {
return err
}
}
m.grpcServer = v3rpc.Server(m.s, tlscfg)
m.serverClient = v3client.New(m.s)
lockpb.RegisterLockServer(m.grpcServer, v3lock.NewLockServer(m.serverClient))
epb.RegisterElectionServer(m.grpcServer, v3election.NewElectionServer(m.serverClient))
go m.grpcServer.Serve(m.grpcListener)
}

m.raftHandler = &testutil.PauseableHandler{Next: etcdhttp.NewPeerHandler(m.s)}

for _, ln := range m.PeerListeners {
cm := cmux.New(ln)
hs := &httptest.Server{
Listener: ln,
Listener: cm.Match(cmux.HTTP1()),
Config: &http.Server{Handler: m.raftHandler},
}
if m.PeerTLSInfo == nil {
Expand All @@ -665,6 +684,12 @@ func (m *member) Launch() error {
}
hs.StartTLS()
}

if m.grpcServer != nil {
go m.grpcServer.Serve(cm.Match(cmux.HTTP2()))
}
go cm.Serve()

m.hss = append(m.hss, hs)
}
for _, ln := range m.ClientListeners {
Expand All @@ -683,22 +708,6 @@ func (m *member) Launch() error {
}
m.hss = append(m.hss, hs)
}
if m.grpcListener != nil {
var (
tlscfg *tls.Config
)
if m.ClientTLSInfo != nil && !m.ClientTLSInfo.Empty() {
tlscfg, err = m.ClientTLSInfo.ServerConfig()
if err != nil {
return err
}
}
m.grpcServer = v3rpc.Server(m.s, tlscfg)
m.serverClient = v3client.New(m.s)
lockpb.RegisterLockServer(m.grpcServer, v3lock.NewLockServer(m.serverClient))
epb.RegisterElectionServer(m.grpcServer, v3election.NewElectionServer(m.serverClient))
go m.grpcServer.Serve(m.grpcListener)
}

plog.Printf("launched %s (%s)", m.Name, m.grpcAddr)
return nil
Expand Down

0 comments on commit 115ae3a

Please sign in to comment.