Commit 38e63c6a authored by Jason Song's avatar Jason Song Committed by GitHub

Use awaitility to stabilize the async tests (#3099)

parent 552bdfda
...@@ -32,6 +32,7 @@ import java.util.List; ...@@ -32,6 +32,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
...@@ -334,10 +335,9 @@ public class NotificationControllerV2Test { ...@@ -334,10 +335,9 @@ public class NotificationControllerV2Test {
//in batch mode, at most one of them should have result //in batch mode, at most one of them should have result
assertFalse(deferredResult.hasResult() && anotherDeferredResult.hasResult()); assertFalse(deferredResult.hasResult() && anotherDeferredResult.hasResult());
TimeUnit.MILLISECONDS.sleep(someBatchInterval * 10);
//now both of them should have result //now both of them should have result
assertTrue(deferredResult.hasResult() && anotherDeferredResult.hasResult()); await().atMost(someBatchInterval * 500, TimeUnit.MILLISECONDS).untilAsserted(
() -> assertTrue(deferredResult.hasResult() && anotherDeferredResult.hasResult()));
} }
@Test @Test
......
...@@ -93,7 +93,7 @@ public abstract class AbstractBaseIntegrationTest { ...@@ -93,7 +93,7 @@ public abstract class AbstractBaseIntegrationTest {
} }
protected void periodicSendMessage(ExecutorService executorService, String message, AtomicBoolean stop) { protected void periodicSendMessage(ExecutorService executorService, String message, AtomicBoolean stop) {
executorService.submit((Runnable) () -> { executorService.submit(() -> {
//wait for the request connected to server //wait for the request connected to server
while (!stop.get() && !Thread.currentThread().isInterrupted()) { while (!stop.get() && !Thread.currentThread().isInterrupted()) {
try { try {
......
...@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.configservice.service; ...@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.configservice.service;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.awaitility.Awaitility.*;
import com.ctrip.framework.apollo.biz.config.BizConfig; import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.entity.AccessKey; import com.ctrip.framework.apollo.biz.entity.AccessKey;
...@@ -10,6 +11,7 @@ import com.ctrip.framework.apollo.biz.repository.AccessKeyRepository; ...@@ -10,6 +11,7 @@ import com.ctrip.framework.apollo.biz.repository.AccessKeyRepository;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.Date; import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.awaitility.Awaitility;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -40,6 +42,10 @@ public class AccessKeyServiceWithCacheTest { ...@@ -40,6 +42,10 @@ public class AccessKeyServiceWithCacheTest {
when(bizConfig.accessKeyCacheScanIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit); when(bizConfig.accessKeyCacheScanIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit);
when(bizConfig.accessKeyCacheRebuildInterval()).thenReturn(scanInterval); when(bizConfig.accessKeyCacheRebuildInterval()).thenReturn(scanInterval);
when(bizConfig.accessKeyCacheRebuildIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit); when(bizConfig.accessKeyCacheRebuildIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit);
Awaitility.reset();
Awaitility.setDefaultTimeout(scanInterval * 100, scanIntervalTimeUnit);
Awaitility.setDefaultPollInterval(scanInterval, scanIntervalTimeUnit);
} }
@Test @Test
...@@ -63,8 +69,7 @@ public class AccessKeyServiceWithCacheTest { ...@@ -63,8 +69,7 @@ public class AccessKeyServiceWithCacheTest {
when(accessKeyRepository.findAllById(anyList())) when(accessKeyRepository.findAllById(anyList()))
.thenReturn(Lists.newArrayList(firstAccessKey, secondAccessKey)); .thenReturn(Lists.newArrayList(firstAccessKey, secondAccessKey));
scanIntervalTimeUnit.sleep(scanInterval * 10); await().untilAsserted(() -> assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId)).isEmpty());
assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId)).isEmpty();
// Update access key, enable both of them // Update access key, enable both of them
firstAccessKey = assembleAccessKey(1L, appId, "secret-1", true, false, 1577808002000L); firstAccessKey = assembleAccessKey(1L, appId, "secret-1", true, false, 1577808002000L);
...@@ -74,8 +79,8 @@ public class AccessKeyServiceWithCacheTest { ...@@ -74,8 +79,8 @@ public class AccessKeyServiceWithCacheTest {
when(accessKeyRepository.findAllById(anyList())) when(accessKeyRepository.findAllById(anyList()))
.thenReturn(Lists.newArrayList(firstAccessKey, secondAccessKey)); .thenReturn(Lists.newArrayList(firstAccessKey, secondAccessKey));
scanIntervalTimeUnit.sleep(scanInterval * 10); await().untilAsserted(() -> assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId))
assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId)).containsExactly("secret-1", "secret-2"); .containsExactly("secret-1", "secret-2"));
// Update access key, disable the first one // Update access key, disable the first one
firstAccessKey = assembleAccessKey(1L, appId, "secret-1", false, false, 1577808004000L); firstAccessKey = assembleAccessKey(1L, appId, "secret-1", false, false, 1577808004000L);
...@@ -84,15 +89,15 @@ public class AccessKeyServiceWithCacheTest { ...@@ -84,15 +89,15 @@ public class AccessKeyServiceWithCacheTest {
when(accessKeyRepository.findAllById(anyList())) when(accessKeyRepository.findAllById(anyList()))
.thenReturn(Lists.newArrayList(firstAccessKey, secondAccessKey)); .thenReturn(Lists.newArrayList(firstAccessKey, secondAccessKey));
scanIntervalTimeUnit.sleep(scanInterval * 10); await().untilAsserted(() -> assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId))
assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId)).containsExactly("secret-2"); .containsExactly("secret-2"));
// Delete access key, delete the second one // Delete access key, delete the second one
when(accessKeyRepository.findAllById(anyList())) when(accessKeyRepository.findAllById(anyList()))
.thenReturn(Lists.newArrayList(firstAccessKey)); .thenReturn(Lists.newArrayList(firstAccessKey));
scanIntervalTimeUnit.sleep(scanInterval * 10); await().untilAsserted(
assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId)).isEmpty(); () -> assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId)).isEmpty());
// Add new access key in runtime, enable by default // Add new access key in runtime, enable by default
when(accessKeyRepository.findFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTimeAsc(new Date(1577808004000L))) when(accessKeyRepository.findFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTimeAsc(new Date(1577808004000L)))
...@@ -100,8 +105,8 @@ public class AccessKeyServiceWithCacheTest { ...@@ -100,8 +105,8 @@ public class AccessKeyServiceWithCacheTest {
when(accessKeyRepository.findAllById(anyList())) when(accessKeyRepository.findAllById(anyList()))
.thenReturn(Lists.newArrayList(firstAccessKey, thirdAccessKey)); .thenReturn(Lists.newArrayList(firstAccessKey, thirdAccessKey));
scanIntervalTimeUnit.sleep(scanInterval * 10); await().untilAsserted(() -> assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId))
assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId)).containsExactly("secret-3"); .containsExactly("secret-3"));
} }
public AccessKey assembleAccessKey(Long id, String appId, String secret, boolean enabled, public AccessKey assembleAccessKey(Long id, String appId, String secret, boolean enabled,
......
...@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository; ...@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.awaitility.Awaitility;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -19,13 +20,14 @@ import java.util.List; ...@@ -19,13 +20,14 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.Silent.class)
public class AppNamespaceServiceWithCacheTest { public class AppNamespaceServiceWithCacheTest {
private AppNamespaceServiceWithCache appNamespaceServiceWithCache; private AppNamespaceServiceWithCache appNamespaceServiceWithCache;
@Mock @Mock
...@@ -49,6 +51,11 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -49,6 +51,11 @@ public class AppNamespaceServiceWithCacheTest {
when(bizConfig.appNamespaceCacheRebuildIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit); when(bizConfig.appNamespaceCacheRebuildIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit);
when(bizConfig.appNamespaceCacheScanInterval()).thenReturn(scanInterval); when(bizConfig.appNamespaceCacheScanInterval()).thenReturn(scanInterval);
when(bizConfig.appNamespaceCacheScanIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit); when(bizConfig.appNamespaceCacheScanIntervalTimeUnit()).thenReturn(scanIntervalTimeUnit);
Awaitility.reset();
Awaitility.setDefaultTimeout(scanInterval * 100, scanIntervalTimeUnit);
Awaitility.setDefaultPollInterval(scanInterval, scanIntervalTimeUnit);
} }
@Test @Test
...@@ -69,8 +76,6 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -69,8 +76,6 @@ public class AppNamespaceServiceWithCacheTest {
String anotherPrivateNamespace = "anotherPrivateNamespace"; String anotherPrivateNamespace = "anotherPrivateNamespace";
long anotherPrivateNamespaceId = 3; long anotherPrivateNamespaceId = 3;
int sleepInterval = scanInterval * 10;
AppNamespace somePrivateAppNamespace = assembleAppNamespace(somePrivateNamespaceId, AppNamespace somePrivateAppNamespace = assembleAppNamespace(somePrivateNamespaceId,
someAppId, somePrivateNamespace, false); someAppId, somePrivateNamespace, false);
AppNamespace somePublicAppNamespace = assembleAppNamespace(somePublicNamespaceId, AppNamespace somePublicAppNamespace = assembleAppNamespace(somePublicNamespaceId,
...@@ -129,29 +134,35 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -129,29 +134,35 @@ public class AppNamespaceServiceWithCacheTest {
somePublicNamespaceId))).thenReturn(Lists.newArrayList(somePrivateAppNamespace, somePublicNamespaceId))).thenReturn(Lists.newArrayList(somePrivateAppNamespace,
somePublicAppNamespace)); somePublicAppNamespace));
scanIntervalTimeUnit.sleep(sleepInterval); await().untilAsserted(() -> {
assertEquals(somePrivateAppNamespace, assertEquals(somePrivateAppNamespace,
appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace)); appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace));
assertEquals(somePrivateAppNamespace, assertEquals(somePrivateAppNamespace,
appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespaceWithIncorrectCase)); appNamespaceServiceWithCache
.findByAppIdAndNamespace(someAppId, somePrivateNamespaceWithIncorrectCase));
check(Lists.newArrayList(somePrivateAppNamespace), appNamespaceServiceWithCache check(Lists.newArrayList(somePrivateAppNamespace), appNamespaceServiceWithCache
.findByAppIdAndNamespaces(someAppId, someAppIdNamespaces)); .findByAppIdAndNamespaces(someAppId, someAppIdNamespaces));
check(Lists.newArrayList(somePrivateAppNamespace), appNamespaceServiceWithCache check(Lists.newArrayList(somePrivateAppNamespace), appNamespaceServiceWithCache
.findByAppIdAndNamespaces(someAppId, someAppIdNamespacesWithIncorrectCase)); .findByAppIdAndNamespaces(someAppId, someAppIdNamespacesWithIncorrectCase));
assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, assertEquals(somePublicAppNamespace,
appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId,
somePublicNamespace)); somePublicNamespace));
assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, assertEquals(somePublicAppNamespace,
appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId,
somePublicNamespaceWithIncorrectCase)); somePublicNamespaceWithIncorrectCase));
check(Lists.newArrayList(somePublicAppNamespace), appNamespaceServiceWithCache check(Lists.newArrayList(somePublicAppNamespace), appNamespaceServiceWithCache
.findByAppIdAndNamespaces(somePublicAppId, somePublicAppIdNamespaces)); .findByAppIdAndNamespaces(somePublicAppId, somePublicAppIdNamespaces));
assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespace)); assertEquals(somePublicAppNamespace,
appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespace));
assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findPublicNamespaceByName assertEquals(somePublicAppNamespace, appNamespaceServiceWithCache.findPublicNamespaceByName
(somePublicNamespaceWithIncorrectCase)); (somePublicNamespaceWithIncorrectCase));
check(Lists.newArrayList(somePublicAppNamespace), appNamespaceServiceWithCache.findPublicNamespacesByNames check(Lists.newArrayList(somePublicAppNamespace),
appNamespaceServiceWithCache.findPublicNamespacesByNames
(publicNamespaces)); (publicNamespaces));
check(Lists.newArrayList(somePublicAppNamespace), appNamespaceServiceWithCache.findPublicNamespacesByNames check(Lists.newArrayList(somePublicAppNamespace),
appNamespaceServiceWithCache.findPublicNamespacesByNames
(publicNamespacesWithIncorrectCase)); (publicNamespacesWithIncorrectCase));
});
// Add 2 private namespaces and 1 public namespace // Add 2 private namespaces and 1 public namespace
when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(somePublicNamespaceId)) when(appNamespaceRepository.findFirst500ByIdGreaterThanOrderByIdAsc(somePublicNamespaceId))
...@@ -159,27 +170,33 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -159,27 +170,33 @@ public class AppNamespaceServiceWithCacheTest {
anotherPublicAppNamespace)); anotherPublicAppNamespace));
when(appNamespaceRepository.findAllById(appNamespaceIds)).thenReturn(allAppNamespaces); when(appNamespaceRepository.findAllById(appNamespaceIds)).thenReturn(allAppNamespaces);
scanIntervalTimeUnit.sleep(sleepInterval); await().untilAsserted(() -> {
check(Lists.newArrayList(somePrivateAppNamespace, yetAnotherPrivateAppNamespace, check(Lists.newArrayList(somePrivateAppNamespace, yetAnotherPrivateAppNamespace,
anotherPublicAppNamespace), Lists anotherPublicAppNamespace), Lists
.newArrayList(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace), .newArrayList(
appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, yetAnotherPrivateNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace),
appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, anotherPublicNamespace))); appNamespaceServiceWithCache
.findByAppIdAndNamespace(someAppId, yetAnotherPrivateNamespace),
appNamespaceServiceWithCache
.findByAppIdAndNamespace(someAppId, anotherPublicNamespace)));
check(Lists.newArrayList(somePrivateAppNamespace, yetAnotherPrivateAppNamespace, check(Lists.newArrayList(somePrivateAppNamespace, yetAnotherPrivateAppNamespace,
anotherPublicAppNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespaces anotherPublicAppNamespace), appNamespaceServiceWithCache.findByAppIdAndNamespaces
(someAppId, someAppIdNamespaces)); (someAppId, someAppIdNamespaces));
check(Lists.newArrayList(somePublicAppNamespace, anotherPrivateAppNamespace), check(Lists.newArrayList(somePublicAppNamespace, anotherPrivateAppNamespace),
Lists.newArrayList(appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, somePublicNamespace), Lists.newArrayList(appNamespaceServiceWithCache
appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, anotherPrivateNamespace))); .findByAppIdAndNamespace(somePublicAppId, somePublicNamespace),
appNamespaceServiceWithCache
.findByAppIdAndNamespace(somePublicAppId, anotherPrivateNamespace)));
check(Lists.newArrayList(somePublicAppNamespace, anotherPrivateAppNamespace), check(Lists.newArrayList(somePublicAppNamespace, anotherPrivateAppNamespace),
appNamespaceServiceWithCache.findByAppIdAndNamespaces(somePublicAppId, appNamespaceServiceWithCache.findByAppIdAndNamespaces(somePublicAppId,
somePublicAppIdNamespaces)); somePublicAppIdNamespaces));
check(Lists.newArrayList(somePublicAppNamespace, anotherPublicAppNamespace), check(Lists.newArrayList(somePublicAppNamespace, anotherPublicAppNamespace),
Lists.newArrayList(appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespace), Lists.newArrayList(
appNamespaceServiceWithCache.findPublicNamespaceByName(somePublicNamespace),
appNamespaceServiceWithCache.findPublicNamespaceByName(anotherPublicNamespace))); appNamespaceServiceWithCache.findPublicNamespaceByName(anotherPublicNamespace)));
check(Lists.newArrayList(somePublicAppNamespace, anotherPublicAppNamespace), check(Lists.newArrayList(somePublicAppNamespace, anotherPublicAppNamespace),
appNamespaceServiceWithCache.findPublicNamespacesByNames(publicNamespaces)); appNamespaceServiceWithCache.findPublicNamespacesByNames(publicNamespaces));
});
// Update name // Update name
String somePrivateNamespaceNew = "somePrivateNamespaceNew"; String somePrivateNamespaceNew = "somePrivateNamespaceNew";
...@@ -216,15 +233,18 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -216,15 +233,18 @@ public class AppNamespaceServiceWithCacheTest {
when(appNamespaceRepository.findAllById(appNamespaceIds)).thenReturn(Lists.newArrayList when(appNamespaceRepository.findAllById(appNamespaceIds)).thenReturn(Lists.newArrayList
(somePrivateAppNamespaceNew, yetAnotherPrivateAppNamespaceNew, somePublicAppNamespaceNew)); (somePrivateAppNamespaceNew, yetAnotherPrivateAppNamespaceNew, somePublicAppNamespaceNew));
scanIntervalTimeUnit.sleep(sleepInterval); await().untilAsserted(() -> {
assertNull(
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace)); appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, somePrivateNamespace));
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, yetAnotherPrivateNamespace)); assertNull(appNamespaceServiceWithCache
assertNull(appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, anotherPublicNamespace)); .findByAppIdAndNamespace(someAppId, yetAnotherPrivateNamespace));
assertNull(
appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppId, anotherPublicNamespace));
check(Collections.emptyList(), appNamespaceServiceWithCache check(Collections.emptyList(), appNamespaceServiceWithCache
.findByAppIdAndNamespaces(someAppId, someAppIdNamespaces)); .findByAppIdAndNamespaces(someAppId, someAppIdNamespaces));
assertEquals(somePublicAppNamespaceNew, assertEquals(somePublicAppNamespaceNew,
appNamespaceServiceWithCache.findByAppIdAndNamespace(somePublicAppId, somePublicNamespace)); appNamespaceServiceWithCache
.findByAppIdAndNamespace(somePublicAppId, somePublicNamespace));
check(Lists.newArrayList(somePublicAppNamespaceNew), check(Lists.newArrayList(somePublicAppNamespaceNew),
appNamespaceServiceWithCache.findByAppIdAndNamespaces(somePublicAppId, appNamespaceServiceWithCache.findByAppIdAndNamespaces(somePublicAppId,
somePublicAppIdNamespaces)); somePublicAppIdNamespaces));
...@@ -238,9 +258,11 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -238,9 +258,11 @@ public class AppNamespaceServiceWithCacheTest {
check(Lists.newArrayList(somePrivateAppNamespaceNew), appNamespaceServiceWithCache check(Lists.newArrayList(somePrivateAppNamespaceNew), appNamespaceServiceWithCache
.findByAppIdAndNamespaces(someAppId, Sets.newHashSet(somePrivateNamespaceNew))); .findByAppIdAndNamespaces(someAppId, Sets.newHashSet(somePrivateNamespaceNew)));
assertEquals(yetAnotherPrivateAppNamespaceNew, assertEquals(yetAnotherPrivateAppNamespaceNew,
appNamespaceServiceWithCache.findByAppIdAndNamespace(someAppIdNew, yetAnotherPrivateNamespace)); appNamespaceServiceWithCache
.findByAppIdAndNamespace(someAppIdNew, yetAnotherPrivateNamespace));
check(Lists.newArrayList(yetAnotherPrivateAppNamespaceNew), appNamespaceServiceWithCache check(Lists.newArrayList(yetAnotherPrivateAppNamespaceNew), appNamespaceServiceWithCache
.findByAppIdAndNamespaces(someAppIdNew, Sets.newHashSet(yetAnotherPrivateNamespace))); .findByAppIdAndNamespaces(someAppIdNew, Sets.newHashSet(yetAnotherPrivateNamespace)));
});
} }
private void check(List<AppNamespace> someList, List<AppNamespace> anotherList) { private void check(List<AppNamespace> someList, List<AppNamespace> anotherList) {
......
...@@ -19,6 +19,7 @@ import java.util.List; ...@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
...@@ -172,8 +173,7 @@ public class ReleaseMessageServiceWithCacheTest { ...@@ -172,8 +173,7 @@ public class ReleaseMessageServiceWithCacheTest {
when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(someMessageId)).thenReturn(Lists when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(someMessageId)).thenReturn(Lists
.newArrayList(newMessage)); .newArrayList(newMessage));
scanIntervalTimeUnit.sleep(scanInterval * 10); await().atMost(scanInterval * 500, scanIntervalTimeUnit).untilAsserted(() -> {
ReleaseMessage newLatestReleaseMsg = ReleaseMessage newLatestReleaseMsg =
releaseMessageServiceWithCache releaseMessageServiceWithCache
.findLatestReleaseMessageForMessages(Sets.newHashSet(someMessageContent)); .findLatestReleaseMessageForMessages(Sets.newHashSet(someMessageContent));
...@@ -185,6 +185,7 @@ public class ReleaseMessageServiceWithCacheTest { ...@@ -185,6 +185,7 @@ public class ReleaseMessageServiceWithCacheTest {
assertEquals(newMessageId, newLatestReleaseMsg.getId()); assertEquals(newMessageId, newLatestReleaseMsg.getId());
assertEquals(someMessageContent, newLatestReleaseMsg.getMessage()); assertEquals(someMessageContent, newLatestReleaseMsg.getMessage());
assertEquals(newLatestReleaseMsg, newLatestReleaseMsgGroupByMsgContent.get(0)); assertEquals(newLatestReleaseMsg, newLatestReleaseMsgGroupByMsgContent.get(0));
});
} }
@Test @Test
......
...@@ -290,6 +290,13 @@ ...@@ -290,6 +290,13 @@
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<version>1.4.191</version> <version>1.4.191</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.0.3</version>
<scope>test</scope>
</dependency> </dependency>
<!-- declare Spring BOMs in order --> <!-- declare Spring BOMs in order -->
<dependency> <dependency>
...@@ -362,6 +369,11 @@ ...@@ -362,6 +369,11 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment