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;
}
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;
}
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));
}
}
Aggregations