use of com.zimbra.soap.admin.message.QueryWaitSetRequest 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.message.QueryWaitSetRequest in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testFolderInterestSyncWaitSetRequest.
@Test
public void testFolderInterestSyncWaitSetRequest() throws Exception {
String user1Name = "testFISyncWaitSetRequest_user1";
acc1 = TestUtil.createAccount(user1Name);
ZMailbox mbox = TestUtil.getZMailbox(user1Name);
String acctId = mbox.getAccountId();
String authToken = mbox.getAuthToken().getValue();
ZimbraLog.test.info("GREN 1");
String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
ZimbraLog.test.info("GREN 2");
ZFolder myFolder = TestUtil.createFolder(mbox, "funFolder");
Set<Integer> folderInterest = Sets.newHashSet();
folderInterest.add(myFolder.getFolderIdInOwnerMailbox());
/* initially only interested in funFolder */
CreateWaitSetResponse resp = createWaitSet(acctId, authToken, folderInterest);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
int seq = resp.getSequence();
WaitSetRequest waitSet = new WaitSetRequest(waitSetId, Integer.toString(seq));
WaitSetResponse wsResp = (WaitSetResponse) sendReq(waitSet, authToken, TestUtil.getSoapUrl());
assertEquals("0", wsResp.getSeqNo());
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
TestUtil.waitForMessages(mbox, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
assertTrue(wsResp.getSeqNo().equals("0"));
assertEquals("Number of signalled accounts", 0, wsResp.getSignalledAccounts().size());
QueryWaitSetResponse qwsResp;
QueryWaitSetRequest qwsReq = new QueryWaitSetRequest(waitSetId);
qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
/* interested in funFolder AND inbox */
folderInterest.add(Integer.valueOf(Mailbox.ID_FOLDER_INBOX));
waitSet.addUpdateAccount(createWaitSetAddSpec(acctId, folderInterest));
wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
assertTrue(wsResp.getSeqNo().equals("0"));
assertEquals("Number of signalled accounts", 0, wsResp.getSignalledAccounts().size());
qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
subject = NAME_PREFIX + " test wait set request 2";
TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
TestUtil.waitForMessages(mbox, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
waitSet = new WaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
assertFalse(wsResp.getSeqNo().equals("0"));
assertEquals("Number of signalled accounts", 1, wsResp.getSignalledAccounts().size());
AccountWithModifications acctInfo = wsResp.getSignalledAccounts().get(0);
assertEquals("Signaled account id", mbox.getAccountId(), acctInfo.getId());
Collection<PendingFolderModifications> mods = acctInfo.getPendingFolderModifications();
assertNotNull("'mod' field should not be null", mods);
assertEquals("Should have 1 folder object with modifications", 1, mods.size());
Integer foldInt = mods.iterator().next().getFolderId();
assertEquals(String.format("Folder ID should be %d (Inbox). Getting %d instead", Mailbox.ID_FOLDER_INBOX, foldInt), foldInt.intValue(), Mailbox.ID_FOLDER_INBOX);
}
use of com.zimbra.soap.admin.message.QueryWaitSetRequest in project zm-mailbox by Zimbra.
the class QueryWaitSet method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
// must be a global admin
WaitSetMgr.checkRightForAllAccounts(zsc);
QueryWaitSetRequest req = (QueryWaitSetRequest) zsc.elementToJaxb(request);
QueryWaitSetResponse resp = new QueryWaitSetResponse();
String waitSetId = req.getWaitSetId();
List<IWaitSet> sets;
if (waitSetId != null) {
sets = new ArrayList<IWaitSet>(1);
IWaitSet ws = WaitSetMgr.lookup(waitSetId);
if (ws == null) {
throw AdminServiceException.NO_SUCH_WAITSET(waitSetId);
}
sets.add(ws);
} else {
sets = WaitSetMgr.getAll();
}
for (IWaitSet set : sets) {
resp.addWaitset(set.handleQuery());
}
return zsc.jaxbToElement(resp);
}
use of com.zimbra.soap.admin.message.QueryWaitSetRequest in project zm-mailbox by Zimbra.
the class TestImapServerListener method testRegisterUnregister.
@Test
public void testRegisterUnregister() throws ServiceException, IOException, HttpException {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
assertNotNull("ImapServerListener instance should not be null", remoteListener);
RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
assertNotNull("ImapMailboxStore instance should not be null", imapStore);
ImapCredentials creds = new ImapCredentials(remoteAccount);
ImapPath path = new ImapPath("INBOX", creds);
assertNotNull("ImapPath instance should not be null", path);
byte params = 0;
ImapHandler handler = new MockImapHandler().setCredentials(creds);
ImapFolder i4folder = new ImapFolder(path, params, handler);
assertNotNull("ImapFolder instance should not be null", i4folder);
assertNotNull("ImapFolder.getCredentials() should not return null", i4folder.getCredentials());
assertNotNull("ImapFolder.getPath() should not return null", i4folder.getPath());
MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
assertNotNull("ImapListener instance should not be null", session);
assertFalse("Expecting ImapServerListener::isListeningOn to return false before calling addListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNull("Should not have a waitset before registering first listener", remoteListener.getWSId());
remoteListener.addListener(session);
assertTrue("Expecting ImapServerListener::isListeningOn to return true after calling addListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNotNull("Should have a waitset after registering first listener", remoteListener.getWSId());
QueryWaitSetRequest req = new QueryWaitSetRequest(remoteListener.getWSId());
SoapTransport transport = TestUtil.getAdminSoapTransport(remoteServer);
QueryWaitSetResponse resp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(req)));
assertNotNull(resp);
List<WaitSetInfo> wsInfoList = resp.getWaitsets();
assertNotNull(wsInfoList);
assertFalse(wsInfoList.isEmpty());
assertEquals(1, wsInfoList.size());
WaitSetInfo wsInfo = wsInfoList.get(0);
assertNotNull(wsInfo);
assertEquals(remoteListener.getWSId(), wsInfo.getWaitSetId());
remoteListener.removeListener(session);
assertFalse("Expecting ImapServerListener::isListeningOn to return false after calling removeListener", remoteListener.isListeningOn(session.getTargetAccountId(), session.getFolderId()));
assertNull("Should not have a waitset after removing last listener", remoteListener.getWSId());
}
use of com.zimbra.soap.admin.message.QueryWaitSetRequest in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testDestroyWaitset.
@Test
public void testDestroyWaitset() throws Exception {
ZimbraLog.test.info("Starting testDestroyWaitset");
String user1Name = "testDestroyWaitset_user1";
acc1 = TestUtil.createAccount(user1Name);
ZMailbox mbox = TestUtil.getZMailbox(user1Name);
Set<String> accountIds = new HashSet<String>();
accountIds.add(mbox.getAccountId());
String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
AdminCreateWaitSetResponse resp = createAdminWaitSet(accountIds, adminAuthToken, false);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
assertNotNull(waitSetId);
QueryWaitSetRequest qwsReq = new QueryWaitSetRequest(waitSetId);
QueryWaitSetResponse qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
validateQueryWaitSetResponse(qwsResp, acc1.getId(), null, null, false);
AdminDestroyWaitSetRequest destroyReq = new AdminDestroyWaitSetRequest(waitSetId);
AdminDestroyWaitSetResponse destroyResp = (AdminDestroyWaitSetResponse) sendReq(destroyReq, adminAuthToken, TestUtil.getAdminSoapUrl());
assertNotNull("AdminDestroyWaitSetResponse should not be null", destroyResp);
assertNotNull("AdminDestroyWaitSetResponse::waitSetId should not be null", destroyResp.getWaitSetId());
assertEquals("AdminDestroyWaitSetResponse has wrong waitSetId", waitSetId, destroyResp.getWaitSetId());
qwsReq = new QueryWaitSetRequest(waitSetId);
Element faultResp = sendReqExpectedToFail(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
assertNotNull("should return Element", faultResp);
try {
TestUtil.getAdminSoapTransport().extractBodyElement(faultResp);
fail("Should thrown SoapFaultException");
} catch (SoapFaultException sfe) {
assertEquals("Expecting admin.NO_SUCH_WAITSET", AdminServiceException.NO_SUCH_WAITSET, sfe.getCode());
} catch (SoapParseException spe) {
fail("Should not be throwing SoapParseException. " + spe.getMessage());
}
waitSetId = null;
}
Aggregations