KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > impl > InMemoryManagedObjectStoreTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.impl;
5
6 import com.tc.object.ObjectID;
7 import com.tc.objectserver.core.api.ManagedObject;
8 import com.tc.objectserver.core.impl.TestManagedObject;
9 import com.tc.objectserver.persistence.impl.TestPersistenceTransaction;
10 import com.tc.test.TCTestCase;
11
12 import java.util.ArrayList JavaDoc;
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
17
18 public class InMemoryManagedObjectStoreTest extends TCTestCase {
19
20   private InMemoryManagedObjectStore os;
21   private Map JavaDoc managed;
22   
23   public void setUp() throws Exception JavaDoc {
24     managed = new HashMap JavaDoc();
25     os = new InMemoryManagedObjectStore(managed);
26   }
27   
28   public void testReleaseAll() {
29     List JavaDoc l = new ArrayList JavaDoc();
30     for (int i=0; i<10; i++) {
31       l.add(new TestManagedObject(new ObjectID(i)));
32     }
33     assertEquals(0, managed.size());
34     
35     try {
36       os.commitAllObjects(TestPersistenceTransaction.NULL_TRANSACTION, l);
37       fail("Shouldn't be able to release objects that haven't been added.");
38     } catch (AssertionError JavaDoc e) {
39       // ok
40
}
41     
42     for (Iterator JavaDoc i = l.iterator(); i.hasNext();) {
43       os.addNewObject((ManagedObject) i.next());
44     }
45     // now it should be ok.
46
os.commitAllObjects(TestPersistenceTransaction.NULL_TRANSACTION, l);
47     
48     assertTrue(managed.values().containsAll(l));
49     assertTrue(l.containsAll(managed.values()));
50   }
51   
52 }
53
Popular Tags