|
9 | 9 | import org.apache.hc.client5.http.impl.classic.HttpClients; |
10 | 10 | import org.hamcrest.Matchers; |
11 | 11 | import org.junit.Assert; |
| 12 | +import org.junit.Before; |
12 | 13 | import org.junit.Test; |
13 | 14 | import org.mockito.Mockito; |
14 | 15 |
|
15 | 16 | import java.io.IOException; |
16 | | -import java.lang.reflect.Field; |
17 | | -import java.lang.reflect.Modifier; |
18 | 17 | import java.net.URI; |
19 | 18 | import java.net.URISyntaxException; |
20 | | -import java.util.concurrent.ExecutorService; |
21 | | -import java.util.concurrent.Executors; |
22 | 19 | import java.util.concurrent.LinkedBlockingQueue; |
23 | 20 |
|
24 | 21 | public class EventsClientImplTest { |
@@ -82,21 +79,22 @@ public void testEventsFlushedWhenSizeLimitReached() throws URISyntaxException, I |
82 | 79 |
|
83 | 80 | @Test |
84 | 81 | public void testEventDropped() throws URISyntaxException, NoSuchFieldException, IllegalAccessException, InterruptedException { |
| 82 | + TelemetryStorage telemetryStorage = Mockito.mock(InMemoryTelemetryStorage.class); |
85 | 83 | CloseableHttpClient client = Mockito.mock(CloseableHttpClient.class); |
86 | 84 | EventClientImpl eventClient = new EventClientImpl(new LinkedBlockingQueue<>(2), |
87 | 85 | client, |
88 | 86 | URI.create("https://kubernetesturl.com/split"), |
89 | 87 | 10000, // Long queue so it doesn't flush by # of events |
90 | 88 | 100000, // Long period so it doesn't flush by timeout expiration. |
91 | | - 0, TELEMETRY_STORAGE); |
| 89 | + 0, telemetryStorage); |
92 | 90 | eventClient.close(); |
93 | 91 | Thread.sleep(1000); |
94 | 92 | for (int i = 0; i < 3; ++i) { |
95 | 93 | Event event = new Event(); |
96 | 94 | eventClient.track(event, 1); |
97 | 95 | } |
98 | 96 |
|
99 | | - Mockito.verify(TELEMETRY_STORAGE, Mockito.times(2)).recordEventStats(EventsDataRecordsEnum.EVENTS_QUEUED, 1); |
100 | | - Mockito.verify(TELEMETRY_STORAGE, Mockito.times(1)).recordEventStats(EventsDataRecordsEnum.EVENTS_DROPPED, 1); |
| 97 | + Mockito.verify(telemetryStorage, Mockito.times(2)).recordEventStats(EventsDataRecordsEnum.EVENTS_QUEUED, 1); |
| 98 | + Mockito.verify(telemetryStorage, Mockito.times(1)).recordEventStats(EventsDataRecordsEnum.EVENTS_DROPPED, 1); |
101 | 99 | } |
102 | 100 | } |
0 commit comments