@@ -25,6 +25,8 @@ import (
2525import (
2626 "github.com/stretchr/testify/assert"
2727 "github.com/stretchr/testify/require"
28+
29+ "gopkg.in/yaml.v3"
2830)
2931
3032import (
@@ -334,6 +336,95 @@ func TestInstanceInitDefaultsExplicitTripleConfig(t *testing.T) {
334336 assert .Equal (t , "4mib" , tri .TripleConfig .MaxServerRecvMsgSize )
335337}
336338
339+ func TestInstanceInitMigratesDeprecatedProtocolMessageSizes (t * testing.T ) {
340+ tests := []struct {
341+ name string
342+ protocol * global.ProtocolConfig
343+ wantLegacySend string
344+ wantLegacyRecv string
345+ wantNestedSend string
346+ wantNestedRecv string
347+ }{
348+ {
349+ name : "deprecated values populate empty nested values" ,
350+ protocol : & global.ProtocolConfig {
351+ MaxServerSendMsgSize : "2mib" ,
352+ MaxServerRecvMsgSize : "3mib" ,
353+ TripleConfig : & global.TripleConfig {},
354+ },
355+ wantLegacySend : "2mib" ,
356+ wantLegacyRecv : "3mib" ,
357+ wantNestedSend : "2mib" ,
358+ wantNestedRecv : "3mib" ,
359+ },
360+ {
361+ name : "nested values take precedence" ,
362+ protocol : & global.ProtocolConfig {
363+ MaxServerSendMsgSize : "2mib" ,
364+ MaxServerRecvMsgSize : "3mib" ,
365+ TripleConfig : & global.TripleConfig {
366+ MaxServerSendMsgSize : "5mib" ,
367+ MaxServerRecvMsgSize : "6mib" ,
368+ },
369+ },
370+ wantLegacySend : "2mib" ,
371+ wantLegacyRecv : "3mib" ,
372+ wantNestedSend : "5mib" ,
373+ wantNestedRecv : "6mib" ,
374+ },
375+ {
376+ name : "empty values use defaults" ,
377+ protocol : & global.ProtocolConfig {},
378+ wantLegacyRecv : "4mib" ,
379+ wantNestedRecv : "4mib" ,
380+ },
381+ }
382+
383+ for _ , tt := range tests {
384+ t .Run (tt .name , func (t * testing.T ) {
385+ ins , err := NewInstance (func (opts * InstanceOptions ) {
386+ opts .Protocols = map [string ]* global.ProtocolConfig {
387+ constant .TriProtocol : tt .protocol ,
388+ }
389+ })
390+ require .NoError (t , err )
391+
392+ tri := ins .insOpts .Protocols [constant .TriProtocol ]
393+ require .NotNil (t , tri )
394+ require .NotNil (t , tri .TripleConfig )
395+ assert .Equal (t , tt .wantLegacySend , tri .MaxServerSendMsgSize )
396+ assert .Equal (t , tt .wantLegacyRecv , tri .MaxServerRecvMsgSize )
397+ assert .Equal (t , tt .wantNestedSend , tri .TripleConfig .MaxServerSendMsgSize )
398+ assert .Equal (t , tt .wantNestedRecv , tri .TripleConfig .MaxServerRecvMsgSize )
399+ })
400+ }
401+ }
402+
403+ func TestInstanceInitMigratesDeprecatedProtocolMessageSizesFromYAML (t * testing.T ) {
404+ var protocols map [string ]* global.ProtocolConfig
405+ err := yaml .Unmarshal ([]byte (`
406+ tri:
407+ name: tri
408+ max-server-send-msg-size: 2mib
409+ max-server-recv-msg-size: 3mib
410+ triple: {}
411+ ` ), & protocols )
412+ require .NoError (t , err )
413+
414+ ins , err := NewInstance (func (opts * InstanceOptions ) {
415+ opts .Protocols = protocols
416+ })
417+ require .NoError (t , err )
418+
419+ tri := ins .insOpts .Protocols [constant .TriProtocol ]
420+ require .NotNil (t , tri )
421+ require .NotNil (t , tri .TripleConfig )
422+ assert .Equal (t , "2mib" , tri .MaxServerSendMsgSize )
423+ assert .Equal (t , "3mib" , tri .MaxServerRecvMsgSize )
424+ assert .Equal (t , "2mib" , tri .TripleConfig .MaxServerSendMsgSize )
425+ assert .Equal (t , "3mib" , tri .TripleConfig .MaxServerRecvMsgSize )
426+ }
427+
337428func TestInstanceInitTranslatesGlobalRegistryAddress (t * testing.T ) {
338429 ins , err := NewInstance (func (opts * InstanceOptions ) {
339430 opts .Registries = map [string ]* global.RegistryConfig {
0 commit comments