Search in sources :

Example 11 with ImapServerListener

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);
}
Also used : ImapServerListener(com.zimbra.cs.imap.ImapServerListener) SomeAccountsWaitSet(com.zimbra.cs.session.SomeAccountsWaitSet)

Example 12 with ImapServerListener

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);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) CountDownLatch(java.util.concurrent.CountDownLatch) HttpException(org.apache.http.HttpException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Aggregations

ImapServerListener (com.zimbra.cs.imap.ImapServerListener)12 ZMailbox (com.zimbra.client.ZMailbox)11 ServiceException (com.zimbra.common.service.ServiceException)10 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)10 ImapFolder (com.zimbra.cs.imap.ImapFolder)10 ImapHandler (com.zimbra.cs.imap.ImapHandler)10 ImapPath (com.zimbra.cs.imap.ImapPath)10 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)10 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 HttpException (org.apache.http.HttpException)10 Test (org.junit.Test)9 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)8 ZMessage (com.zimbra.client.ZMessage)5 ZFolder (com.zimbra.client.ZFolder)2 ZTag (com.zimbra.client.ZTag)2 SoapTransport (com.zimbra.common.soap.SoapTransport)1 Account (com.zimbra.cs.account.Account)1 ImapRemoteSession (com.zimbra.cs.imap.ImapRemoteSession)1 SomeAccountsWaitSet (com.zimbra.cs.session.SomeAccountsWaitSet)1