Skip to content

Commit

Permalink
ZNTA-2057 change int to long for progress fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Jun 15, 2017
1 parent 978639f commit a50d69c
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface Listener {

void hideConfirmation();

void updateFileDownloadProgress(int currentProgress, int maxProgress);
void updateFileDownloadProgress(long currentProgress, long maxProgress);

void setDownloadInProgress(boolean inProgress);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void hideConfirmation() {

@Override
public void
updateFileDownloadProgress(int currentProgress, int maxProgress) {
updateFileDownloadProgress(long currentProgress, long maxProgress) {
confirmationBox.setProgressMessage(currentProgress + " of "
+ maxProgress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ public class GetDownloadAllFilesProgressResult implements DispatchResult {

private static final long serialVersionUID = 1L;

private int currentProgress;
private int maxProgress;
private long currentProgress;
private long maxProgress;
private String downloadId;

@SuppressWarnings("unused")
private GetDownloadAllFilesProgressResult() {
}

public GetDownloadAllFilesProgressResult(int currentProgress,
int maxProgress, String downloadId) {
public GetDownloadAllFilesProgressResult(long currentProgress,
long maxProgress, String downloadId) {
this.maxProgress = maxProgress;
this.currentProgress = currentProgress;
this.downloadId = downloadId;
}

public int getCurrentProgress() {
public long getCurrentProgress() {
return currentProgress;
}

public int getMaxProgress() {
public long getMaxProgress() {
return maxProgress;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ public boolean isError() {
return false;
}

public int getReindexCount() {
public long getReindexCount() {
if (searchIndexManager.getProcessHandle() == null) {
return 0;
} else {
return searchIndexManager.getProcessHandle().getMaxProgress();
}
}

public int getReindexProgress() {
public long getReindexProgress() {
if (searchIndexManager.getProcessHandle() == null) {
return 0;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ public class AsyncTaskHandle<V> implements Serializable {

@SuppressFBWarnings("SE_BAD_FIELD")
private CompletableFuture<V> futureResult;
public int maxProgress = 100;
public int minProgress = 0;
public int currentProgress = 0;
public long maxProgress = 100;
public long currentProgress = 0;
private long startTime = -1;
private long finishTime = -1;

public int increaseProgress(int increaseBy) {
public long increaseProgress(long increaseBy) {
currentProgress += increaseBy;
return currentProgress;
}
Expand Down Expand Up @@ -95,7 +94,7 @@ public Optional<Long> getEstimatedTimeRemaining() {
if (this.startTime > 0 && currentProgress > 0) {
long currentTime = System.currentTimeMillis();
long timeElapsed = currentTime - this.startTime;
int remainingUnits = this.maxProgress - this.currentProgress;
long remainingUnits = this.maxProgress - this.currentProgress;
return Optional
.of(timeElapsed * remainingUnits / this.currentProgress);
} else {
Expand Down Expand Up @@ -151,27 +150,19 @@ void setFutureResult(final CompletableFuture<V> futureResult) {
this.futureResult = futureResult;
}

public int getMaxProgress() {
public long getMaxProgress() {
return this.maxProgress;
}

public void setMaxProgress(final int maxProgress) {
public void setMaxProgress(final long maxProgress) {
this.maxProgress = maxProgress;
}

public int getMinProgress() {
return this.minProgress;
}

public void setMinProgress(final int minProgress) {
this.minProgress = minProgress;
}

public int getCurrentProgress() {
public long getCurrentProgress() {
return this.currentProgress;
}

public void setCurrentProgress(final int currentProgress) {
protected void setCurrentProgress(final long currentProgress) {
this.currentProgress = currentProgress;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.common.base.Splitter;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

Expand Down Expand Up @@ -106,11 +107,15 @@ public AsyncTaskHandle getHandleByKeyId(String keyId) {

public Collection<AsyncTaskHandle> getAllHandles() {
Collection<AsyncTaskHandle> handles = Lists.newArrayList();
handles.addAll(handlesByKey.values());
handles.addAll(getRunningHandles());
handles.addAll(finishedTasks.asMap().values());
return handles;
}

public Collection<AsyncTaskHandle> getRunningHandles() {
return ImmutableList.copyOf(handlesByKey.values());
}

public interface AsyncTaskKey<T> extends Serializable {
/**
* When converting multiple fields to form id string or vice versa, we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ public ProcessStatus getProcessStatus(String processId) {
: ProcessStatusCode.Running);
int perComplete = 100;
if (handle.getMaxProgress() > 0) {
perComplete = (handle.getCurrentProgress() * 100
/ handle.getMaxProgress());
perComplete = (int) (handle.getCurrentProgress() * 100
/ handle.getMaxProgress());
}
status.setPercentageComplete(perComplete);
status.setUrl("" + processId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class GetDownloadAllFilesProgressHandler
public GetDownloadAllFilesProgressResult execute(
GetDownloadAllFilesProgress action, ExecutionContext context)
throws ActionException {
int currentProgress = 0;
int maxProgress = 0;
long currentProgress = 0;
long maxProgress = 0;
String downloadId = "";

AsyncTaskHandle<String> handle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public void testIsCancelled() throws Exception {
@Test
public void testEstimatedTimeRemaining() throws Exception {
AsyncTaskHandle<String> handle = new AsyncTaskHandle<>();
handle.setMinProgress(0);
handle.setMaxProgress(10);
AsyncTaskResult<String> result = new AsyncTaskResult<>();
handle.setFutureResult(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public void executionError() throws Exception {

@Test
public void progressUpdates() throws Exception {
final List<Integer> progressUpdates = Lists.newArrayList();
final List<Long> progressUpdates = Lists.newArrayList();

// Custom handle so that progress updates are recorded
final AsyncTaskHandle<Void> taskHandle =
new AsyncTaskHandle<Void>() {
private static final long serialVersionUID = 1L;

@Override
public void setCurrentProgress(int progress) {
public void setCurrentProgress(long progress) {
super.setCurrentProgress(progress);
progressUpdates.add(progress);
}
Expand All @@ -128,7 +128,7 @@ public void setCurrentProgress(int progress) {
// Progress update calls should match the task's internal updates
assertThat(taskHandle.getCurrentProgress()).isEqualTo(100);
assertThat(progressUpdates.size()).isEqualTo(4);
assertThat(progressUpdates).contains(25, 50, 75, 100);
assertThat(progressUpdates).contains(25L, 50L, 75L, 100L);
}


Expand Down

0 comments on commit a50d69c

Please sign in to comment.