1 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 ; 32 import java.util.HashSet ; 33 34 40 public class GUIDTest extends TestCase 41 { 42 43 private static final int ITERATIONS = 100; 44 45 public void testGuid() throws InterruptedException 46 { 47 HashSet repositoryIDs = new HashSet (); 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 hashKey = new Integer (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 71 { 72 HashSet repositoryIDs = new HashSet (); 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 hashKey = new Integer (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 96 { 97 HashSet repositoryIDs = new HashSet (); 98 System.out.println(); 99 System.out.println("---------------------- testProveVMIDHashCodeIsSame"); 100 VMID guid = null; 101 Method method = VMID.class.getDeclaredMethod("create", new Class []{}); 102 method.setAccessible(true); 103 for (int i = 0; i < ITERATIONS; i++) 104 { 105 guid = (VMID) method.invoke(null, new Object []{}); 106 107 Integer hashKey = new Integer (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 |