|
16 | 16 |
|
17 | 17 | package org.springframework.retry.backoff;
|
18 | 18 |
|
| 19 | +import org.apache.commons.logging.Log; |
19 | 20 | import org.junit.jupiter.api.Test;
|
| 21 | +import org.mockito.ArgumentCaptor; |
| 22 | +import org.springframework.beans.DirectFieldAccessor; |
20 | 23 |
|
21 | 24 | import static org.assertj.core.api.Assertions.assertThat;
|
22 | 25 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
| 26 | +import static org.mockito.Mockito.mock; |
| 27 | +import static org.mockito.Mockito.verify; |
23 | 28 |
|
24 | 29 | /**
|
25 | 30 | * @author Rob Harrop
|
26 | 31 | * @author Dave Syer
|
27 | 32 | * @author Gary Russell
|
28 | 33 | * @author Marius Lichtblau
|
29 | 34 | * @author Anton Aharkau
|
| 35 | + * @author Kim Sumin |
30 | 36 | */
|
31 | 37 | public class ExponentialBackOffPolicyTests {
|
32 | 38 |
|
@@ -125,4 +131,50 @@ public void sleep(long backOffPeriod) throws InterruptedException {
|
125 | 131 | assertThat(Thread.interrupted()).isTrue();
|
126 | 132 | }
|
127 | 133 |
|
| 134 | + @Test |
| 135 | + public void testSetMultiplierWithWarning() { |
| 136 | + Log logMock = mock(Log.class); |
| 137 | + ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); |
| 138 | + |
| 139 | + DirectFieldAccessor accessor = new DirectFieldAccessor(strategy); |
| 140 | + accessor.setPropertyValue("logger", logMock); |
| 141 | + |
| 142 | + strategy.setMultiplier(1.0); |
| 143 | + |
| 144 | + ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); |
| 145 | + verify(logMock).warn(captor.capture()); |
| 146 | + assertThat(captor.getValue()) |
| 147 | + .isEqualTo("Multiplier must be > 1.0 for effective exponential backoff, but was 1.0"); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + public void testSetInitialIntervalWithWarning() { |
| 152 | + Log logMock = mock(Log.class); |
| 153 | + ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); |
| 154 | + |
| 155 | + DirectFieldAccessor accessor = new DirectFieldAccessor(strategy); |
| 156 | + accessor.setPropertyValue("logger", logMock); |
| 157 | + |
| 158 | + strategy.setInitialInterval(0); |
| 159 | + |
| 160 | + ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); |
| 161 | + verify(logMock).warn(captor.capture()); |
| 162 | + assertThat(captor.getValue()).isEqualTo("Initial interval must be at least 1, but was 0"); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void testSetMaxIntervalWithWarning() { |
| 167 | + Log logMock = mock(Log.class); |
| 168 | + ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); |
| 169 | + |
| 170 | + DirectFieldAccessor accessor = new DirectFieldAccessor(strategy); |
| 171 | + accessor.setPropertyValue("logger", logMock); |
| 172 | + |
| 173 | + strategy.setMaxInterval(0); |
| 174 | + |
| 175 | + ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); |
| 176 | + verify(logMock).warn(captor.capture()); |
| 177 | + assertThat(captor.getValue()).isEqualTo("Max interval must be positive, but was 0"); |
| 178 | + } |
| 179 | + |
128 | 180 | }
|
0 commit comments