Search in sources :

Example 6 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse 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 7 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse 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 8 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse 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 9 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse 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 10 with QueryWaitSetResponse

use of com.zimbra.soap.admin.message.QueryWaitSetResponse in project zm-mailbox by Zimbra.

the class TestImapServerListener method testNotifyWrongFolder.

@Test
public void testNotifyWrongFolder() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    ZFolder folder = TestUtil.createFolder(mboxStore, "/TestImapServerListener-testNotifyNewFolder");
    ImapServerListener remoteListener = ImapServerListenerPool.getInstance().get(mboxStore);
    RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
    ImapCredentials creds = new ImapCredentials(remoteAccount);
    ImapPath path = new ImapPath("INBOX", creds);
    byte params = 0;
    ImapHandler handler = new MockImapHandler().setCredentials(creds);
    ImapFolder i4folder = new ImapFolder(path, params, handler);
    MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
    session.doneSignal = new CountDownLatch(1);
    remoteListener.addListener(session);
    // wait for waitset session to be created
    QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
    TestUtil.addMessage(mboxStore, "TestImapServerListener - testNotifyWrongFolder", folder.getId());
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    assertFalse("Expected session to not be triggered", session.wasTriggered());
    remoteListener.removeListener(session);
}
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) CountDownLatch(java.util.concurrent.CountDownLatch) HttpException(org.apache.http.HttpException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Aggregations

QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)16 Test (org.junit.Test)13 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)12 ImapFolder (com.zimbra.cs.imap.ImapFolder)12 ImapHandler (com.zimbra.cs.imap.ImapHandler)12 ImapPath (com.zimbra.cs.imap.ImapPath)12 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)12 ZMailbox (com.zimbra.client.ZMailbox)10 ServiceException (com.zimbra.common.service.ServiceException)8 ImapServerListener (com.zimbra.cs.imap.ImapServerListener)8 IOException (java.io.IOException)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 HttpException (org.apache.http.HttpException)8 ZMessage (com.zimbra.client.ZMessage)5 QueryWaitSetRequest (com.zimbra.soap.admin.message.QueryWaitSetRequest)5 ZFolder (com.zimbra.client.ZFolder)3 WaitSetInfo (com.zimbra.soap.admin.type.WaitSetInfo)3 ZTag (com.zimbra.client.ZTag)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 ImapRemoteSession (com.zimbra.cs.imap.ImapRemoteSession)2