mirror of https://github.com/grpc/grpc-go.git
grpc: Add join Dial Option (#5861)
This commit is contained in:
parent
70617b11fa
commit
54b7d03e0f
|
@ -80,3 +80,39 @@ func (s) TestAddExtraServerOptions(t *testing.T) {
|
||||||
t.Fatalf("Unexpected len of extraServerOptions: %d != 0", len(extraServerOptions))
|
t.Fatalf("Unexpected len of extraServerOptions: %d != 0", len(extraServerOptions))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestJoinDialOption tests the join dial option. It configures a joined dial
|
||||||
|
// option with three individual dial options, and verifies that all three are
|
||||||
|
// successfully applied.
|
||||||
|
func (s) TestJoinDialOption(t *testing.T) {
|
||||||
|
const maxRecvSize = 998765
|
||||||
|
const initialWindowSize = 100
|
||||||
|
jdo := newJoinDialOption(WithTransportCredentials(insecure.NewCredentials()), WithReadBufferSize(maxRecvSize), WithInitialWindowSize(initialWindowSize))
|
||||||
|
cc, err := Dial("fake", jdo)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Dialing with insecure credentials failed: %v", err)
|
||||||
|
}
|
||||||
|
defer cc.Close()
|
||||||
|
if cc.dopts.copts.ReadBufferSize != maxRecvSize {
|
||||||
|
t.Fatalf("Unexpected cc.dopts.copts.ReadBufferSize: %d != %d", cc.dopts.copts.ReadBufferSize, maxRecvSize)
|
||||||
|
}
|
||||||
|
if cc.dopts.copts.InitialWindowSize != initialWindowSize {
|
||||||
|
t.Fatalf("Unexpected cc.dopts.copts.InitialWindowSize: %d != %d", cc.dopts.copts.InitialWindowSize, initialWindowSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestJoinDialOption tests the join server option. It configures a joined
|
||||||
|
// server option with three individual server options, and verifies that all
|
||||||
|
// three are successfully applied.
|
||||||
|
func (s) TestJoinServerOption(t *testing.T) {
|
||||||
|
const maxRecvSize = 998765
|
||||||
|
const initialWindowSize = 100
|
||||||
|
jso := newJoinServerOption(Creds(insecure.NewCredentials()), MaxRecvMsgSize(maxRecvSize), InitialWindowSize(initialWindowSize))
|
||||||
|
s := NewServer(jso)
|
||||||
|
if s.opts.maxReceiveMessageSize != maxRecvSize {
|
||||||
|
t.Fatalf("Unexpected s.opts.maxReceiveMessageSize: %d != %d", s.opts.maxReceiveMessageSize, maxRecvSize)
|
||||||
|
}
|
||||||
|
if s.opts.initialWindowSize != initialWindowSize {
|
||||||
|
t.Fatalf("Unexpected s.opts.initialWindowSize: %d != %d", s.opts.initialWindowSize, initialWindowSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ func init() {
|
||||||
extraDialOptions = nil
|
extraDialOptions = nil
|
||||||
}
|
}
|
||||||
internal.WithBinaryLogger = withBinaryLogger
|
internal.WithBinaryLogger = withBinaryLogger
|
||||||
|
internal.JoinDialOptions = newJoinDialOption
|
||||||
}
|
}
|
||||||
|
|
||||||
// dialOptions configure a Dial call. dialOptions are set by the DialOption
|
// dialOptions configure a Dial call. dialOptions are set by the DialOption
|
||||||
|
@ -111,6 +112,20 @@ func newFuncDialOption(f func(*dialOptions)) *funcDialOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type joinDialOption struct {
|
||||||
|
opts []DialOption
|
||||||
|
}
|
||||||
|
|
||||||
|
func (jdo *joinDialOption) apply(do *dialOptions) {
|
||||||
|
for _, opt := range jdo.opts {
|
||||||
|
opt.apply(do)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newJoinDialOption(opts ...DialOption) DialOption {
|
||||||
|
return &joinDialOption{opts: opts}
|
||||||
|
}
|
||||||
|
|
||||||
// WithWriteBufferSize determines how much data can be batched before doing a
|
// WithWriteBufferSize determines how much data can be batched before doing a
|
||||||
// write on the wire. The corresponding memory allocation for this buffer will
|
// write on the wire. The corresponding memory allocation for this buffer will
|
||||||
// be twice the size to keep syscalls low. The default value for this buffer is
|
// be twice the size to keep syscalls low. The default value for this buffer is
|
||||||
|
|
|
@ -77,6 +77,9 @@ var (
|
||||||
// ClearGlobalDialOptions clears the array of extra DialOption. This
|
// ClearGlobalDialOptions clears the array of extra DialOption. This
|
||||||
// method is useful in testing and benchmarking.
|
// method is useful in testing and benchmarking.
|
||||||
ClearGlobalDialOptions func()
|
ClearGlobalDialOptions func()
|
||||||
|
// JoinDialOptions combines the dial options passed as arguments into a
|
||||||
|
// single dial option.
|
||||||
|
JoinDialOptions interface{} // func(...grpc.DialOption) grpc.DialOption
|
||||||
// JoinServerOptions combines the server options passed as arguments into a
|
// JoinServerOptions combines the server options passed as arguments into a
|
||||||
// single server option.
|
// single server option.
|
||||||
JoinServerOptions interface{} // func(...grpc.ServerOption) grpc.ServerOption
|
JoinServerOptions interface{} // func(...grpc.ServerOption) grpc.ServerOption
|
||||||
|
|
Loading…
Reference in New Issue