Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/shutdown/ShutdownEntry.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/shutdown/ShutdownEntry.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/shutdown/ShutdownEntry.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/shutdown/ShutdownEntry.java Thu Dec 13 18:17:39 2018 @@ -1,32 +1,13 @@ package org.apache.fulcrum.yaafi.service.shutdown; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.security.MessageDigest; +import java.util.Arrays; import org.apache.avalon.framework.logger.Logger; +import org.apache.commons.io.IOUtils; import org.apache.fulcrum.yaafi.framework.util.InputStreamLocator; /** @@ -35,248 +16,160 @@ import org.apache.fulcrum.yaafi.framewor * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class ShutdownEntry -{ - /** buffer size for copy() */ - private static final int BUF_SIZE = 1024; - - /** the location to monitor for changes */ - private String location; - - /** the last message digest of the location */ - private byte[] digest; - - /** the locator to load the monitored resource */ - private InputStreamLocator locator; - - /** keep a notice for the very first invocation */ - private boolean isFirstInvocation; - - /** the logger to be used */ - private Logger logger; - - /** use System.exit() to shutdown the JVM */ - private boolean useSystemExit; - - /** - * Constructor - * - * @param logger the logger to use - * @param applicationDir the home directory of the application - * @param location the location to monitor for changes - * @param useSystemExit use System.exit() on shutdown - */ - public ShutdownEntry( Logger logger, File applicationDir, String location, boolean useSystemExit ) - { - this.isFirstInvocation = true; - this.useSystemExit = useSystemExit; - this.location = location; - this.locator = new InputStreamLocator( applicationDir ); - this.logger = logger; - } - - /** - * @return has the monitored location changed - */ - public boolean hasChanged() - { - boolean result = false; - InputStream is = null; - byte[] currDigest = null; - - try - { - // get a grip on our resource - - is = this.locate(); - - if( is == null ) - { - String msg = "Unable to find the following resource : " + this.getLocation(); - this.getLogger().warn(msg); - } - else - { - // calculate a SHA-1 digest - - currDigest = this.getDigest(is); - is.close(); - is = null; - - if( this.isFirstInvocation() == true ) - { - isFirstInvocation = false; - this.getLogger().debug( "Storing SHA-1 digest of " + this.getLocation() ); - this.setDigest( currDigest ); - } - else - { - if( equals( this.digest, currDigest ) == false ) - { - this.getLogger().debug( "The following resource has changed : " + this.getLocation() ); - this.setDigest( currDigest ); - result = true; - } - } - } - - return result; - } - catch(Exception e) - { - String msg = "The ShutdownService encountered an internal error"; - this.getLogger().error(msg,e); - return false; - } - finally - { - if( is != null ) - { - try - { - is.close(); - } - catch (Exception e) - { - String msg = "Can't close the InputStream during error recovery"; - this.getLogger().error(msg,e); - } - } - } - - } - - /** - * @return Returns the useSystemExit. - */ - public boolean isUseSystemExit() - { - return useSystemExit; - } - - /** - * @return Returns the isFirstInvocation. - */ - private boolean isFirstInvocation() - { - return isFirstInvocation; - } - - /** - * @return Returns the location. - */ - private String getLocation() - { - return location; - } - - /** - * @return Returns the locator. - */ - private InputStreamLocator getLocator() - { - return locator; - } - - /** - * Creates an InputStream - * @return InputStream of the location - * @throws IOException if unable to open the stream - */ - public InputStream locate() throws IOException - { - return this.getLocator().locate(this.getLocation()); - } - - /** - * Creates a message digest - * @param is Input stream - * @return byte array of the input stream - */ - private byte[] getDigest( InputStream is ) - throws Exception - { - byte[] result = null; - byte[] content = null; - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - copy( is, baos ); - content = baos.toByteArray(); - baos.close(); - - MessageDigest sha1 = MessageDigest.getInstance( "SHA1" ); - sha1.update( content ); - result = sha1.digest(); - - return result; - } - - /** - * @param digest The digest to set. - */ - private void setDigest(byte [] digest) - { - this.digest = digest; - } - - /** - * Compares two byte[] for equality - */ - private static boolean equals(byte[] lhs, byte[] rhs) - { - if( lhs == rhs ) - { - return true; - } - else if( lhs.length != rhs.length ) - { - return false; - } - else - { - for( int i=0; i<lhs.length; i++ ) - { - if( lhs[i] != rhs[i] ) - { - return false; - } - } - } - - return true; - } - - /** - * Pumps the input stream to the output stream. - * - * @param is the source input stream - * @param os the target output stream - * @throws IOException the copying failed - */ - private static void copy( InputStream is, OutputStream os ) - throws IOException - { - byte[] buf = new byte[BUF_SIZE]; - int n = 0; - //int total = 0; - - while ((n = is.read(buf)) > 0) - { - os.write(buf, 0, n); - //total += n; - } - - is.close(); - - os.flush(); - os.close(); - } - - /** - * @return Returns the logger. - */ - private Logger getLogger() - { - return logger; - } +public class ShutdownEntry { + + /** the location to monitor for changes */ + private String location; + + /** the last message digest of the location */ + private byte[] digest; + + /** the locator to load the monitored resource */ + private InputStreamLocator locator; + + /** keep a notice for the very first invocation */ + private boolean isFirstInvocation; + + /** the logger to be used */ + private Logger logger; + + /** use System.exit() to shutdown the JVM */ + private boolean useSystemExit; + + /** + * Constructor + * + * @param logger the logger to use + * @param applicationDir the home directory of the application + * @param location the location to monitor for changes + * @param useSystemExit use System.exit() on shutdown + */ + public ShutdownEntry(Logger logger, File applicationDir, String location, boolean useSystemExit) { + this.isFirstInvocation = true; + this.useSystemExit = useSystemExit; + this.location = location; + this.locator = new InputStreamLocator(applicationDir); + this.logger = logger; + } + + /** + * @return has the monitored location changed + */ + public boolean hasChanged() { + boolean result = false; + InputStream is = null; + byte[] currDigest = null; + + try { + // get a grip on our resource + + is = this.locate(); + + if (is == null) { + String msg = "Unable to find the following resource : " + this.getLocation(); + this.logger.warn(msg); + } else { + // calculate a SHA-1 digest + + currDigest = this.getDigest(is); + is.close(); + is = null; + + if (this.isFirstInvocation() == true) { + isFirstInvocation = false; + this.logger.debug("Storing SHA-1 digest of " + this.getLocation()); + this.setDigest(currDigest); + } else { + if (equals(this.digest, currDigest) == false) { + this.logger.debug("The following resource has changed : " + this.getLocation()); + this.setDigest(currDigest); + result = true; + } + } + } + + return result; + } catch (Exception e) { + String msg = "The ShutdownService encountered an internal error"; + this.logger.error(msg, e); + return false; + } finally { + if (is != null) { + try { + is.close(); + } catch (Exception e) { + String msg = "Can't close the InputStream during error recovery"; + this.logger.error(msg, e); + } + } + } + + } + + /** + * @return Returns the useSystemExit. + */ + public boolean isUseSystemExit() { + return useSystemExit; + } + + /** + * @return Returns the isFirstInvocation. + */ + private boolean isFirstInvocation() { + return isFirstInvocation; + } + + /** + * @return Returns the location. + */ + private String getLocation() { + return location; + } + + /** + * Creates an InputStream + * + * @return InputStream of the location + * @throws IOException if unable to open the stream + */ + public InputStream locate() throws IOException { + return this.locator.locate(this.getLocation()); + } + + /** + * Creates a message digest + * + * @param is Input stream + * @return byte array of the input stream + */ + private byte[] getDigest(InputStream is) throws Exception { + byte[] result = null; + byte[] content = null; + + // convert to byte array + content = IOUtils.toByteArray(is); + + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + sha1.update(content); + result = sha1.digest(); + + return result; + } + + /** + * @param digest The digest to set. + */ + private void setDigest(byte[] digest) { + this.digest = digest; + } + + /** + * Compares two byte[] for equality + */ + private static boolean equals(byte[] lhs, byte[] rhs) { + // JDK provided method + return Arrays.equals(lhs, rhs); + } + }
Modified: turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/shutdown/ShutdownServiceImpl.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/shutdown/ShutdownServiceImpl.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/shutdown/ShutdownServiceImpl.java (original) +++ turbine/fulcrum/trunk/yaafi/src/java/org/apache/fulcrum/yaafi/service/shutdown/ShutdownServiceImpl.java Thu Dec 13 18:17:39 2018 @@ -36,225 +36,190 @@ import org.apache.avalon.framework.servi import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; - /** - * Monitors the componentConfiguration.xml and triggers a reconfiguration - * if the content of the component configuration file has changed. + * Monitors the componentConfiguration.xml and triggers a reconfiguration if the + * content of the component configuration file has changed. * * @author <a href="mailto:[email protected]">Siegfried Goeschl</a> */ -public class ShutdownServiceImpl - extends AbstractLogEnabled - implements ShutdownService, Serviceable, Contextualizable, - Reconfigurable, Initializable, Runnable, Startable, Disposable -{ - /** the interval between two checks in ms */ - private int interval; - - /** shall the worker thread terminate immediately */ - private boolean terminateNow; - - /** the worker thread polling the resource */ - private Thread workerThread; - - /** the ServiceManager to use */ - private ServiceManager serviceManager; - - /** the application directory */ - private File applicationDir; - - /** our own and only shutdown entry */ - private ShutdownEntry shutdownEntry; - - ///////////////////////////////////////////////////////////////////////// - // Avalon Service Lifecycle Implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * Constructor - */ - public ShutdownServiceImpl() - { - this.terminateNow = false; - } - - /** - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(ServiceManager manager) throws ServiceException - { - this.serviceManager = manager; - } - - /** - * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) - */ - public void contextualize(Context context) throws ContextException - { - this.applicationDir = (File) context.get("urn:avalon:home"); - } - - /** - * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) - */ - public void configure(Configuration configuration) throws ConfigurationException - { - // limit to minimum interval of 1 second - - this.interval = Math.max( configuration.getAttributeAsInteger("interval",5000), 1000 ); - - this.getLogger().debug( "Monitoring the resources every " + this.interval + " ms" ); - - if( configuration.getChild("entry",false) != null ) - { - Configuration shutdownConfig = configuration.getChild("entry"); - - String shutdownEntryLocation = shutdownConfig.getChild("location").getValue(); - - this.shutdownEntry = new ShutdownEntry( - this.getLogger(), - this.applicationDir, - shutdownEntryLocation, - shutdownConfig.getChild("useSystemExit").getValueAsBoolean(false) - ); - - this.getLogger().debug( "Using a shutdown entry : " + shutdownEntryLocation ); - } - else - { - this.shutdownEntry = null; - this.getLogger().debug( "No shutdown entry defined" ); - } - } - - /** - * @see org.apache.avalon.framework.activity.Initializable#initialize() - */ - public void initialize() throws Exception - { - // request a SHA-1 to make sure that it is supported - - MessageDigest.getInstance( "SHA1" ); - - // check that the ServiceManager inplements Disposable - - if( (this.serviceManager instanceof Disposable) == false ) - { - String msg = "The ServiceManager instance does not implement Disposable?!"; - throw new IllegalArgumentException( msg ); - } - - // create the worker thread polling the target - - this.workerThread = new Thread( this, "ShutdownService" ); - } - - /** - * @see org.apache.avalon.framework.activity.Startable#start() - */ - public void start() throws Exception - { - this.getLogger().debug( "Starting worker thread ..." ); - this.workerThread.start(); - } - - /** - * @see org.apache.avalon.framework.activity.Startable#stop() - */ - public void stop() throws Exception - { - this.getLogger().debug( "Stopping worker thread ..." ); - this.terminateNow = true; - this.workerThread.interrupt(); - this.workerThread.join( 10000 ); - } - - /** - * @see org.apache.avalon.framework.activity.Disposable#dispose() - */ - public void dispose() - { - this.terminateNow = false; - this.applicationDir = null; - this.workerThread = null; - this.serviceManager = null; - } - - /** - * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) - */ - public void reconfigure(Configuration configuration) - throws ConfigurationException - { - this.configure(configuration); - } - - ///////////////////////////////////////////////////////////////////////// - // Service interface implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * @see java.lang.Runnable#run() - */ - public void run() - { - while( this.terminateNow == false ) - { - try - { - Thread.sleep( this.interval ); - } - catch (InterruptedException e) - { - // nothing to do - } - - if( this.hasShutdownEntry() && this.getShutdownEntry().hasChanged() ) - { - if( this.serviceManager instanceof Disposable ) - { - if( this.getShutdownEntry().isUseSystemExit() ) - { - this.getLogger().warn( "Forcing a shutdown using System.exit() ..." ); - } - else - { - this.getLogger().warn( "Forcing a shutdown ..." ); - } - - // create a demon thread to shutdown the container - - Shutdown shutdown = new Shutdown( - (Disposable) this.serviceManager, - this.getShutdownEntry().isUseSystemExit() - ); - - Thread shutdownThread = new Thread( shutdown, "ShutdownServiceThread" ); - shutdownThread.setDaemon(true); - shutdownThread.start(); - } - } - } - } - - ///////////////////////////////////////////////////////////////////////// - // Service implementation - ///////////////////////////////////////////////////////////////////////// - - /** - * @return Returns the shutdownEntry. - */ - private ShutdownEntry getShutdownEntry() - { - return this.shutdownEntry; - } - - /** - * @return Is a shutdown entry defined? - */ - private boolean hasShutdownEntry() - { - return ( this.shutdownEntry != null ? true : false ); - } +public class ShutdownServiceImpl extends AbstractLogEnabled implements ShutdownService, Serviceable, Contextualizable, + Reconfigurable, Initializable, Runnable, Startable, Disposable { + /** the interval between two checks in ms */ + private int interval; + + /** shall the worker thread terminate immediately */ + private boolean terminateNow; + + /** the worker thread polling the resource */ + private Thread workerThread; + + /** the ServiceManager to use */ + private ServiceManager serviceManager; + + /** the application directory */ + private File applicationDir; + + /** our own and only shutdown entry */ + private ShutdownEntry shutdownEntry; + + ///////////////////////////////////////////////////////////////////////// + // Avalon Service Lifecycle Implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * Constructor + */ + public ShutdownServiceImpl() { + this.terminateNow = false; + } + + /** + * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) + */ + public void service(ServiceManager manager) throws ServiceException { + this.serviceManager = manager; + } + + /** + * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) + */ + public void contextualize(Context context) throws ContextException { + this.applicationDir = (File) context.get("urn:avalon:home"); + } + + /** + * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) + */ + public void configure(Configuration configuration) throws ConfigurationException { + // limit to minimum interval of 1 second + + this.interval = Math.max(configuration.getAttributeAsInteger("interval", 5000), 1000); + + this.getLogger().debug("Monitoring the resources every " + this.interval + " ms"); + + if (configuration.getChild("entry", false) != null) { + Configuration shutdownConfig = configuration.getChild("entry"); + + String shutdownEntryLocation = shutdownConfig.getChild("location").getValue(); + + this.shutdownEntry = new ShutdownEntry(this.getLogger(), this.applicationDir, shutdownEntryLocation, + shutdownConfig.getChild("useSystemExit").getValueAsBoolean(false)); + + this.getLogger().debug("Using a shutdown entry : " + shutdownEntryLocation); + } else { + this.shutdownEntry = null; + this.getLogger().debug("No shutdown entry defined"); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.avalon.framework.activity.Initializable#initialize() + */ + public void initialize() throws Exception { + + // request a SHA-1 to make sure that it is supported + MessageDigest.getInstance("SHA1"); + + // check that the ServiceManager inplements Disposable + if (this.serviceManager instanceof Disposable == false) { + String msg = "The ServiceManager instance does not implement Disposable?!"; + throw new IllegalArgumentException(msg); + } + + // create the worker thread polling the target + this.workerThread = new Thread(this, "ShutdownService"); + } + + /* + * (non-Javadoc) + * + * @see org.apache.avalon.framework.activity.Startable#start() + */ + public void start() throws Exception { + this.getLogger().debug("Starting worker thread ..."); + this.workerThread.start(); + } + + /** + * @see org.apache.avalon.framework.activity.Startable#stop() + */ + public void stop() throws Exception { + this.getLogger().debug("Stopping worker thread ..."); + this.terminateNow = true; + this.workerThread.interrupt(); + this.workerThread.join(10000); + } + + /** + * @see org.apache.avalon.framework.activity.Disposable#dispose() + */ + public void dispose() { + this.terminateNow = false; + this.applicationDir = null; + this.workerThread = null; + this.serviceManager = null; + } + + /** + * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration) + */ + public void reconfigure(Configuration configuration) throws ConfigurationException { + this.configure(configuration); + } + + ///////////////////////////////////////////////////////////////////////// + // Service interface implementation + ///////////////////////////////////////////////////////////////////////// + + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + public void run() { + while (this.terminateNow == false) { + try { + Thread.sleep(this.interval); + } catch (InterruptedException e) { + // nothing to do + } + + if (this.hasShutdownEntry() && this.getShutdownEntry().hasChanged() + && this.serviceManager instanceof Disposable) { + + if (this.getShutdownEntry().isUseSystemExit()) { + this.getLogger().warn("Forcing a shutdown using System.exit() ..."); + } else { + this.getLogger().warn("Forcing a shutdown ..."); + } + + // create a demon thread to shutdown the container + Shutdown shutdown = new Shutdown((Disposable) this.serviceManager, + this.getShutdownEntry().isUseSystemExit()); + + Thread shutdownThread = new Thread(shutdown, "ShutdownServiceThread"); + shutdownThread.setDaemon(true); + shutdownThread.start(); + } + } + } + + ///////////////////////////////////////////////////////////////////////// + // Service implementation + ///////////////////////////////////////////////////////////////////////// + + /** + * @return Returns the shutdownEntry. + */ + private ShutdownEntry getShutdownEntry() { + return this.shutdownEntry; + } + + /** + * @return Is a shutdown entry defined? + */ + private boolean hasShutdownEntry() { + return (this.shutdownEntry != null ? true : false); + } } Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/TestComponentTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/TestComponentTest.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/TestComponentTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/TestComponentTest.java Thu Dec 13 18:17:39 2018 @@ -73,7 +73,7 @@ public class TestComponentTest extends B /** * Verify bug fix for not calling dispose method of components - * @throws Exception + * @throws Exception generic exception */ public void testTestComponentDecomissioned() throws Exception { Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/cli/MainTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/cli/MainTest.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/cli/MainTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/cli/MainTest.java Thu Dec 13 18:17:39 2018 @@ -43,7 +43,7 @@ public class MainTest extends TestCase super(name); } - /** + /* (non-Javadoc) * @see junit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception @@ -54,6 +54,7 @@ public class MainTest extends TestCase /** * @return get our simple test component + * @throws ServiceException if the component is not found */ private TestComponent getTestComponent() throws ServiceException { @@ -64,6 +65,7 @@ public class MainTest extends TestCase /** * Initialize the CLI using a valid container configuration + * @throws Exception generic exception */ public void testValidContainerConfiguration() throws Exception { @@ -80,6 +82,7 @@ public class MainTest extends TestCase /** * Test the toString() method provding diagnostic information + * @throws Exception generic exception */ public void testToString() throws Exception { @@ -97,6 +100,7 @@ public class MainTest extends TestCase /** * Initialize the CLI using an invalid container configuration + * @throws Exception generic exception */ public void testInvlidContainerConfiguration() throws Exception { Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/framework/container/ServiceLifecycleManagerTest.java Thu Dec 13 18:17:39 2018 @@ -152,11 +152,11 @@ public class ServiceLifecycleManagerTest System.out.println("Decommissiong " + serviceName + " ..."); assertTrue(this.container.hasService(serviceName)); - this.lifecycleManager.decommision(serviceName); + this.lifecycleManager.decommission(serviceName); assertTrue(this.container.hasService(serviceName)); this.container.lookup(serviceName); assertTrue(this.container.hasService(serviceName)); - this.lifecycleManager.decommision(serviceName); + this.lifecycleManager.decommission(serviceName); assertTrue(this.container.hasService(serviceName)); } } @@ -179,7 +179,7 @@ public class ServiceLifecycleManagerTest // reconfigure/decommission/reconfigure the service this.lifecycleManager.reconfigure(serviceNames); - this.lifecycleManager.decommision(serviceName); + this.lifecycleManager.decommission(serviceName); this.lifecycleManager.reconfigure(serviceNames); // run a reconfiguration over all services @@ -188,7 +188,7 @@ public class ServiceLifecycleManagerTest // reconfigure/decommission/reconfigure the service this.container.lookup(serviceName); this.lifecycleManager.reconfigure(serviceNames); - this.lifecycleManager.decommision(serviceName); + this.lifecycleManager.decommission(serviceName); this.lifecycleManager.reconfigure(serviceNames); } } @@ -207,7 +207,7 @@ public class ServiceLifecycleManagerTest serviceName = TestComponent.class.getName(); this.checkTestComponent(); - this.lifecycleManager.decommision(serviceName); + this.lifecycleManager.decommission(serviceName); this.checkTestComponent(); // terminate the ReconfigurationService which is currently @@ -217,7 +217,7 @@ public class ServiceLifecycleManagerTest serviceName = ReconfigurationService.class.getName(); - this.lifecycleManager.decommision(ReconfigurationService.class.getName()); + this.lifecycleManager.decommission(ReconfigurationService.class.getName()); this.container.lookup(ReconfigurationService.class.getName()); // now we should see that the service is starting up @@ -226,7 +226,7 @@ public class ServiceLifecycleManagerTest // and terminate it again - this.lifecycleManager.decommision(ReconfigurationService.class.getName()); + this.lifecycleManager.decommission(ReconfigurationService.class.getName()); } /** Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/interceptor/util/ArgumentToStringBuilderTest.java Thu Dec 13 18:17:39 2018 @@ -152,6 +152,7 @@ public class ArgumentToStringBuilderTest /** * Create a plain vanilla Java object + * @throws Exception generic exception */ public void testPlainVanillaObject() throws Exception { Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnitTest.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnitTest.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnitTest.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/BaseUnitTest.java Thu Dec 13 18:17:39 2018 @@ -19,162 +19,159 @@ package org.apache.fulcrum.yaafi.testcon * under the License. */ -import junit.framework.TestCase; - import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.service.ServiceException; +import junit.framework.TestCase; + /** - * Base class for unit tests for components. This version doesn't load the container until the - * first request for a component. This allows the tester to populate the configurationFileName and - * roleFileName, possible one per test. + * Base class for unit tests for components. This version doesn't load the + * container until the first request for a component. This allows the tester to + * populate the configurationFileName and roleFileName, possible one per test. * * @author <a href="mailto:[email protected]">Eric Pugh</a> * @author <a href="mailto:[email protected]">Quinton McCombs</a> */ -public abstract class BaseUnitTest extends TestCase -{ - /** YaffiContainer for the components */ - private Container container; - /** Setup our default configurationFileName */ - private String configurationFileName = "src/test/TestComponentConfig.xml"; - /** Setup our default roleFileName */ - private String roleFileName = "src/test/TestRoleConfig.xml"; - /** Setup our paramterFileName */ - private String parameterFileName = "src/test/TestParameters.properties"; - - /** - * Gets the configuration file name for the container should use for this test. By default it - * is src/test/TestComponentConfig. - * - * @param configurationFileName - */ - protected void setConfigurationFileName(String configurationFileName) - { - this.configurationFileName = configurationFileName; - } - - /** - * Override the role file name for the container should use for this test. By default it is - * src/test/TestRoleConfig. - * - * @param roleFileName - */ - protected void setRoleFileName(String roleFileName) - { - this.roleFileName = roleFileName; - } - - /** - * Override the parameter file name for the container should use for this test. By default it is - * src/test/TestRoleConfig. - * - * @param parameterFileName the name of the parameter file - */ - protected void setParameterFileName(String parameterFileName) - { - this.parameterFileName = parameterFileName; - } - - /** - * Constructor for test. - * - * @param testName name of the test being executed - */ - public BaseUnitTest(String testName) - { - super(testName); - } - - /** - * Clean up after each test is run. - */ - protected void tearDown() throws Exception - { - if (this.container != null) - { - this.container.dispose(); - } - this.container = null; - } - /** - * Gets the configuration file name for the container should use for this test. - * - * @return The filename of the configuration file - */ - protected String getConfigurationFileName() - { - return this.configurationFileName; - } - /** - * Gets the role file name for the container should use for this test. - * - * @return The filename of the role configuration file - */ - protected String getRoleFileName() - { - return this.roleFileName; - } - /** - * Gets the parameter file name for the container should use for this test. - * - * @return The filename of the parameter file - */ - protected String getParameterFileName() - { - return this.parameterFileName; - } - /** - * Returns an instance of the named component. Starts the container if it hasn't been started. - * - * @param roleName Name of the role the component fills. - * @throws ComponentException generic exception - */ - protected Object lookup(String roleName) throws ComponentException - { - if (this.container == null) - { - this.container = new Container(); - this.container.startup(getConfigurationFileName(), getRoleFileName(), getParameterFileName()); - } - return this.container.lookup(roleName); - } - /** - * Releases the component - * - * @param component - */ - protected void release(Component component) - { - if (this.container != null) - { - this.container.release(component); - } - } - /** - * Releases the component - * - * @param component - */ - protected void release(Object component) - { - if (this.container != null) - { - this.container.release(component); - } - } - - /** - * Decommision the service - * @param name the name of the service - */ - protected void decommision( String name ) - throws ServiceException, Exception - { - if (this.container != null) - { - this.container.decommision( name ); - } - } +public abstract class BaseUnitTest extends TestCase { + + /** YaffiContainer for the components */ + private Container container; + + /** Setup our default configurationFileName */ + private String configurationFileName = "src/test/TestComponentConfig.xml"; + + /** Setup our default roleFileName */ + private String roleFileName = "src/test/TestRoleConfig.xml"; + + /** Setup our paramterFileName */ + private String parameterFileName = "src/test/TestParameters.properties"; + + /** + * Gets the configuration file name for the container should use for this test. + * By default it is src/test/TestComponentConfig. + * + * @param configurationFileName config file name + */ + protected void setConfigurationFileName(String configurationFileName) { + this.configurationFileName = configurationFileName; + } + + /** + * Override the role file name for the container should use for this test. By + * default it is src/test/TestRoleConfig. + * + * @param roleFileName role file name + */ + protected void setRoleFileName(String roleFileName) { + this.roleFileName = roleFileName; + } + + /** + * Override the parameter file name for the container should use for this test. + * By default it is src/test/TestRoleConfig. + * + * @param parameterFileName the name of the parameter file + */ + protected void setParameterFileName(String parameterFileName) { + this.parameterFileName = parameterFileName; + } + + /** + * Constructor for test. + * + * @param testName name of the test being executed + */ + public BaseUnitTest(String testName) { + super(testName); + } + + /* + * (non-Javadoc) Clean up after each test is run. + * + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + if (this.container != null) { + this.container.dispose(); + } + this.container = null; + } + + /** + * Gets the configuration file name for the container should use for this test. + * + * @return The filename of the configuration file + */ + protected String getConfigurationFileName() { + return this.configurationFileName; + } + + /** + * Gets the role file name for the container should use for this test. + * + * @return The filename of the role configuration file + */ + protected String getRoleFileName() { + return this.roleFileName; + } + + /** + * Gets the parameter file name for the container should use for this test. + * + * @return The filename of the parameter file + */ + protected String getParameterFileName() { + return this.parameterFileName; + } + + /** + * Returns an instance of the named component. Starts the container if it hasn't + * been started. + * + * @param roleName Name of the role the component fills. + * @return Object representing the named component + * @throws ComponentException if the component is not found + */ + protected Object lookup(String roleName) throws ComponentException { + if (this.container == null) { + this.container = new Container(); + this.container.startup(getConfigurationFileName(), getRoleFileName(), getParameterFileName()); + } + return this.container.lookup(roleName); + } + + /** + * Releases the component + * + * @param component the component to be released + */ + protected void release(Component component) { + if (this.container != null) { + this.container.release(component); + } + } + + /** + * Releases the component + * + * @param component the component to be released + */ + protected void release(Object component) { + if (this.container != null) { + this.container.release(component); + } + } + + /** + * Decommision the service + * + * @param name the name of the service + * @throws ServiceException if the service is not found + */ + protected void decommision(String name) throws ServiceException { + if (this.container != null) { + this.container.decommission(name); + } + } } Modified: turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/Container.java URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/Container.java?rev=1848876&r1=1848875&r2=1848876&view=diff ============================================================================== --- turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/Container.java (original) +++ turbine/fulcrum/trunk/yaafi/src/test/org/apache/fulcrum/yaafi/testcontainer/Container.java Thu Dec 13 18:17:39 2018 @@ -65,6 +65,7 @@ public class Container extends AbstractL * * @param configFileName Name of the component configuration file * @param roleFileName Name of the role configuration file + * @param parametersFileName Name of the parameters file */ public void startup( String configFileName, @@ -102,10 +103,9 @@ public class Container extends AbstractL // Avalon lifecycle interfaces // ------------------------------------------------------------- - /** + /* (non-Javadoc) * Initializes the container - * - * @throws Exception generic exception + * @see org.apache.avalon.framework.activity.Initializable#initialize() */ public void initialize() throws Exception { @@ -128,6 +128,7 @@ public class Container extends AbstractL * Returns an instance of the named component * * @param roleName Name of the role the component fills. + * @return the instance of the named component * @throws ComponentException generic exception */ public Object lookup(String roleName) throws ComponentException @@ -145,9 +146,9 @@ public class Container extends AbstractL /** * Releases the component implementing the Component interface. This - * interface is depracted but still around in Fulcrum + * interface is deprecated but still around in Fulcrum * - * @param component + * @param component the named component to release */ public void release(Component component) { @@ -157,7 +158,7 @@ public class Container extends AbstractL /** * Releases the component * - * @param component + * @param component the named component to release */ public void release(Object component) { @@ -166,15 +167,16 @@ public class Container extends AbstractL } /** - * Decommision the service + * Decommission the service * @param name the name of the service + * @throws ServiceException if the service is not found */ - protected void decommision( String name ) - throws ServiceException, Exception + protected void decommission( String name ) + throws ServiceException { if( this.manager != null ) { - this.manager.decommision( name ); + this.manager.decommission( name ); } } }
