use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ContactTest method createInvalidImageAttachment.
/**
* Tests Invalid image attachment (bug 71868).
*/
@Test
public void createInvalidImageAttachment() throws Exception {
// Create a contact with an attachment.
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("fullName", "Get Attachment Content");
byte[] attachData = "attachment 1".getBytes();
Attachment attachment = new Attachment(attachData, "image/png", "image", "file1.png");
try {
ParsedContact pc = new ParsedContact(attrs, Lists.newArrayList(attachment));
Assert.fail("Expected INVALID_IMAGE exception");
} catch (ServiceException se) {
Assert.assertEquals("check the INVALID_IMAGE exception", "mail.INVALID_IMAGE", se.getCode());
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ACLTest method testRegrantDifferentPermission.
@Test
public void testRegrantDifferentPermission() throws Exception {
Account owner = Provisioning.getInstance().get(Key.AccountBy.name, "owner@zimbra.com");
Account grantee = Provisioning.getInstance().get(Key.AccountBy.name, "principal@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(owner);
Folder folder = mbox.createFolder(null, "shared", new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT));
OperationContext octxt = new OperationContext(owner);
mbox.grantAccess(octxt, folder.getId(), grantee.getId(), ACL.GRANTEE_USER, ACL.stringToRights("r"), null);
try {
mbox.grantAccess(octxt, folder.getId(), grantee.getId(), ACL.GRANTEE_USER, ACL.stringToRights("rw"), null);
} catch (ServiceException se) {
if (!se.getCode().equals(MailServiceException.GRANT_EXISTS)) {
Assert.fail("regrant throws ServiceException with code " + se.getCode());
}
Assert.fail("regrant has failed");
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class ACLTest method testRegrant.
@Test
public void testRegrant() throws Exception {
Account owner = Provisioning.getInstance().get(Key.AccountBy.name, "owner@zimbra.com");
Account grantee = Provisioning.getInstance().get(Key.AccountBy.name, "principal@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(owner);
Folder folder = mbox.createFolder(null, "shared", new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT));
OperationContext octxt = new OperationContext(owner);
mbox.grantAccess(octxt, folder.getId(), grantee.getId(), ACL.GRANTEE_USER, ACL.stringToRights("r"), null);
try {
mbox.grantAccess(octxt, folder.getId(), grantee.getId(), ACL.GRANTEE_USER, ACL.stringToRights("r"), null);
Assert.fail("regrant has succeeded");
} catch (ServiceException se) {
if (!se.getCode().equals(MailServiceException.GRANT_EXISTS)) {
Assert.fail("regrant throws ServiceException with code " + se.getCode());
}
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class MailboxLockTest method tooManyWaiters.
@Test
public void tooManyWaiters() {
Mailbox mbox = null;
try {
mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
} catch (ServiceException e) {
Assert.fail();
}
int threads = LC.zimbra_mailbox_lock_max_waiting_threads.intValue();
final AtomicBoolean done = new AtomicBoolean(false);
final Set<Thread> waitThreads = new HashSet<Thread>();
for (int i = 0; i < threads; i++) {
Thread waitThread = new Thread("MailboxLockTest-Waiter") {
@Override
public void run() {
Mailbox mbox;
try {
mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
mbox.lock.lock(false);
while (!done.get()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
mbox.lock.release();
} catch (ServiceException e) {
}
}
};
waitThread.setDaemon(true);
waitThreads.add(waitThread);
}
Thread writeThread = new Thread("MailboxLockTest-Writer") {
@Override
public void run() {
Mailbox mbox;
try {
mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
mbox.lock.lock(true);
for (Thread waiter : waitThreads) {
waiter.start();
}
while (!done.get()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
mbox.lock.release();
} catch (ServiceException e) {
}
}
};
writeThread.start();
while (mbox.lock.getQueueLength() < LC.zimbra_mailbox_lock_max_waiting_threads.intValue()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
try {
//one more reader...this should give too many waiters
mbox.lock.lock(false);
Assert.fail("expected too many waiters");
} catch (LockFailedException e) {
//expected
Assert.assertTrue(e.getMessage().startsWith("too many waiters"));
//cause writer to finish
done.set(true);
}
long joinTimeout = 50000;
joinWithTimeout(writeThread, joinTimeout);
for (Thread t : waitThreads) {
joinWithTimeout(t, joinTimeout);
}
//now do a write lock in same thread. previously this would break due to read assert not clearing
mbox.lock.lock(true);
mbox.lock.release();
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class MailboxLockTest method tooManyWaitersWithMultipleReadOwners.
@Test
public void tooManyWaitersWithMultipleReadOwners() {
Mailbox mbox = null;
try {
mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
} catch (ServiceException e) {
Assert.fail();
}
int threads = LC.zimbra_mailbox_lock_max_waiting_threads.intValue();
final AtomicBoolean done = new AtomicBoolean(false);
final Set<Thread> waitThreads = new HashSet<Thread>();
for (int i = 0; i < threads; i++) {
Thread waitThread = new Thread("MailboxLockTest-Waiter-" + i) {
@Override
public void run() {
Mailbox mbox;
try {
mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
mbox.lock.lock(true);
while (!done.get()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
mbox.lock.release();
} catch (ServiceException e) {
}
}
};
waitThread.setDaemon(true);
waitThreads.add(waitThread);
}
int readThreadCount = 20;
final Set<Thread> readThreads = new HashSet<Thread>();
for (int i = 0; i < readThreadCount; i++) {
Thread readThread = new Thread("MailboxLockTest-Reader-" + i) {
@Override
public void run() {
Mailbox mbox;
try {
mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
int holdCount = 20;
for (int i = 0; i < holdCount; i++) {
mbox.lock.lock(false);
}
while (!done.get()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
for (int i = 0; i < holdCount; i++) {
mbox.lock.release();
}
} catch (ServiceException e) {
}
}
};
readThreads.add(readThread);
}
Thread lastReadThread = new Thread("MailboxLockTest-LastReader") {
@Override
public void run() {
Mailbox mbox;
try {
mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
int holdCount = 20;
for (int i = 0; i < holdCount; i++) {
mbox.lock.lock(false);
}
//and the other readers
for (Thread reader : readThreads) {
reader.start();
}
for (Thread waiter : waitThreads) {
waiter.start();
}
while (!done.get()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
for (int i = 0; i < holdCount; i++) {
mbox.lock.release();
}
} catch (ServiceException e) {
}
}
};
lastReadThread.start();
while (mbox.lock.getQueueLength() < LC.zimbra_mailbox_lock_max_waiting_threads.intValue()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
try {
//one more reader...this should give too many waiters
mbox.lock.lock(false);
Assert.fail("expected too many waiters");
} catch (LockFailedException e) {
//expected
Assert.assertTrue(e.getMessage().startsWith("too many waiters"));
//cause writer to finish
done.set(true);
}
long joinTimeout = 50000;
joinWithTimeout(lastReadThread, joinTimeout);
for (Thread t : readThreads) {
joinWithTimeout(t, joinTimeout);
}
for (Thread t : waitThreads) {
joinWithTimeout(t, joinTimeout);
}
//now do a write lock in same thread. previously this would break due to read assert not clearing
mbox.lock.lock(true);
mbox.lock.release();
}
Aggregations