Search in sources :

Example 1 with NormalMessage

use of org.opensolaris.opengrok.configuration.messages.NormalMessage in project OpenGrok by OpenGrok.

the class RuntimeEnvironmentTest method testCanAcceptMessage.

@Test
public void testCanAcceptMessage() throws Exception {
    RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
    instance.removeAllMessages();
    Message m1 = new NormalMessage();
    m1.addTag("main");
    m1.setExpiration(new Date(System.currentTimeMillis() - 3000));
    Assert.assertFalse(instance.canAcceptMessage(m1));
    m1.setExpiration(new Date(System.currentTimeMillis() - 2000));
    Assert.assertFalse(instance.canAcceptMessage(m1));
    m1.setExpiration(new Date(System.currentTimeMillis() - 1000));
    Assert.assertFalse(instance.canAcceptMessage(m1));
    m1.setExpiration(new Date(System.currentTimeMillis() - 1));
    Assert.assertFalse(instance.canAcceptMessage(m1));
    m1.setExpiration(new Date(System.currentTimeMillis() - 0));
    Assert.assertTrue(instance.canAcceptMessage(m1));
    m1.setExpiration(new Date(System.currentTimeMillis() + 1));
    Assert.assertTrue(instance.canAcceptMessage(m1));
    m1.setExpiration(new Date(System.currentTimeMillis() + 5000));
    Assert.assertEquals(0, instance.getMessagesInTheSystem());
    for (int i = 0; i < instance.getMessageLimit(); i++) {
        Message m2 = new NormalMessage();
        m2.addTag("main");
        m2.setText("text");
        m2.setExpiration(new Date(System.currentTimeMillis() + 5000));
        m2.setCreated(new Date(System.currentTimeMillis() + i));
        Assert.assertTrue(instance.canAcceptMessage(m2));
        m2.apply(instance);
        Assert.assertEquals(i + 1, instance.getMessagesInTheSystem());
    }
    Assert.assertEquals(instance.getMessageLimit(), instance.getMessagesInTheSystem());
    for (int i = 0; i < instance.getMessageLimit() * 2; i++) {
        Message m2 = new NormalMessage();
        m2.addTag("main");
        m2.setText("text");
        m2.setExpiration(new Date(System.currentTimeMillis() + 5000));
        m2.setCreated(new Date(System.currentTimeMillis() + i + instance.getMessageLimit()));
        Assert.assertFalse(instance.canAcceptMessage(m2));
        m2.apply(instance);
        Assert.assertEquals(instance.getMessageLimit(), instance.getMessagesInTheSystem());
    }
    instance.removeAllMessages();
}
Also used : NormalMessage(org.opensolaris.opengrok.configuration.messages.NormalMessage) NormalMessage(org.opensolaris.opengrok.configuration.messages.NormalMessage) Message(org.opensolaris.opengrok.configuration.messages.Message) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)1 Test (org.junit.Test)1 Message (org.opensolaris.opengrok.configuration.messages.Message)1 NormalMessage (org.opensolaris.opengrok.configuration.messages.NormalMessage)1