Skip to content

Commit

Permalink
[ISPN-151] (Configuration.clone() should not clone status) Fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
galderz committed Aug 21, 2009
1 parent 9937f01 commit ff2b3ab
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -77,4 +77,12 @@ public void inject(ComponentRegistry cr) {
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;
}

}
Expand Up @@ -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@jboss.org">manik@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;
Expand Down Expand Up @@ -878,4 +879,11 @@ public Set<Component> getRegisteredComponents() {
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;
}
}
@@ -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;

@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");
}
}

0 comments on commit ff2b3ab

Please sign in to comment.