001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.guid;
023:
024: import junit.framework.TestCase;
025: import org.jboss.util.id.GUID;
026: import org.jboss.util.id.VMID;
027: import org.jboss.util.id.UID;
028:
029: import java.lang.reflect.Method;
030: import java.util.HashSet;
031:
032: /**
033: * $Id: GUIDUnitTestCase.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
034: *
035: * @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
036: * @author Eike Dawid (JIRA user)
037: */
038: public class GUIDUnitTestCase extends TestCase {
039:
040: private static final int ITERATIONS = 100;
041:
042: public void testGuid() throws InterruptedException {
043: HashSet repositoryIDs = new HashSet();
044: System.out.println();
045: System.out
046: .println("---------------------- testProveGuidHashCodeIsSame");
047: GUID guid = null;
048: for (int i = 0; i < ITERATIONS; i++) {
049: guid = new GUID();
050:
051: Integer hashKey = new Integer(guid.hashCode());
052:
053: if (!repositoryIDs.contains(hashKey)) {
054: repositoryIDs.add(hashKey);
055: }
056: System.out.println("guid.hashCode()=" + guid.hashCode());
057: }
058:
059: if (repositoryIDs.size() == 1) {
060: fail("HashCode is always returning the same hash");
061: }
062: }
063:
064: public void testUID() throws InterruptedException {
065: HashSet repositoryIDs = new HashSet();
066: System.out.println();
067: System.out
068: .println("---------------------- testProveUIDHashCodeIsSame");
069: UID guid = null;
070: for (int i = 0; i < ITERATIONS; i++) {
071: guid = new UID();
072:
073: Integer hashKey = new Integer(guid.hashCode());
074:
075: if (!repositoryIDs.contains(hashKey)) {
076: repositoryIDs.add(hashKey);
077: }
078: System.out.println("guid.hashCode()=" + guid.hashCode());
079: }
080:
081: if (repositoryIDs.size() == 1) {
082: fail("HashCode is always returning the same hash");
083: }
084: }
085:
086: public void testVMID() throws Exception {
087: HashSet repositoryIDs = new HashSet();
088: System.out.println();
089: System.out
090: .println("---------------------- testProveVMIDHashCodeIsSame");
091: VMID guid = null;
092: Method method = VMID.class.getDeclaredMethod("create",
093: new Class[] {});
094: method.setAccessible(true);
095: for (int i = 0; i < ITERATIONS; i++) {
096: guid = (VMID) method.invoke(null, new Object[] {});
097:
098: Integer hashKey = new Integer(guid.hashCode());
099:
100: if (!repositoryIDs.contains(hashKey)) {
101: repositoryIDs.add(hashKey);
102: }
103: System.out.println("guid.hashCode()=" + guid.hashCode());
104: }
105:
106: if (repositoryIDs.size() == 1) {
107: fail("HashCode is always returning the same hash");
108: }
109: }
110: }
|