tests/libjava-mauve/src/gnu/testlet/org/omg/PortableServer/POA/TestDestroy.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.4
       
     2 
       
     3 // Copyright (c) Object Oriented Concepts, Inc. Billerica, MA, USA
       
     4 
       
     5 // Adapted for Mauve by Audrius Meskauskas <audriusa@bluewin.ch>
       
     6 
       
     7 // This file is part of Mauve.
       
     8 
       
     9 // Mauve is free software; you can redistribute it and/or modify
       
    10 // it under the terms of the GNU General Public License as published by
       
    11 // the Free Software Foundation; either version 2, or (at your option)
       
    12 // any later version.
       
    13 
       
    14 // Mauve is distributed in the hope that it will be useful,
       
    15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    17 // GNU General Public License for more details.
       
    18 
       
    19 // You should have received a copy of the GNU General Public License
       
    20 // along with Mauve; see the file COPYING.  If not, write to
       
    21 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    22 // Boston, MA 02111-1307, USA.
       
    23 
       
    24 /*
       
    25 This code originally came from the OMG's CORBA Open Source Testing project,
       
    26 which lived at cost.omg.org. That site no longer exists.
       
    27 
       
    28 All the contributing companies agreed to release their tests under the
       
    29 terms of the GNU Lesser General Public License, available in the file
       
    30 COPYING.LIB.
       
    31 
       
    32 The code has been modified integrating into Mauve test environment and
       
    33 removing tests that are not yet supported by Suns jre 1.4. Hence the license
       
    34 is now GPL.
       
    35 
       
    36 We downloaded the code from http://sourceforge.net/projects/corba-cost/,
       
    37 administrated by Duncan Grisby.
       
    38 */
       
    39 
       
    40 
       
    41 // **********************************************************************
       
    42 //
       
    43 // Copyright (c) 2000
       
    44 // Object Oriented Concepts, Inc.
       
    45 // Billerica, MA, USA
       
    46 //
       
    47 // All Rights Reserved
       
    48 //
       
    49 // **********************************************************************
       
    50 
       
    51 
       
    52 package gnu.testlet.org.omg.PortableServer.POA;
       
    53 
       
    54 import gnu.testlet.TestHarness;
       
    55 import gnu.testlet.Testlet;
       
    56 
       
    57 import org.omg.CORBA.ORB;
       
    58 import org.omg.CORBA.Policy;
       
    59 import org.omg.CORBA.SystemException;
       
    60 import org.omg.PortableServer.POA;
       
    61 import org.omg.PortableServer.POAManager;
       
    62 import org.omg.PortableServer.POAPackage.AdapterAlreadyExists;
       
    63 import org.omg.PortableServer.POAPackage.AdapterNonExistent;
       
    64 import org.omg.PortableServer.POAPackage.InvalidPolicy;
       
    65 
       
    66 public final class TestDestroy
       
    67   extends TestBase
       
    68   implements Testlet
       
    69 {
       
    70   static final class Test_impl2
       
    71     extends TestPOA
       
    72   {
       
    73     private POA poa_;
       
    74     private boolean called_ = false;
       
    75     private boolean finished_ = false;
       
    76 
       
    77     Test_impl2(POA poa)
       
    78     {
       
    79       poa_ = poa;
       
    80     }
       
    81 
       
    82     public synchronized void aMethod()
       
    83     {
       
    84       called_ = true;
       
    85       notify();
       
    86 
       
    87       try
       
    88         {
       
    89           wait(1000);
       
    90         }
       
    91       catch (InterruptedException ex)
       
    92         {
       
    93         }
       
    94       finished_ = true;
       
    95     }
       
    96 
       
    97     public POA _default_POA()
       
    98     {
       
    99       return poa_;
       
   100     }
       
   101 
       
   102     synchronized void blockUntilCalled()
       
   103     {
       
   104       while (!called_)
       
   105         {
       
   106           try
       
   107             {
       
   108               wait();
       
   109             }
       
   110           catch (InterruptedException ex)
       
   111             {
       
   112             }
       
   113         }
       
   114     }
       
   115 
       
   116     synchronized boolean callComplete()
       
   117     {
       
   118       return finished_;
       
   119     }
       
   120   }
       
   121 
       
   122   static final class LongCaller
       
   123     extends Thread
       
   124   {
       
   125     private Test t_;
       
   126 
       
   127     LongCaller(Test t)
       
   128     {
       
   129       t_ = t;
       
   130     }
       
   131 
       
   132     public void run()
       
   133     {
       
   134       try
       
   135         {
       
   136           t_.aMethod();
       
   137         }
       
   138       catch (SystemException se)
       
   139         {
       
   140           System.err.println(se.getMessage());
       
   141           se.printStackTrace();
       
   142         }
       
   143     }
       
   144   }
       
   145 
       
   146   //
       
   147   // This is a more rigorous test of POA::destroy. We want to ensure
       
   148   // that the POA isn't destroyed during a method call.
       
   149   //
       
   150   void uTestDestroyThreaded(ORB orb, POA root)
       
   151   {
       
   152     POAManager rootMgr = root.the_POAManager();
       
   153     TEST(rootMgr != null);
       
   154 
       
   155     Policy[] policies = new Policy[ 1 ];
       
   156     policies [ 0 ] =
       
   157       root.create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION);
       
   158 
       
   159     //
       
   160     // Create child POA
       
   161     //
       
   162     POA poa = null;
       
   163     try
       
   164       {
       
   165         poa = root.create_POA("poa1", rootMgr, policies);
       
   166       }
       
   167     catch (InvalidPolicy ex)
       
   168       {
       
   169         fail(ex);
       
   170         throw new RuntimeException(ex);
       
   171       }
       
   172     catch (AdapterAlreadyExists ex)
       
   173       {
       
   174         fail(ex);
       
   175         throw new RuntimeException(ex);
       
   176       }
       
   177 
       
   178     Test_impl2 impl = new Test_impl2(poa);
       
   179 
       
   180     Test t = impl._this(orb);
       
   181 
       
   182     Thread thr = new LongCaller(t);
       
   183 
       
   184     thr.start();
       
   185     impl.blockUntilCalled();
       
   186 
       
   187     //
       
   188     // Test: Destroy the POA while a method call is active
       
   189     //
       
   190     poa.destroy(true, true);
       
   191 
       
   192     //
       
   193     // The destroy call shouldn't return until the aMethod call is
       
   194     // complete
       
   195     //
       
   196     TEST(impl.callComplete());
       
   197 
       
   198     while (thr.isAlive())
       
   199       {
       
   200         try
       
   201           {
       
   202             thr.join();
       
   203           }
       
   204         catch (InterruptedException ex)
       
   205           {
       
   206           }
       
   207       }
       
   208   }
       
   209 
       
   210   void uTestDestroyBlocking(ORB orb, POA root)
       
   211   {
       
   212     org.omg.CORBA.Object obj;
       
   213     Policy[] policies = new Policy[ 0 ];
       
   214     POA poa;
       
   215     POA parent;
       
   216     POA poa2;
       
   217     POA poa3;
       
   218     POAManager mgr;
       
   219     String str;
       
   220 
       
   221     POAManager rootMgr = root.the_POAManager();
       
   222     TEST(rootMgr != null);
       
   223 
       
   224     //
       
   225     // Create child POA
       
   226     //
       
   227     try
       
   228       {
       
   229         poa = root.create_POA("poa1", rootMgr, policies);
       
   230       }
       
   231     catch (InvalidPolicy ex)
       
   232       {
       
   233         fail(ex);
       
   234         throw new RuntimeException(ex);
       
   235       }
       
   236     catch (AdapterAlreadyExists ex)
       
   237       {
       
   238         fail(ex);
       
   239         throw new RuntimeException(ex);
       
   240       }
       
   241 
       
   242     //
       
   243     // Test: destroy
       
   244     //
       
   245     poa.destroy(true, true);
       
   246 
       
   247     //
       
   248     // Ensure parent no longer knows about child
       
   249     //
       
   250     try
       
   251       {
       
   252         root.find_POA("poa1", false);
       
   253         TEST(false); // find_POA should not have succeeded
       
   254       }
       
   255     catch (AdapterNonExistent ex)
       
   256       {
       
   257         // expected
       
   258       }
       
   259 
       
   260     //
       
   261     // Create child POA
       
   262     //
       
   263     try
       
   264       {
       
   265         poa = root.create_POA("poa1", rootMgr, policies);
       
   266       }
       
   267     catch (AdapterAlreadyExists ex)
       
   268       {
       
   269         fail(ex);
       
   270         throw new RuntimeException(ex);
       
   271       }
       
   272     catch (InvalidPolicy ex)
       
   273       {
       
   274         fail(ex);
       
   275         throw new RuntimeException(ex);
       
   276       }
       
   277 
       
   278     //
       
   279     // Create child of child POA
       
   280     //
       
   281     try
       
   282       {
       
   283         poa2 = poa.create_POA("child1", rootMgr, policies);
       
   284       }
       
   285     catch (AdapterAlreadyExists ex)
       
   286       {
       
   287         fail(ex);
       
   288         throw new RuntimeException(ex);
       
   289       }
       
   290     catch (InvalidPolicy ex)
       
   291       {
       
   292         fail(ex);
       
   293         throw new RuntimeException(ex);
       
   294       }
       
   295 
       
   296     //
       
   297     // Test: destroy - should destroy poa1 and poa1/child1
       
   298     //
       
   299     poa.destroy(true, true);
       
   300 
       
   301     //
       
   302     // Ensure parent no longer knows about child
       
   303     //
       
   304     try
       
   305       {
       
   306         root.find_POA("poa1", false);
       
   307         TEST(false); // find_POA should not have succeeded
       
   308       }
       
   309     catch (AdapterNonExistent ex)
       
   310       {
       
   311         // expected
       
   312       }
       
   313 
       
   314     //
       
   315     // XXX Test: etherealize w/ servant manager
       
   316     //
       
   317   }
       
   318 
       
   319   public void testIt()
       
   320   {
       
   321     java.util.Properties props = System.getProperties();
       
   322 
       
   323     ORB orb = null;
       
   324 
       
   325     //
       
   326     // Create ORB
       
   327     //
       
   328     orb = ORB.init(new String[ 0 ], props);
       
   329 
       
   330     POA root = TestUtil.GetRootPOA(orb);
       
   331 
       
   332     POAManager rootMgr = root.the_POAManager();
       
   333     TEST(rootMgr != null);
       
   334 
       
   335     try
       
   336       {
       
   337         rootMgr.activate();
       
   338       }
       
   339     catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex)
       
   340       {
       
   341         fail(ex);
       
   342         throw new RuntimeException(ex);
       
   343       }
       
   344 
       
   345     uTestDestroyBlocking(orb, root);
       
   346     uTestDestroyThreaded(orb, root);
       
   347 
       
   348     if (orb != null)
       
   349       orb.destroy();
       
   350   }
       
   351 
       
   352   public void test(TestHarness a_harness)
       
   353   {
       
   354     harness = a_harness;
       
   355     testIt();
       
   356   }
       
   357 }