KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > fjank > tests > DiskPerformanceTest


1 /* Open Source Java Caching Service
2  * Copyright (C) 2002 Frank Karlstrøm
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * The author can be contacted by email: fjankk@users.sourceforge.net
18  */

19 package org.fjank.tests;
20
21 import junit.framework.TestCase;
22
23 /**
24  * Test class used during optimization of the disk writing system.
25  * @author Frank Karlstrøm
26  *
27  */

28 public class DiskPerformanceTest extends TestCase {
29     public static void main(String JavaDoc[] args) {
30         junit.textui.TestRunner.run(DiskPerformanceTest.class);
31     }
32
33     public final void testSerialize() {
34 // try {
35
// CacheAccessFactory factory = CacheAccessFactory.getInstance();
36
// factory.defineRegion("region");
37
// CacheMap access = factory.getMapAccess("region");
38
// access.defineGroup("group");
39
// CacheImpl cache = CacheImpl.getCache(true);
40
// CacheRegion region = cache.getRegion("region");
41
// CacheGroup group = region.getGroup("group");
42
// CacheObject obj = new CacheObject("key", "ref", group, region, CacheImpl.getCache(true).getReferenceQueue());
43
// Attributes att = factory.getDefaultAttributes();
44
// att.setVersion(1234);
45
// obj.setAttributes(att);
46
// DiskCacheObject diskCacheObject = new DiskCacheObject(obj);
47
//
48
// CacheFileAdapter adap = new CacheFileAdapter(new File("C:/test.ser"));
49
// /*now everything is set up, and we serialize,
50
// * write to disk, read from disk and deserialize.
51
// * every point is measured,
52
// * and a final check is made to see that the object
53
// * still is "the same".
54
// * This test is not in the general tests, since
55
// * performance will vary so much from computer to computer,
56
// * its not a good idea to include this test in the general JUnit
57
// * tests.
58
// */
59
// int repeats = 100000;
60
// long[] positions = new long[repeats];
61
// Object[] localS = new Object[repeats];
62
// long time = System.currentTimeMillis();
63
// for (int i = 0; i < repeats; i++) {
64
// localS[i] = CacheFileAdapter.serialize(diskCacheObject);
65
// }
66
// System.out.println("serialize:" + (System.currentTimeMillis()-time));
67
// time = System.currentTimeMillis();
68
// for (int i = 0; i < repeats; i++) {
69
// positions[i]=adap.length();
70
// adap.append((byte[]) localS[i]);
71
// }
72
//
73
// System.out.println("write:" + (System.currentTimeMillis()-time));
74
// time = System.currentTimeMillis();
75
// for (int i = 0; i < repeats; i++) {
76
// localS[i]= adap.read(positions[i]);
77
// }
78
// System.out.println("read:" + (System.currentTimeMillis()-time));
79
// time = System.currentTimeMillis();
80
//
81
// //now convert the object back
82
// DiskCacheObject dco=null;
83
// for (int i = 0; i < repeats; i++) {
84
// dco= CacheFileAdapter.deSerialize((byte[]) localS[i]);
85
// }
86
// System.out.println("deserialize:" + (System.currentTimeMillis()-time));
87
//
88
// CacheObject cacheObject = dco.getCacheObject();
89
// assertEquals(obj, cacheObject);
90
// } catch (CacheException e) {
91
// e.printStackTrace();
92
// fail(e.getMessage());
93
// }
94
}
95 }
Popular Tags