This commit is contained in:
Michele Artini 2021-10-04 15:46:12 +02:00
parent 31a6ad1d79
commit 0a9ef34b56
1 changed files with 60 additions and 24 deletions

View File

@ -18,6 +18,8 @@ class IndexNotificationsJobTest {
private List<Subscription> subscriptions; private List<Subscription> subscriptions;
private static final int N_TIMES = 1_000_000;
@BeforeEach @BeforeEach
void setUp() throws Exception { void setUp() throws Exception {
final Subscription s = new Subscription(); final Subscription s = new Subscription();
@ -32,15 +34,8 @@ class IndexNotificationsJobTest {
final Event event = new Event(); final Event event = new Event();
event.setTopic("ENRICH/MISSING/PROJECT"); event.setTopic("ENRICH/MISSING/PROJECT");
for (int i = 0; i < 10; i++) { final NotificationGroup res = IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
final long start = System.currentTimeMillis(); assertEquals(0, res.getData().size());
final NotificationGroup res = IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
final long end = System.currentTimeMillis();
System.out.println("no topic - execution time (ms): " + (end - start));
assertEquals(0, res.getData().size());
}
} }
@Test @Test
@ -51,15 +46,8 @@ class IndexNotificationsJobTest {
event.getMap().setTargetDatasourceName("reposiTUm"); event.getMap().setTargetDatasourceName("reposiTUm");
event.getMap().setTrust(0.8f); event.getMap().setTrust(0.8f);
for (int i = 0; i < 10; i++) { final NotificationGroup res = IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
final long start = System.currentTimeMillis(); assertEquals(1, res.getData().size());
final NotificationGroup res = IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
final long end = System.currentTimeMillis();
System.out.println("topic match - execution time (ms): " + (end - start));
assertEquals(1, res.getData().size());
}
} }
@Test @Test
@ -70,15 +58,63 @@ class IndexNotificationsJobTest {
event.getMap().setTargetDatasourceName("Puma"); event.getMap().setTargetDatasourceName("Puma");
event.getMap().setTrust(0.8f); event.getMap().setTrust(0.8f);
for (int i = 0; i < 10; i++) { final NotificationGroup res = IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
final long start = System.currentTimeMillis(); assertEquals(0, res.getData().size());
final NotificationGroup res = IndexNotificationsJob.generateNotifications(event, subscriptions, 0); }
final long end = System.currentTimeMillis();
System.out.println("topic no match - execution time (ms): " + (end - start)); @Test
void testGenerateNotifications_invalid_topic_repeated() {
final Event event = new Event();
event.setTopic("ENRICH/MISSING/PROJECT");
assertEquals(0, res.getData().size()); // warm up
IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
final long start = System.currentTimeMillis();
for (int i = 0; i < N_TIMES; i++) {
IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
} }
final long end = System.currentTimeMillis();
System.out.println(String.format("no topic - repeated %s times - execution time: %s ms ", N_TIMES, end - start));
}
@Test
void testGenerateNotifications_topic_match_repeated() {
final Event event = new Event();
event.setTopic("ENRICH/MISSING/PID");
event.setMap(new MappedFields());
event.getMap().setTargetDatasourceName("reposiTUm");
event.getMap().setTrust(0.8f);
// warm up
IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
final long start = System.currentTimeMillis();
for (int i = 0; i < N_TIMES; i++) {
IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
}
final long end = System.currentTimeMillis();
System.out.println(String.format("topic match - repeated %s times - execution time: %s ms ", N_TIMES, end - start));
}
@Test
void testGenerateNotifications_topic_no_match_repeated() {
final Event event = new Event();
event.setTopic("ENRICH/MISSING/PID");
event.setMap(new MappedFields());
event.getMap().setTargetDatasourceName("Puma");
event.getMap().setTrust(0.8f);
// warm up
IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
final long start = System.currentTimeMillis();
for (int i = 0; i < N_TIMES; i++) {
IndexNotificationsJob.generateNotifications(event, subscriptions, 0);
}
final long end = System.currentTimeMillis();
System.out.println(String.format("topic no match - repeated %s times - execution time: %s ms ", N_TIMES, end - start));
} }
} }