Search in sources :

Example 1 with WaitSetSessionInfo

use of com.zimbra.soap.admin.type.WaitSetSessionInfo 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 2 with WaitSetSessionInfo

use of com.zimbra.soap.admin.type.WaitSetSessionInfo 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 3 with WaitSetSessionInfo

use of com.zimbra.soap.admin.type.WaitSetSessionInfo 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)3 WaitSetInfo (com.zimbra.soap.admin.type.WaitSetInfo)3 WaitSetSessionInfo (com.zimbra.soap.admin.type.WaitSetSessionInfo)3 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 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 QueryWaitSetRequest (com.zimbra.soap.admin.message.QueryWaitSetRequest)1 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1