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 @@ -515,9 +515,10 @@ private synchronized void scheduleNextPoll() {

private void setClientConfiguration(ClientConfiguration result) {
ClientConfiguration old;
ClientConfiguration normalized = normalizeConfig(result);
synchronized (this) {
old = this.clientConfiguration;
clientConfiguration = normalizeConfig(result);
clientConfiguration = normalized;
if (clientConfiguration.hasPollingConfiguration()) {
this.validUntil =
Instant.now()
Expand All @@ -529,8 +530,8 @@ private void setClientConfiguration(ClientConfiguration result) {
}
}

maybeLogConfigChange(old, result);
notifyListeners(old, result);
maybeLogConfigChange(old, normalized);
notifyListeners(old, normalized);
}

private void maybeLogConfigChange(ClientConfiguration oldCfg, ClientConfiguration newCfg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,33 @@ void stopPollingTest() throws Exception {
verify(mockExecutor, never()).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
}

@Test
void expiredConfigResetNotifiesListenersWithNormalizedConfig() throws Exception {
ClientConfiguration.Builder initialBuilder = service.config.get().toBuilder();
initialBuilder.getPollingConfigurationBuilder().setValidityDuration(Durations.fromSeconds(-1));
service.config.set(initialBuilder.build());

ClientConfiguration initialConfig = manager.start().get();
assertThat(initialConfig.getSessionConfiguration()).isNotEqualToDefaultInstance();

ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(mockExecutor, times(1)).schedule(runnableCaptor.capture(), anyLong(), any());

@SuppressWarnings("unchecked")
ConfigListener<SessionClientConfiguration> mockListener = Mockito.mock(ConfigListener.class);
manager.addListener(ClientConfiguration::getSessionConfiguration, mockListener);

// Fail all attempts of the next poll so handleFailedFetch resets to defaultConfig (which has
// session_load=0, but non-empty channel/session pool configs before normalization).
service.emptyResponses.set(10);
runnableCaptor.getValue().run();
outstandingRpcCounter.waitUntilRpcsDone();

assertThat(manager.getClientConfiguration().getSessionConfiguration())
.isEqualToDefaultInstance();
verify(mockListener, times(1)).onChange(eq(SessionClientConfiguration.getDefaultInstance()));
}

@Test
void metadataDoesNotAccumulateAcrossPollsWithHeaderAttachingInterceptor() throws Exception {
manager.close();
Expand Down
Loading