Search in sources :

Example 6 with MockMessage

use of jetbrains.communicator.mock.MockMessage in project intellij-plugins by JetBrains.

the class LocalMessageDispatcherTest method testClearHistory_Persistence.

public void testClearHistory_Persistence() throws Exception {
    myDispatcher.sendNow(myUser, new MockMessage(new Date()));
    Thread.sleep(SAVE_WAIT_TIMEOUT);
    assertFalse(myDispatcher.isHistoryEmpty());
    myDispatcher.clearHistory();
    Thread.sleep(SAVE_WAIT_TIMEOUT);
    assertEquals("History should be deleted", 0, new File(myIdeFacade.getCacheDir(), "history").listFiles().length);
    myDispatcher.sendNow(myUser, new MockMessage(new Date()));
    myDispatcher.clearHistory();
    Thread.sleep(SAVE_WAIT_TIMEOUT);
    assertEquals("History should be deleted", 0, new File(myIdeFacade.getCacheDir(), "history").listFiles().length);
    assertEquals(0, myDispatcher.getHistory(myUser, null).length);
    assertTrue(myDispatcher.isHistoryEmpty());
}
Also used : MockMessage(jetbrains.communicator.mock.MockMessage) File(java.io.File) Date(java.util.Date)

Example 7 with MockMessage

use of jetbrains.communicator.mock.MockMessage in project intellij-plugins by JetBrains.

the class LocalMessageDispatcherTest method testAddPendingMessage.

public void testAddPendingMessage() throws Exception {
    MockMessage message = new MockMessage();
    myDispatcher.addPendingMessage(myUser, message);
    assertEquals(1, myDispatcher.getPendingMessages(myUser).length);
    assertSame(message, myDispatcher.getPendingMessages(myUser)[0]);
    // add again
    myDispatcher.addPendingMessage(myUser, message);
    assertEquals("Should be added once", 1, myDispatcher.getPendingMessages(myUser).length);
    myDispatcher.addPendingMessage(myUser, null);
    assertEquals("Should have no problems with nulls", 1, myDispatcher.getPendingMessages(myUser).length);
}
Also used : MockMessage(jetbrains.communicator.mock.MockMessage)

Example 8 with MockMessage

use of jetbrains.communicator.mock.MockMessage in project intellij-plugins by JetBrains.

the class LocalMessageDispatcherTest method testPersistency.

public void testPersistency() throws Exception {
    myDispatcher.addPendingMessage(myUser, new MockMessage());
    assertEquals("Should have no problems with nulls", 1, myDispatcher.getPendingMessages(myUser).length);
    // test persistency
    LocalMessageDispatcherImpl localMessageDispatcher = createLocalMessageDispatcher();
    assertEquals(1, localMessageDispatcher.getPendingMessages(myUser).length);
    localMessageDispatcher.sendNow(myUser, localMessageDispatcher.getPendingMessages(myUser)[0]);
    localMessageDispatcher = new LocalMessageDispatcherImpl(getBroadcaster(), myIdeFacade, myUserModel);
    disposeOnTearDown(localMessageDispatcher);
    assertEquals(0, localMessageDispatcher.getPendingMessages(myUser).length);
}
Also used : MockMessage(jetbrains.communicator.mock.MockMessage)

Example 9 with MockMessage

use of jetbrains.communicator.mock.MockMessage in project intellij-plugins by JetBrains.

the class LocalMessageDispatcherTest method testPerformance.

public void testPerformance() throws Exception {
    Logger logger = Logger.getLogger("jetbrains.communicator");
    Level oldLevel = logger.getLevel();
    try {
        logger.setLevel(Level.WARN);
        for (int i = 0; i < 1000; i++) {
            Date date = new Date(System.currentTimeMillis() + i * 1000L * 3600L);
            myDispatcher.sendNow(myUser, new MockMessage(date));
        }
        Thread.sleep(SAVE_WAIT_TIMEOUT * 2);
        WatchDog watchDog = new WatchDog("Load history");
        LocalMessageDispatcherImpl localMessageDispatcher = createLocalMessageDispatcher();
        LocalMessage[] messages = localMessageDispatcher.getHistory(myUser, yesterday());
        assertEquals(1000, messages.length);
        long diff = watchDog.diff();
        watchDog.watchAndReset("done");
        assertTrue("Too long getting history:" + diff, diff < 1500);
        messages = localMessageDispatcher.getHistory(myUser, null);
        assertEquals(1000, messages.length);
        diff = watchDog.diff();
        watchDog.watchAndReset("again done");
        assertTrue("Too long getting history second time:" + diff, diff < 100);
    } finally {
        logger.setLevel(oldLevel);
    }
}
Also used : LocalMessage(jetbrains.communicator.core.dispatcher.LocalMessage) WatchDog(jetbrains.communicator.util.WatchDog) MockMessage(jetbrains.communicator.mock.MockMessage) Level(org.apache.log4j.Level) Logger(org.apache.log4j.Logger) Date(java.util.Date)

Example 10 with MockMessage

use of jetbrains.communicator.mock.MockMessage in project intellij-plugins by JetBrains.

the class LocalMessageDispatcherTest method testHistoryPersistence_SortLoadedHistory.

public void testHistoryPersistence_SortLoadedHistory() throws Exception {
    myDispatcher.sendNow(myUser, new MockMessage(yesterday(), "someText"));
    MockMessage message = new MockMessage();
    myDispatcher.sendNow(myUser, message);
    Thread.sleep(SAVE_WAIT_TIMEOUT);
    LocalMessageDispatcherImpl localMessageDispatcher = createLocalMessageDispatcher();
    localMessageDispatcher.sendNow(myUser, message);
    Thread.sleep(SAVE_WAIT_TIMEOUT);
    assertEquals(2, localMessageDispatcher.getHistory(myUser, a_moment_ago()).length);
    LocalMessage[] messages = localMessageDispatcher.getHistory(myUser, null);
    assertEquals(3, messages.length);
    assertEquals("someText", ((MockMessage) messages[0]).getMessage());
}
Also used : LocalMessage(jetbrains.communicator.core.dispatcher.LocalMessage) MockMessage(jetbrains.communicator.mock.MockMessage)

Aggregations

MockMessage (jetbrains.communicator.mock.MockMessage)22 LocalMessage (jetbrains.communicator.core.dispatcher.LocalMessage)7 Date (java.util.Date)6 MockTransport (jetbrains.communicator.mock.MockTransport)3 File (java.io.File)2 ArrayList (java.util.ArrayList)1 Message (jetbrains.communicator.core.dispatcher.Message)1 TransportEvent (jetbrains.communicator.core.transport.TransportEvent)1 UserEvent (jetbrains.communicator.core.users.UserEvent)1 SendMessageEvent (jetbrains.communicator.ide.SendMessageEvent)1 MockUser (jetbrains.communicator.mock.MockUser)1 WaitFor (jetbrains.communicator.util.WaitFor)1 WatchDog (jetbrains.communicator.util.WatchDog)1 Level (org.apache.log4j.Level)1 Logger (org.apache.log4j.Logger)1