db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker FarAwayReferenceIF.java JUnitExtensions.java AllTests.java FarAwayClass.java FarAwayReference.java MultipleDBTest.java ReferenceTest.java
Date Thu, 22 May 2003 19:39:43 GMT
arminw      2003/05/22 12:39:42

  Modified:    src/test/org/apache/ojb/broker/metadata MetadataTest.java
               src/test/org/apache/ojb/broker AllTests.java
                        FarAwayClass.java FarAwayReference.java
                        MultipleDBTest.java ReferenceTest.java
  Added:       src/test/org/apache/ojb/broker/metadata
                        MetadataMultithreadedTest.java
               src/test/org/apache/ojb/broker FarAwayReferenceIF.java
                        JUnitExtensions.java
  Log:
  - update test cases using references
  - add extension for junit to run
  multithreaded test cases
  - update metadata test case
  
  Revision  Changes    Path
  1.7       +2 -176    db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java
  
  Index: MetadataTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MetadataTest.java	26 Feb 2003 00:30:29 -0000	1.6
  +++ MetadataTest.java	22 May 2003 19:39:42 -0000	1.7
  @@ -1,16 +1,13 @@
   package org.apache.ojb.broker.metadata;
   
   import junit.framework.TestCase;
  -import org.apache.ojb.broker.PBFactoryException;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.TestHelper;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  -import org.apache.ojb.broker.sequence.SMMaxA;
   import org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl;
   import org.apache.ojb.odmg.OJB;
   import org.apache.ojb.odmg.collections.DListImpl;
  @@ -77,7 +74,7 @@
   
           ConnectionRepository mergedCR = mm.connectionRepository();
           JdbcConnectionDescriptor jcd = mergedCR.getDescriptor(new PBKey("runtime"));
  -        assertNotNull("Runtime merge of ConnectionRepository failed",jcd);
  +        assertNotNull("Runtime merge of ConnectionRepository failed", jcd);
       }
   
       public void testRuntimeMergeDescriptorRepository() throws Exception
  @@ -88,41 +85,7 @@
   
           DescriptorRepository mergedDR = mm.getRepository();
           ClassDescriptor cld = mergedDR.getDescriptorFor(MetadataTest.CldTestObject.class);
  -        assertNotNull("Runtime merge of DescriptorRepository failed",cld);
  -    }
  -
  -    public void testRuntimeMetadataChanges() throws Exception
  -    {
  -        int loops = 10;
  -        // enable the per thread changes of metadata
  -        MetadataManager.getInstance().setEnablePerThreadChanges(true);
  -        long period = System.currentTimeMillis();
  -        GlobalUsingBroker gub = new GlobalUsingBroker(loops);
  -        ThreadedUsingBroker tub = new ThreadedUsingBroker(loops);
  -        ThreadGroup metadata = new ThreadGroup("metadata");
  -        new Thread(metadata, gub).start();
  -        new Thread(metadata, tub).start();
  -        while (metadata.activeCount() > 0)
  -        {
  -            Thread.sleep(50);
  -        }
  -        period = System.currentTimeMillis() - period;
  -        System.out.println("RuntimeMetadataChanges test take: " + period + " ms");
  -        MetadataManager.getInstance().setEnablePerThreadChanges(false);
  -
  -        PersistenceBroker broker = null;
  -        try
  -        {
  -            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            ClassDescriptor cld = broker.getClassDescriptor(SMMaxA.class);
  -            String name = cld.getClassNameOfObject();
  -            assertEquals(SMMaxA.class.getName(), name);
  -            assertFalse(MetadataManager.getInstance().isEnablePerThreadChanges());
  -        }
  -        finally
  -        {
  -            if (broker != null) broker.close();
  -        }
  +        assertNotNull("Runtime merge of DescriptorRepository failed", cld);
       }
   
       /**
  @@ -329,143 +292,6 @@
           assertNotNull(seq.getAttribute("key2"));
           assertEquals("value2", seq.getAttribute("key2"));
       }
  -
  -
  -
  -
  -    // ======================================================================
  -    // inner test class
  -    // ======================================================================
  -    class GlobalUsingBroker implements Runnable
  -    {
  -        int loops;
  -
  -        public GlobalUsingBroker(int loops)
  -        {
  -            this.loops = loops;
  -        }
  -
  -        public void run()
  -        {
  -            PersistenceBroker broker = null;
  -            int k = 0;
  -            try
  -            {
  -                while (k < loops)
  -                {
  -                    try
  -                    {
  -                        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                        ClassDescriptor cld = broker.getClassDescriptor(SMMaxA.class);
  -                        String name = cld.getClassNameOfObject();
  -                        assertEquals(SMMaxA.class.getName(), name);
  -                        assertTrue(MetadataManager.getInstance().isEnablePerThreadChanges());
  -                    }
  -                    finally
  -                    {
  -                        if (broker != null) broker.close();
  -                    }
  -                    try
  -                    {
  -                        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                        ClassDescriptor cld = broker.getClassDescriptor(SMMaxA.class);
  -                        String name = cld.getClassNameOfObject();
  -                        assertEquals(SMMaxA.class.getName(), name);
  -                        // System.out.println("Default: found "+name);
  -                    }
  -                    finally
  -                    {
  -                        if (broker != null) broker.close();
  -                    }
  -
  -                    k++;
  -                    try
  -                    {
  -                        Thread.sleep(50);
  -                    }
  -                    catch (InterruptedException e)
  -                    {
  -                    }
  -                }
  -            }
  -            catch (PBFactoryException e)
  -            {
  -                e.printStackTrace();
  -            }
  -            catch (PersistenceBrokerException e)
  -            {
  -            }
  -        }
  -    }
  -
  -
  -
  -    // ======================================================================
  -    // inner test class
  -    // ======================================================================
  -    class ThreadedUsingBroker implements Runnable
  -    {
  -        int loops;
  -
  -        public ThreadedUsingBroker(int loops)
  -        {
  -            this.loops = loops;
  -        }
  -
  -        public void run()
  -        {
  -            MetadataManager mm = MetadataManager.getInstance();
  -            DescriptorRepository dr = mm.copyOfGlobalRepository();
  -            ClassDescriptor cld = dr.getDescriptorFor(SMMaxA.class);
  -            // we change the class descriptor
  -            cld.setClassOfObject(null);
  -            // set the changed repository for this thread
  -            mm.setPerThreadDescriptor(dr);
  -
  -            int k = 0;
  -            while (k < loops)
  -            {
  -                PersistenceBroker broker = null;
  -                try
  -                {
  -                    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                    cld = broker.getClassDescriptor(SMMaxA.class);
  -                    String name = cld.getClassNameOfObject();
  -                    assertNull(name);
  -                    assertTrue(MetadataManager.getInstance().isEnablePerThreadChanges());
  -                }
  -                finally
  -                {
  -                    if (broker != null) broker.close();
  -                }
  -
  -                try
  -                {
  -                    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                    cld = broker.getClassDescriptor(SMMaxA.class);
  -                    String name = cld.getClassNameOfObject();
  -                    assertNull(name);
  -                    // System.out.println("Changed: found "+name);
  -                }
  -                finally
  -                {
  -                    if (broker != null) broker.close();
  -                }
  -
  -                k++;
  -                try
  -                {
  -                    Thread.sleep(50);
  -                }
  -                catch (InterruptedException e)
  -                {
  -                }
  -            }
  -
  -        }
  -    }
  -
  -
   
   
       // ======================================================================
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataMultithreadedTest.java
  
  Index: MetadataMultithreadedTest.java
  ===================================================================
  package org.apache.ojb.broker.metadata;
  
  import org.apache.ojb.broker.JUnitExtensions;
  import org.apache.ojb.broker.OJBRuntimeException;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  import org.apache.ojb.broker.sequence.SMMaxA;
  
  /**
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: MetadataMultithreadedTest.java,v 1.1 2003/05/22 19:39:42 arminw Exp $
   */
  public class MetadataMultithreadedTest extends JUnitExtensions.MultiThreadedTestCase
  {
      private String newTestObjectString = "test_string";
      private String oldTestObjectString;
      private Class targetTestClass = SMMaxA.class;
  
      public MetadataMultithreadedTest(String s)
      {
          super(s);
      }
  
      public static void main(String[] args)
      {
          String[] arr = {MetadataMultithreadedTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      private String getTestObjectString()
      {
          return oldTestObjectString;
      }
  
      public void testRuntimeMetadataChanges() throws Exception
      {
          int loops = 10;
          PersistenceBroker broker = null;
          try
          {
              // enable the per thread changes of metadata
              MetadataManager.getInstance().setEnablePerThreadChanges(true);
  
              long period = System.currentTimeMillis();
              broker = PersistenceBrokerFactory.defaultPersistenceBroker();
              ClassDescriptor cld = broker.getClassDescriptor(targetTestClass);
  
              // we manipulate the schema name of the class
              // thus we note the original value
              oldTestObjectString = cld.getSchema();
              broker.close();
  
              TestCaseRunnable tct [] = new TestCaseRunnable[10];
              for (int i = 0; i < 10; i++)
              {
                  if (i < 5)
                      tct[i] = new ThreadedUsingBroker(loops);
                  else
                      tct[i] = new GlobalUsingBroker(loops);
              }
              // run test classes
              runTestCaseRunnables(tct);
  
              period = System.currentTimeMillis() - period;
              System.out.println("RuntimeMetadataChanges test take: " + period + " ms");
              MetadataManager.getInstance().setEnablePerThreadChanges(false);
  
              broker = PersistenceBrokerFactory.defaultPersistenceBroker();
              cld = broker.getClassDescriptor(targetTestClass);
              String name = cld.getSchema();
              assertEquals(oldTestObjectString, name);
              assertFalse(MetadataManager.getInstance().isEnablePerThreadChanges());
          }
          finally
          {
              if (broker != null) broker.close();
          }
      }
  
      // ======================================================================
      // inner test class
      // ======================================================================
      class ThreadedUsingBroker extends JUnitExtensions.MultiThreadedTestCase.TestCaseRunnable
      {
          int loops;
  
          public ThreadedUsingBroker()
          {
          }
  
          public ThreadedUsingBroker(int loops)
          {
              this.loops = loops;
          }
  
          public void runTestCase()
          {
              MetadataManager mm = MetadataManager.getInstance();
              DescriptorRepository dr = mm.copyOfGlobalRepository();
              ClassDescriptor cld = dr.getDescriptorFor(targetTestClass);
              // we change a class descriptor value
              cld.setSchema(newTestObjectString);
              // set the changed repository for this thread
              mm.setPerThreadDescriptor(dr);
  
              int k = 0;
              while (k < loops)
              {
                  PersistenceBroker broker = null;
                  try
                  {
                      broker = PersistenceBrokerFactory.defaultPersistenceBroker();
                      cld = broker.getClassDescriptor(targetTestClass);
                      String name = cld.getSchema();
                      assertEquals(newTestObjectString, name);
                      assertTrue(MetadataManager.getInstance().isEnablePerThreadChanges());
                  }
                  finally
                  {
                      if (broker != null) broker.close();
                  }
  
                  try
                  {
                      broker = PersistenceBrokerFactory.defaultPersistenceBroker();
                      cld = broker.getClassDescriptor(targetTestClass);
                      String name = cld.getSchema();
                      assertEquals(newTestObjectString, name);
                      assertTrue(MetadataManager.getInstance().isEnablePerThreadChanges());
                  }
                  finally
                  {
                      if (broker != null) broker.close();
                  }
  
                  k++;
                  try
                  {
                      Thread.sleep(5);
                  }
                  catch (InterruptedException e)
                  {
                  }
              }
  
          }
      }
  
      // ======================================================================
      // inner test class
      // ======================================================================
      class GlobalUsingBroker extends JUnitExtensions.MultiThreadedTestCase.TestCaseRunnable
      {
          int loops;
  
          public GlobalUsingBroker(int loops)
          {
              this.loops = loops;
          }
  
          public void runTestCase()
          {
              PersistenceBroker broker = null;
              int k = 0;
              try
              {
                  while (k < loops)
                  {
                      try
                      {
                          broker = PersistenceBrokerFactory.defaultPersistenceBroker();
                          ClassDescriptor cld = broker.getClassDescriptor(targetTestClass);
                          assertTrue(MetadataManager.getInstance().isEnablePerThreadChanges());
                          String name = cld.getSchema();
                          // this PB instance use unchanged global metadata repository
                          assertEquals(getTestObjectString(), name);
                      }
                      finally
                      {
                          if (broker != null) broker.close();
                      }
                      try
                      {
                          broker = PersistenceBrokerFactory.defaultPersistenceBroker();
                          ClassDescriptor cld = broker.getClassDescriptor(targetTestClass);
                          assertTrue(MetadataManager.getInstance().isEnablePerThreadChanges());
                          String name = cld.getSchema();
                          // this PB instance use unchanged global metadata repository
                          assertEquals(getTestObjectString(), name);
                          // System.out.println("Default: found "+name);
                      }
                      finally
                      {
                          if (broker != null) broker.close();
                      }
  
                      k++;
                      try
                      {
                          Thread.sleep(5);
                      }
                      catch (InterruptedException e)
                      {
                      }
                  }
              }
              catch (Exception e)
              {
                  e.printStackTrace();
                  throw new OJBRuntimeException(e);
              }
          }
      }
  }
  
  
  
  1.28      +2 -0      db-ojb/src/test/org/apache/ojb/broker/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AllTests.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- AllTests.java	9 May 2003 23:58:18 -0000	1.27
  +++ AllTests.java	22 May 2003 19:39:42 -0000	1.28
  @@ -6,6 +6,7 @@
   import org.apache.ojb.broker.metadata.MetadataTest;
   import org.apache.ojb.broker.metadata.RepositoryPersistorTest;
   import org.apache.ojb.broker.metadata.RepositoryElementsTest;
  +import org.apache.ojb.broker.metadata.MetadataMultithreadedTest;
   import org.apache.ojb.broker.sequence.SequenceManagerTest;
   import org.apache.ojb.broker.sequence.NativeIdentifierTest;
   
  @@ -67,6 +68,7 @@
           suite.addTest(new TestSuite(OneToOneTest.class));
           suite.addTest(new TestSuite(MetaDataSerializationTest.class));
           suite.addTest(new TestSuite(MetadataTest.class));
  +        suite.addTest(new TestSuite(MetadataMultithreadedTest.class));
           suite.addTest(new TestSuite(FieldConversionTest.class));
           suite.addTest(new TestSuite(FieldConversionTest_2.class));
           suite.addTest(new TestSuite(FieldConversionTest_3.class));
  
  
  
  1.4       +4 -4      db-ojb/src/test/org/apache/ojb/broker/FarAwayClass.java
  
  Index: FarAwayClass.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/FarAwayClass.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FarAwayClass.java	1 Apr 2003 14:06:11 -0000	1.3
  +++ FarAwayClass.java	22 May 2003 19:39:42 -0000	1.4
  @@ -13,7 +13,7 @@
       private int id;
       private String description;
       private Integer referenceId;
  -    private FarAwayReference reference;
  +    private FarAwayReferenceIF reference;
   
       public int getId()
       {
  @@ -25,12 +25,12 @@
           this.id = id;
       }
   
  -    public FarAwayReference getReference()
  +    public FarAwayReferenceIF getReference()
       {
           return reference;
       }
   
  -    public void setReference(FarAwayReference reference)
  +    public void setReference(FarAwayReferenceIF reference)
       {
           this.reference = reference;
       }
  
  
  
  1.3       +3 -2      db-ojb/src/test/org/apache/ojb/broker/FarAwayReference.java
  
  Index: FarAwayReference.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/FarAwayReference.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FarAwayReference.java	1 Apr 2003 14:06:11 -0000	1.2
  +++ FarAwayReference.java	22 May 2003 19:39:42 -0000	1.3
  @@ -7,7 +7,8 @@
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class FarAwayReference implements Serializable
  +public class FarAwayReference
  +        implements FarAwayReferenceIF
   {
       private String name;
       private int id;
  
  
  
  1.10      +56 -15    db-ojb/src/test/org/apache/ojb/broker/MultipleDBTest.java
  
  Index: MultipleDBTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MultipleDBTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MultipleDBTest.java	7 Apr 2003 16:01:44 -0000	1.9
  +++ MultipleDBTest.java	22 May 2003 19:39:42 -0000	1.10
  @@ -7,6 +7,7 @@
   import org.apache.ojb.broker.query.Criteria;
   
   import java.sql.Connection;
  +import java.io.Serializable;
   
   /**
    * Test to check support for multiple DB.
  @@ -15,6 +16,8 @@
    */
   public class MultipleDBTest extends TestCase
   {
  +    private static final String REFERENCE_NAME = "Test reference";
  +
       public MultipleDBTest(String s)
       {
           super(s);
  @@ -247,6 +250,22 @@
           FarAwayClass f1 = doReferenceMatchingStore(secKey);
           FarAwayClass f2 = doReferenceMatchingStore(secKey);
   
  +        PersistenceBroker broker = null;
  +        try
  +        {
  +            broker = PersistenceBrokerFactory.createPersistenceBroker(secKey);
  +            broker.clearCache();
  +            Identity oid = new Identity(f1,broker);
  +            FarAwayClass fac = (FarAwayClass) broker.getObjectByIdentity(oid);
  +            FarAwayReferenceIF ref = fac.getReference();
  +            assertNotNull(ref);
  +            assertEquals(REFERENCE_NAME, ref.getName());
  +        }
  +        finally
  +        {
  +            if(broker != null) broker.close();
  +        }
  +
           doReferenceMatchingDelete(secKey, f1);
           doReferenceMatchingDelete(secKey, f2);
       }
  @@ -254,8 +273,8 @@
       private FarAwayClass doReferenceMatchingStore(PBKey key) throws Exception
       {
           FarAwayClass fa = createFarAwayObject();
  -        FarAwayReference ref = new FarAwayReference();
  -        ref.setName("Test reference");
  +        FarAwayReferenceIF ref = new FarAwayReference();
  +        ref.setName(REFERENCE_NAME);
   
           PersistenceBroker farAwayPB = PersistenceBrokerFactory.createPersistenceBroker(key);
           farAwayPB.beginTransaction();
  @@ -280,20 +299,42 @@
       private void doReferenceMatchingDelete(PBKey key, FarAwayClass farAwayClass) throws
Exception
       {
           Integer refId = farAwayClass.getReferenceId();
  +        Integer mainId = new Integer(farAwayClass.getId());
           PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(key);
  -        broker.beginTransaction();
  -        broker.delete(farAwayClass);
  -        broker.commitTransaction();
  -        broker.close();
  -
  -        broker = PersistenceBrokerFactory.createPersistenceBroker(key);
  -        Criteria criteria = new Criteria();
  -        criteria.addEqualTo("id", refId);
  -        FarAwayReference result = (FarAwayReference) broker.getObjectByQuery(
  -                new QueryByCriteria(FarAwayClass.class, criteria));
  -        broker.close();
  -
  -        assertNull("Reference was not deleted", result);
  +        try
  +        {
  +            Criteria criteria = new Criteria();
  +            criteria.addEqualTo("id", mainId);
  +            FarAwayClass result = (FarAwayClass) broker.getObjectByQuery(
  +                    new QueryByCriteria(FarAwayClass.class, criteria));
  +            assertNotNull("Object not found", result);
  +
  +            Criteria criteriaRef = new Criteria();
  +            criteriaRef.addEqualTo("id", refId);
  +            FarAwayReferenceIF resultRef = (FarAwayReferenceIF) broker.getObjectByQuery(
  +                    new QueryByCriteria(FarAwayReference.class, criteriaRef));
  +            assertNotNull("Object not found", result);
  +
  +            broker.beginTransaction();
  +            broker.delete(farAwayClass);
  +            broker.commitTransaction();
  +
  +            criteria = new Criteria();
  +            criteria.addEqualTo("id", mainId);
  +            result = (FarAwayClass) broker.getObjectByQuery(
  +                    new QueryByCriteria(FarAwayClass.class, criteria));
  +            assertNull("Object was not deleted", result);
  +
  +            criteriaRef = new Criteria();
  +            criteriaRef.addEqualTo("id", refId);
  +            resultRef = (FarAwayReferenceIF) broker.getObjectByQuery(
  +                    new QueryByCriteria(FarAwayReference.class, criteriaRef));
  +            assertNull("Reference object was not deleted", resultRef);
  +        }
  +        finally
  +        {
  +            if(broker != null) broker.close();
  +        }
       }
   
   
  
  
  
  1.5       +24 -12    db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java
  
  Index: ReferenceTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReferenceTest.java	1 Apr 2003 14:06:11 -0000	1.4
  +++ ReferenceTest.java	22 May 2003 19:39:42 -0000	1.5
  @@ -17,6 +17,7 @@
    */
   public class ReferenceTest extends TestCase
   {
  +    private static String REF_TEST_STRING = "refTest";
       private PersistenceBroker broker;
   
       public static void main(String[] args)
  @@ -63,6 +64,8 @@
           assertNotNull(repository[0].getRef());
           assertNotNull(repository[0].getRefA());
           assertNotNull(repository[0].getRefB());
  +        // lookup reference name, set in prepareRepository method
  +        assertEquals(repository[0].getRefB().getRefNameB(), REF_TEST_STRING);
       }
   
       public void testReferenceGetByIdentity()
  @@ -84,6 +87,7 @@
           Identity oid_refA = new Identity(repository[0].getRefA(), broker);
           Identity oid_refB = new Identity(repository[0].getRefB(), broker);
   
  +        broker.clearCache();
           Object result;
           result = broker.getObjectByIdentity(oid_ref);
           assertTrue(result instanceof Reference);
  @@ -91,6 +95,14 @@
           assertTrue(result instanceof ReferenceA);
           result = broker.getObjectByIdentity(oid_refB);
           assertTrue(result instanceof ReferenceB);
  +
  +        broker.clearCache();
  +        Identity repOID = new Identity(repository[0], broker);
  +        Repository repositoryObj = (Repository) broker.getObjectByIdentity(repOID);
  +        assertNotNull(repositoryObj);
  +        ReferenceBIF refB = repositoryObj.getRefB();
  +        assertNotNull(refB);
  +        assertEquals(refB.getRefNameB(), REF_TEST_STRING);
       }
   
       public void testQueryReferences()
  @@ -223,7 +235,7 @@
               new ReferenceA(referenceNamePrefix + "refA_2", "a2"),
               new ReferenceA(referenceNamePrefix + "refA_3", "a3")};
           ReferenceB[] refB = new ReferenceB[]{
  -            new ReferenceB(referenceNamePrefix + "refB_1", "b1"),
  +            new ReferenceB(referenceNamePrefix + "refB_1", REF_TEST_STRING),
               new ReferenceB(referenceNamePrefix + "refB_2", "b2"),
               new ReferenceB(referenceNamePrefix + "refB_3", "b3")};
   
  @@ -256,7 +268,7 @@
               new ReferenceA(referenceNamePrefix + "refA_2", "a2"),
               new ReferenceA(referenceNamePrefix + "refA_3", "a3")};
           ReferenceB[] refB = new ReferenceB[]{
  -            new ReferenceB(referenceNamePrefix + "refB_1", "b1"),
  +            new ReferenceB(referenceNamePrefix + "refB_1", REF_TEST_STRING),
               new ReferenceB(referenceNamePrefix + "refB_2", "b2"),
               new ReferenceB(referenceNamePrefix + "refB_3", "b3")};
   
  @@ -292,40 +304,40 @@
           private Integer refAId;
           private Integer refBId;
   
  -        private Reference ref;
  -        private ReferenceA refA;
  -        private ReferenceB refB;
  +        private ReferenceIF ref;
  +        private ReferenceAIF refA;
  +        private ReferenceBIF refB;
   
           public Repository()
           {
           }
   
  -        public Reference getRef()
  +        public ReferenceIF getRef()
           {
               return ref;
           }
   
  -        public void setRef(Reference ref)
  +        public void setRef(ReferenceIF ref)
           {
               this.ref = ref;
           }
   
  -        public ReferenceA getRefA()
  +        public ReferenceAIF getRefA()
           {
               return refA;
           }
   
  -        public void setRefA(ReferenceA refA)
  +        public void setRefA(ReferenceAIF refA)
           {
               this.refA = refA;
           }
   
  -        public ReferenceB getRefB()
  +        public ReferenceBIF getRefB()
           {
               return refB;
           }
   
  -        public void setRefB(ReferenceB refB)
  +        public void setRefB(ReferenceBIF refB)
           {
               this.refB = refB;
           }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/FarAwayReferenceIF.java
  
  Index: FarAwayReferenceIF.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import java.io.Serializable;
  
  /**
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: FarAwayReferenceIF.java,v 1.1 2003/05/22 19:39:42 arminw Exp $
   */
  public interface FarAwayReferenceIF extends Serializable
  {
      int getId();
  
      void setId(int id);
  
      String getName();
  
      void setName(String name);
  
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/JUnitExtensions.java
  
  Index: JUnitExtensions.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import junit.framework.AssertionFailedError;
  import junit.framework.TestCase;
  import junit.framework.TestResult;
  
  /**
   * Extensions for junit to write test cases for multithreaded tests.
   * All classes are from an
   * <a href="http://www.javaworld.com/javaworld/jw-12-2000/jw-1221-junit.html">
   * javaworld article</a> about junit.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: JUnitExtensions.java,v 1.1 2003/05/22 19:39:42 arminw Exp $
   */
  public class JUnitExtensions
  {
      /**
       * A multi-threaded JUnit test case.
       * To perform test cases that spin off threads to do tests: <p>
       * <UL>
       * <LI>Extend <code>MultiThreadedTestCase</code>
       * <LI>Write your tests cases as normal except for when you want to spin off threads.
       * <LI>When you want to spin off threads:
       * <UL>
       * <LI>Instead of implementing <code>Runnable</code> extend <code>MultiThreadedTestCase.TestCaseRunnable</code>.
       * <LI>Define <code>runTestCase ()</code> to do your test, you may
call <code>fail (), assert ()</code> etc. and throw
       * exceptions with impunity.
       * <LI>Handle thread interrupts by finishing.
       * </UL>
       * <LI>Instantiate all the runnables (one for each thread you wish to spawn) and
pass an array of them
       * to <code>runTestCaseRunnables ()</code>.
       * </UL>
       * That's it. An example is below:
       * <PRE>
       * public class MTTest extends JUnitExtensions.MultiThreadedTestCase
       * {
       *   MTTest (String s) { super (s); }
       *   public class CounterThread extends JUnitExtensions.TestCaseRunnable
       *   {
       *     public void runTestCase () throws Throwable
       *     {
       *       for (int i = 0; i < 1000; i++)
       *       {
       *         System.out.println ("Counter Thread: " + Thread.currentThread () + " : "
+ i);
       *         // Do some testing...
       *         if (Thread.currentThread ().isInterrupted ()) {
       *           return;
       *         }
       *       }
       *     }
       *   }
       *
       *   public void test1 ()
       *   {
       *     TestCaseRunnable tct [] = new TestCaseRunnable [5];
       *     for (int i = 0; i < 5; i++)
       *     {
       *       tct[i] = new CounterThread ();
       *      }
       *     runTestCaseRunnables (tct);
       *   }
       * }
       * </PRE>
       * <BR><STRONG>Category: Test</STRONG>
       * <BR><STRONG>Not guaranteed to be thread safe.</STRONG>
       */
      public static class MultiThreadedTestCase extends TestCase
      {
          /**
           * The threads that are executing.
           */
          private Thread threads[] = null;
          /**
           * The tests TestResult.*/
          private TestResult testResult = null;
  
          /**
           * Simple constructor.
           */
  
          public MultiThreadedTestCase(String s)
          {
              super(s);
          }
  
          /**
           * Interrupt the running threads.
           */
          public void interruptThreads()
          {
              if (threads != null)
              {
                  for (int i = 0; i < threads.length; i++)
                  {
                      threads[i].interrupt();
                  }
              }
          }
  
          /**
           * Override run so we can squirrel away the test result.*/
  
          public void run(final TestResult result)
          {
              testResult = result;
              super.run(result);
              testResult = null;
          }
  
          /**
           * Run the test case threads.*/
  
          protected void runTestCaseRunnables(final TestCaseRunnable[] runnables)
          {
              if (runnables == null)
              {
                  throw new IllegalArgumentException("runnables is null");
              }
              threads = new Thread[runnables.length];
              for (int i = 0; i < threads.length; i++)
              {
                  threads[i] = new Thread(runnables[i]);
              }
              for (int i = 0; i < threads.length; i++)
              {
                  threads[i].start();
              }
              try
              {
                  for (int i = 0; i < threads.length; i++)
                  {
                      threads[i].join();
                  }
              }
              catch (InterruptedException ignore)
              {
                  System.out.println("Thread join interrupted.");
              }
              threads = null;
          }
  
          /**
           * Handle an exception. Since multiple threads won't have their
           * exceptions caught the threads must manually catch them and call
           * <code>handleException ()</code>.
           * @param t Exception to handle.
           */
          private void handleException(final Throwable t)
          {
              synchronized (testResult)
              {
                  if (t instanceof AssertionFailedError)
                  {
                      testResult.addFailure(this, (AssertionFailedError) t);
                  }
                  else
                  {
                      testResult.addError(this, t);
                  }
              }
          }
  
          // ======================================================================
          // inner class
          // ======================================================================
          /**
           * A test case thread. Override runTestCase () and define
           * behaviour of test in there.*/
          protected abstract class TestCaseRunnable implements Runnable
          {
              /**
               * Override this to define the test*/
  
              public abstract void runTestCase()
                      throws Throwable;
  
              /**
               * Run the test in an environment where
               * we can handle the exceptions generated by the test method.*/
  
              public void run()
              {
                  try
                  {
                      runTestCase();
                  }
                  catch (Throwable t) /* Any other exception we handle and then we interrupt
the other threads.*/
                  {
                      handleException(t);
                      interruptThreads();
                  }
              }
          }
      }
  }
  
  
  

Mime
View raw message