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());
}
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);
}
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);
}
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);
}
}
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());
}
Aggregations