Skip to content
Open
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 @@ -469,9 +469,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 @@ -483,8 +484,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 @@ -688,6 +688,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()));
}

static class FakeConfigService extends BigtableGrpc.BigtableImplBase {
private final AtomicReference<ClientConfiguration> config = new AtomicReference<>();

Expand Down
Loading