Skip to content

Commit

Permalink
Improvements: tests changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sboesebeck committed Nov 13, 2021
1 parent 285198b commit 7f64c6f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 24 deletions.
39 changes: 29 additions & 10 deletions test/de/caluga/test/mongo/suite/messaging/MessagingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ public void testMsgLifecycle() throws Exception {

@SuppressWarnings("Duplicates")
@Test
public void multithreaddingTest() throws Exception {
public void multithreaddingTestSingle() throws Exception {
int amount = 65;
Messaging producer = new Messaging(morphium, 500, false);
producer.start();
for (int i = 0; i < 100; i++) {
for (int i = 0; i < amount; i++) {
if (i % 10 == 0) {
log.info("Messages sent: " + i);
}
Msg m = new Msg("test" + i, "tm", "" + i + System.currentTimeMillis(), 30000);
producer.sendMessage(m);
}
Expand All @@ -127,41 +131,56 @@ public void multithreaddingTest() throws Exception {
});
long start = System.currentTimeMillis();
consumer.start();
while (count.get() < 100) {
while (count.get() < amount) {
log.info("Messages processed: " + count.get());
Thread.sleep(1000);
if (System.currentTimeMillis() - start > 20000) throw new RuntimeException("Timeout");
}
long dur = System.currentTimeMillis() - start;
log.info("processing 100 multithreaded but single messages took " + dur + "ms == " + (100 / (dur / 1000)) + " msg/sec");
log.info("processing " + amount + " multithreaded but single messages took " + dur + "ms == " + (amount / (dur / 1000)) + " msg/sec");

consumer.terminate();
producer.terminate();

}


@Test
public void mutlithreaddingTestMultiple() throws Exception {
int amount = 650;
Messaging producer = new Messaging(morphium, 500, false);
producer.start();
log.info("now multithreadded and multiprocessing");
for (int i = 0; i < 2500; i++) {
for (int i = 0; i < amount; i++) {
if (i % 10 == 0) {
log.info("Messages sent: " + i);
}
Msg m = new Msg("test" + i, "tm", "" + i + System.currentTimeMillis(), 30000);
producer.sendMessage(m);
}
final AtomicInteger count = new AtomicInteger();
count.set(0);
consumer = new Messaging(morphium, 100, true, true, 100);
Messaging consumer = new Messaging(morphium, 100, true, true, 100);
consumer.addMessageListener((msg, m) -> {
// log.info("Got message!");
count.incrementAndGet();
return null;
});
start = System.currentTimeMillis();
long start = System.currentTimeMillis();
consumer.start();
while (count.get() < 2500) {
while (count.get() < amount) {
log.info("Messages processed: " + count.get());
Thread.sleep(1000);
if (System.currentTimeMillis() - start > 20000) throw new RuntimeException("Timeout!");
}
dur = System.currentTimeMillis() - start;
long dur = System.currentTimeMillis() - start;
log.info("processing 2500 multithreaded and multiprocessing messages took " + dur + "ms == " + (2500 / (dur / 1000)) + " msg/sec");


consumer.terminate();
producer.terminate();
log.info("Messages processed: " + count.get());
log.info("Messages left: " + consumer.getPendingMessagesCount());

}


Expand Down
46 changes: 32 additions & 14 deletions test/de/caluga/test/mongo/suite/ncmessaging/MessagingNCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ public void testMsgLifecycle() throws Exception {

@SuppressWarnings("Duplicates")
@Test
public void multithreaddingTest() throws Exception {
public void multithreaddingTestSingle() throws Exception {
int amount = 65;
Messaging producer = new Messaging(morphium, 500, false);
producer.setUseChangeStream(false).start();
for (int i = 0; i < 100; i++) {
producer.start();
for (int i = 0; i < amount; i++) {
if (i % 10 == 0) {
log.info("Messages sent: " + i);
}
Msg m = new Msg("test" + i, "tm", "" + i + System.currentTimeMillis(), 30000);
producer.sendMessage(m);
}
Expand All @@ -112,44 +116,58 @@ public void multithreaddingTest() throws Exception {
});
long start = System.currentTimeMillis();
consumer.setUseChangeStream(false).start();
while (count.get() < 100) {
while (count.get() < amount) {
log.info("Messages processed: " + count.get());
Thread.sleep(1000);
if (System.currentTimeMillis() - start > 20000) throw new RuntimeException("Timeout");
}
long dur = System.currentTimeMillis() - start;
log.info("processing 100 multithreaded but single messages took " + dur + "ms == " + (100 / (dur / 1000)) + " msg/sec");
log.info("processing " + amount + " multithreaded but single messages took " + dur + "ms == " + (amount / (dur / 1000)) + " msg/sec");

consumer.terminate();
producer.terminate();

}


@Test
public void mutlithreaddingTestMultiple() throws Exception {
int amount = 650;
Messaging producer = new Messaging(morphium, 500, false);
producer.start();
log.info("now multithreadded and multiprocessing");
for (int i = 0; i < 2500; i++) {
for (int i = 0; i < amount; i++) {
if (i % 10 == 0) {
log.info("Messages sent: " + i);
}
Msg m = new Msg("test" + i, "tm", "" + i + System.currentTimeMillis(), 30000);
producer.sendMessage(m);
}
final AtomicInteger count = new AtomicInteger();
count.set(0);
consumer = new Messaging(morphium, 100, true, true, 100);
Messaging consumer = new Messaging(morphium, 100, true, true, 100);
consumer.addMessageListener((msg, m) -> {
// log.info("Got message!");
count.incrementAndGet();
return null;
});
start = System.currentTimeMillis();
long start = System.currentTimeMillis();
consumer.setUseChangeStream(false).start();
while (count.get() < 2500) {
while (count.get() < amount) {
log.info("Messages processed: " + count.get());
Thread.sleep(1000);
if (System.currentTimeMillis() - start > 20000) throw new RuntimeException("Timeout!");
}
dur = System.currentTimeMillis() - start;
long dur = System.currentTimeMillis() - start;
log.info("processing 2500 multithreaded and multiprocessing messages took " + dur + "ms == " + (2500 / (dur / 1000)) + " msg/sec");


consumer.terminate();
producer.terminate();
log.info("Messages processed: " + count.get());
log.info("Messages left: " + consumer.getPendingMessagesCount());

}


@Test
public void messagingTest() throws Exception {
error = false;
Expand Down Expand Up @@ -671,7 +689,7 @@ public void severalMessagingsTest() throws Exception {
});

procCounter.set(0);
for (int i = 0; i < 180; i++) {
for (int i = 0; i < 10; i++) {
new Thread() {
public void run() {
Msg m = new Msg("test", "nothing", "value");
Expand All @@ -683,7 +701,7 @@ public void run() {
}.start();

}
while (procCounter.get() < 180) {
while (procCounter.get() < 10) {
Thread.sleep(1000);
log.info("Recieved " + procCounter.get());
}
Expand Down

0 comments on commit 7f64c6f

Please sign in to comment.