[infinispan-commits] Infinispan SVN: r718 - in trunk/core/src: main/java/org/infinispan/factories and 1 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Aug 21 09:48:18 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-08-21 09:48:18 -0400 (Fri, 21 Aug 2009)
New Revision: 718

Added:
   trunk/core/src/test/java/org/infinispan/config/ConfigurationCloneTest.java
Modified:
   trunk/core/src/main/java/org/infinispan/config/AbstractNamedCacheConfigurationBean.java
   trunk/core/src/main/java/org/infinispan/factories/AbstractComponentRegistry.java
Log:
[ISPN-151] (Configuration.clone() should not clone status) Fixed.

Modified: trunk/core/src/main/java/org/infinispan/config/AbstractNamedCacheConfigurationBean.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/AbstractNamedCacheConfigurationBean.java	2009-08-21 13:45:28 UTC (rev 717)
+++ trunk/core/src/main/java/org/infinispan/config/AbstractNamedCacheConfigurationBean.java	2009-08-21 13:48:18 UTC (rev 718)
@@ -4,7 +4,6 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 
 import org.infinispan.factories.ComponentRegistry;
@@ -18,6 +17,7 @@
  * Adds named cache specific features to the {@link org.infinispan.config.AbstractConfigurationBean}.
  *
  * @author Manik Surtani
+ * @author Galder Zamarreño
  * @since 4.0
  */
 @Scope(Scopes.NAMED_CACHE)
@@ -77,4 +77,12 @@
    protected boolean hasComponentStarted() {
       return cr != null && cr.getStatus() != null && cr.getStatus() == ComponentStatus.RUNNING;
    }
+
+   @Override
+   public AbstractNamedCacheConfigurationBean clone() throws CloneNotSupportedException {
+      AbstractNamedCacheConfigurationBean dolly = (AbstractNamedCacheConfigurationBean) super.clone();
+      if (cr != null) dolly.cr = (ComponentRegistry) cr.clone(); 
+      return dolly;
+   }
+
 }

Modified: trunk/core/src/main/java/org/infinispan/factories/AbstractComponentRegistry.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/factories/AbstractComponentRegistry.java	2009-08-21 13:45:28 UTC (rev 717)
+++ trunk/core/src/main/java/org/infinispan/factories/AbstractComponentRegistry.java	2009-08-21 13:48:18 UTC (rev 718)
@@ -72,12 +72,13 @@
  * Cache configuration can only be changed and will only be reinjected if the cache is not in the {@link
  * org.infinispan.lifecycle.ComponentStatus#RUNNING} state.
  *
- * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @author Manik Surtani
+ * @author Galder Zamarreño
  * @since 4.0
  */
 @NonVolatile
 @Scope(Scopes.NAMED_CACHE)
-public abstract class AbstractComponentRegistry implements Lifecycle {
+public abstract class AbstractComponentRegistry implements Lifecycle, Cloneable {
 
    // Make sure this is ALWAYS false when being checked in to the code repository!
    public static final boolean DEBUG_DEPENDENCIES = false;
@@ -878,4 +879,11 @@
       HashSet<Component> defensiveCopy = new HashSet<Component>(componentLookup.values());
       return Collections.unmodifiableSet(defensiveCopy);
    }
+   
+   @Override
+   public AbstractComponentRegistry clone() throws CloneNotSupportedException {
+      AbstractComponentRegistry dolly = (AbstractComponentRegistry) super.clone();
+      dolly.state = ComponentStatus.INSTANTIATED;
+      return dolly;
+   }
 }

Added: trunk/core/src/test/java/org/infinispan/config/ConfigurationCloneTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/ConfigurationCloneTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/config/ConfigurationCloneTest.java	2009-08-21 13:48:18 UTC (rev 718)
@@ -0,0 +1,55 @@
+/*
+ * 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.infinispan.config;
+
+import org.infinispan.manager.CacheManager;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.Test;
+
+ at Test(groups = "functional", testName = "config.ConfigurationCloneTest")
+public class ConfigurationCloneTest extends SingleCacheManagerTest {
+
+   @Override
+   protected CacheManager createCacheManager() throws Exception {
+      CacheManager cm = TestCacheManagerFactory.createLocalCacheManager();
+      return cm;
+   }
+
+   public void testCloningBeforeStart() {
+      Configuration defaultConfig = cacheManager.defineConfiguration("default", new Configuration());
+      Configuration clone = defaultConfig.clone();
+      assert clone.equals(defaultConfig);
+      clone.setEvictionMaxEntries(Integer.MAX_VALUE);
+      cacheManager.defineConfiguration("new-default", clone);
+      cacheManager.getCache("new-default");
+   }
+
+   public void testCloningAfterStart() {
+      Configuration defaultConfig = cacheManager.getCache("default").getConfiguration();
+      Configuration clone = defaultConfig.clone();
+      assert clone.equals(defaultConfig);
+      clone.setEvictionMaxEntries(Integer.MAX_VALUE);
+      cacheManager.defineConfiguration("new-default", clone);
+      cacheManager.getCache("new-default");
+   }
+}



More information about the infinispan-commits mailing list