@@ -101,11 +101,14 @@ public void setup() {
101101 // Create a real ClusterSettings instance with the plugin's settings
102102 plugin = new GrpcPlugin ();
103103
104+ // Mock ThreadPool and ThreadContext
105+ when (threadPool .getThreadContext ()).thenReturn (new ThreadContext (Settings .EMPTY ));
106+
104107 // Set the client in the plugin
105108 plugin .createComponents (
106109 client ,
107110 null , // ClusterService
108- null , // ThreadPool
111+ threadPool , // ThreadPool (now properly mocked)
109112 null , // ResourceWatcherService
110113 null , // ScriptService
111114 null , // NamedXContentRegistry
@@ -255,7 +258,9 @@ public void testGetSecureAuxTransportsWithNullClient() {
255258
256259 public void testGetAuxTransportsWithServiceFactories () {
257260 GrpcPlugin newPlugin = new GrpcPlugin ();
258- newPlugin .createComponents (Mockito .mock (Client .class ), null , null , null , null , null , null , null , null , null , null );
261+ ThreadPool mockThreadPool = Mockito .mock (ThreadPool .class );
262+ when (mockThreadPool .getThreadContext ()).thenReturn (new ThreadContext (Settings .EMPTY ));
263+ newPlugin .createComponents (Mockito .mock (Client .class ), null , mockThreadPool , null , null , null , null , null , null , null , null );
259264 ExtensiblePlugin .ExtensionLoader mockLoader = Mockito .mock (ExtensiblePlugin .ExtensionLoader .class );
260265 when (mockLoader .loadExtensions (GrpcServiceFactory .class )).thenReturn (List .of (new LoadableMockServiceFactory ()));
261266 plugin .loadExtensions (mockLoader );
@@ -274,7 +279,9 @@ public void testGetAuxTransportsWithServiceFactories() {
274279
275280 public void testGetSecureAuxTransportsWithServiceFactories () {
276281 GrpcPlugin newPlugin = new GrpcPlugin ();
277- newPlugin .createComponents (Mockito .mock (Client .class ), null , null , null , null , null , null , null , null , null , null );
282+ ThreadPool mockThreadPool = Mockito .mock (ThreadPool .class );
283+ when (mockThreadPool .getThreadContext ()).thenReturn (new ThreadContext (Settings .EMPTY ));
284+ newPlugin .createComponents (Mockito .mock (Client .class ), null , mockThreadPool , null , null , null , null , null , null , null , null );
278285 ExtensiblePlugin .ExtensionLoader mockLoader = Mockito .mock (ExtensiblePlugin .ExtensionLoader .class );
279286 when (mockLoader .loadExtensions (GrpcServiceFactory .class )).thenReturn (List .of (new LoadableMockServiceFactory ()));
280287 plugin .loadExtensions (mockLoader );
@@ -430,11 +437,45 @@ public void testLoadExtensionsWithGrpcInterceptorsOrdering() {
430437 }
431438
432439 public void testLoadExtensionsWithDuplicateGrpcInterceptorOrder () {
433- testInterceptorLoading (List .of (1 , 1 ), IllegalArgumentException .class );
440+ GrpcPlugin plugin = new GrpcPlugin ();
441+ ExtensiblePlugin .ExtensionLoader mockLoader = createMockLoader (List .of (1 , 1 ));
442+
443+ assertDoesNotThrow (() -> plugin .loadExtensions (mockLoader ));
444+
445+ ThreadPool mockThreadPool = Mockito .mock (ThreadPool .class );
446+ when (mockThreadPool .getThreadContext ()).thenReturn (new org .opensearch .common .util .concurrent .ThreadContext (Settings .EMPTY ));
447+
448+ IllegalArgumentException exception = expectThrows (
449+ IllegalArgumentException .class ,
450+ () -> plugin .createComponents (client , null , mockThreadPool , null , null , null , null , null , null , null , null )
451+ );
452+
453+ String errorMessage = exception .getMessage ();
454+ assertTrue (errorMessage .contains ("Multiple gRPC interceptors have the same order value [1]" ));
455+ assertTrue (errorMessage .contains ("ServerInterceptor" )); // Mock class name will contain this
456+ assertTrue (errorMessage .contains ("Each interceptor must have a unique order value" ));
434457 }
435458
436459 public void testLoadExtensionsWithMultipleProvidersAndDuplicateOrder () {
437- testInterceptorLoadingWithMultipleProviders (List .of (List .of (5 ), List .of (5 )), IllegalArgumentException .class );
460+ GrpcPlugin plugin = new GrpcPlugin ();
461+ ExtensiblePlugin .ExtensionLoader mockLoader = createMockLoaderWithMultipleProviders (List .of (List .of (5 ), List .of (5 )));
462+
463+ // loadExtensions should succeed
464+ assertDoesNotThrow (() -> plugin .loadExtensions (mockLoader ));
465+
466+ // createComponents should fail with duplicate order
467+ ThreadPool mockThreadPool = Mockito .mock (ThreadPool .class );
468+ when (mockThreadPool .getThreadContext ()).thenReturn (new org .opensearch .common .util .concurrent .ThreadContext (Settings .EMPTY ));
469+
470+ IllegalArgumentException exception = expectThrows (
471+ IllegalArgumentException .class ,
472+ () -> plugin .createComponents (client , null , mockThreadPool , null , null , null , null , null , null , null , null )
473+ );
474+
475+ String errorMessage = exception .getMessage ();
476+ assertTrue (errorMessage .contains ("Multiple gRPC interceptors have the same order value [5]" ));
477+ assertTrue (errorMessage .contains ("ServerInterceptor" ));
478+ assertTrue (errorMessage .contains ("Each interceptor must have a unique order value" ));
438479 }
439480
440481 public void testLoadExtensionsWithNullGrpcInterceptorProviders () {
@@ -446,7 +487,23 @@ public void testLoadExtensionsWithEmptyGrpcInterceptorList() {
446487 }
447488
448489 public void testLoadExtensionsWithSameExplicitOrderInterceptors () {
449- testInterceptorLoading (List .of (5 , 5 ), IllegalArgumentException .class );
490+ GrpcPlugin plugin = new GrpcPlugin ();
491+ ExtensiblePlugin .ExtensionLoader mockLoader = createMockLoader (List .of (5 , 5 ));
492+
493+ assertDoesNotThrow (() -> plugin .loadExtensions (mockLoader ));
494+
495+ ThreadPool mockThreadPool = Mockito .mock (ThreadPool .class );
496+ when (mockThreadPool .getThreadContext ()).thenReturn (new org .opensearch .common .util .concurrent .ThreadContext (Settings .EMPTY ));
497+
498+ IllegalArgumentException exception = expectThrows (
499+ IllegalArgumentException .class ,
500+ () -> plugin .createComponents (client , null , mockThreadPool , null , null , null , null , null , null , null , null )
501+ );
502+
503+ String errorMessage = exception .getMessage ();
504+ assertTrue (errorMessage .contains ("Multiple gRPC interceptors have the same order value [5]" ));
505+ assertTrue (errorMessage .contains ("ServerInterceptor" ));
506+ assertTrue (errorMessage .contains ("Each interceptor must have a unique order value" ));
450507 }
451508
452509 // Test cases for interceptor chain failure handling
@@ -867,10 +924,16 @@ public void testGrpcInterceptorChainWithDuplicateOrders() {
867924 when (mockThreadPool .getThreadContext ()).thenReturn (new org .opensearch .common .util .concurrent .ThreadContext (Settings .EMPTY ));
868925
869926 // Should throw exception due to duplicate orders during createComponents
870- expectThrows (
927+ IllegalArgumentException exception = expectThrows (
871928 IllegalArgumentException .class ,
872929 () -> plugin .createComponents (client , null , mockThreadPool , null , null , null , null , null , null , null , null )
873930 );
931+
932+ // Verify error message includes order value and interceptor class names
933+ String errorMessage = exception .getMessage ();
934+ assertTrue (errorMessage .contains ("Multiple gRPC interceptors have the same order value [10]" ));
935+ assertTrue (errorMessage .contains ("GrpcPluginTests" ));
936+ assertTrue (errorMessage .contains ("Each interceptor must have a unique order value" ));
874937 }
875938
876939 /**
0 commit comments