You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ma...@apache.org on 2012/02/08 00:41:54 UTC

svn commit: r1241703 - in /felix/trunk/deploymentadmin/autoconf/src: main/java/org/apache/felix/deployment/rp/autoconf/ test/java/org/apache/felix/deployment/rp/autoconf/

Author: marrs
Date: Tue Feb  7 23:41:54 2012
New Revision: 1241703

URL: http://svn.apache.org/viewvc?rev=1241703&view=rev
Log:
FELIX-3329 FELIX-3330 Some small fixes and a lot of extra debug logging, added until we get coverage and confidence in the new code up. Renamed the TestUtils to Utils because they were being picked up as tests (having Test in the name).

Added:
    felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java   (contents, props changed)
      - copied, changed from r1241559, felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/TestUtils.java
Removed:
    felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/TestUtils.java
Modified:
    felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
    felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java

Modified: felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java?rev=1241703&r1=1241702&r2=1241703&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java (original)
+++ felix/trunk/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java Tue Feb  7 23:41:54 2012
@@ -92,6 +92,7 @@ public class AutoConfResourceProcessor i
 	}
 	
     public void begin(DeploymentSession session) {
+        m_log.log(LogService.LOG_DEBUG, "beginning session " + session);
         synchronized (LOCK) {
             if (m_session != null) {
                 throw new IllegalArgumentException("Trying to begin new deployment session while already in one.");
@@ -99,13 +100,15 @@ public class AutoConfResourceProcessor i
             if (session == null) {
                 throw new IllegalArgumentException("Trying to begin new deployment session with a null session.");
             }
+            if (m_toBeInstalled.size() > 0 || m_toBeDeleted.size() > 0 || m_configurationAdminTasks.size() > 0 || m_postCommitTasks.size() > 0) {
+                throw new IllegalStateException("State not reset correctly at start of session.");
+            }
             m_session = session;
-            m_toBeInstalled.clear();
-            m_toBeDeleted.clear();
         }
     }
  
     public void process(String name, InputStream stream) throws ResourceProcessorException {
+        m_log.log(LogService.LOG_DEBUG, "processing " + name);
         // initial validation
         synchronized (LOCK) {
             if (m_session == null) {
@@ -167,9 +170,11 @@ public class AutoConfResourceProcessor i
             List resources = (List) m_toBeInstalled.get(name);
             resources.add(new AutoConfResource(name, designate.getPid(), designate.getFactoryPid(), designate.getBundleLocation(), designate.isMerge(), dict, filter));
         }
+        m_log.log(LogService.LOG_DEBUG, "processing " + name + " done");
     }
 
     public void dropped(String name) throws ResourceProcessorException {
+        m_log.log(LogService.LOG_DEBUG, "dropped " + name);
         synchronized (LOCK) {
         	if (m_session == null) {
         		throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Can not process resource without a Deployment Session");
@@ -185,9 +190,11 @@ public class AutoConfResourceProcessor i
     	catch (IOException ioe) {
     		throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Unable to drop resource: " + name, ioe);
     	}
+        m_log.log(LogService.LOG_DEBUG, "dropped " + name + " done");
     }
 
     public void dropAllResources() throws ResourceProcessorException {
+        m_log.log(LogService.LOG_DEBUG, "drop all resources");
         synchronized (LOCK) {
         	if (m_session == null) {
         		throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Can not drop all resources without a Deployment Session");
@@ -214,18 +221,21 @@ public class AutoConfResourceProcessor i
     	else {
     		throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Unable to drop resources, data area is not accessible");
     	}
+        m_log.log(LogService.LOG_DEBUG, "drop all resources done");
     }
     
     private List m_configurationAdminTasks = new ArrayList();
     private List m_postCommitTasks = new ArrayList();
 
     public void prepare() throws ResourceProcessorException {
+        m_log.log(LogService.LOG_DEBUG, "prepare");
         synchronized (LOCK) {
         	if (m_session == null) {
         		throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Can not process resource without a Deployment Session");
         	}
         }
     	try {
+            m_log.log(LogService.LOG_DEBUG, "prepare delete");
     		// delete dropped resources
     		for (Iterator i = m_toBeDeleted.keySet().iterator(); i.hasNext();) {
     			String name = (String) i.next();
@@ -237,6 +247,7 @@ public class AutoConfResourceProcessor i
     			m_postCommitTasks.add(new DeleteResourceTask(name));
     		}
 
+            m_log.log(LogService.LOG_DEBUG, "prepare install/update");
     		// install new/updated resources
     		for (Iterator j = m_toBeInstalled.keySet().iterator(); j.hasNext();) {
     			String name = (String) j.next();
@@ -250,9 +261,7 @@ public class AutoConfResourceProcessor i
     			List resources = (List) m_toBeInstalled.get(name);
     			for (Iterator iterator = resources.iterator(); iterator.hasNext();) {
     				AutoConfResource resource = (AutoConfResource) iterator.next();
-    				
     				m_configurationAdminTasks.add(new InstallOrUpdateResourceTask(resource));
-
     			}
     			// remove existing configurations that were not in the new version of the resource
     			for (Iterator i = existingResources.iterator(); i.hasNext();) {
@@ -272,18 +281,22 @@ public class AutoConfResourceProcessor i
     		m_toBeInstalled.clear();
     		throw new ResourceProcessorException(ResourceProcessorException.CODE_PREPARE, "Unable to prepare for commit for resource", ioe);
     	}
+        m_log.log(LogService.LOG_DEBUG, "prepare done");
     }
 
     public synchronized void commit() {
+        m_log.log(LogService.LOG_DEBUG, "commit");
         DependencyManager dm = m_component.getDependencyManager();
         m_configurationAdminDependency = dm.createServiceDependency()
             .setService(ConfigurationAdmin.class)
             .setCallbacks("addConfigurationAdmin", null)
             .setRequired(false);
         m_component.add(m_configurationAdminDependency);
+        m_log.log(LogService.LOG_DEBUG, "commit done");
     }
     
     public void addConfigurationAdmin(ServiceReference ref, ConfigurationAdmin ca) {
+        m_log.log(LogService.LOG_DEBUG, "found configuration admin " + ref);
         Iterator iterator = m_configurationAdminTasks.iterator();
         while (iterator.hasNext()) {
             ConfigurationAdminTask task = (ConfigurationAdminTask) iterator.next();
@@ -306,9 +319,11 @@ public class AutoConfResourceProcessor i
                 m_log.log(LogService.LOG_ERROR, "Exception during configuration to " + ca + ". Trying to continue.", e);
             }
         }
+        m_log.log(LogService.LOG_DEBUG, "found configuration admin " + ref + " done");
     }
     
     public void postcommit() {
+        m_log.log(LogService.LOG_DEBUG, "post commit");
         m_component.remove(m_configurationAdminDependency);
         Iterator iterator = m_postCommitTasks.iterator();
         while (iterator.hasNext()) {
@@ -320,15 +335,20 @@ public class AutoConfResourceProcessor i
                 m_log.log(LogService.LOG_ERROR, "Exception during post commit wrap-up. Trying to continue.", e);
             }
         }
+        endSession();
+        m_log.log(LogService.LOG_DEBUG, "post commit done");
+    }
+
+    private void endSession() {
         m_toBeInstalled.clear();
         m_toBeDeleted.clear();
         m_postCommitTasks.clear();
         m_configurationAdminTasks.clear();
         m_session = null;
-        m_component.remove(m_configurationAdminDependency);
     }
 
     public void rollback() {
+        m_log.log(LogService.LOG_DEBUG, "rollback");
     	Set keys = m_toBeInstalled.keySet();
     	for (Iterator i = keys.iterator(); i.hasNext();) {
     		List configs = (List) m_toBeInstalled.get(i.next());
@@ -337,19 +357,20 @@ public class AutoConfResourceProcessor i
     			String name = resource.getName();
     			try {
     				dropped(name);
-    			} catch (ResourceProcessorException e) {
+    			}
+    			catch (ResourceProcessorException e) {
     				m_log.log(LogService.LOG_ERROR, "Unable to roll back resource '" + name + "', reason: " + e.getMessage() + ", caused by: " + e.getCause().getMessage());
     			}
     			break;
     		}
     	}
-    	m_toBeInstalled.clear();
-    	m_session = null;
+    	endSession();
+        m_log.log(LogService.LOG_DEBUG, "rollback done");
     }
 
     public void cancel() {
+        m_log.log(LogService.LOG_DEBUG, "cancel");
     	rollback();
-    	m_session = null;
     }
 
     /**

Modified: felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java?rev=1241703&r1=1241702&r2=1241703&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java (original)
+++ felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java Tue Feb  7 23:41:54 2012
@@ -55,10 +55,10 @@ public class AutoConfResourceProcessorTe
     /** Go through a simple session, containing two empty configurations. */
     public void testSimpleSession() throws Exception {
         AutoConfResourceProcessor p = new AutoConfResourceProcessor();
-        TestUtils.configureObject(p, LogService.class);
-        TestUtils.configureObject(p, Component.class, TestUtils.createMockObjectAdapter(Component.class, new Object() {
+        Utils.configureObject(p, LogService.class);
+        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
             public DependencyManager getDependencyManager() {
-                return new DependencyManager((BundleContext) TestUtils.createNullObject(BundleContext.class));
+                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
             }
         }));
         File tempDir = File.createTempFile("persistence", "dir");
@@ -67,7 +67,7 @@ public class AutoConfResourceProcessorTe
         
         System.out.println("Temporary dir: " + tempDir);
         
-        TestUtils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
+        Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
         Session s = new Session();
         p.begin(s);
         p.process("a", new ByteArrayInputStream("<MetaData />".getBytes()));
@@ -75,27 +75,27 @@ public class AutoConfResourceProcessorTe
         p.prepare();
         p.commit();
         p.postcommit();
-        TestUtils.removeDirectoryWithContent(tempDir);
+        Utils.removeDirectoryWithContent(tempDir);
     }
 
     /** Go through a simple session, containing two empty configurations. */
     public void testSimpleInstallAndUninstallSession() throws Throwable {
         AutoConfResourceProcessor p = new AutoConfResourceProcessor();
-        TestUtils.configureObject(p, LogService.class);
-        TestUtils.configureObject(p, Component.class, TestUtils.createMockObjectAdapter(Component.class, new Object() {
+        Utils.configureObject(p, LogService.class);
+        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
             public DependencyManager getDependencyManager() {
-                return new DependencyManager((BundleContext) TestUtils.createNullObject(BundleContext.class));
+                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
             }
         }));
         Logger logger = new Logger();
-        TestUtils.configureObject(p, LogService.class, logger);
+        Utils.configureObject(p, LogService.class, logger);
         File tempDir = File.createTempFile("persistence", "dir");
         tempDir.delete();
         tempDir.mkdirs();
         
         System.out.println("Temporary dir: " + tempDir);
         
-        TestUtils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
+        Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
         Session s = new Session();
         p.begin(s);
         p.process("a", new ByteArrayInputStream("<MetaData />".getBytes()));
@@ -110,17 +110,17 @@ public class AutoConfResourceProcessorTe
         p.commit();
         p.postcommit();
         logger.failOnException();
-        TestUtils.removeDirectoryWithContent(tempDir);
+        Utils.removeDirectoryWithContent(tempDir);
     }
     
     /** Go through a simple session, containing two empty configurations. */
     public void testBasicConfigurationSession() throws Throwable {
         AutoConfResourceProcessor p = new AutoConfResourceProcessor();
         Logger logger = new Logger();
-        TestUtils.configureObject(p, LogService.class, logger);
-        TestUtils.configureObject(p, Component.class, TestUtils.createMockObjectAdapter(Component.class, new Object() {
+        Utils.configureObject(p, LogService.class, logger);
+        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
             public DependencyManager getDependencyManager() {
-                return new DependencyManager((BundleContext) TestUtils.createNullObject(BundleContext.class));
+                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
             }
         }));
         File tempDir = File.createTempFile("persistence", "dir");
@@ -129,7 +129,7 @@ public class AutoConfResourceProcessorTe
         
         System.out.println("Temporary dir: " + tempDir);
         
-        TestUtils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
+        Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
         Session s = new Session();
         p.begin(s);
         String config =
@@ -171,22 +171,22 @@ public class AutoConfResourceProcessorTe
         });
         p.postcommit();
         logger.failOnException();
-        TestUtils.removeDirectoryWithContent(tempDir);
+        Utils.removeDirectoryWithContent(tempDir);
     }
 
     /** Go through a simple session, containing two empty configurations. */
     public void testFilteredConfigurationSession() throws Throwable {
         AutoConfResourceProcessor p = new AutoConfResourceProcessor();
         Logger logger = new Logger();
-        TestUtils.configureObject(p, LogService.class, logger);
-        TestUtils.configureObject(p, Component.class, TestUtils.createMockObjectAdapter(Component.class, new Object() {
+        Utils.configureObject(p, LogService.class, logger);
+        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
             public DependencyManager getDependencyManager() {
-                return new DependencyManager((BundleContext) TestUtils.createNullObject(BundleContext.class));
+                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
             }
         }));
-        TestUtils.configureObject(p, BundleContext.class, TestUtils.createMockObjectAdapter(BundleContext.class, new Object() {
+        Utils.configureObject(p, BundleContext.class, Utils.createMockObjectAdapter(BundleContext.class, new Object() {
             public Filter createFilter(String condition) {
-                return (Filter) TestUtils.createMockObjectAdapter(Filter.class, new Object() {
+                return (Filter) Utils.createMockObjectAdapter(Filter.class, new Object() {
                     public boolean match(ServiceReference ref) {
                         Object id = ref.getProperty("id");
                         if (id != null && id.equals(Integer.valueOf(42))) {
@@ -203,7 +203,7 @@ public class AutoConfResourceProcessorTe
         
         System.out.println("Temporary dir: " + tempDir);
         
-        TestUtils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
+        Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
         Session s = new Session();
         p.begin(s);
         String config =
@@ -273,7 +273,7 @@ public class AutoConfResourceProcessorTe
         logger.failOnException();
         assertEquals("test", configuration.getProperties().get("name"));
         assertNull(emptyConfiguration.getProperties());
-        TestUtils.removeDirectoryWithContent(tempDir);
+        Utils.removeDirectoryWithContent(tempDir);
     }
 
     private static class ConfigurationImpl implements Configuration {

Copied: felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java (from r1241559, felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/TestUtils.java)
URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java?p2=felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java&p1=felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/TestUtils.java&r1=1241559&r2=1241703&rev=1241703&view=diff
==============================================================================
--- felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/TestUtils.java (original)
+++ felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java Tue Feb  7 23:41:54 2012
@@ -28,7 +28,7 @@ import java.lang.reflect.Proxy;
 /**
  * Utility class that injects dependencies. Can be used to unit test service implementations.
  */
-public class TestUtils {
+public class Utils {
     /**
      * Configures an object to use a null object for the specified service interface.
      *

Propchange: felix/trunk/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain