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.common.concurrency;
22:
23: import com.db4o.ObjectSet;
24: import com.db4o.config.Configuration;
25: import com.db4o.config.TSerializable;
26: import com.db4o.db4ounit.common.persistent.*;
27: import com.db4o.ext.ExtObjectContainer;
28: import com.db4o.query.Query;
29:
30: import db4ounit.Assert;
31: import db4ounit.extensions.Db4oClientServerTestCase;
32:
33: public class ByteArrayTestCase extends Db4oClientServerTestCase {
34:
35: static final int ITERATIONS = 15;
36:
37: static final int INSTANCES = 2;
38:
39: static final int ARRAY_LENGTH = 1024 * 512;
40:
41: public static void main(String[] args) {
42: new ByteArrayTestCase().runConcurrency();
43: }
44:
45: /**
46: * @sharpen.if !CF_1_0 && !CF_2_0
47: */
48: protected void configure(Configuration config) {
49: config.objectClass(SerializableByteArrayHolder.class)
50: .translate(new TSerializable());
51:
52: }
53:
54: protected void store() {
55: for (int i = 0; i < INSTANCES; ++i) {
56: store(new ByteArrayHolder(createByteArray()));
57: store(new SerializableByteArrayHolder(createByteArray()));
58: }
59: }
60:
61: public void concByteArrayHolder(ExtObjectContainer oc) {
62: timeQueryLoop(oc, "raw byte array", ByteArrayHolder.class);
63: }
64:
65: public void concSerializableByteArrayHolder(ExtObjectContainer oc) {
66: timeQueryLoop(oc, "TSerializable",
67: SerializableByteArrayHolder.class);
68: }
69:
70: private void timeQueryLoop(ExtObjectContainer oc, String label,
71: final Class clazz) {
72: for (int i = 0; i < ITERATIONS; ++i) {
73: Query query = oc.query();
74: query.constrain(clazz);
75:
76: ObjectSet os = query.execute();
77: Assert.areEqual(INSTANCES, os.size());
78:
79: while (os.hasNext()) {
80: Assert.areEqual(ARRAY_LENGTH, ((IByteArrayHolder) os
81: .next()).getBytes().length);
82: }
83: }
84: }
85:
86: byte[] createByteArray() {
87: byte[] bytes = new byte[ARRAY_LENGTH];
88: for (int i = 0; i < bytes.length; ++i) {
89: bytes[i] = (byte) (i % 256);
90: }
91: return bytes;
92: }
93: }
|