Source Code Cross Referenced for TestNodeCache.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » graph » 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 » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.graph.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003:          [See end of file]
004:          $Id: TestNodeCache.java,v 1.5 2008/01/02 12:05:31 andy_seaborne Exp $
005:         */
006:
007:        package com.hp.hpl.jena.graph.test;
008:
009:        import junit.framework.*;
010:
011:        import com.hp.hpl.jena.graph.*;
012:
013:        /**
014:         TestNodeCache - make some (minimal, driving) tests for the NodeCache used
015:         to reduce store turnover for repeated Node construction.
016:
017:         @author kers
018:         */
019:        public class TestNodeCache extends GraphTestBase {
020:            public TestNodeCache(String name) {
021:                super (name);
022:            }
023:
024:            public static TestSuite suite() {
025:                return new TestSuite(TestNodeCache.class);
026:            }
027:
028:            /**
029:                 Utility to find short strings with the same hashcode, which can be used as
030:                 the basis for constructing nodes with the same hashcode - this is what
031:                 was used to find the clashing strings used below.
032:             */
033:            public static void main(String[] ignoredArguments) {
034:                String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
035:                String[] strings = new String[32000];
036:                for (int i = 0; i < alphabet.length(); i += 1)
037:                    for (int j = 0; j < alphabet.length(); j += 1) {
038:                        String s = "" + alphabet.charAt(i) + alphabet.charAt(j);
039:                        if (i == 10 && j == 10)
040:                            System.err.println(s);
041:                        int hash = s.hashCode();
042:                        if (strings[hash] == null)
043:                            strings[hash] = s;
044:                        else
045:                            System.out.println(">> " + strings[hash] + " and "
046:                                    + s + " both hash to " + hash);
047:                    }
048:            }
049:
050:            /**
051:                 Visible evidence that the pairs of strings used have the same hashcode.
052:             */
053:            public void testClashettes() {
054:                assertEquals("eg:aa".hashCode(), "eg:bB".hashCode());
055:                assertEquals("eg:ab".hashCode(), "eg:bC".hashCode());
056:                assertEquals("eg:ac".hashCode(), "eg:bD".hashCode());
057:                assertEquals("eg:Yv".hashCode(), "eg:ZW".hashCode());
058:                assertEquals("eg:Yx".hashCode(), "eg:ZY".hashCode());
059:            }
060:
061:            /**
062:                 An array of distinct URIs as ad-hoc probes into the cache under test.
063:             */
064:            protected static String[] someURIs = inventURIs();
065:
066:            protected static String[] inventURIs() {
067:                String[] a = { "a", "mig", "spoo-", "gilbert", "124c41+" };
068:                String[] b = { "b", "class", "procedure", "spindizzy", "rake" };
069:                String[] c = { "c", "bucket", "42", "+1", "#mark" };
070:                int here = 0;
071:                String[] result = new String[a.length * b.length * c.length];
072:                for (int i = 0; i < a.length; i += 1)
073:                    for (int j = 0; j < b.length; j += 1)
074:                        for (int k = 0; k < c.length; k += 1)
075:                            result[here++] = "eg:" + a[i] + b[j] + c[k];
076:                return result;
077:            }
078:
079:            /**
080:                test that a new cache is empty - none of the proble URIs are bound. 
081:             */
082:            public void testNewCacheEmpty() {
083:                NodeCache c = new NodeCache();
084:                for (int i = 0; i < someURIs.length; i += 1)
085:                    assertEquals(null, c.get(someURIs[i]));
086:            }
087:
088:            /**
089:                test that an element put into the cache is immediately retrievable
090:             */
091:            public void testNewCacheUpdates() {
092:                NodeCache c = new NodeCache();
093:                for (int i = 0; i < someURIs.length; i += 1) {
094:                    Node it = Node.createURI(someURIs[i]);
095:                    c.put(someURIs[i], it);
096:                    assertEquals(it, c.get(someURIs[i]));
097:                }
098:            }
099:
100:            /**
101:                test that labels with the same hashcode are not confused.
102:             */
103:            public void testClashing() {
104:                String A = "eg:aa", B = "eg:bB";
105:                assertEquals(A.hashCode(), B.hashCode());
106:                /* */
107:                NodeCache c = new NodeCache();
108:                c.put(A, Node.createURI(A));
109:                assertEquals(null, c.get(B));
110:                c.put(B, Node.createURI(B));
111:                assertEquals(Node.createURI(B), c.get(B));
112:            }
113:
114:        }
115:
116:        /*
117:         (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
118:         All rights reserved.
119:
120:         Redistribution and use in source and binary forms, with or without
121:         modification, are permitted provided that the following conditions
122:         are met:
123:
124:         1. Redistributions of source code must retain the above copyright
125:         notice, this list of conditions and the following disclaimer.
126:
127:         2. Redistributions in binary form must reproduce the above copyright
128:         notice, this list of conditions and the following disclaimer in the
129:         documentation and/or other materials provided with the distribution.
130:
131:         3. The name of the author may not be used to endorse or promote products
132:         derived from this software without specific prior written permission.
133:
134:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
135:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
136:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
137:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
138:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
139:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
140:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
141:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
142:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
143:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
144:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.