01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.db4ounit.jre11.concurrency.staging;
22:
23: import java.util.*;
24:
25: import com.db4o.*;
26: import com.db4o.config.*;
27: import com.db4o.db4ounit.common.persistent.*;
28: import com.db4o.ext.*;
29:
30: import db4ounit.*;
31: import db4ounit.extensions.*;
32:
33: public class CascadeToHashtableTestCase extends AbstractDb4oTestCase {
34:
35: public static void main(String[] args) {
36: new CascadeToHashtableTestCase().runConcurrency();
37: }
38:
39: public Hashtable ht;
40:
41: protected void configure(Configuration config) {
42: config.objectClass(this ).cascadeOnUpdate(true);
43: config.objectClass(this ).cascadeOnDelete(true);
44: config.objectClass(Atom.class).cascadeOnDelete(false);
45: }
46:
47: protected void store() {
48: CascadeToHashtableTestCase cth = new CascadeToHashtableTestCase();
49: cth.ht = new Hashtable();
50: cth.ht.put("key1", new Atom("stored1"));
51: cth.ht.put("key2",
52: new Atom(new Atom("storedChild1"), "stored2"));
53: store(cth);
54: }
55:
56: public void conc(ExtObjectContainer oc) {
57: CascadeToHashtableTestCase cth = (CascadeToHashtableTestCase) retrieveOnlyInstance(
58: oc, CascadeToHashtableTestCase.class);
59: cth.ht.put("key1", new Atom("updated1"));
60: Atom atom = (Atom) cth.ht.get("key2");
61: atom.name = "updated2";
62: oc.set(cth);
63: }
64:
65: public void check(ExtObjectContainer oc) {
66: CascadeToHashtableTestCase cth = (CascadeToHashtableTestCase) retrieveOnlyInstance(
67: oc, CascadeToHashtableTestCase.class);
68: Atom atom = (Atom) cth.ht.get("key1");
69: Assert.areEqual("updated1", atom.name);
70: atom = (Atom) cth.ht.get("key2");
71: Assert.areEqual("updated2", atom.name);
72: }
73:
74: public void concDelete(ExtObjectContainer oc, int seq)
75: throws Exception {
76: ObjectSet os = oc.query(CascadeToHashtableTestCase.class);
77: if (os.size() == 0) { // already deleted
78: return;
79: }
80: Assert.areEqual(1, os.size());
81: CascadeToHashtableTestCase cth = (CascadeToHashtableTestCase) os
82: .next();
83: // wait for other threads
84: Thread.sleep(500);
85: oc.delete(cth);
86: }
87:
88: public void checkDelete(ExtObjectContainer oc) {
89: // Cascade-On-Delete Test: We only want one atom to remain.
90: assertOccurrences(oc, Atom.class, 1);
91: }
92: }
|