1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package org.onap.so.utils;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.env.Environment;
@RunWith(MockitoJUnitRunner.class)
public class ExternalTaskUtilsTest {
@Mock
private Environment mockenv;
@InjectMocks
private ExternalTaskUtils externalTaskUtilsAnony = new ExternalTaskUtils() {
};
@Test
public void retry_sequence_calculation_Test() {
Mockito.when(mockenv.getProperty("mso.workflow.topics.retryMultiplier", "6000")).thenReturn("6000");
long firstRetry = externalTaskUtilsAnony.calculateRetryDelay(8);
assertEquals(6000L, firstRetry);
long secondRetry = externalTaskUtilsAnony.calculateRetryDelay(7);
assertEquals(6000L, secondRetry);
long thirdRetry = externalTaskUtilsAnony.calculateRetryDelay(6);
assertEquals(12000L, thirdRetry);
long fourthRetry = externalTaskUtilsAnony.calculateRetryDelay(5);
assertEquals(18000L, fourthRetry);
long fifthRetry = externalTaskUtilsAnony.calculateRetryDelay(4);
assertEquals(30000L, fifthRetry);
long sixRetry = externalTaskUtilsAnony.calculateRetryDelay(3);
assertEquals(48000L, sixRetry);
long seventhRetry = externalTaskUtilsAnony.calculateRetryDelay(2);
assertEquals(78000L, seventhRetry);
long eigthRetry = externalTaskUtilsAnony.calculateRetryDelay(1);
assertEquals(120000L, eigthRetry);
}
@Test
public void retry_sequence_Test() {
Mockito.when(mockenv.getProperty("mso.workflow.topics.retryMultiplier", "6000")).thenReturn("6000");
long firstRetry = externalTaskUtilsAnony.calculateRetryDelay(8);
assertEquals(6000L, firstRetry);
long secondRetry = externalTaskUtilsAnony.calculateRetryDelay(7);
assertEquals(6000L, secondRetry);
long thirdRetry = externalTaskUtilsAnony.calculateRetryDelay(6);
assertEquals(12000L, thirdRetry);
long fourthRetry = externalTaskUtilsAnony.calculateRetryDelay(5);
assertEquals(18000L, fourthRetry);
long fifthRetry = externalTaskUtilsAnony.calculateRetryDelay(4);
assertEquals(30000L, fifthRetry);
long sixRetry = externalTaskUtilsAnony.calculateRetryDelay(3);
assertEquals(48000L, sixRetry);
long seventhRetry = externalTaskUtilsAnony.calculateRetryDelay(2);
assertEquals(78000L, seventhRetry);
long eigthRetry = externalTaskUtilsAnony.calculateRetryDelay(1);
assertEquals(120000L, eigthRetry);
}
}
|