|
7 | 7 | import static org.junit.jupiter.api.Assertions.assertNull; |
8 | 8 | import static org.junit.jupiter.api.Assertions.assertThrows; |
9 | 9 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 10 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 11 | + |
10 | 12 |
|
11 | 13 | import com.fasterxml.jackson.core.JsonProcessingException; |
12 | 14 | import com.fasterxml.jackson.core.type.TypeReference; |
13 | 15 | import com.fasterxml.jackson.databind.JsonNode; |
14 | | -import com.flagsmith.responses.FlagsAndTraitsResponse; |
15 | 16 | import com.flagsmith.config.FlagsmithCacheConfig; |
16 | 17 | import com.flagsmith.config.FlagsmithConfig; |
17 | 18 | import com.flagsmith.exceptions.FlagsmithApiError; |
|
24 | 25 | import com.flagsmith.models.DefaultFlag; |
25 | 26 | import com.flagsmith.models.Flags; |
26 | 27 | import com.flagsmith.models.Segment; |
| 28 | +import com.flagsmith.responses.FlagsAndTraitsResponse; |
27 | 29 | import com.flagsmith.threads.PollingManager; |
28 | 30 | import com.flagsmith.threads.RequestProcessor; |
29 | 31 |
|
@@ -692,4 +694,36 @@ public void testGetIdentityFlags_UsesDefaultFlags_IfLocalEvaluationEnvironmentNu |
692 | 694 | assertEquals(identityFlags.getFeatureValue("foo"), DEFAULT_FLAG_VALUE); |
693 | 695 | assertEquals(identityFlags.isFeatureEnabled("foo"), DEFAULT_FLAG_STATE); |
694 | 696 | } |
| 697 | + |
| 698 | + @Test |
| 699 | + public void testClose() throws FlagsmithApiError, InterruptedException { |
| 700 | + // Given |
| 701 | + int pollingInterval = 1; |
| 702 | + |
| 703 | + FlagsmithConfig config = FlagsmithConfig |
| 704 | + .newBuilder() |
| 705 | + .withLocalEvaluation(true) |
| 706 | + .withEnvironmentRefreshIntervalSeconds(pollingInterval) |
| 707 | + .build(); |
| 708 | + |
| 709 | + FlagsmithApiWrapper mockedApiWrapper = mock(FlagsmithApiWrapper.class); |
| 710 | + when(mockedApiWrapper.getEnvironment()).thenReturn(FlagsmithTestHelper.environmentModel()); |
| 711 | + when(mockedApiWrapper.getConfig()).thenReturn(config); |
| 712 | + |
| 713 | + FlagsmithClient client = FlagsmithClient.newBuilder() |
| 714 | + .withFlagsmithApiWrapper(mockedApiWrapper) |
| 715 | + .withConfiguration(config) |
| 716 | + .setApiKey("ser.dummy-key") |
| 717 | + .build(); |
| 718 | + |
| 719 | + // When |
| 720 | + client.close(); |
| 721 | + |
| 722 | + // Then |
| 723 | + // Since the thread will only stop once it reads the interrupt signal correctly |
| 724 | + // on its next polling interval, we need to wait for the polling interval |
| 725 | + // to complete before checking the thread has been killed correctly. |
| 726 | + Thread.sleep(pollingInterval); |
| 727 | + assertFalse(client.getPollingManager().getIsThreadAlive()); |
| 728 | + } |
695 | 729 | } |
0 commit comments