@@ -851,109 +851,10 @@ void testDoubleRelease() throws Exception {
851851 }
852852
853853 @ Test
854- void settingsValidationFailsWhenMinChannelsExceedsMaxChannels () {
854+ void settingsValidationFailsWhenMaxResizeDeltaExceedsLimit () {
855855 ChannelPoolSettings .Builder builder =
856- ChannelPoolSettings .builder ().setMinChannelCount (2 ).setMaxChannelCount (1 );
857- Assertions .assertThrows (IllegalStateException .class , () -> builder .build ());
858- }
859-
860- @ Test
861- void minChannelsClampedToMaxChannelCountUnderHighLoad () throws Exception {
862- ScheduledExecutorService executor = Mockito .mock (ScheduledExecutorService .class );
863- FixedExecutorProvider provider = FixedExecutorProvider .create (executor );
864-
865- List <ManagedChannel > channels = new ArrayList <>();
866- ChannelFactory channelFactory = createMockChannelFactory (channels , null );
867-
868- pool =
869- new ChannelPool (
870- ChannelPoolSettings .builder ()
871- .setInitialChannelCount (1 )
872- .setMinRpcsPerChannel (1 )
873- .setMaxRpcsPerChannel (2 )
874- .setMaxResizeDelta (10 ) // Allow large growth
875- .setMinChannelCount (1 )
876- .setMaxChannelCount (5 )
877- .build (),
878- channelFactory ,
879- provider );
880- assertThat (pool .entries .get ()).hasSize (1 );
881-
882- // Add 20 RPCs, which would require 10 channels (20/2)
883- // But max is 5
884- for (int i = 0 ; i < 20 ; i ++) {
885- ClientCalls .futureUnaryCall (
886- pool .newCall (METHOD_RECOGNIZE , CallOptions .DEFAULT ), Color .getDefaultInstance ());
887- }
888-
889- pool .resize ();
890-
891- // Should be clamped to maxChannelCount = 5
892- assertThat (pool .entries .get ()).hasSize (5 );
893- }
894-
895- @ Test
896- void resizeDampenedByMaxResizeDelta () throws Exception {
897- ScheduledExecutorService executor = Mockito .mock (ScheduledExecutorService .class );
898- FixedExecutorProvider provider = FixedExecutorProvider .create (executor );
899-
900- List <ManagedChannel > channels = new ArrayList <>();
901- ChannelFactory channelFactory = createMockChannelFactory (channels , null );
902-
903- pool =
904- new ChannelPool (
905- ChannelPoolSettings .builder ()
906- .setInitialChannelCount (1 )
907- .setMinRpcsPerChannel (1 )
908- .setMaxRpcsPerChannel (2 )
909- .setMaxResizeDelta (2 ) // Limit growth to 2 channels per cycle
910- .setMinChannelCount (1 )
911- .setMaxChannelCount (10 )
912- .build (),
913- channelFactory ,
914- provider );
915- assertThat (pool .entries .get ()).hasSize (1 );
916-
917- // Add 20 RPCs, which would require 10 channels (20/2)
918- // Desired delta is +9 (10 - 1)
919- // maxResizeDelta is 2, so it should be dampened to 2
920- for (int i = 0 ; i < 20 ; i ++) {
921- ClientCalls .futureUnaryCall (
922- pool .newCall (METHOD_RECOGNIZE , CallOptions .DEFAULT ), Color .getDefaultInstance ());
923- }
924-
925- pool .resize ();
926-
927- // Should be dampened to 1 + 2 = 3 channels
928- assertThat (pool .entries .get ()).hasSize (3 );
929- }
930-
931- @ Test
932- void maxChannelsClampedToMinChannelCountUnderLowLoad () throws Exception {
933- ScheduledExecutorService executor = Mockito .mock (ScheduledExecutorService .class );
934- FixedExecutorProvider provider = FixedExecutorProvider .create (executor );
935-
936- List <ManagedChannel > channels = new ArrayList <>();
937- ChannelFactory channelFactory = createMockChannelFactory (channels , null );
938-
939- pool =
940- new ChannelPool (
941- ChannelPoolSettings .builder ()
942- .setInitialChannelCount (5 )
943- .setMinRpcsPerChannel (1 )
944- .setMaxRpcsPerChannel (2 )
945- .setMinChannelCount (3 )
946- .setMaxChannelCount (10 )
947- .build (),
948- channelFactory ,
949- provider );
950- assertThat (pool .entries .get ()).hasSize (5 );
951-
952- // With no outstanding RPCs, the pool should want to shrink to 0
953- // But min is 3
954- pool .resize ();
955-
956- // Should be clamped to minChannelCount = 3
957- assertThat (pool .entries .get ()).hasSize (3 );
856+ ChannelPoolSettings .builder ().setMaxResizeDelta (26 ).setMaxChannelCount (30 );
857+ org .junit .jupiter .api .Assertions .assertThrows (
858+ IllegalStateException .class , () -> builder .build ());
958859 }
959860}
0 commit comments