hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r430360 - in /hivemind/branches/branch-2-0-annot/framework/src: java/org/apache/hivemind/definition/ java/org/apache/hivemind/impl/ java/org/apache/hivemind/internal/ test/hivemind/test/ test/hivemind/test/services/ test/org/apache/hivemind...
Date Thu, 10 Aug 2006 12:02:01 GMT
Author: ahuegen
Date: Thu Aug 10 05:01:57 2006
New Revision: 430360

URL: http://svn.apache.org/viewvc?rev=430360&view=rev
Log:
Switched more unit tests in framework from xml to registry api.


Removed:
    hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/EagerLoadPooled.xml
    hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/EagerLoadPrimitive.xml
    hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/EagerLoadSingleton.xml
    hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/EagerLoadThreaded.xml
    hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/servicemodel/ShutdownListenerServices.xml
    hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/SerIntegration.xml
Modified:
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/RegistryDefinition.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/CoreServicesProvider.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServiceModel.java
    hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/ModuleDefinitionHelper.java
    hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestEagerLoader.java
    hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestShutdown.java
    hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/servicemodel/TestRegistryShutdownListenerServices.java
    hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/AdderWrapper.java
    hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/TestServiceSerializationHelper.java

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java
Thu Aug 10 05:01:57 2006
@@ -157,5 +157,20 @@
         UnresolvedExtension unresolvedExtension = new UnresolvedExtension(contribution,
                 qualifiedConfigurationPointId);
         _unresolvedContributions.add(unresolvedExtension);
+    }
+
+    public List getContributions()
+    {
+        return _unresolvedContributions;
+    }
+
+    public List getImplementations()
+    {
+        return _unresolvedImplementations;
+    }
+
+    public List getInterceptors()
+    {
+        return _unresolvedInterceptors;
     }    
 }

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/RegistryDefinition.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/RegistryDefinition.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/RegistryDefinition.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/RegistryDefinition.java
Thu Aug 10 05:01:57 2006
@@ -133,14 +133,19 @@
      */
     public void resolveExtensions()
     {
-        resolveImplementations();
-        resolveInterceptors();
-        resolveConfigurations();
+        for (Iterator iterModules = _modules.values().iterator(); iterModules.hasNext();)
+        {
+            ModuleDefinition module = (ModuleDefinition) iterModules.next();
+        
+            resolveImplementations(module);
+            resolveInterceptors(module);
+            resolveConfigurations(module);
+        }
     }
 
-    public void resolveImplementations()
+    public void resolveImplementations(ModuleDefinition module)
     {
-        for (Iterator iter = _unresolvedImplementations.iterator(); iter.hasNext();)
+        for (Iterator iter = module.getImplementations().iterator(); iter.hasNext();)
         {
             UnresolvedExtension unresolved = (UnresolvedExtension) iter.next();
             String servicePointId = unresolved.getExtensionPointId();
@@ -161,9 +166,9 @@
         }
     }
     
-    public void resolveInterceptors()
+    public void resolveInterceptors(ModuleDefinition module)
     {
-        for (Iterator iter = _unresolvedInterceptors.iterator(); iter.hasNext();)
+        for (Iterator iter = module.getInterceptors().iterator(); iter.hasNext();)
         {
             UnresolvedExtension unresolved = (UnresolvedExtension) iter.next();
             String servicePointId = unresolved.getExtensionPointId();
@@ -184,9 +189,9 @@
         }
     }
     
