Source Code Cross Referenced for BLOBTest.java in  » Database-DBMS » Ozone-1.1 » org » ozoneDB » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » Ozone 1.1 » org.ozoneDB.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // You can redistribute this software and/or modify it under the terms of
002:        // the Ozone Library License version 1 published by ozone-db.org.
003:        //
004:        // The original code and portions created by SMB are
005:        // Copyright (C) 1997-2001 by SMB GmbH. All rights reserved.
006:        //
007:        // $Id: BLOBTest.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
008:
009:        package org.ozoneDB.test;
010:
011:        import java.io.*;
012:        import java.util.*;
013:        import java.util.zip.*;
014:
015:        import org.ozoneDB.*;
016:        import org.ozoneDB.util.*;
017:
018:        class BLOB extends Thread {
019:
020:            final static int POOLSIZE = 10;
021:            final static int BUFFERSIZE = 32000;
022:            final static int PAGESIZE = 32;
023:            final static int MINSIZE = 1;
024:            final static int MAXSIZE = 1024;
025:
026:            int pool;
027:            int bsize;
028:            int page;
029:            int min;
030:            int max;
031:
032:            String[] names;
033:            int[] sizes;
034:            byte[] buffer;
035:            long[] check;
036:            RemoteDatabase db;
037:
038:            Random objNr;
039:            Random objSize;
040:
041:            boolean halted = false;
042:
043:            long movement = 0;
044:            long avWritespeed = 0;
045:            int writecount = 0;
046:            long avReadspeed = 0;
047:            int readcount = 0;
048:
049:            /** Constructor */
050:            public BLOB(RemoteDatabase _db, int _poolsize, int _buffersize,
051:                    int _pagesize, int _rangeMin, int _rangeMax) {
052:
053:                pool = _poolsize;
054:                bsize = _buffersize;
055:                page = _pagesize;
056:                min = _rangeMin;
057:                max = _rangeMax;
058:
059:                names = new String[pool];
060:                sizes = new int[pool];
061:                check = new long[pool];
062:                buffer = new byte[_buffersize];
063:                db = _db;
064:
065:                objNr = new Random();
066:                objSize = new Random();
067:            }
068:
069:            /**  RUN THE THREAD */
070:            public void run() {
071:
072:                int size;
073:
074:                while (true) {
075:
076:                    int actObj = objNr.nextInt() % pool;
077:                    actObj = actObj < 0 ? -actObj : actObj;
078:
079:                    try {
080:                        if (names[actObj] == null) {
081:                            // at this place there isnt an object yet -> create one
082:                            if (halted) {
083:                                break;
084:                            }
085:                            createBlob(actObj);
086:                        } else {
087:                            // there is one -> try to find it
088:                            BLOBContainer blob = (BLOBContainer) db
089:                                    .objectForName(names[actObj]);
090:                            if (blob != null) {
091:                                // read and verify it
092:                                if (halted) {
093:                                    break;
094:                                }
095:                                verifyBlob(blob, actObj);
096:                                // delete it
097:                                db.deleteObject(blob);
098:                                names[actObj] = null;
099:                                sizes[actObj] = 0;
100:                                check[actObj] = 0;
101:                                System.out.println(" -> deleted.");
102:                                // create a new one
103:                                if (halted) {
104:                                    break;
105:                                }
106:                                createBlob(actObj);
107:                            } else {
108:                                System.out
109:                                        .println("\nERROR!!! Object for name '"
110:                                                + names[actObj]
111:                                                + "' not found!\n");
112:                            }
113:                        }
114:
115:                    } catch (Throwable e) {
116:                        e.printStackTrace(System.out);
117:                    }
118:                }
119:
120:                try {
121:                    System.out.println("\n\nclearing database...");
122:                    for (int i = 0; i < pool; i++) {
123:                        if (names[i] != null) {
124:                            BLOBContainer blob = (BLOBContainer) db
125:                                    .objectForName(names[i]);
126:                            db.deleteObject(blob);
127:                            System.out.println(names[i] + " deleted.");
128:                        }
129:                    }
130:
131:                } catch (Throwable e) {
132:                    e.printStackTrace(System.out);
133:                }
134:
135:            }
136:
137:            /** */
138:            private void createBlob(int _actObj) throws Exception {
139:
140:                int size = objSize.nextInt() % (max - min);
141:                size = (size < 0 ? -size : size) + min;
142:                size *= 1024;
143:
144:                String name = new String("Blob" + String.valueOf(_actObj));
145:                System.out.print("create " + name + "...");
146:                BLOBContainer blob = (BLOBContainer) db.createObject(
147:                        BLOBContainerImpl.class.getName(),
148:                        OzoneInterface.Public, name);
149:                blob.init(page);
150:                names[_actObj] = name;
151:                sizes[_actObj] = size;
152:
153:                // fill it up...
154:                BLOBOutputStream out = new BLOBOutputStream(blob);
155:                CRC32 checksum = new CRC32();
156:                CheckedOutputStream checkedOut = new CheckedOutputStream(out,
157:                        checksum);
158:                int pos = 0;
159:                long start = System.currentTimeMillis();
160:                for (int i = 0; i < size; i++) {
161:                    buffer[pos++] = (byte) i;
162:
163:                    if (pos == bsize) {
164:                        // flush buffer
165:                        checkedOut.write(buffer);
166:                        pos = 0;
167:                    }
168:                }
169:
170:                if (pos != 0) {
171:                    // flush buffer last time
172:                    checkedOut.write(buffer, 0, pos);
173:                }
174:                long stop = System.currentTimeMillis();
175:
176:                long bps = (long) size * 1000 / (stop - start);
177:                avWritespeed += bps;
178:                writecount++;
179:                movement += size;
180:
181:                check[_actObj] = checksum.getValue();
182:
183:                System.out.println("ok. (Size: " + sizes[_actObj] / 1024
184:                        + " kB, " + bps / 1024 + " kB/s)");
185:            }
186:
187:            /** */
188:            private void verifyBlob(BLOBContainer _blob, int _actObj)
189:                    throws Exception {
190:
191:                System.out.print("verify " + names[_actObj] + "...");
192:
193:                BLOBInputStream in = new BLOBInputStream(_blob);
194:                CRC32 checksum = new CRC32();
195:                CheckedInputStream checkedIn = new CheckedInputStream(in,
196:                        checksum);
197:                int read = 0;
198:                int got;
199:
200:                long start = System.currentTimeMillis();
201:                while ((got = checkedIn.read(buffer)) != -1) {
202:                    read += got;
203:                }
204:                long stop = System.currentTimeMillis();
205:
206:                long bps = (long) read * 1000 / (stop - start);
207:                avReadspeed += bps;
208:                readcount++;
209:                movement += read;
210:
211:                if (read == sizes[_actObj]
212:                        && checksum.getValue() == check[_actObj]) {
213:                    System.out.print("ok. (Size: "
214:                            + String.valueOf(read / 1024) + " kB, " + bps
215:                            / 1024 + " kB/s), Checksum: " + checksum.getValue()
216:                            + ")");
217:                } else {
218:                    System.out.println("\nERROR!!! " + names[_actObj]
219:                            + " is invalid. Size: "
220:                            + String.valueOf(read / 1024) + " kB != "
221:                            + String.valueOf(sizes[_actObj] / 1024) + "kB");
222:                    System.out.println("                CHECKSUM is "
223:                            + checksum.getValue() + " (should be "
224:                            + check[_actObj] + ")\n");
225:                }
226:            }
227:
228:            public static void main(String[] _args) throws Exception {
229:
230:                int pool = POOLSIZE;
231:                int buffer = BUFFERSIZE;
232:                int page = PAGESIZE;
233:                int min = MINSIZE;
234:                int max = MAXSIZE;
235:                String host = "localhost";
236:                int port = 3333;
237:
238:                try {
239:                    for (int i = 0; i < _args.length; i++) {
240:                        if (_args[i].startsWith("-help")) {
241:                            help();
242:                        } else if (_args[i].startsWith("-pool")) {
243:                            pool = Integer.parseInt(_args[i].substring(5));
244:                        } else if (_args[i].startsWith("-buffer")) {
245:                            buffer = Integer.parseInt(_args[i].substring(7));
246:                        } else if (_args[i].startsWith("-page")) {
247:                            page = Integer.parseInt(_args[i].substring(5));
248:                        } else if (_args[i].startsWith("-min")) {
249:                            min = Integer.parseInt(_args[i].substring(4));
250:                        } else if (_args[i].startsWith("-max")) {
251:                            max = Integer.parseInt(_args[i].substring(4));
252:                        } else if (_args[i].startsWith("-host")) {
253:                            host = _args[i].substring(5);
254:                        } else {
255:                            if (_args[i].startsWith("-port")) {
256:                                port = Integer.parseInt(_args[i].substring(5));
257:                            }
258:                        }
259:                    }
260:                } catch (Exception e) {
261:                    help();
262:                }
263:
264:                RemoteDatabase db = new RemoteDatabase();
265:                try {
266:                    db.open(host, port);
267:                } catch (Exception e) {
268:                    System.out.print("No db found...");
269:                    System.exit(0);
270:                }
271:
272:                db.reloadClasses();
273:                System.out.println("connected...");
274:
275:                BLOB blob = new BLOB(db, pool, buffer, page * 1024, min, max);
276:
277:                System.out
278:                        .println("----------------------------------------------------------------");
279:                System.out
280:                        .println("  B L O B Test  starting the testthread. Press ENTER to abort.\n");
281:                System.out.println("environment:");
282:                System.out.println("connected to db at " + host + ":" + port);
283:                System.out.println("a pool of " + pool
284:                        + " Blobs will be managed. ");
285:                System.out.println("Streambuffersize = " + buffer + " byte");
286:                System.out.println("BlobPagesize = " + page + " kB");
287:                System.out.println("Blobs will be created in the range from "
288:                        + min + " kB to " + max + " kB");
289:                System.out
290:                        .println("----------------------------------------------------------------");
291:
292:                blob.start();
293:                long start = System.currentTimeMillis();
294:                System.in.read();
295:                blob.halted = true;
296:                System.out
297:                        .println("\nTest halted. Waiting for last databaseoperation to quit...");
298:                blob.join();
299:                long stop = System.currentTimeMillis();
300:                db.close();
301:                System.out.println("disconnected.");
302:
303:                System.out
304:                        .println("----------------------------------------------------------------");
305:                System.out.println("statistics:");
306:                stop = (stop - start) / 1000;
307:                start = stop / 60;
308:                stop = (stop - start * 60);
309:                System.out.println("test runs " + start + " min and " + stop
310:                        + " seconds, ca." + blob.movement / 1024 / 1024
311:                        + " MB of data were moved (read + write)");
312:                System.out.println("average writespeed: " + blob.avWritespeed
313:                        / (blob.writecount == 0 ? 1 : blob.writecount)
314:                        + " Bytes/s");
315:                System.out.println("average readspeed:  " + blob.avReadspeed
316:                        / (blob.readcount == 0 ? 1 : blob.readcount)
317:                        + " Bytes/s");
318:
319:            }
320:
321:            private static void help() {
322:                System.out
323:                        .println("usage: BLOB -pool<> -buffer<> -page<> -min<> -max<> -host<> -port<>");
324:                System.out.println(" -pool<number of managed objects>");
325:                System.out.println(" -buffer<size of StreamBuffer (bytes)>");
326:                System.out.println(" -page<BlobPagesize (kBytes)>");
327:                System.out.println(" -min<minSize for Blobs (kBytes)>");
328:                System.out.println(" -max<maxSize for Blobs (kBytes)>");
329:                System.out
330:                        .println(" -host<databaseserver (default: localhost)>");
331:                System.out.println(" -port<port for dbserver (default: 3333)>");
332:                System.out.println(" NOTE: Database has to be running!");
333:                System.exit(0);
334:            }
335:
336:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.