Search in sources :

Example 1 with AdminDestroyWaitSetResponse

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

the class TestImapServerListener method testDestroyWaitset.

@Test
public void testDestroyWaitset() throws Exception {
    Assume.assumeNotNull(remoteServer);
    Assume.assumeNotNull(remoteAccount);
    ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
    TestUtil.addMessage(mboxStore, "TestImapServerListener - testDestroyWaitset - init message", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    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);
    remoteListener.addListener(session);
    // wait for waitset session to be created
    String waitSetId = remoteListener.getWSId();
    TestUtil.waitForSessions(1, 1, 6000, waitSetId, remoteServer);
    // delete waitset
    ZimbraLog.test.debug("Destroying waitset %s", waitSetId);
    AdminDestroyWaitSetRequest destroyReq = new AdminDestroyWaitSetRequest(waitSetId);
    SoapTransport transport = TestUtil.getAdminSoapTransport(remoteServer);
    AdminDestroyWaitSetResponse destroyResp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(destroyReq)));
    Assert.assertNotNull("AdminDestroyWaitSetResponse should not be null", destroyResp);
    Assert.assertNotNull("AdminDestroyWaitSetResponse::waitSetId should not be null", destroyResp.getWaitSetId());
    Assert.assertEquals("AdminDestroyWaitSetResponse has wrong waitSetId", waitSetId, destroyResp.getWaitSetId());
    // wait for ImapServerListener to create a new WaitSet
    int maxWait = 5000;
    while (maxWait > 0) {
        if (remoteListener.getWSId() != null && !waitSetId.equalsIgnoreCase(remoteListener.getWSId())) {
            break;
        } else {
            maxWait -= 500;
            Thread.sleep(500);
        }
    }
    Assert.assertFalse("ImapServerListener should have created a new waitset", waitSetId.equalsIgnoreCase(remoteListener.getWSId()));
    // send a message
    session.doneSignal = new CountDownLatch(1);
    String subject = "TestImapServerListener - testDestroyWaitset - trigger message";
    TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), TestUtil.getAddress("TestImapServerListener-testDestroyWaitset"));
    TestUtil.waitForMessages(mboxStore, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
    try {
        session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
    } catch (Exception e) {
        Assert.fail("Wait interrupted.");
    }
    assertTrue("Expected session to NOT be triggered", session.wasTriggered());
    assertFalse("ImapServerListener should have created a new waitset", remoteListener.getWSId().equalsIgnoreCase(waitSetId));
}
Also used : ImapFolder(com.zimbra.cs.imap.ImapFolder) 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) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 2 with AdminDestroyWaitSetResponse

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

ZMailbox (com.zimbra.client.ZMailbox)2 AdminDestroyWaitSetRequest (com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest)2 AdminDestroyWaitSetResponse (com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse)2 Test (org.junit.Test)2 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 SoapParseException (com.zimbra.common.soap.SoapParseException)1 SoapTransport (com.zimbra.common.soap.SoapTransport)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 ImapServerListener (com.zimbra.cs.imap.ImapServerListener)1 RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)1 AdminCreateWaitSetResponse (com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)1 QueryWaitSetRequest (com.zimbra.soap.admin.message.QueryWaitSetRequest)1 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1