1 19 20 package org.apache.james.mailboxmanager.torque.om; 21 22 import java.sql.SQLException ; 23 import java.util.SortedSet ; 24 import java.util.TreeSet ; 25 26 import org.apache.james.mailboxmanager.torque.AbstractMailboxRowTestCase; 27 import org.apache.torque.TorqueException; 28 29 public class MailboxRowTest extends AbstractMailboxRowTestCase { 30 31 public MailboxRowTest() throws TorqueException { 32 super(); 33 } 34 35 36 public void testConcurrentConsumeUid() throws Exception { 37 MailboxRow mr=new MailboxRow("#users.tuser.INBOX",100); 38 mr.save(); 39 mr=MailboxRowPeer.retrieveByName("#users.tuser.INBOX"); 40 ConsumeUidThread[] t=new ConsumeUidThread[10]; 41 for (int i = 0; i < t.length; i++) { 42 t[i]=new ConsumeUidThread(mr); 43 t[i].start(); 44 } 45 SortedSet set=new TreeSet (); 46 for (int i = 0; i < t.length; i++) { 47 t[i].join(); 48 set.add(new Long (t[i].mr.getLastUid())); 49 } 50 assertEquals(t.length,set.size()); 51 52 } 53 54 class ConsumeUidThread extends Thread { 55 MailboxRow mr; 56 57 ConsumeUidThread( MailboxRow mr) { 58 this.mr=mr; 59 } 60 public void run() { 61 try { 62 mr=mr.consumeNextUid(); 63 } catch (TorqueException e) { 64 e.printStackTrace(); 65 } catch (SQLException e) { 66 e.printStackTrace(); 67 } 68 } 69 70 } 71 72 public void testConsumeUid() throws Exception { 73 MailboxRow mr=new MailboxRow("#users.tuser2.INBOX",100); 74 mr.save(); 75 mr=MailboxRowPeer.retrieveByName("#users.tuser2.INBOX"); 76 assertEquals(0,mr.getLastUid()); 77 mr=mr.consumeNextUid(); 78 assertEquals(1,mr.getLastUid()); 79 mr=mr.consumeNextUid(); 80 assertEquals(2,mr.getLastUid()); 81 mr=mr.consumeNextUid(); 82 assertEquals(3,mr.getLastUid()); 83 } 84 85 } 86 | Popular Tags |