Skip to content

Commit 7e69aae

Browse files
Pearl1594dhslove
authored andcommitted
Veeam: Use restore timeout as an interval as opposed to a counter (apache#11772)
* Veeam: Use restore timeout as a time interval as opposed to a counter * fix log * fix unit test * remove unused imports * fix comment * unused import * change to while - issure refactoring
1 parent f4e0b79 commit 7e69aae

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException
364364
* that is used to wait for the restore to complete before throwing a {@link CloudRuntimeException}.
365365
*/
366366
protected void checkIfRestoreSessionFinished(String type, String path) throws IOException {
367-
for (int j = 0; j < restoreTimeout; j++) {
367+
long startTime = System.currentTimeMillis();
368+
long timeoutMs = restoreTimeout * 1000L;
369+
while (System.currentTimeMillis() - startTime < timeoutMs) {
368370
HttpResponse relatedResponse = get(path);
369371
RestoreSession session = parseRestoreSessionResponse(relatedResponse);
370372
if (session.getResult().equals("Success")) {
@@ -378,7 +380,8 @@ protected void checkIfRestoreSessionFinished(String type, String path) throws IO
378380
getRestoreVmErrorDescription(StringUtils.substringAfterLast(sessionUid, ":"))));
379381
throw new CloudRuntimeException(String.format("Restore job [%s] failed.", sessionUid));
380382
}
381-
logger.debug(String.format("Waiting %s seconds, out of a total of %s seconds, for the restore backup process to finish.", j, restoreTimeout));
383+
logger.debug("Waiting {} seconds, out of a total of {} seconds, for the restore backup process to finish.",
384+
(System.currentTimeMillis() - startTime) / 1000, restoreTimeout);
382385

383386
try {
384387
Thread.sleep(1000);

plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
2626
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
2727
import static org.junit.Assert.fail;
28-
import static org.mockito.Mockito.times;
2928

3029
import java.io.ByteArrayInputStream;
3130
import java.io.IOException;
@@ -157,7 +156,7 @@ public void getRepositoryNameFromJobTestSuccess() throws Exception {
157156
@Test
158157
public void checkIfRestoreSessionFinishedTestTimeoutException() throws IOException {
159158
try {
160-
ReflectionTestUtils.setField(mockClient, "restoreTimeout", 10);
159+
ReflectionTestUtils.setField(mockClient, "restoreTimeout", 2);
161160
RestoreSession restoreSession = Mockito.mock(RestoreSession.class);
162161
HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
163162
Mockito.when(mockClient.get(Mockito.anyString())).thenReturn(httpResponse);
@@ -169,7 +168,7 @@ public void checkIfRestoreSessionFinishedTestTimeoutException() throws IOExcepti
169168
} catch (Exception e) {
170169
Assert.assertEquals("Related job type: RestoreTest was not successful", e.getMessage());
171170
}
172-
Mockito.verify(mockClient, times(10)).get(Mockito.anyString());
171+
Mockito.verify(mockClient, Mockito.atLeastOnce()).get(Mockito.anyString());
173172
}
174173

175174
@Test

0 commit comments

Comments
 (0)