[jboss-cvs] JBossAS SVN: r107272 - in projects/cluster/ha-server-cache-spi/trunk: src and 11 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 2 12:45:38 EDT 2010
Author: pferraro
Date: 2010-08-02 12:45:37 -0400 (Mon, 02 Aug 2010)
New Revision: 107272
Added:
projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java
projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java
projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java
projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java
projects/cluster/ha-server-cache-spi/trunk/src/test/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerTest.java
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java
projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java
Removed:
projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java
projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java
projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java
projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java
Modified:
projects/cluster/ha-server-cache-spi/trunk/pom.xml
Log:
Migrate unit tests for BatchingManager and SessionAttributeMarshaller from ha-server-cache-ispn
Modified: projects/cluster/ha-server-cache-spi/trunk/pom.xml
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/pom.xml 2010-08-02 16:28:54 UTC (rev 107271)
+++ projects/cluster/ha-server-cache-spi/trunk/pom.xml 2010-08-02 16:45:37 UTC (rev 107272)
@@ -34,6 +34,8 @@
<version.jgroups>2.10.0.GA</version.jgroups>
<version.org.jboss.naming>5.0.5.Final</version.org.jboss.naming>
<version.org.jboss.metadata.war>2.0.0.Alpha14</version.org.jboss.metadata.war>
+ <version.junit>4.8.1</version.junit>
+ <version.easymock>3.0</version.easymock>
</properties>
<build>
@@ -76,6 +78,19 @@
<version>${version.org.jboss.metadata.war}</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${version.junit}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>${version.easymock}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Deleted: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java 2010-08-02 16:28:54 UTC (rev 107271)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -1,109 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
-
-import javax.transaction.RollbackException;
-import javax.transaction.Status;
-import javax.transaction.TransactionManager;
-
-import org.jboss.logging.Logger;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
-
-/**
- * @author Paul Ferraro
- */
-public class BatchingManagerImpl implements BatchingManager
-{
- private static final Logger log = Logger.getLogger(BatchingManagerImpl.class);
-
- private final TransactionManager tm;
-
- public BatchingManagerImpl(TransactionManager tm)
- {
- this.tm = tm;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#isBatchInProgress()
- */
- @Override
- public boolean isBatchInProgress() throws Exception
- {
- return this.tm.getTransaction() != null;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#startBatch()
- */
- @Override
- public void startBatch() throws Exception
- {
- this.tm.begin();
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#setBatchRollbackOnly()
- */
- @Override
- public void setBatchRollbackOnly() throws Exception
- {
- this.tm.setRollbackOnly();
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#endBatch()
- */
- @Override
- public void endBatch()
- {
- try
- {
- if (this.tm.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK)
- {
- this.tm.commit();
- }
- else
- {
- log.debug("endBatch(): rolling back batch");
-
- this.tm.rollback();
- }
- }
- catch (RollbackException e)
- {
- // Do nothing here since cache may rollback automatically.
- log.warn("endBatch(): rolling back transaction with exception", e);
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new RuntimeException("endTransaction(): Caught Exception ending batch: ", e);
- }
- }
-}
Copied: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java (from rev 107270, projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java)
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java (rev 0)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
+
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Logger;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
+
+/**
+ * @author Paul Ferraro
+ */
+public class BatchingManagerImpl implements BatchingManager
+{
+ private static final Logger log = Logger.getLogger(BatchingManagerImpl.class);
+
+ private final TransactionManager tm;
+
+ public BatchingManagerImpl(TransactionManager tm)
+ {
+ this.tm = tm;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#isBatchInProgress()
+ */
+ @Override
+ public boolean isBatchInProgress() throws Exception
+ {
+ return this.tm.getTransaction() != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#startBatch()
+ */
+ @Override
+ public void startBatch() throws Exception
+ {
+ this.tm.begin();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#setBatchRollbackOnly()
+ */
+ @Override
+ public void setBatchRollbackOnly() throws Exception
+ {
+ this.tm.setRollbackOnly();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#endBatch()
+ */
+ @Override
+ public void endBatch()
+ {
+ try
+ {
+ if (this.tm.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK)
+ {
+ this.tm.commit();
+ }
+ else
+ {
+ log.debug("endBatch(): rolling back batch");
+
+ this.tm.rollback();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Do nothing here since cache may rollback automatically.
+ log.warn("endBatch(): rolling back transaction with exception", e);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("endTransaction(): Caught Exception ending batch: ", e);
+ }
+ }
+}
Deleted: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java 2010-08-02 16:28:54 UTC (rev 107271)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -1,117 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.web.tomcat.service.session.distributedcache.impl;
-
-import java.util.Map;
-
-import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData;
-
-
-/**
- * Base implementation of {@link DistributableSessionData}.
- *
- * @author Brian Stansberry
- */
-public class IncomingDistributableSessionDataImpl implements IncomingDistributableSessionData
-{
- private final int version;
- private final long timestamp;
- private final DistributableSessionMetadata metadata;
- private volatile Map<String, Object> attributes;
-
- public IncomingDistributableSessionDataImpl(Integer version, Long timestamp, DistributableSessionMetadata metadata)
- {
- assert version != null : "version is null";
- assert timestamp != null : "timestamp is null";
- assert metadata != null : "metadata is null";
-
- this.version = version.intValue();
- this.timestamp = timestamp.longValue();
- this.metadata = metadata;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#providesSessionAttributes()
- */
- @Override
- public boolean providesSessionAttributes()
- {
- return this.attributes != null;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#getSessionAttributes()
- */
- @Override
- public Map<String, Object> getSessionAttributes()
- {
- if (this.attributes == null)
- {
- throw new IllegalStateException("Not configured to provide session attributes");
- }
-
- return attributes;
- }
-
- /**
- * Sets the session attributes.
- * @param attributes a map of session attributes
- */
- public void setSessionAttributes(Map<String, Object> attributes)
- {
- this.attributes = attributes;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#getMetadata()
- */
- @Override
- public DistributableSessionMetadata getMetadata()
- {
- return metadata;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#getTimestamp()
- */
- @Override
- public long getTimestamp()
- {
- return timestamp;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#getVersion()
- */
- @Override
- public int getVersion()
- {
- return version;
- }
-}
Copied: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java (from rev 107270, projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java)
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java (rev 0)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.web.tomcat.service.session.distributedcache.impl;
+
+import java.util.Map;
+
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
+
+
+/**
+ * Base implementation of {@link DistributableSessionData}.
+ *
+ * @author Brian Stansberry
+ */
+public class IncomingDistributableSessionDataImpl implements org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData
+{
+ private final int version;
+ private final long timestamp;
+ private final DistributableSessionMetadata metadata;
+ private volatile Map<String, Object> attributes;
+
+ public IncomingDistributableSessionDataImpl(Integer version, Long timestamp, DistributableSessionMetadata metadata)
+ {
+ assert version != null : "version is null";
+ assert timestamp != null : "timestamp is null";
+ assert metadata != null : "metadata is null";
+
+ this.version = version.intValue();
+ this.timestamp = timestamp.longValue();
+ this.metadata = metadata;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#providesSessionAttributes()
+ */
+ @Override
+ public boolean providesSessionAttributes()
+ {
+ return this.attributes != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#getSessionAttributes()
+ */
+ @Override
+ public Map<String, Object> getSessionAttributes()
+ {
+ if (this.attributes == null)
+ {
+ throw new IllegalStateException("Not configured to provide session attributes");
+ }
+
+ return attributes;
+ }
+
+ /**
+ * Sets the session attributes.
+ * @param attributes a map of session attributes
+ */
+ public void setSessionAttributes(Map<String, Object> attributes)
+ {
+ this.attributes = attributes;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#getMetadata()
+ */
+ @Override
+ public DistributableSessionMetadata getMetadata()
+ {
+ return metadata;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#getTimestamp()
+ */
+ @Override
+ public long getTimestamp()
+ {
+ return timestamp;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData#getVersion()
+ */
+ @Override
+ public int getVersion()
+ {
+ return version;
+ }
+}
Deleted: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java 2010-08-02 16:28:54 UTC (rev 107271)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
-
-import org.jboss.ha.framework.interfaces.ObjectStreamSource;
-import org.jboss.ha.framework.server.MarshalledValueObjectStreamSource;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshallerFactory;
-
-/**
- * Default factory for creating session attribute marshallers.
- * @author Paul Ferraro
- */
-public class SessionAttributeMarshallerFactoryImpl implements SessionAttributeMarshallerFactory
-{
- private final ObjectStreamSource source;
-
- public SessionAttributeMarshallerFactoryImpl()
- {
- this(new MarshalledValueObjectStreamSource());
- }
-
- public SessionAttributeMarshallerFactoryImpl(ObjectStreamSource source)
- {
- this.source = source;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshallerFactory#createMarshaller(org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager)
- */
- @Override
- public SessionAttributeMarshaller createMarshaller(LocalDistributableSessionManager manager)
- {
- return new SessionAttributeMarshallerImpl(manager, this.source);
- }
-}
Copied: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java (from rev 107270, projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java)
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java (rev 0)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryImpl.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.jboss.ha.framework.interfaces.ObjectStreamSource;
+import org.jboss.ha.framework.server.MarshalledValueObjectStreamSource;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshallerFactory;
+
+/**
+ * Default factory for creating session attribute marshallers.
+ * @author Paul Ferraro
+ */
+public class SessionAttributeMarshallerFactoryImpl implements SessionAttributeMarshallerFactory
+{
+ private final ObjectStreamSource source;
+
+ public SessionAttributeMarshallerFactoryImpl()
+ {
+ this(new MarshalledValueObjectStreamSource());
+ }
+
+ public SessionAttributeMarshallerFactoryImpl(ObjectStreamSource source)
+ {
+ this.source = source;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshallerFactory#createMarshaller(org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager)
+ */
+ @Override
+ public SessionAttributeMarshaller createMarshaller(LocalDistributableSessionManager manager)
+ {
+ return new SessionAttributeMarshallerImpl(manager, this.source);
+ }
+}
Deleted: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java 2010-08-02 16:28:54 UTC (rev 107271)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -1,96 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.security.AccessController;
-
-import org.jboss.ha.framework.interfaces.ObjectStreamSource;
-import org.jboss.ha.framework.server.MarshalledValueHelper;
-import org.jboss.ha.framework.server.SimpleCachableMarshalledValue;
-import org.jboss.util.loading.ContextClassLoaderSwitcher;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller;
-
-/**
- * Session attribute marshaller that marshals attribute values using a {@link SimpleCachableMarshalledValue}.
- * @author Paul Ferraro
- */
-public class SessionAttributeMarshallerImpl implements SessionAttributeMarshaller
-{
- @SuppressWarnings("unchecked")
- // Need to cast since ContextClassLoaderSwitcher.NewInstance does not generically implement PrivilegedAction<ContextClassLoaderSwitcher>
- private final ContextClassLoaderSwitcher switcher = (ContextClassLoaderSwitcher) AccessController.doPrivileged(ContextClassLoaderSwitcher.INSTANTIATOR);
-
- private final LocalDistributableSessionManager manager;
- private final ObjectStreamSource source;
-
- public SessionAttributeMarshallerImpl(LocalDistributableSessionManager manager, ObjectStreamSource source)
- {
- this.manager = manager;
- this.source = source;
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller#marshal(java.lang.Object)
- */
- @Override
- public Object marshal(Object value)
- {
- if ((value == null) || MarshalledValueHelper.isTypeExcluded(value.getClass())) return value;
-
- if (!(value instanceof Serializable))
- {
- throw new IllegalArgumentException(String.format("%s does not implement %s", value, Serializable.class.getName()));
- }
-
- return new SimpleCachableMarshalledValue((Serializable) value, this.source, true);
- }
-
- /**
- * {@inheritDoc}
- * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller#unmarshal(java.lang.Object)
- */
- @Override
- public Object unmarshal(Object object) throws IOException, ClassNotFoundException
- {
- if ((object == null) || !(object instanceof SimpleCachableMarshalledValue)) return object;
-
- SimpleCachableMarshalledValue value = (SimpleCachableMarshalledValue) object;
-
- // Swap in/out the class loader for this web app. Needed only for unmarshalling.
- ContextClassLoaderSwitcher.SwitchContext switchContext = this.switcher.getSwitchContext(this.manager.getApplicationClassLoader());
-
- try
- {
- value.setObjectStreamSource(this.source);
-
- return value.get();
- }
- finally
- {
- switchContext.reset();
- }
- }
-}
Copied: projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java (from rev 107270, projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java)
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java (rev 0)
+++ projects/cluster/ha-server-cache-spi/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.security.AccessController;
+
+import org.jboss.ha.framework.interfaces.ObjectStreamSource;
+import org.jboss.ha.framework.server.MarshalledValueHelper;
+import org.jboss.ha.framework.server.SimpleCachableMarshalledValue;
+import org.jboss.util.loading.ContextClassLoaderSwitcher;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller;
+
+/**
+ * Session attribute marshaller that marshals attribute values using a {@link SimpleCachableMarshalledValue}.
+ * @author Paul Ferraro
+ */
+public class SessionAttributeMarshallerImpl implements SessionAttributeMarshaller
+{
+ @SuppressWarnings("unchecked")
+ // Need to cast since ContextClassLoaderSwitcher.NewInstance does not generically implement PrivilegedAction<ContextClassLoaderSwitcher>
+ private final ContextClassLoaderSwitcher switcher = (ContextClassLoaderSwitcher) AccessController.doPrivileged(ContextClassLoaderSwitcher.INSTANTIATOR);
+
+ private final LocalDistributableSessionManager manager;
+ private final ObjectStreamSource source;
+
+ public SessionAttributeMarshallerImpl(LocalDistributableSessionManager manager, ObjectStreamSource source)
+ {
+ this.manager = manager;
+ this.source = source;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller#marshal(java.lang.Object)
+ */
+ @Override
+ public Object marshal(Object value)
+ {
+ if ((value == null) || MarshalledValueHelper.isTypeExcluded(value.getClass())) return value;
+
+ if (!(value instanceof Serializable))
+ {
+ throw new IllegalArgumentException(String.format("%s does not implement %s", value, Serializable.class.getName()));
+ }
+
+ return new SimpleCachableMarshalledValue((Serializable) value, this.source, true);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller#unmarshal(java.lang.Object)
+ */
+ @Override
+ public Object unmarshal(Object object) throws IOException, ClassNotFoundException
+ {
+ if ((object == null) || !(object instanceof SimpleCachableMarshalledValue)) return object;
+
+ SimpleCachableMarshalledValue value = (SimpleCachableMarshalledValue) object;
+
+ // Swap in/out the class loader for this web app. Needed only for unmarshalling.
+ ContextClassLoaderSwitcher.SwitchContext switchContext = this.switcher.getSwitchContext(this.manager.getApplicationClassLoader());
+
+ try
+ {
+ value.setObjectStreamSource(this.source);
+
+ return value.get();
+ }
+ finally
+ {
+ switchContext.reset();
+ }
+ }
+}
Copied: projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerTest.java (from rev 107268, projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/BatchingManagerTest.java)
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerTest.java (rev 0)
+++ projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/BatchingManagerTest.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -0,0 +1,150 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
+
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.easymock.EasyMock;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.BatchingManagerImpl;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class BatchingManagerTest
+{
+ private final TransactionManager tm = EasyMock.createStrictMock(TransactionManager.class);
+ private final BatchingManager bm = new BatchingManagerImpl(this.tm);
+
+ @Test
+ public void isBatchInProgress() throws Exception
+ {
+ EasyMock.expect(this.tm.getTransaction()).andReturn(null);
+
+ EasyMock.replay(this.tm);
+
+ boolean result = this.bm.isBatchInProgress();
+
+ EasyMock.verify(this.tm);
+
+ Assert.assertFalse(result);
+
+ EasyMock.reset(this.tm);
+
+
+ Transaction transaction = EasyMock.createStrictMock(Transaction.class);
+
+ EasyMock.expect(this.tm.getTransaction()).andReturn(transaction);
+
+ EasyMock.replay(this.tm);
+
+ result = this.bm.isBatchInProgress();
+
+ EasyMock.verify(this.tm);
+
+ Assert.assertTrue(result);
+
+ EasyMock.reset(this.tm);
+ }
+
+ @Test
+ public void setRollbackOnly() throws Exception
+ {
+ this.tm.setRollbackOnly();
+
+ EasyMock.replay(this.tm);
+
+ this.bm.setBatchRollbackOnly();
+
+ EasyMock.verify(this.tm);
+
+ EasyMock.reset(this.tm);
+ }
+
+ @Test
+ public void startBatch() throws Exception
+ {
+ this.tm.begin();
+
+ EasyMock.replay(this.tm);
+
+ this.bm.startBatch();
+
+ EasyMock.verify(this.tm);
+
+ EasyMock.reset(this.tm);
+ }
+
+ @Test
+ public void endBatch() throws Exception
+ {
+ this.commitBatch(Status.STATUS_ACTIVE);
+ this.commitBatch(Status.STATUS_COMMITTED);
+ this.commitBatch(Status.STATUS_COMMITTING);
+ this.rollbackBatch(Status.STATUS_MARKED_ROLLBACK);
+ this.commitBatch(Status.STATUS_NO_TRANSACTION);
+ this.commitBatch(Status.STATUS_PREPARED);
+ this.commitBatch(Status.STATUS_PREPARING);
+ this.commitBatch(Status.STATUS_ROLLEDBACK);
+ this.commitBatch(Status.STATUS_ROLLING_BACK);
+ this.commitBatch(Status.STATUS_UNKNOWN);
+ }
+
+ private void commitBatch(int status) throws Exception
+ {
+ Transaction transaction = EasyMock.createStrictMock(Transaction.class);
+
+ EasyMock.expect(this.tm.getTransaction()).andReturn(transaction);
+ EasyMock.expect(transaction.getStatus()).andReturn(status);
+
+ this.tm.commit();
+
+ EasyMock.replay(this.tm, transaction);
+
+ this.bm.endBatch();
+
+ EasyMock.verify(this.tm, transaction);
+ EasyMock.reset(this.tm, transaction);
+ }
+
+ private void rollbackBatch(int status) throws Exception
+ {
+ Transaction transaction = EasyMock.createStrictMock(Transaction.class);
+
+ EasyMock.expect(this.tm.getTransaction()).andReturn(transaction);
+ EasyMock.expect(transaction.getStatus()).andReturn(status);
+
+ this.tm.rollback();
+
+ EasyMock.replay(this.tm, transaction);
+
+ this.bm.endBatch();
+
+ EasyMock.verify(this.tm, transaction);
+ EasyMock.reset(this.tm, transaction);
+ }
+}
Copied: projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java (from rev 107268, projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java)
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java (rev 0)
+++ projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerFactoryTest.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
+
+import org.junit.Assert;
+
+import org.easymock.EasyMock;
+import org.jboss.ha.framework.interfaces.ObjectStreamSource;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionAttributeMarshallerFactoryImpl;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionAttributeMarshallerImpl;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshallerFactory;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionAttributeMarshallerFactoryTest
+{
+ @Test
+ public void test()
+ {
+ ObjectStreamSource source = EasyMock.createStrictMock(ObjectStreamSource.class);
+ LocalDistributableSessionManager manager = EasyMock.createStrictMock(LocalDistributableSessionManager.class);
+ SessionAttributeMarshallerFactory factory = new SessionAttributeMarshallerFactoryImpl(source);
+
+ EasyMock.replay(source, manager);
+
+ SessionAttributeMarshaller marshaller = factory.createMarshaller(manager);
+
+ EasyMock.verify(source, manager);
+
+ Assert.assertNotNull(marshaller);
+ Assert.assertTrue(marshaller instanceof SessionAttributeMarshallerImpl);
+ }
+}
Copied: projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java (from rev 107268, projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java)
===================================================================
--- projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java (rev 0)
+++ projects/cluster/ha-server-cache-spi/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java 2010-08-02 16:45:37 UTC (rev 107272)
@@ -0,0 +1,138 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.web.tomcat.service.session.distributedcache.impl;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Date;
+
+import org.easymock.EasyMock;
+import org.jboss.ha.framework.server.MarshalledValueObjectStreamSource;
+import org.jboss.web.tomcat.service.session.distributedcache.impl.SessionAttributeMarshallerImpl;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionAttributeMarshallerTest
+{
+ private final LocalDistributableSessionManager manager = EasyMock.createStrictMock(LocalDistributableSessionManager.class);
+
+ private final SessionAttributeMarshaller marshaller = new SessionAttributeMarshallerImpl(this.manager, new MarshalledValueObjectStreamSource());
+
+ @Test
+ public void test() throws IOException, ClassNotFoundException
+ {
+ this.test((Serializable) null, true);
+ this.test("test", true);
+ this.test(Boolean.TRUE, true);
+ this.test(Byte.valueOf(Byte.MAX_VALUE), true);
+ this.test(Character.valueOf(Character.MAX_VALUE), true);
+ this.test(Double.valueOf(Double.MAX_VALUE), true);
+ this.test(Float.valueOf(Float.MAX_VALUE), true);
+ this.test(Integer.valueOf(Integer.MAX_VALUE), true);
+ this.test(Long.valueOf(Long.MAX_VALUE), true);
+ this.test(Short.valueOf(Short.MAX_VALUE), true);
+ this.test(new String[] { "test" }, true);
+ this.test(new boolean[] { Boolean.TRUE }, true);
+ this.test(new byte[] { Byte.MAX_VALUE }, true);
+ this.test(new char[] { Character.MAX_VALUE }, true);
+ this.test(new double[] { Double.MAX_VALUE }, true);
+ this.test(new float[] { Float.MAX_VALUE }, true);
+ this.test(new int[] { Integer.MAX_VALUE }, true);
+ this.test(new long[] { Long.MAX_VALUE }, true);
+ this.test(new short[] { Short.MAX_VALUE }, true);
+ this.test(new Boolean[] { Boolean.TRUE }, true);
+ this.test(new Byte[] { Byte.valueOf(Byte.MAX_VALUE) }, true);
+ this.test(new Character[] { Character.valueOf(Character.MAX_VALUE) }, true);
+ this.test(new Double[] { Double.valueOf(Double.MAX_VALUE) }, true);
+ this.test(new Float[] { Float.valueOf(Float.MAX_VALUE) }, true);
+ this.test(new Integer[] { Integer.valueOf(Integer.MAX_VALUE) }, true);
+ this.test(new Long[] { Long.valueOf(Long.MAX_VALUE) }, true);
+ this.test(new Short[] { Short.valueOf(Short.MAX_VALUE) }, true);
+ this.test(this.getClass(), false);
+ this.test(new Date(System.currentTimeMillis()), false);
+ this.test(new Object(), false);
+ }
+
+ private void test(Object original, boolean same) throws IOException, ClassNotFoundException
+ {
+ EasyMock.replay(this.manager);
+
+ try
+ {
+ Object marshalled = this.marshaller.marshal(original);
+
+ if (original != null)
+ {
+ Assert.assertTrue(original instanceof Serializable);
+ }
+ if (marshalled != null)
+ {
+ Assert.assertTrue(marshalled instanceof Serializable);
+ }
+
+ if (same)
+ {
+ Assert.assertSame(original, marshalled);
+ }
+ else
+ {
+ Assert.assertNotSame(original, marshalled);
+ }
+
+ EasyMock.verify(this.manager);
+ EasyMock.reset(this.manager);
+
+ if (!same)
+ {
+ EasyMock.expect(this.manager.getApplicationClassLoader()).andReturn(Thread.currentThread().getContextClassLoader());
+ }
+
+ EasyMock.replay(this.manager);
+
+ Object unmarshalled = this.marshaller.unmarshal(marshalled);
+
+ if (same)
+ {
+ Assert.assertSame(marshalled, unmarshalled);
+ }
+ else
+ {
+ Assert.assertNotSame(marshalled, unmarshalled);
+ Assert.assertEquals(original, unmarshalled);
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ Assert.assertFalse(same);
+ Assert.assertFalse(original instanceof Serializable);
+ }
+
+ EasyMock.verify(this.manager);
+ EasyMock.reset(this.manager);
+ }
+}
More information about the jboss-cvs-commits
mailing list