-    public void resolveConfigurations()
+    public void resolveConfigurations(ModuleDefinition module)
     {
-        for (Iterator iter = _unresolvedContributions.iterator(); iter.hasNext();)
+        for (Iterator iter = module.getContributions().iterator(); iter.hasNext();)
         {
             UnresolvedExtension unresolved = (UnresolvedExtension) iter.next();
             String configurationPointId = unresolved.getExtensionPointId();

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/CoreServicesProvider.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/CoreServicesProvider.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/CoreServicesProvider.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/CoreServicesProvider.java
Thu Aug 10 05:01:57 2006
@@ -80,7 +80,7 @@
     private void addClassFactory(ModuleDefinition md)
     {
         ServicePointDefinition spd = helper.addServicePoint("ClassFactory", ClassFactory.class.getName());
-        helper.addSimpleServiceImplementation(spd, ClassFactoryImpl.class.getName(), ServiceModel.PRITIMIVE);
+        helper.addSimpleServiceImplementation(spd, ClassFactoryImpl.class.getName(), ServiceModel.PRIMITIVE);
     }
 
     /**
@@ -169,7 +169,7 @@
             }
         };
         ServiceImplementationDefinition sid = new ServiceImplementationDefinition(md.getLocation(),
-                constructor, ServiceModel.PRITIMIVE, true);
+                constructor, ServiceModel.PRIMITIVE, true);
         spd.addImplementation(sid);
         
         // Configuration to which services may be contributed. The corresponding services
are instantiated eagerly, as the Registry is started. 

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServiceModel.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServiceModel.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServiceModel.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/internal/ServiceModel.java
Thu Aug 10 05:01:57 2006
@@ -24,7 +24,7 @@
  */
 public interface ServiceModel
 {
-    public static final String PRITIMIVE = "primitive";
+    public static final String PRIMITIVE = "primitive";
     public static final String SINGLETON = "singleton";
     public static final String THREADED = "threaded";
     public static final String POOLED = "pooled";

Modified: hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/ModuleDefinitionHelper.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/ModuleDefinitionHelper.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/ModuleDefinitionHelper.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/ModuleDefinitionHelper.java
Thu Aug 10 05:01:57 2006
@@ -9,6 +9,7 @@
 import org.apache.hivemind.impl.CreateClassServiceConstructor;
 import org.apache.hivemind.internal.ConfigurationConstructor;
 import org.apache.hivemind.internal.Contribution;
+import org.apache.hivemind.internal.ServiceImplementationConstructor;
 import org.apache.hivemind.internal.ServiceModel;
 import org.apache.hivemind.internal.Visibility;
 
@@ -37,16 +38,25 @@
         addSimpleServiceImplementation(result, defaultImplementationName, ServiceModel.SINGLETON);
         return result;
     }
-    
-    public ServiceImplementationDefinition addSimpleServiceImplementation(
+ 
+    public ServiceImplementationDefinition addServiceImplementation(
             ServicePointDefinition servicePoint,
-            String serviceImplementationClass, String serviceModel)
+            ServiceImplementationConstructor constructor, String serviceModel
+            )
     {
         ServiceImplementationDefinition result = new ServiceImplementationDefinition(_module
-                .getLocation(), new CreateClassServiceConstructor(_module.getLocation(),
_module.getId(),
-                serviceImplementationClass), serviceModel, true);
+                .getLocation(), constructor, serviceModel, true);
         servicePoint.addImplementation(result);
         return result;
+    }
+    
+    public ServiceImplementationDefinition addSimpleServiceImplementation(
+            ServicePointDefinition servicePoint,
+            String serviceImplementationClass, String serviceModel)
+    {
+        return addServiceImplementation(servicePoint, 
+                new CreateClassServiceConstructor(_module.getLocation(), _module.getId(),
serviceImplementationClass), 
+                serviceModel);
     }
     
     public ConfigurationPointDefinition addConfigurationPoint(String configurationPointId,


Modified: hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestEagerLoader.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestEagerLoader.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestEagerLoader.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestEagerLoader.java
Thu Aug 10 05:01:57 2006
@@ -61,7 +61,7 @@
     {
         interceptLogging("hivemind.test.services.Loud");
 
-        buildFrameworkRegistry("EagerLoadSingleton.xml");
+        createEagerLoadModule(ServiceModel.SINGLETON);
 
         assertLoggedMessage("Instantiated.");
     }
@@ -70,7 +70,7 @@
     {
         interceptLogging("hivemind.test.services.Loud");
 
-        buildFrameworkRegistry("EagerLoadPrimitive.xml");
+        createEagerLoadModule(ServiceModel.PRIMITIVE);
 
         assertLoggedMessage("Instantiated.");
     }
@@ -79,7 +79,7 @@
     {
         interceptLogging("hivemind.test.services.Loud");
 
-        buildFrameworkRegistry("EagerLoadThreaded.xml");
+        createEagerLoadModule(ServiceModel.THREADED);
 
         assertLoggedMessage("Instantiated.");
     }
@@ -94,7 +94,8 @@
     }
     
     /**
-     * 
+     * Creates a Registry with one module, that defines a Service "Loud" added to the EagerLoad

+     * configuration.
      */
     private Registry createEagerLoadModule(final String serviceModel)
     {

Modified: hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestShutdown.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestShutdown.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestShutdown.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/services/TestShutdown.java
Thu Aug 10 05:01:57 2006
@@ -132,7 +132,7 @@
 
     public void testPrimitiveCore() throws Exception
     {
-        Registry r = createModuleWithShutdownListener(ServiceModel.PRITIMIVE);
+        Registry r = createModuleWithShutdownListener(ServiceModel.PRIMITIVE);
 
         Runnable s = (Runnable) r.getService("module1.Listener", Runnable.class);
 

Modified: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/servicemodel/TestRegistryShutdownListenerServices.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/servicemodel/TestRegistryShutdownListenerServices.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/servicemodel/TestRegistryShutdownListenerServices.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/servicemodel/TestRegistryShutdownListenerServices.java
Thu Aug 10 05:01:57 2006
@@ -14,20 +14,29 @@
 
 package org.apache.hivemind.impl.servicemodel;
 
+import hivemind.test.FrameworkTestCase;
+import hivemind.test.ModuleDefinitionHelper;
+
 import org.apache.hivemind.Registry;
-import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.hivemind.ShutdownCoordinator;
+import org.apache.hivemind.definition.ModuleDefinition;
+import org.apache.hivemind.definition.ServicePointDefinition;
+import org.apache.hivemind.internal.AbstractServiceImplementationConstructor;
+import org.apache.hivemind.internal.Module;
+import org.apache.hivemind.internal.ServiceImplementationConstructor;
+import org.apache.hivemind.internal.ServiceModel;
+import org.apache.hivemind.internal.ServicePoint;
 
 /**
  * @author James Carman
  * @version 1.0
  */
-public class TestRegistryShutdownListenerServices extends HiveMindTestCase
+public class TestRegistryShutdownListenerServices extends FrameworkTestCase
 {
-    private void executeShutdownListenerTest(String type) throws Exception
+    private void executeShutdownListenerTest(String serviceModel, boolean manual) throws
Exception
     {
-        Registry registry = buildFrameworkRegistry("ShutdownListenerServices.xml");
-        Simple simple = (Simple) registry.getService("hivemind.lib.test."
-                + type + "Simple", Simple.class);
+        Registry registry = createRegistryWithSimpleService(serviceModel, manual);
+        Simple simple = (Simple) registry.getService("hivemind.lib.test.Simple", Simple.class);
         final Counter counter = new Counter();
         simple.setCounter(counter);
         registry.shutdown();
@@ -36,45 +45,98 @@
 
     public void testPooledCalled() throws Exception
     {
-        executeShutdownListenerTest("pooledManual");
-        executeShutdownListenerTest("pooledAuto");
+        executeShutdownListenerTest(ServiceModel.POOLED, true);
+        executeShutdownListenerTest(ServiceModel.POOLED, false);
     }
 
     public void testSingleton() throws Exception
     {
-        executeShutdownListenerTest("singletonManual");
-        executeShutdownListenerTest("singletonAuto");        
+        executeShutdownListenerTest(ServiceModel.SINGLETON, true);
+        executeShutdownListenerTest(ServiceModel.SINGLETON, false);
     }
 
     public void testPrimitive() throws Exception
     {
-        executeShutdownListenerTest("primitiveManual");
-        executeShutdownListenerTest("primitiveAuto");        
+        executeShutdownListenerTest(ServiceModel.PRIMITIVE, true);
+        executeShutdownListenerTest(ServiceModel.PRIMITIVE, false);
     }
     
     public void testSingletonBeanRegistryShutdownListener() throws Exception
     {
-        Registry registry = buildFrameworkRegistry("ShutdownListenerServices.xml");
-        RegistryShutdownBean bean = ( RegistryShutdownBean )registry.getService( "hivemind.lib.test.registryShutdownBeanSingleton",
RegistryShutdownBean.class );
+        Registry registry = createRegistryWithPojo(ServiceModel.SINGLETON);
+        RegistryShutdownBean bean = ( RegistryShutdownBean )registry.getService( "hivemind.lib.test.RegistryShutdownBean",
RegistryShutdownBean.class );
         bean.someMethod();
     }
 
     public void testThreadedBeanRegistryShutdownListener() throws Exception
     {
-        Registry registry = buildFrameworkRegistry("ShutdownListenerServices.xml");
-        RegistryShutdownBean bean = ( RegistryShutdownBean )registry.getService( "hivemind.lib.test.registryShutdownBeanThreaded",
RegistryShutdownBean.class );
+        Registry registry = createRegistryWithPojo(ServiceModel.THREADED);
+        RegistryShutdownBean bean = ( RegistryShutdownBean )registry.getService( "hivemind.lib.test.RegistryShutdownBean",
RegistryShutdownBean.class );
         bean.someMethod();
     }
+
     public void testPooledBeanRegistryShutdownListener() throws Exception
     {
-        Registry registry = buildFrameworkRegistry("ShutdownListenerServices.xml");
-        RegistryShutdownBean bean = ( RegistryShutdownBean )registry.getService( "hivemind.lib.test.registryShutdownBeanPooled",
RegistryShutdownBean.class );
+        Registry registry = createRegistryWithPojo(ServiceModel.POOLED);
+        RegistryShutdownBean bean = ( RegistryShutdownBean )registry.getService( "hivemind.lib.test.RegistryShutdownBean",
RegistryShutdownBean.class );
         bean.someMethod();
     }
+
     public void testPrimitiveBeanRegistryShutdownListener() throws Exception
     {
-        Registry registry = buildFrameworkRegistry("ShutdownListenerServices.xml");
-        RegistryShutdownBean bean = ( RegistryShutdownBean )registry.getService( "hivemind.lib.test.registryShutdownBeanPrimitive",
RegistryShutdownBean.class );
+        Registry registry = createRegistryWithPojo(ServiceModel.PRIMITIVE);
+        RegistryShutdownBean bean = ( RegistryShutdownBean )registry.getService( "hivemind.lib.test.RegistryShutdownBean",
RegistryShutdownBean.class );
         bean.someMethod();
     }
+    
+    /**
+     * Creates a Registry with one module, that defines a Service "Simple" with an interface
and 
+     * separate implementation class. 
+     * @param manual  If true, the service is manually added to the {@link ShutdownCoordinator}
+     */
+    private Registry createRegistryWithSimpleService(final String serviceModel, final boolean
manual)
+    {
+        ModuleDefinition module = createModuleDefinition("hivemind.lib.test");
+        ModuleDefinitionHelper helper = new ModuleDefinitionHelper(module);
+
+        ServicePointDefinition sp1 = helper.addServicePoint("Simple", Simple.class.getName());
+
+        // Define inline implementation constructor, that passes the ShutdownCoordinator
service if manual is true 
+        ServiceImplementationConstructor constructor = new AbstractServiceImplementationConstructor(module.getLocation(),
+                module.getId())
+        {
+            public Object constructCoreServiceImplementation(ServicePoint servicePoint,
+                    Module contributingModule)
+            {
+                Object result;
+                if (manual) {
+                    ShutdownCoordinator coordinator = (ShutdownCoordinator) contributingModule.getService(ShutdownCoordinator.class);
+                    result = new SimpleImpl(coordinator);
+                } else {
+                    result = new SimpleImpl();
+                }
+                return result;
+            }
+        };
+        
+        helper.addServiceImplementation(sp1, constructor, serviceModel);
+
+        return buildFrameworkRegistry(module);
+    }
+  
+    /**
+     * Creates a registry with one module, that defines a Service "RegistryShutdownBean"
which
+     * is a pojo
+     */
+    private Registry createRegistryWithPojo(final String serviceModel)
+    {
+        ModuleDefinition module = createModuleDefinition("hivemind.lib.test");
+        ModuleDefinitionHelper helper = new ModuleDefinitionHelper(module);
+
+        ServicePointDefinition sp1 = helper.addServicePoint("RegistryShutdownBean", RegistryShutdownBean.class.getName());
+        helper.addSimpleServiceImplementation(sp1, RegistryShutdownBean.class.getName(),
serviceModel);
+
+        return buildFrameworkRegistry(module);
+    }
+     
 }

Modified: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/AdderWrapper.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/AdderWrapper.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/AdderWrapper.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/AdderWrapper.java
Thu Aug 10 05:01:57 2006
@@ -14,6 +14,8 @@
 
 package org.apache.hivemind.internal.ser;
 
+import hivemind.test.services.SimpleService;
+
 import java.io.Serializable;
 
 /**
@@ -23,9 +25,9 @@
 public class AdderWrapper implements Serializable
 {
     private static final long serialVersionUID = 1L;
-    private Adder _adder;
+    private SimpleService _adder;
 
-    public AdderWrapper(Adder a)
+    public AdderWrapper(SimpleService a)
     {
         _adder = a;
     }

Modified: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/TestServiceSerializationHelper.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/TestServiceSerializationHelper.java?rev=430360&r1=430359&r2=430360&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/TestServiceSerializationHelper.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/internal/ser/TestServiceSerializationHelper.java
Thu Aug 10 05:01:57 2006
@@ -15,6 +15,8 @@
 package org.apache.hivemind.internal.ser;
 
 import hivemind.test.FrameworkTestCase;
+import hivemind.test.services.SimpleModule;
+import hivemind.test.services.SimpleService;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -65,9 +67,9 @@
 
     public void testIntegration() throws Exception
     {
-        Registry r = buildFrameworkRegistry("SerIntegration.xml");
+        Registry r = buildFrameworkRegistry(new SimpleModule());
 
-        Adder a = (Adder) r.getService(Adder.class);
+        SimpleService a = (SimpleService) r.getService(SimpleService.class);
 
         AdderWrapper aw1 = new AdderWrapper(a);
 



Mime
View raw message