Search in sources :

Example 1 with QueryWaitSetRequest

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;
}
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 QueryWaitSetRequest

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);
}
Also used : CreateWaitSetRequest(com.zimbra.soap.mail.message.CreateWaitSetRequest) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) WaitSetRequest(com.zimbra.soap.mail.message.WaitSetRequest) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) AdminWaitSetRequest(com.zimbra.soap.admin.message.AdminWaitSetRequest) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) WaitSetResponse(com.zimbra.soap.mail.message.WaitSetResponse) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) AdminWaitSetResponse(com.zimbra.soap.admin.message.AdminWaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) AccountWithModifications(com.zimbra.soap.type.AccountWithModifications) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) CreateWaitSetResponse(com.zimbra.soap.mail.message.CreateWaitSetResponse) PendingFolderModifications(com.zimbra.soap.mail.type.PendingFolderModifications) Test(org.junit.Test)

Example 3 with QueryWaitSetRequest

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);
}
Also used : IWaitSet(com.zimbra.cs.session.IWaitSet) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest)

Example 4 with QueryWaitSetRequest

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());
}
Also used : 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) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) WaitSetInfo(com.zimbra.soap.admin.type.WaitSetInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 5 with QueryWaitSetRequest

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;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) Element(com.zimbra.common.soap.Element) SoapParseException(com.zimbra.common.soap.SoapParseException) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) SoapFaultException(com.zimbra.common.soap.SoapFaultException) HashSet(java.util.HashSet) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) Test(org.junit.Test)

Aggregations

QueryWaitSetRequest (com.zimbra.soap.admin.message.QueryWaitSetRequest)5 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)5 Test (org.junit.Test)3 ZMailbox (com.zimbra.client.ZMailbox)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 AdminCreateWaitSetResponse (com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)2 AdminDestroyWaitSetRequest (com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest)2 AdminDestroyWaitSetResponse (com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse)2 WaitSetInfo (com.zimbra.soap.admin.type.WaitSetInfo)2 ZFolder (com.zimbra.client.ZFolder)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 Element (com.zimbra.common.soap.Element)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 SoapParseException (com.zimbra.common.soap.SoapParseException)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 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)1 IWaitSet (com.zimbra.cs.session.IWaitSet)1