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.jre5.concurrency.collections;
022:
023: import java.util.Map;
024:
025: import com.db4o.collections.ArrayMap4;
026: import com.db4o.config.Configuration;
027: import com.db4o.db4ounit.jre5.collections.ArrayMap4Asserter;
028: import com.db4o.db4ounit.jre5.collections.CollectionsUtil;
029: import com.db4o.ext.ExtObjectContainer;
030: import com.db4o.ta.TransparentActivationSupport;
031:
032: import db4ounit.Assert;
033: import db4ounit.extensions.Db4oConcurrenyTestCase;
034:
035: public class ArrayMap4TestCase extends Db4oConcurrenyTestCase {
036:
037: public static void main(String[] args) {
038: new ArrayMap4TestCase().runEmbeddedConcurrency();
039: }
040:
041: protected void store() throws Exception {
042: ArrayMap4<String, Integer> map = new ArrayMap4<String, Integer>();
043: putData(map);
044: store(map);
045: }
046:
047: protected void configure(Configuration config) throws Exception {
048: config.add(new TransparentActivationSupport());
049: super .configure(config);
050: }
051:
052: private void putData(Map<String, Integer> map) {
053: for (int i = 0; i < 10; i++) {
054: map.put(String.valueOf(i), Integer.valueOf(i * 100));
055: }
056: }
057:
058: @SuppressWarnings("unchecked")
059: private ArrayMap4<String, Integer> retrieveOnlyInstance(
060: ExtObjectContainer db) {
061: ArrayMap4<String, Integer> map = CollectionsUtil
062: .retrieveMapFromDB(db, reflector());
063: return map;
064: }
065:
066: @SuppressWarnings("unchecked")
067: public void conc(ExtObjectContainer db) throws Exception {
068: retrieveOnlyInstance(db);
069: }
070:
071: public void concClear(ExtObjectContainer db, int seq)
072: throws Exception {
073: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
074:
075: ArrayMap4Asserter.assertClear(map);
076: markTaskDone(seq, true);
077: waitForAllTasksDone();
078: db.set(map);
079: }
080:
081: public void checkClear(ExtObjectContainer db) throws Exception {
082: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
083: ArrayMap4Asserter.checkClear(map);
084: }
085:
086: @SuppressWarnings("unchecked")
087: public void concClone(ExtObjectContainer db, int seq)
088: throws Exception {
089: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
090:
091: ArrayMap4Asserter.assertClone(map);
092: markTaskDone(seq, true);
093: waitForAllTasksDone();
094: db.set(map);
095: }
096:
097: public void concContainsKey(ExtObjectContainer db, int seq) {
098: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
099:
100: ArrayMap4Asserter.assertContainsKey(map);
101: }
102:
103: public void concContainsValue(ExtObjectContainer db, int seq) {
104: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
105:
106: ArrayMap4Asserter.assertContainsValue(map);
107: }
108:
109: public void concEntrySet(ExtObjectContainer db, int seq) {
110: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
111:
112: ArrayMap4Asserter.assertEntrySet(map);
113: }
114:
115: public void concGet(ExtObjectContainer db, int seq) {
116: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
117:
118: ArrayMap4Asserter.assertGet(map);
119: }
120:
121: public void concIsEmpty(ExtObjectContainer db, int seq) {
122: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
123:
124: ArrayMap4Asserter.assertIsEmpty(map);
125: }
126:
127: public void concKeySet(ExtObjectContainer db, int seq) {
128: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
129:
130: ArrayMap4Asserter.assertKeySet(map);
131: }
132:
133: public void concPut(ExtObjectContainer db, int seq)
134: throws Exception {
135: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
136:
137: ArrayMap4Asserter.assertPut(map);
138: markTaskDone(seq, true);
139: waitForAllTasksDone();
140: db.set(map);
141: }
142:
143: public void checkPut(ExtObjectContainer db) {
144: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
145:
146: ArrayMap4Asserter.checkPut(map);
147: }
148:
149: public void concPutAll(ExtObjectContainer db, int seq)
150: throws Exception {
151: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
152:
153: ArrayMap4Asserter.assertPutAll(map);
154: markTaskDone(seq, true);
155: waitForAllTasksDone();
156: db.set(map);
157: }
158:
159: public void checkPutAll(ExtObjectContainer db) {
160: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
161:
162: ArrayMap4Asserter.checkMap(map, 0, 20);
163: }
164:
165: public void concRemove_FromHead(ExtObjectContainer db, int seq)
166: throws Exception {
167: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
168:
169: ArrayMap4Asserter.assertRemove_FromHead(map);
170: markTaskDone(seq, true);
171: waitForAllTasksDone();
172: db.set(map);
173: }
174:
175: public void checkRemove_FromHead(ExtObjectContainer db) {
176: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
177:
178: ArrayMap4Asserter.checkRemove(map, 1, 10, "0");
179: }
180:
181: public void concRemove_FromEnd(ExtObjectContainer db, int seq)
182: throws Exception {
183: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
184:
185: ArrayMap4Asserter.assertRemove_FromEnd(map);
186: markTaskDone(seq, true);
187: waitForAllTasksDone();
188: db.set(map);
189: }
190:
191: public void checkRemove_FromEnd(ExtObjectContainer db) {
192: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
193: ArrayMap4Asserter.checkRemove(map, 0, 9, "9");
194: }
195:
196: public void concRemove_FromMiddle(ExtObjectContainer db, int seq)
197: throws Exception {
198: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
199:
200: ArrayMap4Asserter.assertRemove_FromMiddle(map);
201: markTaskDone(seq, true);
202: waitForAllTasksDone();
203: db.set(map);
204: }
205:
206: public void checkRemove_FromMiddle(ExtObjectContainer db) {
207: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
208:
209: ArrayMap4Asserter.checkRemove_FromMiddle(map);
210: }
211:
212: public void concSize(ExtObjectContainer db, int seq)
213: throws Exception {
214: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
215:
216: ArrayMap4Asserter.assertSize(map);
217: markTaskDone(seq, true);
218: waitForAllTasksDone();
219: db.set(map);
220: }
221:
222: public void checkSize(ExtObjectContainer db) {
223: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
224: Assert.isNull(map.get("1"));
225: Assert.areEqual(Integer.valueOf(1234), map.get("x"));
226: Assert.areEqual(10, map.size());
227: }
228:
229: public void concValues(ExtObjectContainer db, int seq) {
230: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
231:
232: ArrayMap4Asserter.assertValues(map);
233: }
234:
235: public void concEquals(ExtObjectContainer db, int seq) {
236: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
237:
238: ArrayMap4Asserter.assertEquals(map);
239: }
240:
241: public void concIncreaseSize(ExtObjectContainer db, int seq)
242: throws Exception {
243: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
244:
245: ArrayMap4Asserter.assertIncreaseSize(map);
246: markTaskDone(seq, true);
247: waitForAllTasksDone();
248: db.set(map);
249: }
250:
251: public void checkIncreaseSize(ExtObjectContainer db) {
252: ArrayMap4<String, Integer> map = retrieveOnlyInstance(db);
253:
254: ArrayMap4Asserter.checkMap(map, 0, 50);
255: }
256:
257: }
|