KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > tx > LockTest


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8

9 package test.tx;
10
11 import junit.framework.*;
12 import org.ozoneDB.LocalDatabase;
13 import org.ozoneDB.core.*;
14 import org.ozoneDB.core.User;
15 import test.OzoneTestCase;
16
17
18 /**
19  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
20  * @version $Revision$Date$
21  */

22 public class LockTest extends OzoneTestCase {
23
24
25     public LockTest( String JavaDoc name ) {
26         super( name );
27     }
28
29     public void testExclusiveLock() throws Exception JavaDoc {
30         if (!(db() instanceof LocalDatabase)) {
31             // only works on LocalDatabase
32
return;
33         }
34         LocalDatabase db = (LocalDatabase)db();
35         User owner = db.env.userManager.userForName( db.userName );
36         Lock lock = new ExclusiveLock();
37         Transaction ta1 = db.env.transactionManager.newTransaction( owner );
38         assertFalse (lock.tryAcquire(ta1,Lock.LEVEL_WRITE) == Lock.NOT_ACQUIRED);
39         assertFalse (lock.tryAcquire(ta1,Lock.LEVEL_READ) == Lock.NOT_ACQUIRED);
40
41         // todo: test that the lock is exclusive
42
//assertFalse (lock.tryAcquire (ta1, Lock.LEVEL_WRITE) == Lock.NOT_ACQUIRED);
43
//assertTrue (lock.tryAcquire (ta2, Lock.LEVEL_WRITE) == Lock.NOT_ACQUIRED);
44
//ta1.commit();
45
//ta2.commit();
46
//assertEquals (lock.tryAcquire (ta2, Lock.LEVEL_READ), Lock.NOT_ACQUIRED);
47
}
48
49     class TransactionThread extends Thread JavaDoc {
50         LocalDatabase db;
51         Transaction ta;
52         User owner;
53
54         TransactionThread(LocalDatabase _db, User _owner) {
55             this.db = _db;
56             this.owner = _owner;
57         }
58
59         public void run() {
60             ta = db.env.transactionManager.newTransaction( owner );
61         }
62
63         int aquire(Lock lock, int lockLevel){
64             return lock.tryAcquire (ta, lockLevel);
65         }
66
67     }
68
69     public void testSharedLock() {
70         // todo: implement me
71
}
72
73
74     public void testMROWLock() {
75         // todo: implement me
76
}
77
78
79     public static Test suite() {
80         TestSuite suite = new TestSuite();
81
82         suite.addTest( new LockTest( "testExclusiveLock" ) );
83         suite.addTest( new LockTest( "testSharedLock" ) );
84         return suite;
85     }
86
87
88     public static void main( String JavaDoc[] args ) {
89 // junit.textui.TestRunner.run( LockTest.suite() );
90
}
91
92 }
93
Popular Tags