Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Aug 30, 2024
1 parent 0741b83 commit 176b267
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public SplitTaskExecutionInfo execute() {
long latency = 0;
try {
// if target change number is outdated, we don't need to fetch
if (changeNumberIsOutdated()) {
if (targetChangeNumberIsOutdated()) {
Logger.v("Target CN is outdated. Skipping membership fetch");
return SplitTaskExecutionInfo.success(mTaskType);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ public SplitTaskExecutionInfo execute() {
return SplitTaskExecutionInfo.success(mTaskType);
}

private boolean changeNumberIsOutdated() {
private boolean targetChangeNumberIsOutdated() {
if (mTargetSegmentsChangeNumber == null && mTargetLargeSegmentsChangeNumber == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,38 @@ public void noFetchWhenLargeSegmentsChangeNumberIsNewerThanTarget() throws HttpF
verify(mMySegmentsFetcher, never()).execute(any(), any());
}

@Test
public void fetchWhenSegmentsChangeNumberInStorageIsNewerThanTargetAndLargeSegmentsChangeNumberIsOlder() throws HttpFetcherException {
long targetSegmentsChangeNumber = 5L;
long targetLargeSegmentsChangeNumber = 4L;
when(mySegmentsStorage.getTill()).thenReturn(6L);
when(myLargeSegmentsStorage.getTill()).thenReturn(3L);
when(mMySegmentsFetcher.execute(noParams, null))
.thenReturn(createChange(6L, 4L));

mTask = new MySegmentsSyncTask(mMySegmentsFetcher, mySegmentsStorage, myLargeSegmentsStorage, false, mEventsManager, mMySegmentsChangeChecker, mTelemetryRuntimeProducer, MySegmentsSyncTaskConfig.get(), targetSegmentsChangeNumber, targetLargeSegmentsChangeNumber, mock(BackoffCounter.class), 1);
mTask.execute();

verify(mMySegmentsFetcher).execute(any(), any());
verify(mMySegmentsFetcher).execute(noParams, null);
}

@Test
public void fetchIsPerformedWhenLargeSegmentsChangeNumberInStorageIsNewerThanTargetAndSegmentsChangeNumberIsOlder() throws HttpFetcherException {
long targetSegmentsChangeNumber = 5L;
long targetLargeSegmentsChangeNumber = 4L;
when(mySegmentsStorage.getTill()).thenReturn(3L);
when(myLargeSegmentsStorage.getTill()).thenReturn(6L);
when(mMySegmentsFetcher.execute(noParams, null))
.thenReturn(createChange(5L, 6L));

mTask = new MySegmentsSyncTask(mMySegmentsFetcher, mySegmentsStorage, myLargeSegmentsStorage, false, mEventsManager, mMySegmentsChangeChecker, mTelemetryRuntimeProducer, MySegmentsSyncTaskConfig.get(), targetSegmentsChangeNumber, targetLargeSegmentsChangeNumber, mock(BackoffCounter.class), 1);
mTask.execute();

verify(mMySegmentsFetcher).execute(any(), any());
verify(mMySegmentsFetcher).execute(noParams, null);
}

@NonNull
private static AllSegmentsChange createChange(Long msChangeNumber, Long lsChangeNumber) {
return AllSegmentsChange.create(
Expand Down

0 comments on commit 176b267

Please sign in to comment.