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).
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1241703 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
index 71cb54e..fc7a06b 100644
--- a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
+++ b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
@@ -92,6 +92,7 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
/**
diff --git a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java b/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java
index d3d8ca0..9e1a390 100644
--- a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java
+++ b/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java
@@ -55,10 +55,10 @@
/** 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 @@
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 @@
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 @@
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 @@
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 @@
});
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 @@
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 @@
logger.failOnException();
assertEquals("test", configuration.getProperties().get("name"));
assertNull(emptyConfiguration.getProperties());
- TestUtils.removeDirectoryWithContent(tempDir);
+ Utils.removeDirectoryWithContent(tempDir);
}
private static class ConfigurationImpl implements Configuration {
diff --git a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/TestUtils.java b/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java
similarity index 99%
rename from deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/TestUtils.java
rename to deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java
index fecaab5..a199404 100644
--- a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/TestUtils.java
+++ b/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java
@@ -28,7 +28,7 @@
/**
* 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.
*