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 @@ -366,7 +366,9 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException
* that is used to wait for the restore to complete before throwing a {@link CloudRuntimeException}.
*/
protected void checkIfRestoreSessionFinished(String type, String path) throws IOException {
for (int j = 0; j < restoreTimeout; j++) {
long startTime = System.currentTimeMillis();
long timeoutMs = restoreTimeout * 1000L;
if (System.currentTimeMillis() - startTime < timeoutMs) {
HttpResponse relatedResponse = get(path);
RestoreSession session = parseRestoreSessionResponse(relatedResponse);
if (session.getResult().equals("Success")) {
Expand All @@ -380,7 +382,8 @@ protected void checkIfRestoreSessionFinished(String type, String path) throws IO
getRestoreVmErrorDescription(StringUtils.substringAfterLast(sessionUid, ":"))));
throw new CloudRuntimeException(String.format("Restore job [%s] failed.", sessionUid));
}
logger.debug(String.format("Waiting %s seconds, out of a total of %s seconds, for the restore backup process to finish.", j, restoreTimeout));
logger.debug("Waiting {} seconds, out of a total of {} seconds, for the restore backup process to finish.",
(System.currentTimeMillis() - startTime) / 1000, restoreTimeout);

try {
Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.times;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -157,7 +156,7 @@ public void getRepositoryNameFromJobTestSuccess() throws Exception {
@Test
public void checkIfRestoreSessionFinishedTestTimeoutException() throws IOException {
try {
ReflectionTestUtils.setField(mockClient, "restoreTimeout", 10);
ReflectionTestUtils.setField(mockClient, "restoreTimeout", 2);
RestoreSession restoreSession = Mockito.mock(RestoreSession.class);
HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
Mockito.when(mockClient.get(Mockito.anyString())).thenReturn(httpResponse);
Expand All @@ -169,7 +168,7 @@ public void checkIfRestoreSessionFinishedTestTimeoutException() throws IOExcepti
} catch (Exception e) {
Assert.assertEquals("Related job type: RestoreTest was not successful", e.getMessage());
}
Mockito.verify(mockClient, times(10)).get(Mockito.anyString());
Mockito.verify(mockClient, Mockito.atLeastOnce()).get(Mockito.anyString());
}

@Test
Expand Down
Loading