@@ -97,6 +97,7 @@ public void testConfig() {
97
97
config .setNamingUrl ("a://b" );
98
98
config .setTarget ("a://b" );
99
99
config .setRequestTimeout (10 );
100
+ config .setBackupRequestTimeMs (100 );
100
101
config .setProtocol ("trpc" );
101
102
config .setSerialization ("pb" );
102
103
config .setCompressor ("gzip" );
@@ -129,6 +130,7 @@ public void testConfig() {
129
130
assertEquals (70 , config .getConnsPerAddr ());
130
131
assertEquals (80 , config .getConnTimeout ());
131
132
assertEquals (10 , config .getRequestTimeout ());
133
+ assertEquals (100 , config .getBackupRequestTimeMs ());
132
134
assertEquals (true , config .isIoThreadGroupShare ());
133
135
assertEquals (1000 , config .getIoThreads ());
134
136
assertEquals ("/trpc" , config .getBasePath ());
@@ -149,27 +151,41 @@ public void testConfig() {
149
151
}
150
152
151
153
@ Test
152
- public void testSetCallee () {
153
- ExtensionLoader
154
- .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
154
+ public void testNoSetCallee () {
155
+ ExtensionLoader .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
155
156
BackendConfig config = new BackendConfig ();
156
157
config .setName ("trpc.calleeapp.calleeserver.calleeservice.calleemethod" );
157
158
config .setNamingUrl ("ip://127.0.0.1:8888" );
158
159
config .setExtMap (ImmutableMap .of ("attalog" , (Object ) "attalog" ));
159
160
config .setFilters (Lists .newArrayList ("attalog" ));
160
161
config .setGroup ("group" );
161
- config .setCallee ("trpc.app.server.service" );
162
162
config .init ();
163
163
assertEquals (config .getCalleeApp (), "" );
164
164
assertEquals (config .getCalleeServer (), "" );
165
165
assertEquals (config .getCalleeService (), "" );
166
166
assertEquals ("127.0.0.1:8888" , config .getCallee ());
167
167
}
168
168
169
+ @ Test
170
+ public void testSetCallee () {
171
+ ExtensionLoader .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
172
+ BackendConfig config = new BackendConfig ();
173
+ config .setName ("trpc.calleeapp.calleeserver.calleeservice.calleemethod" );
174
+ config .setNamingUrl ("ip://127.0.0.1:8888" );
175
+ config .setExtMap (ImmutableMap .of ("attalog" , (Object ) "attalog" ));
176
+ config .setFilters (Lists .newArrayList ("attalog" ));
177
+ config .setGroup ("group" );
178
+ config .setCallee ("trpc.app.server.service" );
179
+ config .init ();
180
+ assertEquals (config .getCalleeApp (), "app" );
181
+ assertEquals (config .getCalleeServer (), "server" );
182
+ assertEquals (config .getCalleeService (), "service" );
183
+ assertEquals ("trpc.app.server.service" , config .getCallee ());
184
+ }
185
+
169
186
@ Test
170
187
public void testNameSpace () {
171
- ExtensionLoader
172
- .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
188
+ ExtensionLoader .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
173
189
BackendConfig config = new BackendConfig ();
174
190
config .setName ("trpc.calleeapp.calleeserver.calleeservice.calleemethod" );
175
191
config .setNamingUrl ("ip://127.0.0.1:8888" );
@@ -183,16 +199,15 @@ public void testNameSpace() {
183
199
config .init ();
184
200
config .toString ();
185
201
assertEquals (0 , config .getNamingMap ().size ());
186
- assertEquals (config .getCalleeApp (), "" );
187
- assertEquals (config .getCalleeServer (), "" );
188
- assertEquals (config .getCalleeService (), "" );
202
+ assertEquals (config .getCalleeApp (), "app " );
203
+ assertEquals (config .getCalleeServer (), "server " );
204
+ assertEquals (config .getCalleeService (), "service " );
189
205
assertEquals (config .getNamingOptions ().getExtMap ().get ("namespace" ), "abc" );
190
206
}
191
207
192
208
@ Test
193
209
public void testIp () {
194
- ExtensionLoader
195
- .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
210
+ ExtensionLoader .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
196
211
ExtensionLoader .registerPlugin (ThreadWorkerPool .newThreadWorkerPoolConfig ("thread" , 10 , Boolean .FALSE ));
197
212
BackendConfig config = new BackendConfig ();
198
213
config .setNamingUrl ("ip://127.0.0.1:8888" );
@@ -237,10 +252,8 @@ public void testIp() {
237
252
238
253
@ Test
239
254
public void test () {
240
- ExtensionLoader
241
- .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
242
- ExtensionLoader .registerPlugin (ThreadWorkerPool .newThreadWorkerPoolConfig ("thread" , 10 ,
243
- 10 , Boolean .FALSE ));
255
+ ExtensionLoader .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
256
+ ExtensionLoader .registerPlugin (ThreadWorkerPool .newThreadWorkerPoolConfig ("thread" , 10 , Boolean .FALSE ));
244
257
BackendConfig config = new BackendConfig ();
245
258
config .setCallee ("trpc.calleeapp.calleeserver.calleeservice.calleemethod" );
246
259
config .setNamingUrl ("ip://127.0.0.1:8888" );
@@ -273,9 +286,9 @@ public void test() {
273
286
assertEquals (config .getServiceInterface (), GenericClient .class );
274
287
assertEquals (config .getRequestTimeout (), 1234 );
275
288
assertEquals (config .getVersion (), "v888" );
276
- assertEquals (config .getCalleeApp (), "" );
277
- assertEquals (config .getCalleeServer (), "" );
278
- assertEquals (config .getCalleeService (), "" );
289
+ assertEquals (config .getCalleeApp (), "calleeapp " );
290
+ assertEquals (config .getCalleeServer (), "calleeserver " );
291
+ assertEquals (config .getCalleeService (), "calleeservice " );
279
292
ServiceId serviceId = config .toNamingServiceId ();
280
293
assertEquals (serviceId .getGroup (), "group" );
281
294
assertEquals (serviceId .getServiceName (), "127.0.0.1:8888" );
@@ -294,8 +307,7 @@ public void testGetProxy() {
294
307
config .setServiceInterface (GenericClient .class );
295
308
config .setName ("client" );
296
309
config .setNamingUrl ("ip://127.0.0.1:12345" );
297
- ConfigManager .getInstance ().getClientConfig ().getBackendConfigMap ()
298
- .put ("client" , config );
310
+ ConfigManager .getInstance ().getClientConfig ().getBackendConfigMap ().put ("client" , config );
299
311
ConsumerConfig <GenericClient > consumerConfig = new ConsumerConfig <>();
300
312
consumerConfig .setBackendConfig (config );
301
313
consumerConfig .setServiceInterface (GenericClient .class );
@@ -317,8 +329,7 @@ public void testGetProxy() {
317
329
318
330
@ Test
319
331
public void testNotDefault () {
320
- ExtensionLoader
321
- .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
332
+ ExtensionLoader .registerPlugin (new PluginConfig ("attalog" , Filter .class , RemoteLoggerTest .class ));
322
333
ExtensionLoader .registerPlugin (ThreadWorkerPool .newThreadWorkerPoolConfig ("thread" , 10 , Boolean .FALSE ));
323
334
BackendConfig config = new BackendConfig ();
324
335
config .setName ("trpc.calleeapp.calleeserver.calleeservice.calleemethod" );
@@ -351,6 +362,54 @@ public void testNotDefault() {
351
362
}
352
363
}
353
364
365
+ @ Test
366
+ public void testSetDestinationSet () {
367
+ BackendConfig config = new BackendConfig ();
368
+ config .setNamingUrl ("polaris://127.0.0.1:8888" );
369
+ config .setDestinationSet ("testSet" );
370
+ Object metaData = config .getNamingMap ().get (Constants .METADATA );
371
+ assertNotNull (metaData );
372
+ assertTrue (metaData instanceof Map );
373
+ assertEquals ("testSet" , ((Map <?, ?>) metaData ).get (Constants .POLARIS_PLUGIN_SET_NAME_KEY ));
374
+ }
375
+
376
+ @ Test
377
+ public void testNewConsumerConfig () {
378
+ BackendConfig config = new BackendConfig ();
379
+ ConsumerConfig <GenericClient > consumerConfig = config .newConsumerConfig (GenericClient .class );
380
+ assertNotNull (consumerConfig );
381
+ assertEquals (GenericClient .class , consumerConfig .getServiceInterface ());
382
+ }
383
+
384
+ @ Test
385
+ public void testOverrideConfigDefault () {
386
+ BackendConfig config = new BackendConfig ();
387
+ ClientConfig clientConfig = new ClientConfig ();
388
+ clientConfig .setRequestTimeout (5000 );
389
+ config .overrideConfigDefault (clientConfig );
390
+ assertEquals (5000 , config .getRequestTimeout ());
391
+ }
392
+
393
+ @ Test
394
+ public void testMergeConfig () {
395
+ BackendConfig config = new BackendConfig ();
396
+ ClientConfig clientConfig = new ClientConfig ();
397
+ clientConfig .setFilters (Lists .newArrayList ("testFilter" ));
398
+ config .mergeConfig (clientConfig );
399
+ assertEquals (1 , config .getFilters ().size ());
400
+ assertEquals ("testFilter" , config .getFilters ().get (0 ));
401
+ }
402
+
403
+ @ Test
404
+ public void testGenerateProtocolConfig () {
405
+ BackendConfig config = new BackendConfig ();
406
+ ProtocolConfig protocolConfig = config .generateProtocolConfig ("127.0.0.1" , 8080 , "tcp" );
407
+ assertNotNull (protocolConfig );
408
+ assertEquals ("127.0.0.1" , protocolConfig .getIp ());
409
+ assertEquals (8080 , protocolConfig .getPort ());
410
+ assertEquals ("tcp" , protocolConfig .getNetwork ());
411
+ }
412
+
354
413
public static final class RemoteLoggerTest extends RemoteLoggerFilter {
355
414
356
415
@ Override
0 commit comments