Skip to content

Commit

Permalink
Support configuring test environments
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChenX committed Dec 16, 2023
1 parent 435261d commit bdd8df6
Show file tree
Hide file tree
Showing 52 changed files with 2,308 additions and 639 deletions.
14 changes: 14 additions & 0 deletions turms-gateway/src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
spring:
netty:
leak-detection: paranoid

############################### Turms ###############################

turms:
logging:
console:
enabled: true
plugin:
js:
debug:
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package integration.im.turms.gateway.storage.mongo;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import im.turms.gateway.storage.mongo.MongoConfig;
Expand All @@ -41,13 +42,19 @@
*/
class MongoConfigIT extends BaseIntegrationTest {

@BeforeAll
static void setup() {
setupTestEnvironment();
}

@Test
void userMongoClient_shouldReturnNotNullInstance() {
MongoConfig mongoConfig = new MongoConfig(mock(TurmsApplicationContext.class));
TurmsProperties properties = new TurmsProperties().toBuilder()
.gateway(new GatewayProperties().toBuilder()
.mongo(new MongoProperties().toBuilder()
.user(new TurmsMongoProperties(getMongoUri()))
.user(new TurmsMongoProperties(
testEnvironmentManager.getMongoUri()))
.build())
.session(new SessionProperties().toBuilder()
.identityAccessManagement(
Expand All @@ -65,4 +72,4 @@ void userMongoClient_shouldReturnNotNullInstance() {
assertThat(mongoClient).isNotNull();
}

}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.function.Consumer;

import io.lettuce.core.GeoCoordinates;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -56,8 +57,6 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SessionLocationServiceIT extends BaseIntegrationTest {

static final SessionLocationService SESSION_LOCATION_SERVICE;

static final int METERS_PER_LATITUDE_DEGREE = 111_320;

static final long USER_1_ID = 1;
Expand All @@ -76,7 +75,12 @@ class SessionLocationServiceIT extends BaseIntegrationTest {
static final long NONEXISTENT_USER_ID = 99999;
static final DeviceType NONEXISTENT_USER_DEVICE = DeviceType.ANDROID;

static {
static SessionLocationService sessionLocationService;

@BeforeAll
static void setup() {
setupTestEnvironment();

PluginManager pluginManager = mock(PluginManager.class);
when(pluginManager.isEnabled()).thenReturn(false);

Expand All @@ -101,19 +105,19 @@ class SessionLocationServiceIT extends BaseIntegrationTest {
.notifyAndAddGlobalPropertiesChangeListener(any());

RedisProperties redisProperties = new RedisProperties().toBuilder()
.uriList(List.of("redis://%s:%d".formatted(ENV.getRedisHost(), ENV.getRedisPort())))
.uriList(List.of(testEnvironmentManager.getRedisUri()))
.build();
TurmsRedisClientManager manager = new TurmsRedisClientManager(
redisProperties,
RedisCodecContextPool.GEO_USER_SESSION_ID_CODEC_CONTEXT);
SESSION_LOCATION_SERVICE = new SessionLocationService(propertiesManager, manager);
sessionLocationService = new SessionLocationService(propertiesManager, manager);
}

@Order(0)
@Test
void upsertUserLocation_shouldInsert_ifNotExists() {
StepVerifier
.create(SESSION_LOCATION_SERVICE.upsertUserLocation(USER_1_ID,
.create(sessionLocationService.upsertUserLocation(USER_1_ID,
USER_1_DEVICE,
new Date(),
USER_1_COORDINATES_1.longitude(),
Expand All @@ -124,7 +128,7 @@ void upsertUserLocation_shouldInsert_ifNotExists() {
.expectComplete()
.verify(DEFAULT_IO_TIMEOUT);
StepVerifier
.create(SESSION_LOCATION_SERVICE.upsertUserLocation(USER_2_ID,
.create(sessionLocationService.upsertUserLocation(USER_2_ID,
USER_2_DEVICE,
new Date(),
USER_2_COORDINATES.longitude(),
Expand All @@ -135,7 +139,7 @@ void upsertUserLocation_shouldInsert_ifNotExists() {
.expectComplete()
.verify(DEFAULT_IO_TIMEOUT);
StepVerifier
.create(SESSION_LOCATION_SERVICE.upsertUserLocation(USER_3_ID,
.create(sessionLocationService.upsertUserLocation(USER_3_ID,
USER_3_DEVICE,
new Date(),
USER_3_COORDINATES.longitude(),
Expand All @@ -150,7 +154,7 @@ void upsertUserLocation_shouldInsert_ifNotExists() {
@Order(1)
@Test
void upsertUserLocation_shouldUpdate_ifExists() {
Mono<Void> upsertUserLocation = SESSION_LOCATION_SERVICE.upsertUserLocation(USER_1_ID,
Mono<Void> upsertUserLocation = sessionLocationService.upsertUserLocation(USER_1_ID,
USER_1_DEVICE,
new Date(),
USER_1_COORDINATES_2.longitude(),
Expand All @@ -164,7 +168,7 @@ void upsertUserLocation_shouldUpdate_ifExists() {
@Test
void getUserLocation_shouldGet_ifExists() {
Mono<GeoCoordinates> getUserLocation =
SESSION_LOCATION_SERVICE.getUserLocation(USER_1_ID, USER_1_DEVICE);
sessionLocationService.getUserLocation(USER_1_ID, USER_1_DEVICE);
StepVerifier.create(getUserLocation)
.expectNextMatches(coordinates -> {
assertThat(coordinates.getX()
Expand All @@ -180,7 +184,7 @@ void getUserLocation_shouldGet_ifExists() {
@Order(11)
@Test
void getUserLocation_shouldComplete_ifNotExists() {
Mono<GeoCoordinates> getUserLocation = SESSION_LOCATION_SERVICE
Mono<GeoCoordinates> getUserLocation = sessionLocationService
.getUserLocation(NONEXISTENT_USER_ID, NONEXISTENT_USER_DEVICE);
StepVerifier.create(getUserLocation)
.expectComplete()
Expand All @@ -191,7 +195,7 @@ void getUserLocation_shouldComplete_ifNotExists() {
@Test
void queryNearbyUsers_shouldGetNearbyUsers() {
StepVerifier
.create(SESSION_LOCATION_SERVICE.queryNearbyUsers(USER_1_ID,
.create(sessionLocationService.queryNearbyUsers(USER_1_ID,
USER_1_DEVICE,
(short) 100,
15 * METERS_PER_LATITUDE_DEGREE,
Expand All @@ -204,7 +208,7 @@ void queryNearbyUsers_shouldGetNearbyUsers() {
.expectComplete()
.verify(DEFAULT_IO_TIMEOUT);
StepVerifier
.create(SESSION_LOCATION_SERVICE.queryNearbyUsers(USER_2_ID,
.create(sessionLocationService.queryNearbyUsers(USER_2_ID,
USER_2_DEVICE,
(short) 100,
15 * METERS_PER_LATITUDE_DEGREE,
Expand All @@ -223,7 +227,7 @@ void queryNearbyUsers_shouldGetNearbyUsers() {
.expectComplete()
.verify(DEFAULT_IO_TIMEOUT);
StepVerifier
.create(SESSION_LOCATION_SERVICE.queryNearbyUsers(NONEXISTENT_USER_ID,
.create(sessionLocationService.queryNearbyUsers(NONEXISTENT_USER_ID,
NONEXISTENT_USER_DEVICE,
(short) 100,
15 * METERS_PER_LATITUDE_DEGREE,
Expand All @@ -238,7 +242,7 @@ void queryNearbyUsers_shouldGetNearbyUsers() {
@Order(30)
@Test
void removeUserLocation_shouldSucceed_ifExists() {
StepVerifier.create(SESSION_LOCATION_SERVICE.removeUserLocation(USER_1_ID, USER_1_DEVICE))
StepVerifier.create(sessionLocationService.removeUserLocation(USER_1_ID, USER_1_DEVICE))
.expectComplete()
.verify(DEFAULT_IO_TIMEOUT);
}
Expand All @@ -247,7 +251,7 @@ void removeUserLocation_shouldSucceed_ifExists() {
@Test
void removeUserLocation_shouldSucceed_ifNotExists() {
StepVerifier
.create(SESSION_LOCATION_SERVICE.removeUserLocation(NONEXISTENT_USER_ID,
.create(sessionLocationService.removeUserLocation(NONEXISTENT_USER_ID,
NONEXISTENT_USER_DEVICE))
.expectComplete()
.verify(DEFAULT_IO_TIMEOUT);
Expand Down
Loading

0 comments on commit bdd8df6

Please sign in to comment.