KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > guid > GUIDTest


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22
23
24 package org.jboss.test.guid;
25
26 import junit.framework.TestCase;
27 import org.jboss.util.id.GUID;
28 import org.jboss.util.id.VMID;
29 import org.jboss.util.id.UID;
30
31 import java.lang.reflect.Method JavaDoc;
32 import java.util.HashSet JavaDoc;
33
34 /**
35  * $Id: GUIDTest.java 39111 2005-12-16 18:29:38Z csuconic $
36  *
37  * @author <a HREF="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
38  * @author Eike Dawid (JIRA user)
39  */

40 public class GUIDTest extends TestCase
41 {
42
43     private static final int ITERATIONS = 100;
44
45     public void testGuid() throws InterruptedException JavaDoc
46     {
47         HashSet JavaDoc repositoryIDs = new HashSet JavaDoc();
48         System.out.println();
49         System.out.println("---------------------- testProveGuidHashCodeIsSame");
50         GUID guid = null;
51         for (int i = 0; i < ITERATIONS; i++)
52         {
53             guid = new GUID();
54
55             Integer JavaDoc hashKey = new Integer JavaDoc(guid.hashCode());
56
57             if (!repositoryIDs.contains(hashKey))
58             {
59                 repositoryIDs.add(hashKey);
60             }
61             System.out.println("guid.hashCode()=" + guid.hashCode());
62         }
63
64         if (repositoryIDs.size()==1)
65         {
66             fail("HashCode is always returning the same hash");
67         }
68     }
69
70     public void testUID() throws InterruptedException JavaDoc
71     {
72         HashSet JavaDoc repositoryIDs = new HashSet JavaDoc();
73         System.out.println();
74         System.out.println("---------------------- testProveUIDHashCodeIsSame");
75         UID guid = null;
76         for (int i = 0; i < ITERATIONS; i++)
77         {
78             guid = new UID();
79
80             Integer JavaDoc hashKey = new Integer JavaDoc(guid.hashCode());
81
82             if (!repositoryIDs.contains(hashKey))
83             {
84                 repositoryIDs.add(hashKey);
85             }
86             System.out.println("guid.hashCode()=" + guid.hashCode());
87         }
88
89         if (repositoryIDs.size()==1)
90         {
91             fail("HashCode is always returning the same hash");
92         }
93     }
94
95     public void testVMID() throws Exception JavaDoc
96     {
97         HashSet JavaDoc repositoryIDs = new HashSet JavaDoc();
98         System.out.println();
99         System.out.println("---------------------- testProveVMIDHashCodeIsSame");
100         VMID guid = null;
101         Method JavaDoc method = VMID.class.getDeclaredMethod("create", new Class JavaDoc[]{});
102         method.setAccessible(true);
103         for (int i = 0; i < ITERATIONS; i++)
104         {
105             guid = (VMID) method.invoke(null, new Object JavaDoc[]{});
106
107             Integer JavaDoc hashKey = new Integer JavaDoc(guid.hashCode());
108
109             if (!repositoryIDs.contains(hashKey))
110             {
111                 repositoryIDs.add(hashKey);
112             }
113             System.out.println("guid.hashCode()=" + guid.hashCode());
114         }
115
116         if (repositoryIDs.size()==1)
117         {
118             fail("HashCode is always returning the same hash");
119         }
120     }
121 }
122
Popular Tags