|
7 | 7 | import com.fasterxml.jackson.core.JsonProcessingException;
|
8 | 8 | import com.fasterxml.jackson.core.type.TypeReference;
|
9 | 9 | import com.fasterxml.jackson.databind.JsonNode;
|
10 |
| -import com.flagsmith.responses.FlagsAndTraitsResponse; |
11 | 10 | import com.flagsmith.config.FlagsmithCacheConfig;
|
12 | 11 | import com.flagsmith.config.FlagsmithConfig;
|
13 | 12 | import com.flagsmith.exceptions.FlagsmithApiError;
|
|
20 | 19 | import com.flagsmith.models.DefaultFlag;
|
21 | 20 | import com.flagsmith.models.Flags;
|
22 | 21 | import com.flagsmith.models.Segment;
|
| 22 | +import com.flagsmith.responses.FlagsAndTraitsResponse; |
23 | 23 | import com.flagsmith.threads.PollingManager;
|
24 | 24 | import com.flagsmith.threads.RequestProcessor;
|
25 | 25 |
|
@@ -591,4 +591,36 @@ public void testLocalEvaluation_ReturnsConsistentResults() throws FlagsmithClien
|
591 | 591 | Assert.assertEquals(flags.getFeatureValue("some_feature"), expectedValue);
|
592 | 592 | }
|
593 | 593 | }
|
| 594 | + |
| 595 | + @Test(groups = "unit") |
| 596 | + public void testClose() throws FlagsmithApiError, InterruptedException { |
| 597 | + // Given |
| 598 | + int pollingInterval = 1; |
| 599 | + |
| 600 | + FlagsmithConfig config = FlagsmithConfig |
| 601 | + .newBuilder() |
| 602 | + .withLocalEvaluation(true) |
| 603 | + .withEnvironmentRefreshIntervalSeconds(pollingInterval) |
| 604 | + .build(); |
| 605 | + |
| 606 | + FlagsmithApiWrapper mockedApiWrapper = mock(FlagsmithApiWrapper.class); |
| 607 | + when(mockedApiWrapper.getEnvironment()).thenReturn(FlagsmithTestHelper.environmentModel()); |
| 608 | + when(mockedApiWrapper.getConfig()).thenReturn(config); |
| 609 | + |
| 610 | + FlagsmithClient client = FlagsmithClient.newBuilder() |
| 611 | + .withFlagsmithApiWrapper(mockedApiWrapper) |
| 612 | + .withConfiguration(config) |
| 613 | + .setApiKey("ser.dummy-key") |
| 614 | + .build(); |
| 615 | + |
| 616 | + // When |
| 617 | + client.close(); |
| 618 | + |
| 619 | + // Then |
| 620 | + // Since the thread will only stop once it reads the interrupt signal correctly |
| 621 | + // on its next polling interval, we need to wait for the polling interval |
| 622 | + // to complete before checking the thread has been killed correctly. |
| 623 | + Thread.sleep(pollingInterval); |
| 624 | + Assert.assertFalse(client.getPollingManager().getIsThreadAlive()); |
| 625 | + } |
594 | 626 | }
|
0 commit comments