@@ -74,12 +74,7 @@ func TestClientManager_HTTP2AndHTTP3(t *testing.T) {
7474 // If successfully created, verify the client manager
7575 assert .NotNil (t , clientManager )
7676 assert .True (t , clientManager .isIDL )
77- assert .NotEmpty (t , clientManager .triClients )
78-
79- // Verify that the client for the specific method exists
80- client , exists := clientManager .triClients ["testMethod" ]
81- assert .True (t , exists )
82- assert .NotNil (t , client )
77+ assert .NotNil (t , clientManager .triClient )
8378}
8479
8580func TestDualTransport (t * testing.T ) {
@@ -98,104 +93,18 @@ func TestDualTransport(t *testing.T) {
9893 assert .True (t , ok , "transport should implement http.RoundTripper" )
9994}
10095
101- func TestClientManager_GetClient (t * testing.T ) {
102- tests := []struct {
103- desc string
104- cm * clientManager
105- method string
106- expectErr bool
107- }{
108- {
109- desc : "method exists" ,
110- cm : & clientManager {
111- triClients : map [string ]* tri.Client {
112- "TestMethod" : tri .NewClient (& http.Client {}, "http://localhost:8080/test" ),
113- },
114- },
115- method : "TestMethod" ,
116- expectErr : false ,
117- },
118- {
119- desc : "method not exists" ,
120- cm : & clientManager {
121- triClients : map [string ]* tri.Client {
122- "TestMethod" : tri .NewClient (& http.Client {}, "http://localhost:8080/test" ),
123- },
124- },
125- method : "NonExistMethod" ,
126- expectErr : true ,
127- },
128- {
129- desc : "empty triClients" ,
130- cm : & clientManager {
131- triClients : map [string ]* tri.Client {},
132- },
133- method : "AnyMethod" ,
134- expectErr : true ,
135- },
136- }
137-
138- for _ , test := range tests {
139- t .Run (test .desc , func (t * testing.T ) {
140- client , err := test .cm .getClient (test .method )
141- if test .expectErr {
142- require .Error (t , err )
143- assert .Nil (t , client )
144- assert .Contains (t , err .Error (), "missing triple client" )
145- } else {
146- require .NoError (t , err )
147- assert .NotNil (t , client )
148- }
149- })
150- }
151- }
152-
15396func TestClientManager_Close (t * testing.T ) {
15497 cm := & clientManager {
155- isIDL : true ,
156- triClients : map [string ]* tri.Client {
157- "Method1" : tri .NewClient (& http.Client {}, "http://localhost:8080/test1" ),
158- "Method2" : tri .NewClient (& http.Client {}, "http://localhost:8080/test2" ),
159- },
98+ isIDL : true ,
99+ triClient : tri .NewClient (& http.Client {}, "http://localhost:8080/test" ),
160100 }
161101
162102 err := cm .close ()
163103 require .NoError (t , err )
164104}
165105
166- func TestClientManager_CallMethods_MissingClient (t * testing.T ) {
167- cm := & clientManager {
168- triClients : map [string ]* tri.Client {},
169- }
170- ctx := context .Background ()
171-
172- t .Run ("callUnary missing client" , func (t * testing.T ) {
173- err := cm .callUnary (ctx , "NonExist" , nil , nil )
174- require .Error (t , err )
175- assert .Contains (t , err .Error (), "missing triple client" )
176- })
177-
178- t .Run ("callClientStream missing client" , func (t * testing.T ) {
179- stream , err := cm .callClientStream (ctx , "NonExist" )
180- require .Error (t , err )
181- assert .Nil (t , stream )
182- assert .Contains (t , err .Error (), "missing triple client" )
183- })
184-
185- t .Run ("callServerStream missing client" , func (t * testing.T ) {
186- stream , err := cm .callServerStream (ctx , "NonExist" , nil )
187- require .Error (t , err )
188- assert .Nil (t , stream )
189- assert .Contains (t , err .Error (), "missing triple client" )
190- })
191-
192- t .Run ("callBidiStream missing client" , func (t * testing.T ) {
193- stream , err := cm .callBidiStream (ctx , "NonExist" )
194- require .Error (t , err )
195- assert .Nil (t , stream )
196- assert .Contains (t , err .Error (), "missing triple client" )
197- })
198- }
106+ // TestClientManager_CallMethods_MissingClient removed - no longer applicable
107+ // in the service-level client architecture where all methods share a single triClient.
199108
200109func Test_genKeepAliveOptions (t * testing.T ) {
201110 defaultInterval , _ := time .ParseDuration (constant .DefaultKeepAliveInterval )
@@ -359,16 +268,17 @@ func Test_newClientManager_Serialization(t *testing.T) {
359268}
360269
361270func Test_newClientManager_NoMethods (t * testing.T ) {
362- // Test when url has no methods and no RpcServiceKey attribute
271+ // Test when url has no methods - in service-level client architecture,
272+ // this is valid as the client is created at service level, not method level
363273 url := common .NewURLWithOptions (
364274 common .WithLocation ("localhost:20000" ),
365275 common .WithPath ("com.example.TestService" ),
366276 )
367277
368278 cm , err := newClientManager (url )
369- require .Error (t , err )
370- assert .Nil (t , cm )
371- assert .Contains (t , err . Error () , "can't get methods " )
279+ require .NoError (t , err , "service-level client should be created even without method list" )
280+ assert .NotNil (t , cm )
281+ assert .NotNil (t , cm . triClient , "triClient should be created at service level " )
372282}
373283
374284func Test_newClientManager_WithMethods (t * testing.T ) {
@@ -381,10 +291,7 @@ func Test_newClientManager_WithMethods(t *testing.T) {
381291 cm , err := newClientManager (url )
382292 require .NoError (t , err )
383293 assert .NotNil (t , cm )
384- assert .Len (t , cm .triClients , 3 )
385- assert .Contains (t , cm .triClients , "Method1" )
386- assert .Contains (t , cm .triClients , "Method2" )
387- assert .Contains (t , cm .triClients , "Method3" )
294+ assert .NotNil (t , cm .triClient , "triClient should be created" )
388295}
389296
390297func Test_newClientManager_WithGroupAndVersion (t * testing.T ) {
@@ -475,8 +382,8 @@ func Test_newClientManager_WithRpcService(t *testing.T) {
475382 cm , err := newClientManager (url )
476383 require .NoError (t , err )
477384 assert .NotNil (t , cm )
478- // Should have methods from mockService (Reference, TestMethod1, TestMethod2)
479- assert .GreaterOrEqual (t , len ( cm .triClients ), 2 )
385+ // In service-level client architecture, a single triClient is created
386+ assert .NotNil (t , cm .triClient , "triClient should be created for non-IDL mode" )
480387}
481388
482389func TestDualTransport_Structure (t * testing.T ) {
@@ -552,7 +459,7 @@ func Test_newClientManager_URLPrefixHandling(t *testing.T) {
552459 cm , err := newClientManager (url )
553460 require .NoError (t , err )
554461 assert .NotNil (t , cm )
555- assert .Len (t , cm .triClients , 1 )
462+ assert .NotNil (t , cm .triClient , "triClient should be created" )
556463 })
557464 }
558465}
@@ -635,12 +542,8 @@ func Test_newClientManager_MultipleMethods(t *testing.T) {
635542 cm , err := newClientManager (url )
636543 require .NoError (t , err )
637544 assert .NotNil (t , cm )
638- assert .Len (t , cm .triClients , len (methods ))
639-
640- for _ , method := range methods {
641- _ , exists := cm .triClients [method ]
642- assert .True (t , exists , "method %s should exist" , method )
643- }
545+ // In service-level client architecture, a single triClient handles all methods
546+ assert .NotNil (t , cm .triClient , "triClient should be created to handle all methods" )
644547}
645548
646549func Test_newClientManager_InterfaceName (t * testing.T ) {
0 commit comments