use of com.zimbra.cs.session.IWaitSet in project zm-mailbox by Zimbra.
the class TestWaitSet method runMeFirst.
private void runMeFirst() throws Exception {
String waitSetId;
List<WaitSetError> errors;
{
Account user1Acct = TestUtil.getAccount(USER_1_NAME);
List<WaitSetAccount> add = new ArrayList<WaitSetAccount>();
add.add(new WaitSetAccount(user1Acct.getId(), null, TypeEnum.m.getTypes(), null));
Pair<String, List<WaitSetError>> result = WaitSetMgr.create(FAKE_ACCOUNT_ID, true, TypeEnum.m.getTypes(), false, add);
waitSetId = result.getFirst();
errors = result.getSecond();
}
try {
String curSeqNo = "0";
assertEquals("Expecting sequence to be 0 when the test starts", 0, errors.size());
{
// waitset shouldn't signal until message added to a mailbox
WaitSetCallback cb = new WaitSetCallback();
// wait shouldn't find anything yet
IWaitSet ws = WaitSetMgr.lookup(waitSetId);
errors = ws.doWait(cb, "0", null, null);
assertEquals("Expecting sequence to be 0 during first wait", 0, errors.size());
synchronized (cb) {
assertEquals("Callback should not be completed yet", false, cb.completed);
}
// inserting a message to existing account should trigger waitset
String sender = TestUtil.getAddress(USER_1_NAME);
String recipient = TestUtil.getAddress(USER_1_NAME);
String subject = "testWaitSet 1";
TestUtil.addMessageLmtp(subject, recipient, sender);
try {
Thread.sleep(500);
} catch (Exception e) {
}
synchronized (cb) {
assertEquals("callback should be completed now", true, cb.completed);
}
curSeqNo = cb.seqNo;
}
{
// waitset should pick up added user
WaitSetCallback cb = new WaitSetCallback();
IWaitSet ws = WaitSetMgr.lookup(waitSetId);
// create a new account, shouldn't trigger waitset
Account user2Acct = TestUtil.getAccount(USER_2_NAME);
List<WaitSetAccount> add2 = new ArrayList<WaitSetAccount>();
add2.add(new WaitSetAccount(user2Acct.getId(), null, TypeEnum.m.getTypes(), null));
errors = ws.doWait(cb, curSeqNo, add2, null);
// wait shouldn't find anything yet
assertEquals("Should have no errors", 0, errors.size());
synchronized (cb) {
assertEquals("Callback should not be completed before it is triggered by the second account", false, cb.completed);
}
// adding a message to the new account SHOULD trigger waitset
String sender = TestUtil.getAddress(WS_USER_NAME);
String recipient = TestUtil.getAddress(USER_2_NAME);
String subject = "testWaitSet 3";
TestUtil.addMessageLmtp(subject, recipient, sender);
try {
Thread.sleep(500);
} catch (Exception e) {
}
synchronized (cb) {
assertEquals("Callback should be completed after it is triggered by the second account", true, cb.completed);
}
curSeqNo = cb.seqNo;
}
} finally {
WaitSetMgr.destroy(null, FAKE_ACCOUNT_ID, waitSetId);
}
}
use of com.zimbra.cs.session.IWaitSet 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.cs.session.IWaitSet in project zm-mailbox by Zimbra.
the class TestWaitSet method runMeSecond.
public void runMeSecond() throws Exception {
Pair<String, List<WaitSetError>> result = WaitSetMgr.create(FAKE_ACCOUNT_ID, true, TypeEnum.all.getTypes(), true, null);
String waitSetId = result.getFirst();
String curSeqNo = "0";
List<WaitSetError> errors = result.getSecond();
assertEquals("'errors' shoul dbe empty before creating a callback", 0, errors.size());
try {
{
// waitset shouldn't signal until message added to a mailbox
WaitSetCallback cb = new WaitSetCallback();
// wait shouldn't find anything yet
IWaitSet ws = WaitSetMgr.lookup(waitSetId);
errors = ws.doWait(cb, "0", null, null);
assertEquals("'errors' should be empty", 0, errors.size());
synchronized (cb) {
assertFalse("callback for all accounts should not be completed before it is triggered", cb.completed);
}
// inserting a message to existing account should trigger waitset
String sender = TestUtil.getAddress(USER_1_NAME);
String recipient = TestUtil.getAddress(USER_1_NAME);
String subject = "testWaitSet 1";
TestUtil.addMessageLmtp(subject, recipient, sender);
try {
Thread.sleep(500);
} catch (Exception e) {
}
synchronized (cb) {
assertTrue("callback for all accounts should be completed after it is triggered by " + USER_1_NAME, cb.completed);
}
curSeqNo = cb.seqNo;
}
{
// waitset should remain signalled until sequence number is increased
WaitSetCallback cb = new WaitSetCallback();
IWaitSet ws = WaitSetMgr.lookup(waitSetId);
errors = ws.doWait(cb, "0", null, null);
try {
Thread.sleep(500);
} catch (Exception e) {
}
assertEquals(0, errors.size());
synchronized (cb) {
assertTrue("call back for all accounts should remain completed until sequence number is increased", cb.completed);
}
curSeqNo = cb.seqNo;
}
{
// waitset shouldn't signal until a document is added
WaitSetCallback cb = new WaitSetCallback();
// wait shouldn't find anything yet
IWaitSet ws = WaitSetMgr.lookup(waitSetId);
errors = ws.doWait(cb, curSeqNo, null, null);
assertEquals(0, errors.size());
synchronized (cb) {
assertFalse("call back for all accounts should switch to not completed after sequence number is increased", cb.completed);
}
// creating a document in existing account should trigger waitset
String subject = "testWaitSet document 1";
TestUtil.createDocument(TestUtil.getZMailbox(USER_2_NAME), ZFolder.ID_BRIEFCASE, subject, "text/plain", "Hello, world!".getBytes());
try {
Thread.sleep(500);
} catch (Exception e) {
}
synchronized (cb) {
assertTrue("document waitset should be completed", cb.completed);
}
curSeqNo = cb.seqNo;
}
{
// part 2: waitset for "all" should pick up new account added
WaitSetCallback cb = new WaitSetCallback();
// wait shouldn't find anything yet
IWaitSet ws = WaitSetMgr.lookup(waitSetId);
errors = ws.doWait(cb, curSeqNo, null, null);
assertEquals(0, errors.size());
synchronized (cb) {
assertFalse("Doing nothing should not complete the callback", cb.completed);
}
// create a new account, shouldn't trigger waitset
TestUtil.createAccount(WS_USER_NAME);
synchronized (cb) {
assertFalse("creating a new account should not complete the callback", cb.completed);
}
// adding a message to the new account SHOULD trigger waitset
String sender = TestUtil.getAddress(WS_USER_NAME);
String recipient = TestUtil.getAddress(WS_USER_NAME);
String subject = "testWaitSet 2";
TestUtil.addMessageLmtp(subject, recipient, sender);
try {
Thread.sleep(500);
} catch (Exception e) {
}
synchronized (cb) {
assertTrue("Callback should be completed after adding a message to " + WS_USER_NAME, cb.completed);
}
curSeqNo = cb.seqNo;
}
} finally {
WaitSetMgr.destroy(null, FAKE_ACCOUNT_ID, waitSetId);
}
}
Aggregations