Skip to content

Parse NO_CHANGE fetch response for template version #4177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 25, 2022
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 @@ -575,11 +575,14 @@ public static FetchResponse forBackendUpdatesFetched(
lastFetchETag);
}

public static FetchResponse forBackendHasNoUpdates(Date fetchTime) {
// Passing in param fetchedConfigs because it contains templateVersion but no other active
// fields.
public static FetchResponse forBackendHasNoUpdates(
Date fetchTime, ConfigContainer fetchedConfigs) {
return new FetchResponse(
fetchTime,
Status.BACKEND_HAS_NO_UPDATES,
/*fetchedConfigs=*/ null,
/*fetchedConfigs=*/ fetchedConfigs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might add a comment that we're including the fetchConfigs because they include the template version (even though they don't include the config entries or metadata)

/*lastFetchETag=*/ null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ FetchResponse fetch(
} catch (IOException e) {
}
}
ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime);

if (!backendHasUpdates(fetchResponse)) {
return FetchResponse.forBackendHasNoUpdates(currentTime);
return FetchResponse.forBackendHasNoUpdates(currentTime, fetchedConfigs);
}

ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime);
return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ private void setBackendResponseToNoChange(Date date) throws Exception {
/* customHeaders= */ any(),
/* firstOpenTime= */ any(),
/* currentTime= */ any()))
.thenReturn(FetchResponse.forBackendHasNoUpdates(date));
.thenReturn(FetchResponse.forBackendHasNoUpdates(date, firstFetchedContainer));
}

private void fetchCallToBackendThrowsException(int httpErrorCode) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ public void fetch_newValues_responseSet() throws Exception {
}

@Test
public void fetch_noChange_responseNotSet() throws Exception {
public void fetch_noChange_responseOnlyContainsTemplateVersion() throws Exception {
setServerResponseTo(noChangeResponseBody, SECOND_ETAG);

FetchResponse response = fetch(SECOND_ETAG);

assertThat(response.getLastFetchETag()).isNull();
assertThat(response.getFetchedConfigs()).isNull();
assertThat(response.getFetchedConfigs()).isNotNull();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert it only contains template version?

assertThat(response.getFetchedConfigs().getTemplateVersionNumber()).isNotNull();
assertThat(response.getFetchedConfigs().getConfigs().length()).isEqualTo(0);
}

@Test
Expand Down