tests/libjava-mauve/src/gnu/testlet/org/omg/PortableServer/POA/TestActivate.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 // Copyright (c) 2000
       
    43 // Object Oriented Concepts, Inc.
       
    44 // Billerica, MA, USA
       
    45 //
       
    46 // All Rights Reserved
       
    47 //
       
    48 // **********************************************************************
       
    49 
       
    50 
       
    51 package gnu.testlet.org.omg.PortableServer.POA;
       
    52 
       
    53 import gnu.testlet.*;
       
    54 
       
    55 import org.omg.CORBA.ORB;
       
    56 import org.omg.CORBA.Policy;
       
    57 import org.omg.PortableServer.ForwardRequest;
       
    58 import org.omg.PortableServer.POA;
       
    59 import org.omg.PortableServer.POAManager;
       
    60 import org.omg.PortableServer.POAPackage.AdapterAlreadyExists;
       
    61 import org.omg.PortableServer.POAPackage.InvalidPolicy;
       
    62 import org.omg.PortableServer.POAPackage.ObjectAlreadyActive;
       
    63 import org.omg.PortableServer.POAPackage.ObjectNotActive;
       
    64 import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
       
    65 import org.omg.PortableServer.POAPackage.ServantNotActive;
       
    66 import org.omg.PortableServer.POAPackage.WrongPolicy;
       
    67 import org.omg.PortableServer.Servant;
       
    68 import org.omg.PortableServer.ServantActivator;
       
    69 import org.omg.PortableServer.ServantActivatorPOA;
       
    70 
       
    71 /**
       
    72  * This test passes with Suns JDK 1.4.08_b_03 but fails with
       
    73  * Suns JDK 1.5.0._4 (regression). It should pass with
       
    74  * Gnu Classpath.
       
    75  */
       
    76 public final class TestActivate
       
    77   extends TestBase
       
    78   implements Testlet
       
    79 {
       
    80   public static final String regression_note =
       
    81     "This is known regression 1.4.08_b_03 -> 1.5.0._4";
       
    82 
       
    83   final class TestActivator_impl
       
    84     extends ServantActivatorPOA
       
    85   {
       
    86     private byte[] oid_;
       
    87     private POA poa_;
       
    88     private Servant servant_;
       
    89     private boolean valid_;
       
    90 
       
    91     void expect(byte[] oid, POA poa, Servant servant)
       
    92     {
       
    93       oid_ = oid;
       
    94       poa_ = poa;
       
    95       servant_ = servant;
       
    96       valid_ = false;
       
    97     }
       
    98 
       
    99     boolean isValid()
       
   100     {
       
   101       return valid_;
       
   102     }
       
   103 
       
   104     public Servant incarnate(byte[] oid, POA poa)
       
   105                       throws ForwardRequest
       
   106     {
       
   107       return null;
       
   108     }
       
   109 
       
   110     public void etherealize(byte[] oid, POA poa, Servant servant,
       
   111                             boolean cleanup, boolean remaining
       
   112                            )
       
   113     {
       
   114       TEST(TestUtil.Compare(oid_, oid));
       
   115       TEST(poa_._is_equivalent(poa));
       
   116       TEST(servant_ == servant);
       
   117       valid_ = true;
       
   118     }
       
   119   }
       
   120 
       
   121   private void run(ORB orb, POA root)
       
   122   {
       
   123     org.omg.CORBA.Object obj;
       
   124     POA system;
       
   125     POA nonretain;
       
   126     POA multiple;
       
   127     POA ether;
       
   128     byte[] id1;
       
   129     byte[] id2;
       
   130     byte[] id3;
       
   131     Policy[] policies;
       
   132     Test_impl servant1;
       
   133     Test_impl servant2;
       
   134     Servant tmpserv;
       
   135 
       
   136     POAManager manager = root.the_POAManager();
       
   137 
       
   138     try
       
   139       {
       
   140         manager.activate();
       
   141       }
       
   142     catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex)
       
   143       {
       
   144         fail(ex);
       
   145         throw new RuntimeException(ex);
       
   146       }
       
   147 
       
   148     //
       
   149     // Create POAs
       
   150     //
       
   151     policies = new Policy[ 3 ];
       
   152     policies [ 0 ] =
       
   153       root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
       
   154     policies [ 1 ] =
       
   155       root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID);
       
   156     policies [ 2 ] =
       
   157       root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
       
   158     try
       
   159       {
       
   160         system = root.create_POA("system_id", manager, policies);
       
   161       }
       
   162     catch (AdapterAlreadyExists ex)
       
   163       {
       
   164         fail(ex);
       
   165         throw new RuntimeException(ex);
       
   166       }
       
   167     catch (InvalidPolicy ex)
       
   168       {
       
   169         fail(ex);
       
   170         throw new RuntimeException(ex);
       
   171       }
       
   172 
       
   173     policies = new Policy[ 5 ];
       
   174     policies [ 0 ] =
       
   175       root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID);
       
   176     policies [ 1 ] =
       
   177       root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID);
       
   178     policies [ 2 ] =
       
   179       root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN);
       
   180     policies [ 3 ] =
       
   181       root.create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
       
   182     policies [ 4 ] =
       
   183       root.create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION);
       
   184     try
       
   185       {
       
   186         nonretain = root.create_POA("nonretain", manager, policies);
       
   187       }
       
   188     catch (AdapterAlreadyExists ex)
       
   189       {
       
   190         fail(ex);
       
   191         throw new RuntimeException(ex);
       
   192       }
       
   193     catch (InvalidPolicy ex)
       
   194       {
       
   195         fail(ex);
       
   196         throw new RuntimeException(ex);
       
   197       }
       
   198 
       
   199     policies = new Policy[ 3 ];
       
   200     policies [ 0 ] =
       
   201       root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
       
   202     policies [ 1 ] =
       
   203       root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID);
       
   204     policies [ 2 ] =
       
   205       root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
       
   206     try
       
   207       {
       
   208         multiple = root.create_POA("multiple_id", manager, policies);
       
   209       }
       
   210     catch (AdapterAlreadyExists ex)
       
   211       {
       
   212         fail(ex);
       
   213         throw new RuntimeException(ex);
       
   214       }
       
   215     catch (InvalidPolicy ex)
       
   216       {
       
   217         fail(ex);
       
   218         throw new RuntimeException(ex);
       
   219       }
       
   220 
       
   221     policies = new Policy[ 3 ];
       
   222     policies [ 0 ] =
       
   223       root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
       
   224     policies [ 1 ] =
       
   225       root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID);
       
   226     policies [ 2 ] =
       
   227       root.create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
       
   228     try
       
   229       {
       
   230         ether = root.create_POA("ether", manager, policies);
       
   231       }
       
   232     catch (AdapterAlreadyExists ex)
       
   233       {
       
   234         fail(ex);
       
   235         throw new RuntimeException(ex);
       
   236       }
       
   237     catch (InvalidPolicy ex)
       
   238       {
       
   239         fail(ex);
       
   240         throw new RuntimeException(ex);
       
   241       }
       
   242 
       
   243     TestActivator_impl activatorImpl = new TestActivator_impl();
       
   244     ServantActivator activator = activatorImpl._this(orb);
       
   245 
       
   246     //
       
   247     // Start tests
       
   248     //
       
   249     try
       
   250       {
       
   251         ether.set_servant_manager(activator);
       
   252       }
       
   253     catch (WrongPolicy ex)
       
   254       {
       
   255         fail(ex);
       
   256         throw new RuntimeException(ex);
       
   257       }
       
   258 
       
   259     servant1 = new Test_impl(orb, "obj1", false);
       
   260     servant2 = new Test_impl(orb, "obj2", false);
       
   261 
       
   262     //
       
   263     // Test: activate_object w/ SYSTEM_ID POA
       
   264     //
       
   265     try
       
   266       {
       
   267         id1 = system.activate_object(servant1);
       
   268         id2 = system.activate_object(servant2);
       
   269       }
       
   270     catch (ServantAlreadyActive ex)
       
   271       {
       
   272         fail(ex);
       
   273         throw new RuntimeException(ex);
       
   274       }
       
   275     catch (WrongPolicy ex)
       
   276       {
       
   277         fail(ex);
       
   278         throw new RuntimeException(ex);
       
   279       }
       
   280     TEST(!TestUtil.Compare(id1, id2));
       
   281     try
       
   282       {
       
   283         tmpserv = system.id_to_servant(id1);
       
   284       }
       
   285     catch (ObjectNotActive ex)
       
   286       {
       
   287         fail(ex);
       
   288         throw new RuntimeException(ex);
       
   289       }
       
   290     catch (WrongPolicy ex)
       
   291       {
       
   292         fail(ex);
       
   293         throw new RuntimeException(ex);
       
   294       }
       
   295 
       
   296     TEST(tmpserv == servant1);
       
   297     try
       
   298       {
       
   299         tmpserv = system.id_to_servant(id2);
       
   300       }
       
   301     catch (ObjectNotActive ex)
       
   302       {
       
   303         fail(ex);
       
   304         throw new RuntimeException(ex);
       
   305       }
       
   306     catch (WrongPolicy ex)
       
   307       {
       
   308         fail(ex);
       
   309         throw new RuntimeException(ex);
       
   310       }
       
   311     TEST(tmpserv == servant2);
       
   312 
       
   313     //
       
   314     // Test: ServantAlreadyActive exception
       
   315     //
       
   316     try
       
   317       {
       
   318         system.activate_object(servant1);
       
   319         TEST(false); // activate_object should not have succeeded
       
   320       }
       
   321     catch (ServantAlreadyActive ex)
       
   322       {
       
   323         // expected
       
   324       }
       
   325     catch (WrongPolicy ex)
       
   326       {
       
   327         fail(ex);
       
   328         throw new RuntimeException(ex);
       
   329       }
       
   330 
       
   331     try
       
   332       {
       
   333         system.activate_object(servant2);
       
   334         TEST(false); // activate_object should not have succeeded
       
   335       }
       
   336     catch (ServantAlreadyActive ex)
       
   337       {
       
   338         // expected
       
   339       }
       
   340     catch (WrongPolicy ex)
       
   341       {
       
   342         fail(ex);
       
   343         throw new RuntimeException(ex);
       
   344       }
       
   345 
       
   346     //
       
   347     // Test: deactivate_object
       
   348     //
       
   349     try
       
   350       {
       
   351         system.deactivate_object(id2);
       
   352         system.deactivate_object(id1);
       
   353       }
       
   354     catch (ObjectNotActive ex)
       
   355       {
       
   356         fail(ex);
       
   357         throw new RuntimeException(ex);
       
   358       }
       
   359     catch (WrongPolicy ex)
       
   360       {
       
   361         fail(ex);
       
   362         throw new RuntimeException(ex);
       
   363       }
       
   364 
       
   365     //
       
   366     // Test: ObjectNotActive exception
       
   367     //
       
   368     try
       
   369       {
       
   370         system.deactivate_object(id1);
       
   371         TEST(false); // deactivate_object should not have succeeded
       
   372       }
       
   373     catch (ObjectNotActive ex)
       
   374       {
       
   375         // expected
       
   376       }
       
   377     catch (WrongPolicy ex)
       
   378       {
       
   379         fail(ex);
       
   380         throw new RuntimeException(ex);
       
   381       }
       
   382 
       
   383     try
       
   384       {
       
   385         system.deactivate_object(id2);
       
   386         TEST(false); // deactivate_object should not have succeeded
       
   387       }
       
   388     catch (ObjectNotActive ex)
       
   389       {
       
   390         // expected
       
   391       }
       
   392     catch (WrongPolicy ex)
       
   393       {
       
   394         fail(ex);
       
   395         throw new RuntimeException(ex);
       
   396       }
       
   397 
       
   398     //
       
   399     // Test: WrongPolicy exception
       
   400     //
       
   401     try
       
   402       {
       
   403         nonretain.activate_object(servant1);
       
   404         TEST(false); // activate_object should not have succeeded
       
   405       }
       
   406     catch (WrongPolicy ex)
       
   407       {
       
   408         // expected
       
   409       }
       
   410     catch (ServantAlreadyActive ex)
       
   411       {
       
   412         fail(ex);
       
   413         throw new RuntimeException(ex);
       
   414       }
       
   415 
       
   416     try
       
   417       {
       
   418         byte[] id = ("XXX").getBytes();
       
   419         nonretain.activate_object_with_id(id, servant1);
       
   420         TEST(false); // activate_object_with_id should not have succeeded
       
   421       }
       
   422     catch (WrongPolicy ex)
       
   423       {
       
   424         // expected
       
   425       }
       
   426     catch (ServantAlreadyActive ex)
       
   427       {
       
   428         fail(ex);
       
   429         throw new RuntimeException(ex);
       
   430       }
       
   431     catch (ObjectAlreadyActive ex)
       
   432       {
       
   433         fail(ex);
       
   434         throw new RuntimeException(ex);
       
   435       }
       
   436 
       
   437     try
       
   438       {
       
   439         byte[] id = ("XXX").getBytes();
       
   440         nonretain.deactivate_object(id);
       
   441         TEST(false); // deactivate_object should not have succeeded
       
   442       }
       
   443     catch (ObjectNotActive ex)
       
   444       {
       
   445         fail(ex);
       
   446         throw new RuntimeException(ex);
       
   447       }
       
   448     catch (WrongPolicy ex)
       
   449       {
       
   450         // expected
       
   451       }
       
   452 
       
   453     //
       
   454     // Test: activate_object w/ MULTIPLE_ID POA
       
   455     //
       
   456     try
       
   457       {
       
   458         id1 = multiple.activate_object(servant1);
       
   459         id2 = multiple.activate_object(servant1);
       
   460       }
       
   461     catch (ServantAlreadyActive ex)
       
   462       {
       
   463         fail(ex);
       
   464         throw new RuntimeException(ex);
       
   465       }
       
   466     catch (WrongPolicy ex)
       
   467       {
       
   468         fail(ex);
       
   469         throw new RuntimeException(ex);
       
   470       }
       
   471     TEST(!TestUtil.Compare(id1, id2));
       
   472     try
       
   473       {
       
   474         tmpserv = multiple.id_to_servant(id1);
       
   475       }
       
   476     catch (ObjectNotActive ex)
       
   477       {
       
   478         fail(ex);
       
   479         throw new RuntimeException(ex);
       
   480       }
       
   481     catch (WrongPolicy ex)
       
   482       {
       
   483         fail(ex);
       
   484         throw new RuntimeException(ex);
       
   485       }
       
   486     TEST(tmpserv == servant1);
       
   487     try
       
   488       {
       
   489         tmpserv = multiple.id_to_servant(id2);
       
   490       }
       
   491     catch (ObjectNotActive ex)
       
   492       {
       
   493         fail(ex);
       
   494         throw new RuntimeException(ex);
       
   495       }
       
   496     catch (WrongPolicy ex)
       
   497       {
       
   498         fail(ex);
       
   499         throw new RuntimeException(ex);
       
   500       }
       
   501     TEST(tmpserv == servant1);
       
   502 
       
   503     //
       
   504     // Test: confirm servant1 is no longer active
       
   505     //
       
   506     try
       
   507       {
       
   508         multiple.deactivate_object(id1);
       
   509         multiple.deactivate_object(id2);
       
   510       }
       
   511     catch (ObjectNotActive ex)
       
   512       {
       
   513         fail(ex);
       
   514         throw new RuntimeException(ex);
       
   515       }
       
   516     catch (WrongPolicy ex)
       
   517       {
       
   518         fail(ex);
       
   519         throw new RuntimeException(ex);
       
   520       }
       
   521 
       
   522     try
       
   523       {
       
   524         multiple.id_to_servant(id1);
       
   525       }
       
   526     catch (ObjectNotActive ex)
       
   527       {
       
   528         // expected
       
   529       }
       
   530     catch (WrongPolicy ex)
       
   531       {
       
   532         fail(ex);
       
   533         throw new RuntimeException(ex);
       
   534       }
       
   535 
       
   536     try
       
   537       {
       
   538         multiple.id_to_servant(id2);
       
   539       }
       
   540     catch (ObjectNotActive ex)
       
   541       {
       
   542         // expected
       
   543       }
       
   544     catch (WrongPolicy ex)
       
   545       {
       
   546         fail(ex);
       
   547         throw new RuntimeException(ex);
       
   548       }
       
   549 
       
   550     //
       
   551     // Test: confirm ServantActivator::etherealize is invoked on
       
   552     // deactivate
       
   553     //
       
   554     try
       
   555       {
       
   556         id1 = ether.activate_object(servant1);
       
   557         id2 = ether.activate_object(servant1);
       
   558         id3 = ether.activate_object(servant2);
       
   559       }
       
   560     catch (ServantAlreadyActive ex)
       
   561       {
       
   562         fail(ex);
       
   563         throw new RuntimeException(ex);
       
   564       }
       
   565     catch (WrongPolicy ex)
       
   566       {
       
   567         fail(ex);
       
   568         throw new RuntimeException(ex);
       
   569       }
       
   570     activatorImpl.expect(id1, ether, servant1);
       
   571     try
       
   572       {
       
   573         ether.deactivate_object(id1);
       
   574         Thread.sleep(2000);
       
   575       }
       
   576     catch (ObjectNotActive ex)
       
   577       {
       
   578         fail(ex);
       
   579         throw new RuntimeException(ex);
       
   580       }
       
   581     catch (WrongPolicy ex)
       
   582       {
       
   583         fail(ex);
       
   584         throw new RuntimeException(ex);
       
   585       }
       
   586     catch (InterruptedException ex)
       
   587     {
       
   588       fail(ex);
       
   589       throw new RuntimeException(ex);
       
   590     }
       
   591     TEST(activatorImpl.isValid(), regression_note);
       
   592     activatorImpl.expect(id2, ether, servant1);
       
   593     try
       
   594       {
       
   595         ether.deactivate_object(id2);
       
   596         Thread.sleep(2000);
       
   597       }
       
   598     catch (ObjectNotActive ex)
       
   599       {
       
   600         fail(ex);
       
   601         throw new RuntimeException(ex);
       
   602       }
       
   603     catch (WrongPolicy ex)
       
   604       {
       
   605         fail(ex);
       
   606         throw new RuntimeException(ex);
       
   607       }
       
   608     catch (InterruptedException ex)
       
   609     {
       
   610       fail(ex);
       
   611       throw new RuntimeException(ex);
       
   612     }
       
   613     TEST(activatorImpl.isValid(), regression_note);
       
   614     activatorImpl.expect(id3, ether, servant2);
       
   615     try
       
   616       {
       
   617         ether.deactivate_object(id3);
       
   618         Thread.sleep(2000);
       
   619       }
       
   620     catch (ObjectNotActive ex)
       
   621       {
       
   622         fail(ex);
       
   623         throw new RuntimeException(ex);
       
   624       }
       
   625     catch (WrongPolicy ex)
       
   626       {
       
   627         fail(ex);
       
   628         throw new RuntimeException(ex);
       
   629       }
       
   630     catch (InterruptedException ex)
       
   631     {
       
   632       fail(ex);
       
   633       throw new RuntimeException(ex);
       
   634     }
       
   635     TEST(activatorImpl.isValid(), "Regression in 1.5");
       
   636 
       
   637     system.destroy(true, true);
       
   638     nonretain.destroy(true, true);
       
   639     multiple.destroy(true, true);
       
   640     ether.destroy(true, true);
       
   641 
       
   642     //
       
   643     // Since activatorImpl is a stack-based servant, we need to deactivate
       
   644     // it before it goes out of scope
       
   645     //
       
   646     byte[] id = null;
       
   647     try
       
   648       {
       
   649         id = root.servant_to_id(activatorImpl);
       
   650       }
       
   651     catch (ServantNotActive ex)
       
   652       {
       
   653         fail(ex);
       
   654         throw new RuntimeException(ex);
       
   655       }
       
   656     catch (WrongPolicy ex)
       
   657       {
       
   658         fail(ex);
       
   659         throw new RuntimeException(ex);
       
   660       }
       
   661     try
       
   662       {
       
   663         root.deactivate_object(id);
       
   664       }
       
   665     catch (ObjectNotActive ex)
       
   666       {
       
   667         fail(ex);
       
   668         throw new RuntimeException(ex);
       
   669       }
       
   670     catch (WrongPolicy ex)
       
   671       {
       
   672         fail(ex);
       
   673         throw new RuntimeException(ex);
       
   674       }
       
   675 
       
   676     tmpserv = null;
       
   677     servant1 = null;
       
   678     servant2 = null;
       
   679   }
       
   680 
       
   681   public void testIt()
       
   682   {
       
   683     java.util.Properties props = System.getProperties();
       
   684 
       
   685     ORB orb = null;
       
   686 
       
   687     orb = ORB.init(new String[ 0 ], props);
       
   688 
       
   689     POA root = TestUtil.GetRootPOA(orb);
       
   690 
       
   691     run(orb, root);
       
   692 
       
   693     if (orb != null)
       
   694       {
       
   695         orb.destroy();
       
   696       }
       
   697   }
       
   698 
       
   699   public void test(TestHarness a_harness)
       
   700   {
       
   701     harness = a_harness;
       
   702     testIt();
       
   703   }
       
   704 }