01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.objectserver.impl;
05:
06: import com.tc.object.ObjectID;
07: import com.tc.objectserver.core.api.ManagedObject;
08: import com.tc.objectserver.core.impl.TestManagedObject;
09: import com.tc.objectserver.persistence.impl.TestPersistenceTransaction;
10: import com.tc.test.TCTestCase;
11:
12: import java.util.ArrayList;
13: import java.util.HashMap;
14: import java.util.Iterator;
15: import java.util.List;
16: import java.util.Map;
17:
18: public class InMemoryManagedObjectStoreTest extends TCTestCase {
19:
20: private InMemoryManagedObjectStore os;
21: private Map managed;
22:
23: public void setUp() throws Exception {
24: managed = new HashMap();
25: os = new InMemoryManagedObjectStore(managed);
26: }
27:
28: public void testReleaseAll() {
29: List l = new ArrayList();
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(
37: TestPersistenceTransaction.NULL_TRANSACTION, l);
38: fail("Shouldn't be able to release objects that haven't been added.");
39: } catch (AssertionError e) {
40: // ok
41: }
42:
43: for (Iterator i = l.iterator(); i.hasNext();) {
44: os.addNewObject((ManagedObject) i.next());
45: }
46: // now it should be ok.
47: os.commitAllObjects(
48: TestPersistenceTransaction.NULL_TRANSACTION, l);
49:
50: assertTrue(managed.values().containsAll(l));
51: assertTrue(l.containsAll(managed.values()));
52: }
53:
54: }
|