Search in sources :

Example 1 with MessageNotFoundException

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;
}
Also used : MessageNotFoundException(dvoraka.avservice.common.exception.MessageNotFoundException) AvMessage(dvoraka.avservice.common.data.AvMessage)

Example 2 with MessageNotFoundException

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;
}
Also used : MessageNotFoundException(dvoraka.avservice.common.exception.MessageNotFoundException) AvMessage(dvoraka.avservice.common.data.AvMessage)

Example 3 with MessageNotFoundException

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();
        }
    }
}
Also used : MessageNotFoundException(dvoraka.avservice.common.exception.MessageNotFoundException) ArrayList(java.util.ArrayList) AvMessage(dvoraka.avservice.common.data.AvMessage)

Aggregations

AvMessage (dvoraka.avservice.common.data.AvMessage)3 MessageNotFoundException (dvoraka.avservice.common.exception.MessageNotFoundException)3 ArrayList (java.util.ArrayList)1