-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have TargetPoller poll without initial delay and add test for TargetP…
…oller.
- Loading branch information
Anuraag Agrawal
committed
May 16, 2020
1 parent
f14a788
commit efd8447
Showing
3 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 25 additions & 6 deletions
31
...sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/TargetPollerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,51 @@ | ||
package com.amazonaws.xray.strategy.sampling.pollers; | ||
|
||
import com.amazonaws.xray.internal.UnsignedXrayClient; | ||
import com.amazonaws.xray.strategy.sampling.manifest.CentralizedManifest; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.time.Clock; | ||
import java.util.Collections; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import com.amazonaws.services.xray.model.SamplingStatisticsDocument; | ||
import com.amazonaws.xray.internal.UnsignedXrayClient; | ||
import com.amazonaws.xray.strategy.sampling.manifest.CentralizedManifest; | ||
|
||
public class TargetPollerTest { | ||
|
||
@Rule | ||
public MockitoRule mocks = MockitoJUnit.rule(); | ||
|
||
@Mock | ||
private CentralizedManifest manifest; | ||
|
||
@Mock | ||
private UnsignedXrayClient client; | ||
|
||
@Test | ||
public void testPollerShutdown() { | ||
TargetPoller poller = new TargetPoller( | ||
client, new CentralizedManifest(), Clock.systemUTC()); | ||
TargetPoller poller = new TargetPoller(client, manifest, Clock.systemUTC()); | ||
poller.start(); | ||
poller.shutdown(); | ||
|
||
assertThat(poller.getExecutor().isShutdown()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testPollerErrorNotAbruptMainThread() throws InterruptedException { | ||
when(client.getSamplingTargets(any())).thenThrow(new OutOfMemoryError()); | ||
when(manifest.snapshots(any())).thenReturn(Collections.singletonList(new SamplingStatisticsDocument())); | ||
|
||
assertTrue(poller.getExecutor().isShutdown()); | ||
TargetPoller poller = new TargetPoller(client, manifest, Clock.systemUTC()); | ||
poller.start(); | ||
//Give the mocked client time (1s) to throw the pre-defined Error | ||
Thread.sleep(1000L); | ||
assertThat(Thread.currentThread().isAlive()).isTrue(); | ||
} | ||
} |