Search in sources :

Example 1 with ImapPath

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

the class ImapCommandThrottleTest method create.

@Test
public void create() {
    String pathName = "folder123";
    CreateCommand create = new CreateCommand(new ImapPath(pathName, null));
    Assert.assertTrue("same obj", create.isDuplicate(create));
    CreateCommand create2 = new CreateCommand(new ImapPath(pathName, null));
    Assert.assertTrue("same fields", create.isDuplicate(create2));
    create2 = new CreateCommand(new ImapPath("foo", null));
    Assert.assertFalse("different path", create.isDuplicate(create2));
    for (int repeats = 0; repeats < LC.imap_throttle_command_limit.intValue(); repeats++) {
        create2 = new CreateCommand(new ImapPath("foo" + repeats, null));
        Assert.assertFalse(create2.throttle(create));
        create = create2;
    }
    Assert.assertTrue(create2.throttle(create));
}
Also used : ImapPath(com.zimbra.cs.imap.ImapPath) Test(org.junit.Test)

Example 2 with ImapPath

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

the class ImapCommandThrottleTest method select.

@Test
public void select() {
    String pathName = "testfolder";
    SelectCommand select = new SelectCommand(new ImapPath(pathName, null), (byte) 123, makeQri());
    Assert.assertTrue("same obj", select.isDuplicate(select));
    SelectCommand select2 = new SelectCommand(new ImapPath(pathName, null), (byte) 123, makeQri());
    Assert.assertTrue("diff obj same fields", select.isDuplicate(select2));
    SelectCommand select3 = new SelectCommand(new ImapPath(pathName + "foo", null), (byte) 123, makeQri());
    Assert.assertFalse("different path", select.isDuplicate(select3));
    SelectCommand select4 = new SelectCommand(new ImapPath(pathName, null), (byte) 101, makeQri());
    Assert.assertFalse("different params", select.isDuplicate(select4));
    QResyncInfo qri = makeQri();
    qri.setKnownUIDs("foo");
    SelectCommand select5 = new SelectCommand(new ImapPath(pathName, null), (byte) 123, qri);
    Assert.assertFalse("different qri", select.isDuplicate(select5));
}
Also used : SelectCommand(com.zimbra.cs.imap.SelectCommand) ImapPath(com.zimbra.cs.imap.ImapPath) QResyncInfo(com.zimbra.cs.imap.QResyncInfo) Test(org.junit.Test)

Example 3 with ImapPath

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

the class ImapCommandThrottleTest method examine.

@Test
public void examine() {
    String pathName = "testfolder";
    ExamineCommand examine = new ExamineCommand(new ImapPath(pathName, null), (byte) 123, makeQri());
    Assert.assertTrue("same obj", examine.isDuplicate(examine));
    SelectCommand select = new SelectCommand(new ImapPath(pathName, null), (byte) 123, makeQri());
    Assert.assertFalse("select vs examine", examine.isDuplicate(select));
    ExamineCommand examine2 = new ExamineCommand(new ImapPath(pathName, null), (byte) 123, makeQri());
    Assert.assertTrue("diff obj same fields", examine.isDuplicate(examine2));
    ExamineCommand examine3 = new ExamineCommand(new ImapPath(pathName + "foo", null), (byte) 123, makeQri());
    Assert.assertFalse("different path", examine.isDuplicate(examine3));
    ExamineCommand examine4 = new ExamineCommand(new ImapPath(pathName, null), (byte) 101, makeQri());
    Assert.assertFalse("different params", examine.isDuplicate(examine4));
    QResyncInfo qri = makeQri();
    qri.setKnownUIDs("foo");
    ExamineCommand examine5 = new ExamineCommand(new ImapPath(pathName, null), (byte) 123, qri);
    Assert.assertFalse("different qri", examine.isDuplicate(examine5));
}
Also used : ExamineCommand(com.zimbra.cs.imap.ExamineCommand) ImapPath(com.zimbra.cs.imap.ImapPath) SelectCommand(com.zimbra.cs.imap.SelectCommand) QResyncInfo(com.zimbra.cs.imap.QResyncInfo) Test(org.junit.Test)

Example 4 with ImapPath

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

the class SharedImapTests method checkImapPath.

private void checkImapPath(String mboxName, ImapCredentials creds, String expectedPathToString, boolean usingReferent, int expectedReferentFolderId, String expectedReferentFolderAcct) throws ServiceException {
    ImapPath path = new ImapPath(mboxName, creds);
    path.canonicalize();
    ImapPath referent = path.getReferent();
    assertEquals(String.format("toString() for ImapPath for mailbox '%s'", mboxName), expectedPathToString, path.toString());
    if (usingReferent) {
        assertNotSame(String.format("ImapPath=%s and it's getReferent() for mailbox '%s'", path, mboxName), path, referent);
    } else {
        assertSame(String.format("ImapPath=%s and it's getReferent() for mailbox '%s'", path, mboxName), path, referent);
    }
    FolderStore folderForPath = path.getFolder();
    assertEquals(String.format("Folder ID for path.getReferent().getFolder() for mailbox '%s'", mboxName), expectedReferentFolderId, folderIdForFolder(folderForPath));
    assertEquals(String.format("Account ID for path.getReferent().getFolder() for mailbox '%s'", mboxName), expectedReferentFolderAcct, acctIdForFolder(folderForPath));
}
Also used : FolderStore(com.zimbra.common.mailbox.FolderStore) ImapPath(com.zimbra.cs.imap.ImapPath)

Example 5 with ImapPath

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

the class TestImapServerListener method testRemoveFolderInterest.

@Test
public void testRemoveFolderInterest() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
    ImapCredentials creds = new ImapCredentials(remoteAccount);
    // add listener on INBOX
    ImapPath path = new ImapPath("INBOX", creds);
    byte params = 0;
    ImapHandler handler = new MockImapHandler().setCredentials(creds);
    ImapFolder i4folder = new ImapFolder(path, params, handler);
    MockImapListener inboxSession = new MockImapListener(imapStore, i4folder, handler);
    remoteListener.addListener(inboxSession);
    // check created waitset
    QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
    assertNotNull(resp);
    List<WaitSetInfo> wsInfoList = resp.getWaitsets();
    assertFalse(wsInfoList.isEmpty());
    assertEquals(1, wsInfoList.size());
    WaitSetInfo wsInfo = wsInfoList.get(0);
    assertNotNull(wsInfo);
    assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
    List<SessionForWaitSet> sessions = wsInfo.getSessions();
    assertNotNull(sessions);
    assertEquals("expected to find 1 session after adding a listener for INBOX", 1, sessions.size());
    SessionForWaitSet s = sessions.get(0);
    Set<Integer> folders = s.getWaitSetSession().getFolderInterestsAsSet();
    assertNotNull("folder interests cannot be NULL", folders);
    assertEquals("should have one folder interest", 1, folders.size());
    assertTrue("folder interests should contain INBOX", folders.contains(Mailbox.ID_FOLDER_INBOX));
    // add listener on DRAFTS
    path = new ImapPath("DRAFTS", creds);
    params = 0;
    i4folder = new ImapFolder(path, params, handler);
    ImapRemoteSession draftsSession = (ImapRemoteSession) imapStore.createListener(i4folder, handler);
    remoteListener.addListener(draftsSession);
    // check that waitset was updated
    resp = TestUtil.waitForSessions(1, 2, 6000, remoteListener.getWSId(), remoteServer);
    assertNotNull(resp);
    wsInfoList = resp.getWaitsets();
    assertFalse(wsInfoList.isEmpty());
    wsInfo = wsInfoList.get(0);
    assertNotNull(wsInfo);
    assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
    sessions = wsInfo.getSessions();
    assertNotNull(sessions);
    assertEquals("expected to find 1 session after adding a listener for DRAFTS", 1, sessions.size());
    s = sessions.get(0);
    folders = s.getWaitSetSession().getFolderInterestsAsSet();
    assertNotNull("folder interests cannot be NULL", folders);
    assertEquals("should have two folder interests", 2, folders.size());
    assertTrue("folder interests should contain DRAFTS", folders.contains(Mailbox.ID_FOLDER_DRAFTS));
    assertTrue("folder interests should contain INBOX", folders.contains(Mailbox.ID_FOLDER_INBOX));
    remoteListener.removeListener(inboxSession);
    // check that waitset was updated after removing a listener
    resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
    assertNotNull(resp);
    wsInfoList = resp.getWaitsets();
    assertFalse(wsInfoList.isEmpty());
    wsInfo = wsInfoList.get(0);
    assertNotNull(wsInfo);
    assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
    sessions = wsInfo.getSessions();
    assertNotNull(sessions);
    assertEquals("expected to find 1 session after removing listener for inbox", 1, sessions.size());
    s = sessions.get(0);
    folders = s.getWaitSetSession().getFolderInterestsAsSet();
    assertNotNull("folder interests cannot be NULL", folders);
    assertEquals("should have one folder interest after removing a listener", 1, folders.size());
    assertTrue("folder interests should contain DRAFTS after removing INBOX listener", folders.contains(Mailbox.ID_FOLDER_DRAFTS));
}
Also used : ImapRemoteSession(com.zimbra.cs.imap.ImapRemoteSession) 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) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) SessionForWaitSet(com.zimbra.soap.admin.type.SessionForWaitSet) Test(org.junit.Test)

Aggregations

ImapPath (com.zimbra.cs.imap.ImapPath)20 Test (org.junit.Test)18 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)14 ImapFolder (com.zimbra.cs.imap.ImapFolder)14 ImapHandler (com.zimbra.cs.imap.ImapHandler)14 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)14 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)12 ZMailbox (com.zimbra.client.ZMailbox)10 ServiceException (com.zimbra.common.service.ServiceException)10 ImapServerListener (com.zimbra.cs.imap.ImapServerListener)10 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 HttpException (org.apache.http.HttpException)10 ZMessage (com.zimbra.client.ZMessage)5 ZFolder (com.zimbra.client.ZFolder)2 ZTag (com.zimbra.client.ZTag)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 ImapRemoteSession (com.zimbra.cs.imap.ImapRemoteSession)2 QResyncInfo (com.zimbra.cs.imap.QResyncInfo)2 SelectCommand (com.zimbra.cs.imap.SelectCommand)2