Search in sources :

Example 1 with SessionForWaitSet

use of com.zimbra.soap.admin.type.SessionForWaitSet 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)

Example 2 with SessionForWaitSet

use of com.zimbra.soap.admin.type.SessionForWaitSet in project zm-mailbox by Zimbra.

the class TestUtil method waitForSessions.

public static QueryWaitSetResponse waitForSessions(int numExpectedSessions, int numExpectedFolderInterests, int timeout_millis, String wsID, Server server) throws Exception {
    QueryWaitSetResponse resp = null;
    while (timeout_millis > 0) {
        QueryWaitSetRequest req = new QueryWaitSetRequest(wsID);
        SoapTransport transport = getAdminSoapTransport(server);
        resp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(req)));
        List<WaitSetInfo> wsInfoList = resp.getWaitsets();
        assertFalse("Expecting to find a waitset", wsInfoList.isEmpty());
        assertEquals("Expecting to find only one waitset", 1, wsInfoList.size());
        WaitSetInfo wsInfo = wsInfoList.get(0);
        assertEquals("Found wrong waitset", wsID, wsInfo.getWaitSetId());
        List<SessionForWaitSet> sessions = wsInfo.getSessions();
        if (sessions != null && numExpectedSessions > 0) {
            if (sessions.size() == numExpectedSessions) {
                int foundFolderInterests = 0;
                for (SessionForWaitSet s : sessions) {
                    WaitSetSessionInfo sessionInfo = s.getWaitSetSession();
                    if (sessionInfo != null) {
                        foundFolderInterests += s.getWaitSetSession().getFolderInterestsAsSet().size();
                    }
                }
                if (foundFolderInterests == numExpectedFolderInterests) {
                    return resp;
                }
            }
        } else if ((sessions == null || sessions.isEmpty()) && numExpectedSessions == 0) {
            return resp;
        }
        try {
            if (timeout_millis > 500) {
                Thread.sleep(500);
                timeout_millis = timeout_millis - 500;
            } else {
                Thread.sleep(timeout_millis);
                timeout_millis = 0;
            }
        } catch (InterruptedException e) {
            ZimbraLog.test.debug("sleep got interrupted", e);
        }
    }
    return resp;
}
Also used : WaitSetSessionInfo(com.zimbra.soap.admin.type.WaitSetSessionInfo) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) SessionForWaitSet(com.zimbra.soap.admin.type.SessionForWaitSet) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) ZMountpoint(com.zimbra.client.ZMountpoint)

Example 3 with SessionForWaitSet

use of com.zimbra.soap.admin.type.SessionForWaitSet in project zm-mailbox by Zimbra.

the class SomeAccountsWaitSet method handleQuery.

@Override
public synchronized WaitSetInfo handleQuery() {
    WaitSetInfo info = super.handleQuery();
    info.setCbSeqNo(Long.toString(mCbSeqNo));
    info.setCurrentSeqNo(Long.toString(mCurrentSeqNo));
    for (Map.Entry<String, WaitSetAccount> entry : mSessions.entrySet()) {
        String acctId = entry.getKey();
        WaitSetAccount wsa = entry.getValue();
        SessionForWaitSet sess = new SessionForWaitSet(acctId, WaitSetRequest.expandInterestStr(wsa.getInterests()));
        if (!wsa.getAccountId().equals(acctId)) {
            sess.setAcctIdError(wsa.getAccountId());
        }
        if (wsa.getLastKnownSyncToken() != null) {
            sess.setToken(wsa.getLastKnownSyncToken().toString());
        }
        if (wsa.getLastKnownSyncToken() != null) {
            try {
                Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(acctId, FetchMode.ONLY_IF_CACHED);
                if (mbox != null) {
                    int mboxLastChange = mbox.getLastChangeID();
                    sess.setMboxSyncToken(mboxLastChange);
                    sess.setMboxSyncTokenDiff(mboxLastChange - wsa.getLastKnownSyncToken().getChangeId());
                }
            } catch (Exception e) {
                ZimbraLog.session.warn("Caught exception from MailboxManager in SomeAccountsWaitSet.handleQuery() for accountId %s", acctId, e);
            }
        }
        WaitSetSession wss = wsa.getSession();
        if (wss != null) {
            WaitSetSessionInfo waitSetSession = new WaitSetSessionInfo(WaitSetRequest.interestToStr(wss.interest), wss.mHighestChangeId, wss.getLastAccessTime(), wss.getCreationTime(), wss.getSessionId());
            waitSetSession.setFolderInterests(wss.folderInterest);
            if (wss.mSyncToken != null) {
                waitSetSession.setToken(wss.mSyncToken.toString());
            }
            sess.setWaitSetSession(waitSetSession);
        }
        info.addSession(sess);
    }
    return info;
}
Also used : WaitSetSessionInfo(com.zimbra.soap.admin.type.WaitSetSessionInfo) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) SessionForWaitSet(com.zimbra.soap.admin.type.SessionForWaitSet) HashMap(java.util.HashMap) Map(java.util.Map) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Example 4 with SessionForWaitSet

