RED-6310: Added tests to check if concurrent access to notification-preferences works
(cherry picked from commit ef36f5c10f21042ce74621dd8e48a754b6a7258f)
This commit is contained in:
parent
51c2ee2fdd
commit
bbc58379f4
@ -0,0 +1,75 @@
|
|||||||
|
package com.iqser.red.service.peristence.v1.server.integration.tests;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import com.iqser.red.service.peristence.v1.server.controller.NotificationController;
|
||||||
|
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
|
||||||
|
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.NotificationPreferencesPersistenceService;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.experimental.FieldDefaults;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@FieldDefaults(level = AccessLevel.PRIVATE)
|
||||||
|
public class NotificationPreferencesServiceTest extends AbstractPersistenceServerServiceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
NotificationPreferencesPersistenceService notificationPreferencesPersistenceService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
NotificationController notificationController;
|
||||||
|
|
||||||
|
|
||||||
|
// Disabled since tenant-id is not used correctly when directly using the service
|
||||||
|
@Disabled
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void testNotificationPreferencesConcurrent() {
|
||||||
|
|
||||||
|
final String userId = "1";
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
var exceptions = Collections.synchronizedList(new ArrayList<Exception>());
|
||||||
|
|
||||||
|
Thread t1 = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
notificationController.getNotifications(userId, true);
|
||||||
|
notificationPreferencesPersistenceService.getOrCreateNotificationPreferences(userId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Thread t2 = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
notificationController.getNotifications(userId, true);
|
||||||
|
notificationPreferencesPersistenceService.getOrCreateNotificationPreferences(userId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
|
||||||
|
notificationPreferencesPersistenceService.deleteNotificationPreferences(userId);
|
||||||
|
|
||||||
|
for (Exception ex : exceptions) {
|
||||||
|
log.error("Exception during notification creation", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(exceptions).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,6 +3,8 @@ package com.iqser.red.service.peristence.v1.server.integration.tests;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.assertj.core.util.Lists;
|
import org.assertj.core.util.Lists;
|
||||||
@ -17,6 +19,11 @@ import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimiti
|
|||||||
import com.iqser.red.service.persistence.service.v1.api.model.notification.Notification;
|
import com.iqser.red.service.persistence.service.v1.api.model.notification.Notification;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.model.notification.NotificationType;
|
import com.iqser.red.service.persistence.service.v1.api.model.notification.NotificationType;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||||
|
@Slf4j
|
||||||
public class NotificationTest extends AbstractPersistenceServerServiceTest {
|
public class NotificationTest extends AbstractPersistenceServerServiceTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -106,4 +113,84 @@ public class NotificationTest extends AbstractPersistenceServerServiceTest {
|
|||||||
return currentNotifications.iterator().next();
|
return currentNotifications.iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void testNotificationPreferencesConcurrent() {
|
||||||
|
|
||||||
|
final String userId = "1";
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
var exceptions = Collections.synchronizedList(new ArrayList<Exception>());
|
||||||
|
|
||||||
|
Thread t1 = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
notificationPreferencesClient.getNotificationPreferences(userId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Thread t2 = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
notificationPreferencesClient.getNotificationPreferences(userId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
|
||||||
|
notificationPreferencesClient.deleteNotificationPreferences(userId);
|
||||||
|
|
||||||
|
for (Exception ex : exceptions) {
|
||||||
|
log.error("Exception during notification creation", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(exceptions).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void testNotificationsConcurrent() {
|
||||||
|
|
||||||
|
final String userId = "1";
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
var exceptions = Collections.synchronizedList(new ArrayList<Exception>());
|
||||||
|
|
||||||
|
Thread t1 = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
notificationClient.getNotifications(userId, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Thread t2 = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
notificationClient.getNotifications(userId, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
exceptions.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t1.start();
|
||||||
|
t2.start();
|
||||||
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
|
||||||
|
notificationPreferencesClient.deleteNotificationPreferences(userId);
|
||||||
|
|
||||||
|
for (Exception ex : exceptions) {
|
||||||
|
log.error("Exception during notification creation", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(exceptions).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user