mirror of https://github.com/apache/cloudstack.git
Veeam: Use restore timeout as an interval as opposed to a counter (#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
This commit is contained in:
parent
9956d32548
commit
7786cf93c2
|
|
@ -364,7 +364,9 @@ public class VeeamClient {
|
|||
* 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;
|
||||
while (System.currentTimeMillis() - startTime < timeoutMs) {
|
||||
HttpResponse relatedResponse = get(path);
|
||||
RestoreSession session = parseRestoreSessionResponse(relatedResponse);
|
||||
if (session.getResult().equals("Success")) {
|
||||
|
|
@ -378,7 +380,8 @@ public class VeeamClient {
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
|
|||
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;
|
||||
|
|
@ -157,7 +156,7 @@ public class VeeamClientTest {
|
|||
@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);
|
||||
|
|
@ -169,7 +168,7 @@ public class VeeamClientTest {
|
|||
} 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue