Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,10 @@ private ClientConfiguration normalizeConfig(ClientConfiguration cfg) {
// Inject overrides
overrideConfig.ifPresent(builder::mergeFrom);

// When sessions are disabled make sure to clear out the config
if (cfg.getSessionConfiguration().getSessionLoad() == 0) {
// When sessions are disabled make sure to clear out the config. Read from the builder, not
// cfg, so that a nonzero session_load supplied via the override sys-prop is honoured even when
// the server-returned config has session_load=0.
if (builder.getSessionConfiguration().getSessionLoad() == 0) {
builder.clearSessionConfiguration();
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,40 @@ void testDisabledSessions() throws ExecutionException, InterruptedException {
.isEqualToDefaultInstance();
}

@Test
void testDisabledSessionsOverriddenBySysProp()
throws ExecutionException, InterruptedException, IOException {
// Server returns session_load=0 (sessions disabled from the server's perspective)…
ClientConfiguration.Builder disabledBuilder = manager.getDefaultConfig().toBuilder();
disabledBuilder.getSessionConfigurationBuilder().setSessionLoad(0);
service.config.set(disabledBuilder.build());

// …but a sys-prop override forces session_load>0 to opt this client into sessions.
manager.close();
String clientConfigOverrides =
TextFormat.printer()
.printToString(
ClientConfiguration.newBuilder()
.setSessionConfiguration(
SessionClientConfiguration.newBuilder().setSessionLoad(0.75f))
.build());
Properties sysProps = new Properties();
sysProps.setProperty(ClientConfigurationManager.OVERRIDE_SYS_PROP_KEY, clientConfigOverrides);
manager =
new ClientConfigurationManager(
sysProps, FEATURE_FLAGS, CLIENT_INFO, channelProvider, noopDebugTracer, mockExecutor);

ClientConfiguration resolvedConfig = manager.start().get();

// The override must be honoured: session_load and the default SessionPoolConfiguration must
// survive normalization instead of being cleared as if sessions were disabled.
assertThat(resolvedConfig.getSessionConfiguration().getSessionLoad()).isEqualTo(0.75f);
assertThat(resolvedConfig.getSessionConfiguration().getSessionPoolConfiguration())
.isEqualTo(
manager.getDefaultConfig().getSessionConfiguration().getSessionPoolConfiguration());
assertThat(manager.areSessionsRequired()).isTrue();
}

@Deprecated
@Test
void testMigrateSessionPool() throws ExecutionException, InterruptedException {
Expand Down
Loading