use of com.zimbra.soap.admin.message.AdminWaitSetRequest in project zm-mailbox by Zimbra.
the class ImapServerListener method continueWaitSet.
private void continueWaitSet() {
ZimbraLog.imap.debug("Continuing waitset %s", wsID);
cancelPendingRequest();
if (wsID != null) {
// send asynchronous AdminWaitSetRequest
AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(wsID, lastSequence.toString());
waitSetReq.setBlock(true);
waitSetReq.setExpand(true);
try {
checkAuth();
ZimbraLog.imap.debug("Sending followup asynchronous AdminWaitSetRequest. WaitSet ID: %s", wsID);
synchronized (soapProv) {
pendingRequest = soapProv.invokeJaxbAsync(waitSetReq, server, cb);
}
} catch (ServiceException ex) {
ZimbraLog.imap.error("Failed to send WaitSetRequest. ", ex);
}
} else {
ZimbraLog.imap.error("Cannot continue to poll waitset, because waitset ID is not known");
}
}
use of com.zimbra.soap.admin.message.AdminWaitSetRequest in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testBlockingAdminAddAccount.
@Test
public void testBlockingAdminAddAccount() throws Exception {
ZimbraLog.test.info("Starting testBlockingAdminAddAccount");
Set<String> accountIds = new HashSet<String>();
String user1Name = "testBlockingAdminAddAccount_user1";
String user2Name = "testBlockingAdminAddAccount_user2";
acc1 = TestUtil.createAccount(user1Name);
acc2 = TestUtil.createAccount(user2Name);
ZMailbox mbox1 = TestUtil.getZMailbox(user1Name);
accountIds.add(mbox1.getAccountId());
String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
AdminCreateWaitSetResponse resp = createAdminWaitSet(accountIds, adminAuthToken, false);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
assertNotNull(waitSetId);
int seq = resp.getSequence();
AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSetReq.setBlock(true);
final CountDownLatch doneSignal = new CountDownLatch(1);
ZimbraLog.test.info("Should signal only account %s", mbox1.getAccountId());
// should catch only update for user1
waitForAccounts(Arrays.asList(mbox1.getAccountId()), doneSignal, waitSetReq, "testBlockingAdminAddAccount - 1", false);
String subject = NAME_PREFIX + " test wait set request 1";
ZMailbox mbox2 = TestUtil.getZMailbox(user2Name);
// this event will notify waitset
TestUtil.addMessage(mbox1, subject);
// this event will NOT notify waitset
TestUtil.addMessage(mbox2, subject);
try {
doneSignal.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
// test 2, add user2 to the existing waitset
ZimbraLog.test.info("Sending 2d AdminWaitSetRequest");
success.set(false);
failureMessage = null;
cbCalled.set(false);
waitSetReq = new AdminWaitSetRequest(waitSetId, lastSeqNum);
waitSetReq.setBlock(true);
// add user2 to the same waitset
WaitSetAddSpec add = new WaitSetAddSpec();
add.setId(mbox2.getAccountId());
waitSetReq.addAddAccount(add);
final CountDownLatch doneSignal2 = new CountDownLatch(1);
ZimbraLog.test.info("Should signal accounts %s and %s", mbox1.getAccountId(), mbox2.getAccountId());
subject = NAME_PREFIX + " test wait set request 2";
waitForAccounts(Arrays.asList(mbox1.getAccountId(), mbox2.getAccountId()), doneSignal2, waitSetReq, "testBlockingAdminAddAccount - 2", false);
TestUtil.addMessage(mbox1, subject);
TestUtil.addMessage(mbox2, subject);
try {
doneSignal2.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback2 was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
int signalled = numSignalledAccounts.intValue();
while (signalled < 2) {
cbCalled.set(false);
success.set(false);
failureMessage = null;
ZimbraLog.test.info("Sending followup to 2d AdminWaitSetRequest");
// the waitset may return both accounts at once or be triggered for each account separately
waitSetReq = new AdminWaitSetRequest(waitSetId, lastSeqNum);
waitSetReq.setBlock(true);
final CountDownLatch doneSignal1 = new CountDownLatch(1);
waitForAccounts(Arrays.asList(mbox1.getAccountId(), mbox2.getAccountId()), doneSignal1, waitSetReq, "testBlockingAdminAddAccount - 2.5", false);
try {
doneSignal1.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback2.5 was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
signalled += numSignalledAccounts.intValue();
}
assertEquals("Should signal 2 accounts in total", 2, signalled);
// 3rd request
ZimbraLog.test.info("Sending 3rd AdminWaitSetRequest");
success.set(false);
failureMessage = null;
cbCalled.set(false);
final CountDownLatch doneSignal3 = new CountDownLatch(1);
waitSetReq = new AdminWaitSetRequest(waitSetId, lastSeqNum);
waitSetReq.setBlock(true);
// both accounts should get signaled at this time
waitForAccounts(Arrays.asList(mbox1.getAccountId(), mbox2.getAccountId()), doneSignal3, waitSetReq, "testBlockingAdminAddAccount - 3", false);
TestUtil.addMessage(mbox2, subject);
TestUtil.addMessage(mbox1, subject);
try {
doneSignal3.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback3 was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
signalled = numSignalledAccounts.intValue();
while (signalled < 2) {
cbCalled.set(false);
success.set(false);
failureMessage = null;
ZimbraLog.test.info("Sending followup to 3rd AdminWaitSetRequest");
// the waitset may get return both accounts at once or be triggered for each account separately
waitSetReq = new AdminWaitSetRequest(waitSetId, lastSeqNum);
waitSetReq.setBlock(true);
final CountDownLatch doneSignal1 = new CountDownLatch(1);
waitForAccounts(Arrays.asList(mbox1.getAccountId(), mbox2.getAccountId()), doneSignal1, waitSetReq, "testBlockingAdminAddAccount - 3.5", false);
try {
doneSignal1.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback3.5 was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
signalled += numSignalledAccounts.intValue();
}
assertEquals("Should signal 2 accounts in total", 2, signalled);
// 4th request
ZimbraLog.test.info("Sending 4th AdminWaitSetRequest");
success.set(false);
failureMessage = null;
cbCalled.set(false);
final CountDownLatch doneSignal4 = new CountDownLatch(1);
waitSetReq = new AdminWaitSetRequest(waitSetId, lastSeqNum);
waitSetReq.setBlock(true);
// only second account should get signaled this time
waitForAccounts(Arrays.asList(mbox2.getAccountId()), doneSignal4, waitSetReq, "testBlockingAdminAddAccount - 4", false);
TestUtil.addMessage(mbox2, subject);
try {
doneSignal4.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback4 was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
}
use of com.zimbra.soap.admin.message.AdminWaitSetRequest in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testBlockingAdminWait2Accounts.
@Test
public void testBlockingAdminWait2Accounts() throws Exception {
ZimbraLog.test.info("Starting testBlockingAdminWait2Accounts");
Set<String> accountIds = new HashSet<String>();
String user1Name = "testBlockingAdminWait2Accounts_user1";
String user2Name = "testBlockingAdminWait2Accounts_user2";
acc1 = TestUtil.createAccount(user1Name);
acc2 = TestUtil.createAccount(user2Name);
ZMailbox mbox = TestUtil.getZMailbox(user1Name);
accountIds.add(mbox.getAccountId());
ZMailbox mbox2 = TestUtil.getZMailbox(user2Name);
accountIds.add(mbox2.getAccountId());
String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
AdminCreateWaitSetResponse resp = createAdminWaitSet(accountIds, adminAuthToken, false);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
assertNotNull(waitSetId);
int seq = resp.getSequence();
AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSetReq.setBlock(true);
final CountDownLatch doneSignal = new CountDownLatch(1);
waitForAccounts(Arrays.asList(mbox.getAccountId(), mbox2.getAccountId()), doneSignal, waitSetReq, "testBlockingAdminWait2Accounts", false);
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessage(mbox, subject);
TestUtil.addMessage(mbox2, subject);
try {
doneSignal.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
if (numSignalledAccounts.intValue() < 2) {
cbCalled.set(false);
success.set(false);
failureMessage = null;
// the waitset may be triggered for both accounts at once or be triggered for each account separately
waitSetReq = new AdminWaitSetRequest(waitSetId, lastSeqNum);
waitSetReq.setBlock(true);
final CountDownLatch doneSignal1 = new CountDownLatch(1);
waitForAccounts(Arrays.asList(mbox.getAccountId(), mbox2.getAccountId()), doneSignal1, waitSetReq, "testBlockingAdminWait2Accounts", false);
try {
doneSignal1.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
assertEquals("If WaitSet was triggered again, it should have returned only one account", 1, numSignalledAccounts.intValue());
}
}
use of com.zimbra.soap.admin.message.AdminWaitSetRequest in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testBlockingAdminWaitAllAccounts.
@Test
public void testBlockingAdminWaitAllAccounts() throws Exception {
ZimbraLog.test.info("Starting testBlockingAdminWaitAllAccounts");
String user1Name = "testBlockingAdminWaitAllAccounts_user1";
String user2Name = "testBlockingAdminWaitAllAccounts_user2";
String user3Name = "testBlockingAdminWaitAllAccounts_user3";
acc1 = TestUtil.createAccount(user1Name);
acc2 = TestUtil.createAccount(user2Name);
acc3 = TestUtil.createAccount(user3Name);
ZMailbox mbox = TestUtil.getZMailbox(user1Name);
ZMailbox mbox2 = TestUtil.getZMailbox(user2Name);
ZMailbox mbox3 = TestUtil.getZMailbox(user3Name);
String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
AdminCreateWaitSetResponse resp = createAdminWaitSet(null, adminAuthToken, true);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
assertNotNull(waitSetId);
int seq = resp.getSequence();
AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSetReq.setBlock(true);
final CountDownLatch doneSignal = new CountDownLatch(1);
waitForAccounts(Arrays.asList(mbox.getAccountId(), mbox2.getAccountId(), mbox3.getAccountId()), doneSignal, waitSetReq, "testBlockingAdminWaitAllAccounts", true);
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessage(mbox, subject);
TestUtil.addMessage(mbox2, subject);
TestUtil.addMessage(mbox3, subject);
try {
doneSignal.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
assertTrue("callback was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
int signalled = numSignalledAccounts.intValue();
while (signalled < 3) {
cbCalled.set(false);
success.set(false);
failureMessage = null;
// the waitset may be triggered for all accounts at once or be triggered for each account separately
waitSetReq = new AdminWaitSetRequest(waitSetId, lastSeqNum);
waitSetReq.setBlock(true);
final CountDownLatch doneSignal1 = new CountDownLatch(1);
waitForAccounts(Arrays.asList(mbox.getAccountId(), mbox2.getAccountId(), mbox3.getAccountId()), doneSignal1, waitSetReq, "testBlockingAdminWaitAllAccounts", true);
try {
doneSignal1.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted.");
}
signalled += numSignalledAccounts.intValue();
ZimbraLog.test.debug("Signalled %d accounts", signalled);
assertTrue("callback was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
}
assertEquals("This waitset has to signal 3 accounts", 3, signalled);
}
use of com.zimbra.soap.admin.message.AdminWaitSetRequest in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testFolderInterestSyncAdminWaitSetRequest.
@Test
public void testFolderInterestSyncAdminWaitSetRequest() throws Exception {
String user1Name = "testFISyncAdminWaitSetRequest_user1";
String user2Name = "testFISyncAdminWaitSetRequest_user2";
acc1 = TestUtil.createAccount(user1Name);
acc2 = TestUtil.createAccount(user2Name);
ZMailbox zMbox1 = TestUtil.getZMailbox(user1Name);
ZMailbox zMbox2 = TestUtil.getZMailbox(user2Name);
Mailbox mbox1 = TestUtil.getMailbox(user1Name);
Mailbox mbox2 = TestUtil.getMailbox(user2Name);
Set<String> accountIds = new HashSet<String>();
String acct1Id = zMbox1.getAccountId();
String acct2Id = zMbox2.getAccountId();
accountIds.add(acct1Id);
String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
ZFolder user1FunFolder = TestUtil.createFolder(zMbox1, "funFolder");
ZFolder user2FunFolder = TestUtil.createFolder(zMbox2, "funFolder");
ZFolder user2FunFolder2 = TestUtil.createFolder(zMbox2, "funFolder2");
Set<Integer> folderInterest = Sets.newHashSet();
folderInterest.add(user1FunFolder.getFolderIdInOwnerMailbox());
// initially only interested in user1::funFolder
AdminCreateWaitSetResponse resp = createAdminWaitSet(accountIds, adminAuthToken, false);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
int seq = resp.getSequence();
AdminWaitSetRequest waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.addUpdateAccount(createWaitSetAddSpec(acct1Id, folderInterest));
AdminWaitSetResponse wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals(0, seq);
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
TestUtil.waitForMessages(zMbox1, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
assertEquals("Number of signalled accounts", 0, wsResp.getSignalledAccounts().size());
seq = Integer.parseInt(wsResp.getSeqNo());
// now interested in user1::funFolder AND user1::inbox
folderInterest.add(Integer.valueOf(Mailbox.ID_FOLDER_INBOX));
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.addUpdateAccount(createWaitSetAddSpec(acct1Id, folderInterest));
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
// nothing happened, so should not trigger any accounts
assertEquals("Number of signalled accounts (test 1)", 0, wsResp.getSignalledAccounts().size());
seq = Integer.parseInt(wsResp.getSeqNo());
subject = NAME_PREFIX + " test wait set request 2";
TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
TestUtil.waitForMessages(zMbox1, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals("Number of signalled accounts (test 2)", 1, wsResp.getSignalledAccounts().size());
AccountWithModifications acctInfo = wsResp.getSignalledAccounts().get(0);
assertEquals("Signaled account id (should signal user1)", acct1Id, 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);
// Add message to user2 (should not trigger this waitset, because this waitset is not subscribed to user2 yet)
subject = NAME_PREFIX + " test wait set request 3";
TestUtil.addMessageLmtp(subject, user2Name, "user999@example.com");
TestUtil.waitForMessages(zMbox2, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals("Number of signalled accounts (test 3)", 0, wsResp.getSignalledAccounts().size());
// subscribe to user2::funFolder2
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
folderInterest = Sets.newHashSet();
folderInterest.add(user2FunFolder2.getFolderIdInOwnerMailbox());
waitSet.addAddAccount(createWaitSetAddSpec(acct2Id, folderInterest));
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals("Number of signalled accounts (test 4)", 0, wsResp.getSignalledAccounts().size());
// Add message to user2 (should NOT trigger this waitset yet, because WaitSet is subscribed to user2:funFolder2, user1:funFolder and user1:INBOX
subject = NAME_PREFIX + " test wait set request 4";
TestUtil.addMessageLmtp(subject, user2Name, "user999@example.com");
TestUtil.waitForMessages(zMbox2, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals("Number of signalled accounts (test 5)", 0, wsResp.getSignalledAccounts().size());
// add interest in user2:INBOX
folderInterest = Sets.newHashSet();
folderInterest.add(user2FunFolder2.getFolderIdInOwnerMailbox());
folderInterest.add(Integer.valueOf(Mailbox.ID_FOLDER_INBOX));
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.addUpdateAccount(createWaitSetAddSpec(acct2Id, folderInterest));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
// nothing happened, so should not trigger any accounts
assertEquals("Number of signalled accounts (test 6)", 0, wsResp.getSignalledAccounts().size());
// Add message to user2:INBOX (should trigger this WatSet now)
subject = NAME_PREFIX + " test wait set request 5";
TestUtil.addMessageLmtp(subject, user2Name, "user999@example.com");
TestUtil.waitForMessages(zMbox2, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
// now user2 should be triggered
assertEquals("Number of signalled accounts (test 7)", 1, wsResp.getSignalledAccounts().size());
acctInfo = wsResp.getSignalledAccounts().get(0);
assertEquals("Signaled account id (should signal user2)", acct2Id, acctInfo.getId());
mods = acctInfo.getPendingFolderModifications();
assertNotNull("'mod' field should not be null", mods);
assertEquals("Should have 1 folder object with modifications", 1, mods.size());
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);
// Add message to user1:funFolder (should trigger this WatSet)
subject = NAME_PREFIX + " test wait set request 6";
TestUtil.addMessage(mbox1, user1FunFolder.getFolderIdInOwnerMailbox(), subject, System.currentTimeMillis());
TestUtil.waitForMessages(zMbox1, String.format("in:%s is:unread \"%s\"", user1FunFolder.getName(), subject), 1, 1000);
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals("Number of signalled accounts (test 8)", 1, wsResp.getSignalledAccounts().size());
acctInfo = wsResp.getSignalledAccounts().get(0);
assertEquals("Signaled account id (should signal user1)", acct1Id, acctInfo.getId());
mods = acctInfo.getPendingFolderModifications();
assertNotNull("'mod' field should not be null", mods);
assertEquals("Should have 1 folder object with modifications", 1, mods.size());
foldInt = mods.iterator().next().getFolderId();
assertEquals(String.format("Folder ID should be %d (%s). Getting %d instead", user1FunFolder.getFolderIdInOwnerMailbox(), user1FunFolder.getName(), foldInt), foldInt.intValue(), user1FunFolder.getFolderIdInOwnerMailbox());
// Add message to user2:funFolder (should NOT trigger this WatSet, because it is subscribed to INBOX and funFolder2 on user2)
subject = NAME_PREFIX + " test wait set request 7";
TestUtil.addMessage(mbox2, user2FunFolder.getFolderIdInOwnerMailbox(), subject, System.currentTimeMillis());
TestUtil.waitForMessages(zMbox2, String.format("in:%s is:unread \"%s\"", user2FunFolder.getName(), subject), 1, 1000);
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals("Number of signalled accounts (test 9)", 0, wsResp.getSignalledAccounts().size());
// Add message to user2:funFolder2 (should trigger this WatSet)
subject = NAME_PREFIX + " test wait set request 8";
TestUtil.addMessage(mbox2, user2FunFolder2.getFolderIdInOwnerMailbox(), subject, System.currentTimeMillis());
TestUtil.waitForMessages(zMbox2, String.format("in:%s is:unread \"%s\"", user2FunFolder2.getName(), subject), 1, 1000);
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals("Number of signalled accounts (test 10)", 1, wsResp.getSignalledAccounts().size());
acctInfo = wsResp.getSignalledAccounts().get(0);
assertEquals("Signaled account id (should signal user2)", acct2Id, acctInfo.getId());
mods = acctInfo.getPendingFolderModifications();
assertNotNull("'mod' field should not be null", mods);
assertEquals("Should have 1 folder object with modifications", 1, mods.size());
foldInt = mods.iterator().next().getFolderId();
assertEquals(String.format("Folder ID should be %d (%s). Getting %d instead", user2FunFolder2.getFolderIdInOwnerMailbox(), user2FunFolder2.getName(), foldInt), user2FunFolder2.getFolderIdInOwnerMailbox(), foldInt.intValue());
// Add message to user2:funFolder2 and user1:INBOX (should trigger this WatSet)
subject = NAME_PREFIX + " test wait set request 9";
TestUtil.addMessage(mbox2, user2FunFolder2.getFolderIdInOwnerMailbox(), subject, System.currentTimeMillis());
TestUtil.waitForMessages(zMbox2, String.format("in:%s is:unread \"%s\"", user2FunFolder2.getName(), subject), 1, 1000);
subject = NAME_PREFIX + " test wait set request 10";
TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
TestUtil.waitForMessages(zMbox1, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (AdminWaitSetResponse) sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
seq = Integer.parseInt(wsResp.getSeqNo());
assertEquals("Number of signalled accounts (test 11)", 2, wsResp.getSignalledAccounts().size());
boolean user1Triggered = false;
boolean user2Triggered = false;
List<AccountWithModifications> accnts = wsResp.getSignalledAccounts();
for (AccountWithModifications info : accnts) {
if (info.getId().equalsIgnoreCase(acct1Id)) {
user1Triggered = true;
mods = info.getPendingFolderModifications();
PendingFolderModifications fm = ((ArrayList<PendingFolderModifications>) mods).get(0);
foldInt = fm.getFolderId();
assertNotNull("'mods' field should not be null", mods);
assertEquals("Should have 1 folder object with modifications for user1", 1, mods.size());
assertEquals(String.format("Folder ID should be %d (INBOX). Getting %d instead. Account %s", Mailbox.ID_FOLDER_INBOX, foldInt, acct1Id), Mailbox.ID_FOLDER_INBOX, foldInt.intValue());
}
if (info.getId().equalsIgnoreCase(acct2Id)) {
user2Triggered = true;
mods = info.getPendingFolderModifications();
assertNotNull("'mods' field should not be null", mods);
assertEquals("Should have 1 folder object with modifications for user2", 1, mods.size());
PendingFolderModifications fm = ((ArrayList<PendingFolderModifications>) mods).get(0);
foldInt = fm.getFolderId();
assertEquals(String.format("Folder ID should be %d (%s). Getting %d instead. Account %s", user2FunFolder2.getFolderIdInOwnerMailbox(), user2FunFolder2.getName(), foldInt, acct2Id), user2FunFolder2.getFolderIdInOwnerMailbox(), foldInt.intValue());
}
}
assertTrue("Should have signalled user2", user2Triggered);
assertTrue("Should have signalled user1", user1Triggered);
}
Aggregations