001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.db4ounit.jre12.soda.collections;
022:
023: import java.util.*;
024:
025: import com.db4o.config.*;
026: import com.db4o.ext.*;
027:
028: import db4ounit.*;
029: import db4ounit.extensions.*;
030:
031: public class HashtableModifiedUpdateDepthTestCase extends
032: Db4oClientServerTestCase {
033:
034: public static void main(String[] args) {
035: new HashtableModifiedUpdateDepthTestCase().runClientServer();
036: }
037:
038: public static class Item {
039: public Hashtable ht;
040: }
041:
042: public void configure(Configuration config) {
043: config.updateDepth(Integer.MAX_VALUE);
044: }
045:
046: public void store() {
047: Item item = new Item();
048: item.ht = new Hashtable();
049: item.ht.put("hi", "five");
050: store(item);
051: }
052:
053: public void test() {
054: ExtObjectContainer oc1 = openNewClient();
055: ExtObjectContainer oc2 = openNewClient();
056: try {
057: Hashtable ht1 = (Hashtable) retrieveOnlyInstance(oc1,
058: Hashtable.class);
059: Hashtable ht2 = (Hashtable) retrieveOnlyInstance(oc2,
060: Hashtable.class);
061: ht1.put("hi", "updated1");
062: ht2.put("hi", "updated2");
063:
064: // oc1 sets updated value, but doesn't commit
065: oc1.set(ht1);
066: ht1 = (Hashtable) retrieveOnlyInstance(oc1, Hashtable.class);
067: Assert.areEqual("updated1", ht1.get("hi"));
068: ht2 = (Hashtable) retrieveOnlyInstance(oc2, Hashtable.class);
069: oc2.refresh(ht2, Integer.MAX_VALUE);
070: Assert.areEqual("five", ht2.get("hi"));
071:
072: // oc1 commits
073: oc1.commit();
074: ht1 = (Hashtable) retrieveOnlyInstance(oc1, Hashtable.class);
075: Assert.areEqual("updated1", ht1.get("hi"));
076: ht2 = (Hashtable) retrieveOnlyInstance(oc2, Hashtable.class);
077: oc2.refresh(ht2, Integer.MAX_VALUE);
078: Assert.areEqual("updated1", ht2.get("hi"));
079:
080: // oc2 sets updated value, but doesn't commit
081: ht2.put("hi", "updated2");
082: oc2.set(ht2);
083: ht1 = (Hashtable) retrieveOnlyInstance(oc1, Hashtable.class);
084: oc1.refresh(ht1, Integer.MAX_VALUE);
085: Assert.areEqual("updated1", ht1.get("hi"));
086: ht2 = (Hashtable) retrieveOnlyInstance(oc2, Hashtable.class);
087: Assert.areEqual("updated2", ht2.get("hi"));
088:
089: // oc2 commits
090: oc2.commit();
091: ht1 = (Hashtable) retrieveOnlyInstance(oc1, Hashtable.class);
092: oc1.refresh(ht1, Integer.MAX_VALUE);
093: Assert.areEqual("updated2", ht1.get("hi"));
094: ht2 = (Hashtable) retrieveOnlyInstance(oc2, Hashtable.class);
095: Assert.areEqual("updated2", ht2.get("hi"));
096: } finally {
097: oc1.close();
098: oc2.close();
099: }
100: }
101:
102: }
|