Search in sources :

Example 6 with ImapServerListener

use of com.zimbra.cs.imap.ImapServerListener in project zm-mailbox by Zimbra.

the class TestImapNotificationsViaMailbox method runOp.

@Override
protected void runOp(MailboxOperation op, ZMailbox zmbox, ZFolder folder) throws Exception {
    ImapServerListener listener = ImapServerListenerPool.getInstance().get(zmbox);
    Set<ImapRemoteSession> sessions = listener.getListeners(zmbox.getAccountId(), Integer.valueOf(folder.getId()));
    assertFalse(String.format("Folder %s does not have any IMAP listeners", folder.getPath()), sessions.isEmpty());
    ImapRemoteSession session = sessions.iterator().next();
    ZMailbox imapzmbox = (ZMailbox) session.getMailbox();
    op.run(imapzmbox);
    String failure = op.checkResult();
    assertNull(failure, failure);
}
Also used : ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ImapRemoteSession(com.zimbra.cs.imap.ImapRemoteSession) ZMailbox(com.zimbra.client.ZMailbox)

Example 7 with ImapServerListener

use of com.zimbra.cs.imap.ImapServerListener in project zm-mailbox by Zimbra.

the class TestImapServerListener method testNotifyWrongFolder.

@Test
public void testNotifyWrongFolder() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    ZFolder folder = TestUtil.createFolder(mboxStore, "/TestImapServerListener-testNotifyNewFolder");
    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);
    session.doneSignal = new CountDownLatch(1);
    remoteListener.addListener(session);
    // wait for waitset session to be created
    QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
    TestUtil.addMessage(mboxStore, "TestImapServerListener - testNotifyWrongFolder", folder.getId());
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    assertFalse("Expected session to not be triggered", session.wasTriggered());
    remoteListener.removeListener(session);
}
Also used : 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) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 8 with ImapServerListener

use of com.zimbra.cs.imap.ImapServerListener in project zm-mailbox by Zimbra.

the class TestImapServerListener method testNotifyRenameTag.

@Test
public void testNotifyRenameTag() 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 - testNotifyRenameTag";
    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());
    ZTag tag = mboxStore.createTag("testNotifyTag", Color.blue);
    // tag
    session.doneSignal = new CountDownLatch(1);
    mboxStore.tagMessage(msg.getId(), tag.getId(), true);
    msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox tag:testNotifyTag subject:\"%s\"", subject));
    assertTrue("Test message should have testNotifyTag tag after tagging", msg.getTagIds().contains(tag.getId()));
    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 tagging test message", session.wasTriggered());
    // rename tag
    session.doneSignal = new CountDownLatch(1);
    mboxStore.renameTag(tag.getId(), "testNotifyRenamedTag");
    msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox tag:testNotifyRenamedTag subject:\"%s\"", subject));
    assertTrue("Test message should have testNotifyRenamedTag tag after renaming the tag", msg.getTagIds().contains(tag.getId()));
    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 renaming the tag", 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) ZTag(com.zimbra.client.ZTag) 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)

Example 9 with ImapServerListener

use of com.zimbra.cs.imap.ImapServerListener in project zm-mailbox by Zimbra.

the class TestImapServerListener method testDeleteOneOutOfTwoAccounts.

@Test
public void testDeleteOneOutOfTwoAccounts() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    // first account
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    TestUtil.addMessage(mboxStore, "TestImapServerListener - testNotify - init message 1", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    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);
    // second account (will be deleted)
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraMailHost, remoteServer.getServiceHostname());
    Account remoteAccount2 = TestUtil.createAccount(REMOTE_USER_NAME2, attrs);
    ZMailbox mboxStore2 = TestUtil.getZMailbox(REMOTE_USER_NAME2);
    ZimbraLog.test.debug("Created 2d account " + REMOTE_USER_NAME2 + " with ID " + remoteAccount2.getId());
    TestUtil.addMessage(mboxStore2, "TestImapServerListener - testNotify - init message 2", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    ImapServerListener remoteListener2 = ImapServerListenerPool.getInstance().get(mboxStore2);
    assertEquals("Should be getting the same ImapServerListener for both accounts on the same server", remoteListener2, remoteListener);
    RemoteImapMailboxStore imapStore2 = new RemoteImapMailboxStore(mboxStore2);
    ImapCredentials creds2 = new ImapCredentials(remoteAccount2);
    ImapPath path2 = new ImapPath("INBOX", creds2);
    params = 0;
    ImapHandler handler2 = new MockImapHandler().setCredentials(creds2);
    ImapFolder i4folder2 = new ImapFolder(path2, params, handler2);
    MockImapListener session2 = new MockImapListener(imapStore2, i4folder2, handler2);
    remoteListener2.addListener(session2);
    // wait for waitset sessions to be created
    String waitSetId = remoteListener.getWSId();
    assertTrue("Both listener references should be pointing to the same listener with the same waitset", waitSetId.equalsIgnoreCase(remoteListener2.getWSId()));
    TestUtil.waitForSessions(2, 2, 6000, waitSetId, remoteServer);
    // delete the 2d account
    ZimbraLog.test.debug("Deleting " + REMOTE_USER_NAME2);
    TestUtil.deleteAccount(REMOTE_USER_NAME2);
    session2.killSignal = new CountDownLatch(1);
    // send a message to the 1st account
    session.doneSignal = new CountDownLatch(1);
    String subject = "TestImapServerListener - testDeleteOneOutOfTwoAccounts - trigger message";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), TestUtil.getAddress("TestImapServerListener-testDeleteOneOutOfTwoAccounts"));
    TestUtil.waitForMessages(mboxStore, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
    // the 2d account's session should be killed
    try {
        session2.killSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    // the 1st accounts session should be triggered
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    ZimbraLog.test.debug("Checking triggers");
    assertTrue("Expected the 1st account's session to be triggered", session.wasTriggered());
    assertFalse("Expected the 2d account's session to NOT be triggered", session2.wasTriggered());
    assertTrue("Expected the 2d account's session to be unregistered", session2.wasUnregistered());
    assertFalse("Expected the 1st account's session to NOT be unregistered", session.wasUnregistered());
    assertNotNull("ImapServerListener should NOT have deleted the waitset", remoteListener.getWSId());
    assertTrue("Waitset ID should have remained the same", waitSetId.equalsIgnoreCase(remoteListener.getWSId()));
}
Also used : Account(com.zimbra.cs.account.Account) ImapFolder(com.zimbra.cs.imap.ImapFolder) 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)

Example 10 with ImapServerListener

use of com.zimbra.cs.imap.ImapServerListener in project zm-mailbox by Zimbra.

the class TestImapServerListener method testNotifyInbox.

@Test
public void testNotifyInbox() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    TestUtil.addMessage(mboxStore, "TestImapServerListener - testNotify - init message", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    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 - testNotifyInbox - trigger message";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), "randomUserTestImapServerListener@yahoo.com");
    TestUtil.waitForMessages(mboxStore, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
    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", session.wasTriggered());
    remoteListener.removeListener(session);
}
Also used : 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