KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > mailboxmanager > torque > om > MailboxRowTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20 package org.apache.james.mailboxmanager.torque.om;
21
22 import java.sql.SQLException JavaDoc;
23 import java.util.SortedSet JavaDoc;
24 import java.util.TreeSet JavaDoc;
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 JavaDoc {
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 JavaDoc set=new TreeSet JavaDoc();
46         for (int i = 0; i < t.length; i++) {
47             t[i].join();
48             set.add(new Long JavaDoc(t[i].mr.getLastUid()));
49         }
50         assertEquals(t.length,set.size());
51         
52     }
53     
54     class ConsumeUidThread extends Thread JavaDoc {
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 JavaDoc e) {
66                 e.printStackTrace();
67             }
68         }
69         
70     }
71     
72     public void testConsumeUid() throws Exception JavaDoc {
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