use of dvoraka.avservice.common.exception.MessageNotFoundException in project av-service by dvoraka.
the class SimpleChecker method check.
@Override
public boolean check() {
AvMessage normalMessage = Utils.genMessage();
AvMessage infectedMessage = Utils.genInfectedMessage();
sendAvMessage(normalMessage);
try {
AvMessage receivedMessage = receiveMessage(normalMessage.getId());
if (isInfected(receivedMessage)) {
return false;
}
} catch (MessageNotFoundException e) {
log.debug("Message not found.", e);
return false;
}
sendAvMessage(infectedMessage);
try {
AvMessage receivedMessage = receiveMessage(infectedMessage.getId());
if (!isInfected(receivedMessage)) {
return false;
}
} catch (MessageNotFoundException e) {
log.debug("Message not found.", e);
return false;
}
return true;
}
use of dvoraka.avservice.common.exception.MessageNotFoundException in project av-service by dvoraka.
the class PerformanceTester method start.
@Override
public void start() {
running = true;
boolean perfect = true;
final long loops = testProperties.getMsgCount();
final long maxRate = testProperties.getMaxRate();
System.out.println("Load test start for " + loops + " messages...");
long start = System.currentTimeMillis();
long maxRateCounter = start;
for (int i = 0; i < loops; i++) {
AvMessage message = Utils.genInfectedMessage();
checker.sendAvMessage(message);
try {
checker.receiveMessage(message.getId());
} catch (MessageNotFoundException e) {
log.warn("Message not found.", e);
perfect = false;
}
if (maxRate == 0) {
continue;
}
long delta = System.currentTimeMillis() - maxRateCounter;
if (i % maxRate == 0 && delta < MS_PER_SECOND) {
sleep(delta);
maxRateCounter = System.currentTimeMillis();
}
}
long duration = System.currentTimeMillis() - start;
System.out.println("Load test end.");
float durationSeconds = duration / MS_PER_SECOND;
setResult(loops / durationSeconds);
System.out.println("\nDuration: " + durationSeconds + " s");
System.out.println("Messages: " + result + "/s");
if (!perfect) {
System.out.println("\nSome messages were lost.");
} else {
passed = true;
}
running = false;
}
use of dvoraka.avservice.common.exception.MessageNotFoundException in project av-service by dvoraka.
the class SimpleChecker method receiveMessage.
@Override
public AvMessage receiveMessage(String correlationId) throws MessageNotFoundException {
List<AvMessage> savedMessages = new ArrayList<>(QUEUE_CAPACITY);
AvMessage message;
while (true) {
try {
message = queue.poll(MAX_TIMEOUT, TimeUnit.MILLISECONDS);
if (message == null) {
throw new MessageNotFoundException();
}
if (message.getCorrelationId().equals(correlationId)) {
returnMessagesToQueue(savedMessages);
savedMessages.clear();
return message;
} else {
savedMessages.add(message);
}
} catch (InterruptedException e) {
log.warn("Waiting interrupted!", e);
Thread.currentThread().interrupt();
}
}
}
Aggregations