tests/libjava-mauve/src/gnu/testlet/java/rmi/server/Uniqueness.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 /* Uniqueness.java -- The UID uniqueness : describe
       
     2    Copyright (C) 2006 Audrius Meskauskas
       
     3 This file is part of Mauve.
       
     4 
       
     5 Mauve is free software; you can redistribute it and/or modify
       
     6 it under the terms of the GNU General Public License as published by
       
     7 the Free Software Foundation; either version 2, or (at your option)
       
     8 any later version.
       
     9 
       
    10 Mauve is distributed in the hope that it will be useful, but
       
    11 WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13 General Public License for more details.
       
    14 
       
    15 You should have received a copy of the GNU General Public License
       
    16 along with Mauve; see the file COPYING.  If not, write to the
       
    17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
       
    18 02110-1301 USA.
       
    19 
       
    20 */
       
    21 
       
    22 // Tags: 1.4
       
    23 
       
    24 package gnu.testlet.java.rmi.server;
       
    25 
       
    26 import java.rmi.server.UID;
       
    27 import java.util.HashSet;
       
    28 
       
    29 import gnu.testlet.TestHarness;
       
    30 import gnu.testlet.Testlet;
       
    31 
       
    32 public class Uniqueness implements Testlet
       
    33 {
       
    34 
       
    35   static int complete = 0;
       
    36   
       
    37   static class TesterThread extends Thread
       
    38   {
       
    39     UID [] result;
       
    40     
       
    41     public void run()
       
    42     {
       
    43       result = new UID[200];
       
    44       for (int i = 0; i < result.length; i++)
       
    45         {
       
    46           result[i] = new UID();
       
    47         }
       
    48       synchronized (Uniqueness.class)
       
    49         {
       
    50           complete++;
       
    51         }
       
    52     }
       
    53   }
       
    54 
       
    55   public void test(TestHarness harness)
       
    56   {
       
    57     TesterThread[] tt = new TesterThread[20];
       
    58     for (int i = 0; i < tt.length; i++)
       
    59       {
       
    60         tt[i] = new TesterThread();
       
    61         tt[i].start();
       
    62       }
       
    63 
       
    64     // Wait till all complete:
       
    65     do
       
    66       {
       
    67         try
       
    68           {
       
    69             Thread.currentThread().sleep(200);
       
    70           }
       
    71         catch (InterruptedException e)
       
    72           {
       
    73           }
       
    74       }
       
    75     while (complete < tt.length);
       
    76 
       
    77     HashSet ids = new HashSet();
       
    78 
       
    79     for (int i = 0; i < tt.length; i++)
       
    80       {
       
    81         for (int j = 0; j < tt[i].result.length; j++)
       
    82           {
       
    83             UID id = tt[i].result[j];
       
    84             if (ids.contains(id))
       
    85               harness.fail("Duplicate ID " + id);
       
    86             else
       
    87               ids.add(id);
       
    88           }
       
    89       }
       
    90   }
       
    91 }