[jboss-cvs] JBossAS SVN: r89305 - in projects/bootstrap/trunk/impl-as/src: test/java/org/jboss/bootstrap/impl/as/server and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat May 23 12:23:51 EDT 2009
Author: ALRubinger
Date: 2009-05-23 12:23:50 -0400 (Sat, 23 May 2009)
New Revision: 89305
Added:
projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/MutableStartDateNoOpJBossASServer.java
Modified:
projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java
projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerOperationsTestCase.java
Log:
[JBBOOT-73] Tests to ensure we do not leak out internal state of start date
Modified: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java 2009-05-23 15:53:10 UTC (rev 89304)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java 2009-05-23 16:23:50 UTC (rev 89305)
@@ -295,26 +295,7 @@
// Overridden Implementations ---------------------------------------------------||
//-------------------------------------------------------------------------------||
- /*
- *
- * EVERYTHING BELOW THIS LINE IS TODO to either be approved
- * as-is or needs some more work.
- *
- * Likely we'll need some more @ManagementProperty annotations?
- *
- */
-
/* (non-Javadoc)
- * @see org.jboss.bootstrap.impl.mc.server.AbstractMCServerBase#doShutdown()
- */
- @Override
- protected void doShutdown() throws Exception
- {
- // TODO Auto-generated method stub
- super.doShutdown();
- }
-
- /* (non-Javadoc)
* @see org.jboss.bootstrap.impl.mc.server.AbstractMCServerBase#doStart()
*/
@Override
@@ -324,17 +305,19 @@
super.doStart();
// Mark the start date
- this.startDate = new Date();
+ this.setStartDate(new Date());
}
- /* (non-Javadoc)
- * @see org.jboss.bootstrap.spi.server.AbstractServer#start()
+ //-------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * @param startDate the startDate to set
*/
- @Override
- public void start() throws IllegalStateException, Exception
+ protected void setStartDate(final Date startDate)
{
- // Call Super
- super.start();
+ // Clone so we don't give callers access to internal state
+ this.startDate = (Date) startDate.clone();
}
-
}
Modified: projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerOperationsTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerOperationsTestCase.java 2009-05-23 15:53:10 UTC (rev 89304)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/JBossASServerOperationsTestCase.java 2009-05-23 16:23:50 UTC (rev 89305)
@@ -22,6 +22,8 @@
package org.jboss.bootstrap.impl.as.server;
+import java.util.Date;
+
import junit.framework.TestCase;
import org.jboss.bootstrap.impl.as.common.TestUtils;
@@ -114,8 +116,58 @@
// Test started
final boolean startedAfter = server.isStarted();
TestCase.assertTrue("Server should report as started after start lifecycle has been called", startedAfter);
-
+
// Shutdown
server.shutdown();
}
+
+ /**
+ * Ensures that we don't leak out the internal state of the
+ * server start date
+ *
+ * JBBOOT-73
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testMutableStartDateDoesNotLeak() throws Throwable
+ {
+ // Log
+ log.info("testIsStarted");
+
+ // Get Server
+ final MutableStartDateNoOpJBossASServer server = new MutableStartDateNoOpJBossASServer();
+
+ // Define a fail message
+ final String failMessage = "Server has leaked its internal state via getStartDate";
+
+ // Make a new Date to set manually in
+ final Date datePassedIn = new Date();
+ final long manualSetTime = 100L;
+ datePassedIn.setTime(manualSetTime);
+
+ // Set a manual start Date
+ server.setStartDate(datePassedIn);
+
+ // Ensure server's got an equal start date to what we set
+ final Date startDateBeforeOverrideUponStartPassedIn = server.getStartDate();
+ TestCase.assertEquals(failMessage, manualSetTime, datePassedIn.getTime());
+ TestCase.assertEquals(failMessage, manualSetTime, startDateBeforeOverrideUponStartPassedIn.getTime());
+
+ // Increment the manual set date
+ final long overrideSetTime = 200L;
+ datePassedIn.setTime(overrideSetTime);
+
+ // Ensure this hasn't leaked into the server
+ final Date startDateAfterOverrideUponStartPassedIn = server.getStartDate();
+ TestCase.assertEquals(failMessage, manualSetTime, startDateBeforeOverrideUponStartPassedIn.getTime());
+ TestCase.assertEquals(failMessage, manualSetTime, startDateAfterOverrideUponStartPassedIn.getTime());
+
+ // Now try to set the override time directly upon an object returned from the server
+ startDateAfterOverrideUponStartPassedIn.setTime(overrideSetTime);
+
+ // And ensure we didn't leak when setting time upon a server-returned object
+ final Date startDateAfterOverrideUponStartReceived = server.getStartDate();
+ TestCase.assertEquals(failMessage, manualSetTime, startDateAfterOverrideUponStartReceived.getTime());
+ }
}
Added: projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/MutableStartDateNoOpJBossASServer.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/MutableStartDateNoOpJBossASServer.java (rev 0)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/MutableStartDateNoOpJBossASServer.java 2009-05-23 16:23:50 UTC (rev 89305)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.impl.as.server;
+
+import java.util.Date;
+
+/**
+ * MutableStartDateNoOpJBossASServer
+ *
+ * No-Op JBossASServer which allows tests to manually set the start Date
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MutableStartDateNoOpJBossASServer extends NoOpJBossASServer
+{
+
+ //-------------------------------------------------------------------------------------||
+ // OVerridden Implementations ---------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.impl.as.server.JBossASServerImpl#getStartDate()
+ */
+ @Override
+ public void setStartDate(final Date date)
+ {
+ super.setStartDate(date);
+ }
+}
More information about the jboss-cvs-commits
mailing list