use of com.zimbra.soap.admin.type.SessionForWaitSet in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method validateQueryWaitSetResponse.

private void validateQueryWaitSetResponse(QueryWaitSetResponse qwsResp, String acctId, Set<Integer> folderInterests, Set<Integer> expectedChangedFolders, boolean checkOwner) {
    assertEquals("Number of Waitsets in response", 1, qwsResp.getWaitsets().size());
    WaitSetInfo wsInfo = qwsResp.getWaitsets().get(0);
    if (checkOwner) {
        assertEquals("waitSet owner", acctId, wsInfo.getOwner());
    }
    assertEquals("Number of sessions in WaitSetResponse/waitSet", 1, wsInfo.getSessions().size());
    SessionForWaitSet session = wsInfo.getSessions().get(0);
    assertEquals("WaitSetResponse/waitSet/session@account", acctId, session.getAccount());
    WaitSetSessionInfo sessInfo = session.getWaitSetSession();
    if ((null != folderInterests) && !folderInterests.isEmpty()) {
        Set<Integer> respFolderInt = sessInfo.getFolderInterestsAsSet();
        for (Integer folderInterest : folderInterests) {
            assertTrue(String.format("Query reported folderInterests=%s should contain %s", respFolderInt, folderInterest), respFolderInt.contains(folderInterest));
        }
    }
    if ((null != expectedChangedFolders) && !expectedChangedFolders.isEmpty()) {
        Set<Integer> respChangedFolders = sessInfo.getChangedFoldersAsSet();
        for (Integer changedFldr : expectedChangedFolders) {
            assertTrue(String.format("Query reported respChangedFolders=%s should contain %s", respChangedFolders, changedFldr), respChangedFolders.contains(changedFldr));
        }
        String signalledAccts = wsInfo.getSignalledAccounts().getAccounts();
        assertTrue(String.format("ready accts '%s' contains '%s'", signalledAccts, acctId), signalledAccts.contains(acctId));
    }
}
Also used : WaitSetSessionInfo(com.zimbra.soap.admin.type.WaitSetSessionInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) SessionForWaitSet(com.zimbra.soap.admin.type.SessionForWaitSet)

Aggregations

SessionForWaitSet (com.zimbra.soap.admin.type.SessionForWaitSet)4 WaitSetInfo (com.zimbra.soap.admin.type.WaitSetInfo)4 WaitSetSessionInfo (com.zimbra.soap.admin.type.WaitSetSessionInfo)3 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)2 ZMountpoint (com.zimbra.client.ZMountpoint)1 ServiceException (com.zimbra.common.service.ServiceException)1 SoapTransport (com.zimbra.common.soap.SoapTransport)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)1 ImapFolder (com.zimbra.cs.imap.ImapFolder)1 ImapHandler (com.zimbra.cs.imap.ImapHandler)1 ImapPath (com.zimbra.cs.imap.ImapPath)1 ImapRemoteSession (com.zimbra.cs.imap.ImapRemoteSession)1 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 QueryWaitSetRequest (com.zimbra.soap.admin.message.QueryWaitSetRequest)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1