use of com.zimbra.cs.imap.ImapServerListener in project zm-mailbox by Zimbra.
the class TestImapNotificationsViaWaitsets method runOp.
@Override
protected void runOp(MailboxOperation op, ZMailbox zmbox, ZFolder folder) throws Exception {
ImapServerListener listener = ImapServerListenerPool.getInstance().get(zmbox);
String wsID = listener.getWSId();
SomeAccountsWaitSet ws = (SomeAccountsWaitSet) (WaitSetMgr.lookup(wsID));
long lastSequence = ws.getCurrentSeqNo();
op.run(zmbox);
boolean applied = false;
int timeout = 6000;
while (timeout > 0) {
if (listener.getLastKnownSequenceNumber() > lastSequence) {
applied = true;
break;
}
timeout -= 500;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
break;
}
}
assertTrue("operation not applied within 6 seconds", applied);
String failure = op.checkResult();
assertNull(failure, failure);
}
use of com.zimbra.cs.imap.ImapServerListener in project zm-mailbox by Zimbra.
the class TestImapServerListener method testNotifyReadUnread.
@Test
public void testNotifyReadUnread() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
ImapServerListener remoteListener = ImapServerListenerPool.getInstance().get(mboxStore);
RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
ImapCredentials creds = new ImapCredentials(remoteAccount);
ImapPath path = new ImapPath("INBOX", creds);
byte params = 0;
ImapHandler handler = new MockImapHandler().setCredentials(creds);
ImapFolder i4folder = new ImapFolder(path, params, handler);
MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
remoteListener.addListener(session);
// wait for waitset session to be created
QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
session.doneSignal = new CountDownLatch(1);
String subject = "TestImapServerListener - testNotifyReadUnread";
TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), "randomUserTestImapServerListener@yahoo.com");
ZMessage msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox subject:\"%s\"", subject));
assertTrue("New message should have UNREAD flag", msg.isUnread());
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertTrue("Expected session to be triggered after delivering the test message", session.wasTriggered());
// mark read
session.doneSignal = new CountDownLatch(1);
mboxStore.markMessageRead(msg.getId(), true);
msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox is:read subject:\"%s\"", subject));
assertFalse("New message should NOT have UNREAD flag", msg.isUnread());
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertTrue("Expected session to be triggered after marking test message READ", session.wasTriggered());
// mark unread
session.doneSignal = new CountDownLatch(1);
mboxStore.markMessageRead(msg.getId(), false);
msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox is:unread subject:\"%s\"", subject));
assertTrue("New message should have UNREAD flag", msg.isUnread());
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertTrue("Expected session to be triggered after marking test message UREAD", session.wasTriggered());
remoteListener.removeListener(session);
}
Aggregations