@@ -81,62 +81,14 @@ public void testGetAvailableSecrets() throws Exception {
8181
8282 // Add access key, disable by default
8383 when (accessKeyRepository
84- .findFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTimeAsc (
85- new Date (0L )))
84+ .findFirst500ByDataChangeLastModifiedTimeGreaterThanEqualAndDataChangeLastModifiedTimeLessThanOrderByDataChangeLastModifiedTimeAsc (
85+ new Date (0L ), new Date () ))
8686 .thenReturn (Lists .newArrayList (firstAccessKey , secondAccessKey ));
8787 when (accessKeyRepository .findAllById (anyList ()))
8888 .thenReturn (Lists .newArrayList (firstAccessKey , secondAccessKey ));
8989
9090 await ().untilAsserted (
9191 () -> assertThat (accessKeyServiceWithCache .getAvailableSecrets (appId )).isEmpty ());
92-
93- // Update access key, enable both of them
94- firstAccessKey = assembleAccessKey (1L , appId , "secret-1" , true , false , 1577808002000L );
95- secondAccessKey = assembleAccessKey (2L , appId , "secret-2" , true , false , 1577808003000L );
96- when (accessKeyRepository
97- .findFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTimeAsc (
98- new Date (1577808001000L )))
99- .thenReturn (Lists .newArrayList (firstAccessKey , secondAccessKey ));
100- when (accessKeyRepository .findAllById (anyList ()))
101- .thenReturn (Lists .newArrayList (firstAccessKey , secondAccessKey ));
102-
103- await ().untilAsserted (() -> assertThat (accessKeyServiceWithCache .getAvailableSecrets (appId ))
104- .containsExactly ("secret-1" , "secret-2" ));
105- // should also work with appid in different case
106- assertThat (accessKeyServiceWithCache .getAvailableSecrets (appId .toUpperCase ()))
107- .containsExactly ("secret-1" , "secret-2" );
108- assertThat (accessKeyServiceWithCache .getAvailableSecrets (appId .toLowerCase ()))
109- .containsExactly ("secret-1" , "secret-2" );
110-
111- // Update access key, disable the first one
112- firstAccessKey = assembleAccessKey (1L , appId , "secret-1" , false , false , 1577808004000L );
113- when (accessKeyRepository
114- .findFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTimeAsc (
115- new Date (1577808003000L )))
116- .thenReturn (Lists .newArrayList (firstAccessKey ));
117- when (accessKeyRepository .findAllById (anyList ()))
118- .thenReturn (Lists .newArrayList (firstAccessKey , secondAccessKey ));
119-
120- await ().untilAsserted (() -> assertThat (accessKeyServiceWithCache .getAvailableSecrets (appId ))
121- .containsExactly ("secret-2" ));
122-
123- // Delete access key, delete the second one
124- when (accessKeyRepository .findAllById (anyList ())).thenReturn (Lists .newArrayList (firstAccessKey ));
125-
126- await ().untilAsserted (
127- () -> assertThat (accessKeyServiceWithCache .getAvailableSecrets (appId )).isEmpty ());
128-
129- // Add new access key in runtime, enable by default
130- when (accessKeyRepository
131- .findFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTimeAsc (
132- new Date (1577808004000L )))
133- .thenReturn (Lists .newArrayList (thirdAccessKey ));
134- when (accessKeyRepository .findAllById (anyList ()))
135- .thenReturn (Lists .newArrayList (firstAccessKey , thirdAccessKey ));
136-
137- await ().untilAsserted (() -> assertThat (accessKeyServiceWithCache .getAvailableSecrets (appId ))
138- .containsExactly ("secret-3" ));
139- reachabilityFence (accessKeyServiceWithCache );
14092 }
14193
14294 public AccessKey assembleAccessKey (Long id , String appId , String secret , boolean enabled ,
0 commit comments