[jboss-cvs] JBossAS SVN: r107813 - in projects/cluster/ha-server-ispn/trunk/src: main/java/org/jboss/ha/ispn/config and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 26 14:56:47 EDT 2010
Author: pferraro
Date: 2010-08-26 14:56:46 -0400 (Thu, 26 Aug 2010)
New Revision: 107813
Removed:
projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultAdvancedCache.java
projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainer.java
projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/config/Alias.java
projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultAdvancedCacheTest.java
projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerTest.java
Modified:
projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerFactory.java
projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerRegistry.java
projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/config/CacheContainerRegistryConfigurationEntry.java
projects/cluster/ha-server-ispn/trunk/src/main/resources/META-INF/infinispan-configs.xsd
projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java
projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/config/xml/XMLCacheManagerRegistryConfigurationSourceTest.java
projects/cluster/ha-server-ispn/trunk/src/test/resources/infinispan-configs-multiple.xml
projects/cluster/ha-server-ispn/trunk/src/test/resources/infinispan-configs-property-replacement.xml
Log:
Add support for cache container aliasing. Remove support for cache aliasing, for which I can think of no use case. Much cleaner.
Deleted: projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultAdvancedCache.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultAdvancedCache.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultAdvancedCache.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -1,66 +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.ha.ispn;
-
-import org.infinispan.AbstractDelegatingAdvancedCache;
-import org.infinispan.AdvancedCache;
-import org.infinispan.manager.CacheContainer;
-import org.infinispan.stats.Stats;
-
-/**
- * @author Paul Ferraro
- *
- */
-public class DefaultAdvancedCache<K, V> extends AbstractDelegatingAdvancedCache<K, V>
-{
- private final CacheContainer container;
- private final AdvancedCache<K, V> cache;
-
- public DefaultAdvancedCache(CacheContainer container, AdvancedCache<K, V> cache)
- {
- super(cache);
- this.container = container;
- this.cache = cache;
- }
-
- /**
- * {@inheritDoc}
- * @see org.infinispan.AdvancedCache#getStats()
- */
- @Override
- public Stats getStats()
- {
- return this.cache.getStats();
- }
-
- @Override
- public AdvancedCache<K, V> getAdvancedCache()
- {
- return this;
- }
-
- @Override
- public CacheContainer getCacheManager()
- {
- return this.container;
- }
-}
Deleted: projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainer.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainer.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainer.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -1,179 +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.ha.ispn;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
-import org.infinispan.config.GlobalConfiguration;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.infinispan.remoting.transport.Address;
-
-/**
- * Cache container decorator that returns the same cache instance for all aliases of a given cache name.
- * @author Paul Ferraro
- */
-public class DefaultCacheContainer implements EmbeddedCacheManager
-{
- private final EmbeddedCacheManager container;
- private final Map<String, String> aliases;
-
- /**
- * Creates a new alias-aware cache container.
- * @param container the proxied cache container
- * @param aliases an map of cache name aliases
- */
- public DefaultCacheContainer(EmbeddedCacheManager container, Map<String, String> aliases)
- {
- this.container = container;
- this.aliases = aliases;
- }
-
- /**
- * {@inheritDoc}
- * @see org.infinispan.lifecycle.Lifecycle#start()
- */
- @Override
- public void start()
- {
- this.container.start();
- }
-
- /**
- * {@inheritDoc}
- * @see org.infinispan.lifecycle.Lifecycle#stop()
- */
- @Override
- public void stop()
- {
- this.container.stop();
- }
-
- /**
- * {@inheritDoc}
- * @see org.infinispan.manager.CacheContainer#getCache()
- */
- @Override
- public <K, V> Cache<K, V> getCache()
- {
- return this.decorate(this.container.<K, V>getCache());
- }
-
- /**
- * {@inheritDoc}
- * @see org.infinispan.manager.CacheContainer#getCache(java.lang.String)
- */
- @Override
- public <K, V> Cache<K, V> getCache(String alias)
- {
- String name = this.aliases.get(alias);
-
- return this.decorate(this.container.<K, V>getCache((name == null) ? alias : name));
- }
-
- private <K, V> Cache<K, V> decorate(Cache<K, V> cache)
- {
- return new DefaultAdvancedCache<K, V>(this, cache.getAdvancedCache());
- }
-
- @Override
- public void addListener(Object listener)
- {
- this.container.addListener(listener);
- }
-
- @Override
- public void removeListener(Object listener)
- {
- this.container.removeListener(listener);
- }
-
- @Override
- public Set<Object> getListeners()
- {
- return this.container.getListeners();
- }
-
- @Override
- public Configuration defineConfiguration(String cacheName, Configuration configurationOverride)
- {
- return this.container.defineConfiguration(cacheName, configurationOverride);
- }
-
- @Override
- public Configuration defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride)
- {
- return this.container.defineConfiguration(cacheName, templateCacheName, configurationOverride);
- }
-
- @Override
- public String getClusterName()
- {
- return this.container.getClusterName();
- }
-
- @Override
- public List<Address> getMembers()
- {
- return this.container.getMembers();
- }
-
- @Override
- public Address getAddress()
- {
- return this.container.getAddress();
- }
-
- @Override
- public boolean isCoordinator()
- {
- return this.container.isCoordinator();
- }
-
- @Override
- public ComponentStatus getStatus()
- {
- return this.container.getStatus();
- }
-
- @Override
- public GlobalConfiguration getGlobalConfiguration()
- {
- return this.container.getGlobalConfiguration();
- }
-
- @Override
- public Configuration getDefaultConfiguration()
- {
- return this.container.getDefaultConfiguration();
- }
-
- @Override
- public Set<String> getCacheNames()
- {
- return this.container.getCacheNames();
- }
-}
Modified: projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerFactory.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerFactory.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerFactory.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -75,8 +75,6 @@
manager.defineConfiguration(config.getName(), config);
}
- manager.start();
-
return manager;
}
Modified: projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerRegistry.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerRegistry.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/DefaultCacheContainerRegistry.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -21,9 +21,7 @@
*/
package org.jboss.ha.ispn;
-import java.util.AbstractMap;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -34,8 +32,8 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.EmbeddedCacheManager;
-import org.jboss.ha.ispn.config.Alias;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfiguration;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationEntry;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationSource;
@@ -61,9 +59,10 @@
private final CacheContainerFactory factory;
private final CacheContainerRegistryConfigurationSource source;
private final Context context;
- private final Map<String, Map.Entry<String, EmbeddedCacheManager>> containers = new ConcurrentHashMap<String, Map.Entry<String, EmbeddedCacheManager>>();
+ private final Map<String, String> aliases = new ConcurrentHashMap<String, String>();
+ private final Map<String, CacheContainerRegistryEntry> containers = new ConcurrentHashMap<String, CacheContainerRegistryEntry>();
- private EmbeddedCacheManager defaultContainer;
+ private volatile EmbeddedCacheManager defaultContainer;
/**
* Creates a new cache container registry using the specified factory and source.
@@ -110,7 +109,7 @@
defaultEntry = registry.getEntries().get(0);
}
- this.defaultContainer = this.containers.get(defaultEntry.getId()).getValue();
+ this.defaultContainer = this.containers.get(defaultEntry.getId()).getContainer();
singleton.compareAndSet(null, this);
}
@@ -119,23 +118,12 @@
{
singleton.set(null);
- for (Map.Entry<String, EmbeddedCacheManager> entry: this.containers.values())
+ for (CacheContainerRegistryEntry entry: this.containers.values())
{
- String jndiName = entry.getKey();
-
- try
- {
- this.context.unbind(jndiName);
- NonSerializableFactory.unbind(jndiName);
- }
- catch (NamingException e)
- {
- logger.warn(e.getMessage(), e);
- }
-
- entry.getValue().stop();
+ this.stop(entry);
}
+ this.aliases.clear();
this.containers.clear();
this.defaultContainer = null;
}
@@ -165,59 +153,94 @@
* @see org.jboss.ha.ispn.CacheContainerRegistry#getCacheContainer(java.lang.String)
*/
@Override
- public EmbeddedCacheManager getCacheContainer(String name)
+ public EmbeddedCacheManager getCacheContainer(String alias)
{
- Map.Entry<String, EmbeddedCacheManager> entry = (name != null) ? this.containers.get(name) : null;
+ CacheContainerRegistryEntry entry = null;
+ if (alias != null)
+ {
+ // Resolve alias, if possible
+ String id = this.aliases.get(alias);
+
+ entry = this.containers.get((id != null) ? id : alias);
+ }
+
// Return default cache manager, if name was not found or if it was null
- return (entry != null) ? entry.getValue() : this.defaultContainer;
+ return (entry != null) ? entry.getContainer() : this.defaultContainer;
}
- public void add(CacheContainerRegistryConfigurationEntry entry) throws NamingException
+ public void add(CacheContainerRegistryConfigurationEntry configEntry) throws NamingException
{
- EmbeddedCacheManager container = new DefaultCacheContainer(this.factory.createCacheContainer(entry.getConfiguration()), this.mapAliases(entry));
+ String id = configEntry.getId();
+ EmbeddedCacheManager container = this.factory.createCacheContainer(configEntry.getConfiguration());
+ String jndiName = configEntry.getJndiName();
+ List<String> aliases = configEntry.getAliases();
- String jndiName = entry.getJndiName();
+ CacheContainerRegistryEntry entry = new CacheContainerRegistryEntry(container, jndiName, aliases);
// Store cache containers with jndi name, so they can be unbound during stop()
- this.containers.put(entry.getId(), new AbstractMap.SimpleImmutableEntry<String, EmbeddedCacheManager>(jndiName, container));
+ this.containers.put(id, entry);
- // Bind cache container to jndi
- this.bind(jndiName, container);
+ for (String alias: aliases)
+ {
+ this.aliases.put(alias, id);
+ }
+
+ this.start(entry);
}
- private Map<String, String> mapAliases(CacheContainerRegistryConfigurationEntry entry)
+ public void remove(CacheContainerRegistryConfigurationEntry configEntry)
{
- List<Alias> aliases = entry.getAliases();
+ CacheContainerRegistryEntry entry = this.containers.remove(configEntry.getId());
- if ((aliases == null) || aliases.isEmpty()) return Collections.emptyMap();
-
- if (aliases.size() == 1)
+ if (entry != null)
{
- Alias alias = aliases.get(0);
- return Collections.singletonMap(alias.getName(), alias.getTarget());
+ for (String alias: entry.getAliases())
+ {
+ this.aliases.remove(alias);
+ }
+
+ this.stop(entry);
}
+ }
+
+ private void start(CacheContainerRegistryEntry entry)
+ {
+ CacheContainer container = entry.getContainer();
+ container.start();
- Map<String, String> map = new HashMap<String, String>();
+ String jndiName = entry.getJndiName();
- for (Alias alias: aliases)
+ if (jndiName != null)
{
- map.put(alias.getName(), alias.getTarget());
+ try
+ {
+ this.bind(jndiName, container);
+ }
+ catch (NamingException e)
+ {
+ logger.warn(e.getMessage(), e);
+ }
}
-
- return map;
}
- public void remove(CacheContainerRegistryConfigurationEntry config) throws NamingException
+ private void stop(CacheContainerRegistryEntry entry)
{
- Map.Entry<String, EmbeddedCacheManager> entry = this.containers.remove(config.getId());
+ String jndiName = entry.getJndiName();
- if (entry != null)
+ if (jndiName != null)
{
- entry.getValue().stop();
-
- this.unbind(entry.getKey());
+ try
+ {
+ this.unbind(jndiName);
+ }
+ catch (NamingException e)
+ {
+ logger.warn(e.getMessage(), e);
+ }
}
+
+ entry.getContainer().stop();
}
private void bind(String name, Object value) throws NamingException
@@ -230,4 +253,33 @@
this.context.unbind(name);
NonSerializableFactory.unbind(name);
}
+
+ private static class CacheContainerRegistryEntry
+ {
+ private final List<String> aliases;
+ private final String jndiName;
+ private final EmbeddedCacheManager container;
+
+ public CacheContainerRegistryEntry(EmbeddedCacheManager container, String jndiName, List<String> aliases)
+ {
+ this.container = container;
+ this.jndiName = jndiName;
+ this.aliases = aliases;
+ }
+
+ public EmbeddedCacheManager getContainer()
+ {
+ return this.container;
+ }
+
+ public String getJndiName()
+ {
+ return this.jndiName;
+ }
+
+ public List<String> getAliases()
+ {
+ return this.aliases;
+ }
+ }
}
Deleted: projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/config/Alias.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/config/Alias.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/config/Alias.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -1,63 +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.ha.ispn.config;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.XmlValue;
-
-/**
- * Generic alias descriptor.
- * @author Paul Ferraro
- */
- at XmlAccessorType(XmlAccessType.FIELD)
- at XmlType
-public class Alias
-{
- @XmlAttribute(name = "name")
- private String name;
-
- @XmlValue
- private String target;
-
- public String getName()
- {
- return this.name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public String getTarget()
- {
- return this.target;
- }
-
- public void setTarget(String target)
- {
- this.target = target;
- }
-}
Modified: projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/config/CacheContainerRegistryConfigurationEntry.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/config/CacheContainerRegistryConfigurationEntry.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/main/java/org/jboss/ha/ispn/config/CacheContainerRegistryConfigurationEntry.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -21,6 +21,7 @@
*/
package org.jboss.ha.ispn.config;
+import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
@@ -49,8 +50,9 @@
@XmlAttribute(name = "jndi-name", required = false)
private String jndiName;
+ @XmlID
@XmlElement(name = "alias")
- private List<Alias> aliases;
+ private List<String> aliases = new LinkedList<String>();
@XmlJavaTypeAdapter(InfinispanConfigurationAdapter.class)
@XmlElementRef(type = InfinispanConfiguration.class)
@@ -76,12 +78,12 @@
this.jndiName = jndiName;
}
- public List<Alias> getAliases()
+ public List<String> getAliases()
{
return this.aliases;
}
- public void setAliases(List<Alias> aliases)
+ public void setAliases(List<String> aliases)
{
this.aliases = aliases;
}
Modified: projects/cluster/ha-server-ispn/trunk/src/main/resources/META-INF/infinispan-configs.xsd
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/main/resources/META-INF/infinispan-configs.xsd 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/main/resources/META-INF/infinispan-configs.xsd 2010-08-26 18:56:46 UTC (rev 107813)
@@ -1,24 +1,24 @@
<?xml version="1.0"?>
<xs:schema targetNamespace="urn:jboss:infinispan-configs:1.0" xmlns:tns="urn:jboss:infinispan-configs:1.0" xmlns:ispn="urn:infinispan:config:4.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0">
-
+
<xs:import namespace="urn:infinispan:config:4.0" schemaLocation="http://docs.jboss.org/infinispan/schemas/infinispan-config-4.1.xsd"/>
<xs:element name="infinispan-configs" type="tns:cacheContainerRegistryConfiguration"/>
<xs:complexType name="cacheContainerRegistryConfiguration">
- <xs:sequence>
- <xs:element name="infinispan-config" type="tns:cacheContainerRegistryConfigurationEntry" maxOccurs="unbounded"/>
- </xs:sequence>
+ <xs:sequence>
+ <xs:element name="infinispan-config" type="tns:cacheContainerRegistryConfigurationEntry" maxOccurs="unbounded"/>
+ </xs:sequence>
<xs:attribute name="default" type="xs:IDREF"/>
<xs:attribute name="base-jndi-name" type="xs:string" default="java:CacheManager"/>
</xs:complexType>
<xs:complexType name="cacheContainerRegistryConfigurationEntry">
- <xs:sequence>
- <xs:element name="alias" type="tns:alias" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:sequence>
+ <xs:element name="alias" type="xs:ID" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="ispn:infinispan"/>
- </xs:sequence>
- <xs:attribute name="name" type="xs:ID" use="required"/>
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:ID" use="required"/>
<xs:attribute name="jndi-name" type="xs:string"/>
</xs:complexType>
Deleted: projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultAdvancedCacheTest.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultAdvancedCacheTest.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultAdvancedCacheTest.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -1,1407 +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.ha.ispn;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import javax.transaction.TransactionManager;
-
-import org.easymock.EasyMock;
-import org.infinispan.AdvancedCache;
-import org.infinispan.batch.BatchContainer;
-import org.infinispan.config.Configuration;
-import org.infinispan.config.GlobalConfiguration;
-import org.infinispan.container.DataContainer;
-import org.infinispan.context.Flag;
-import org.infinispan.context.InvocationContextContainer;
-import org.infinispan.distribution.DistributionManager;
-import org.infinispan.eviction.EvictionManager;
-import org.infinispan.factories.ComponentRegistry;
-import org.infinispan.factories.GlobalComponentRegistry;
-import org.infinispan.interceptors.CallInterceptor;
-import org.infinispan.interceptors.base.CommandInterceptor;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.CacheContainer;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.infinispan.remoting.rpc.RpcManager;
-import org.infinispan.stats.Stats;
-import org.infinispan.util.concurrent.NotifyingFuture;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class DefaultAdvancedCacheTest
-{
- private final EmbeddedCacheManager container = EasyMock.createStrictMock(EmbeddedCacheManager.class);
- @SuppressWarnings("unchecked")
- private final AdvancedCache<Object, Object> advancedCache = EasyMock.createStrictMock(AdvancedCache.class);
- private final AdvancedCache<Object, Object> cache = new DefaultAdvancedCache<Object, Object>(this.container, this.advancedCache);
-
- @After
- public void after()
- {
- EasyMock.reset(this.advancedCache);
- }
-
- @Test
- public void putForExternalRead()
- {
- Object key = new Object();
- Object value = new Object();
-
- this.advancedCache.putForExternalRead(EasyMock.same(key), EasyMock.same(value));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.putForExternalRead(key, value);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void evict()
- {
- Object key = new Object();
-
- this.advancedCache.evict(EasyMock.same(key));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.evict(key);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void getConfiguration()
- {
- Configuration configuration = new Configuration();
-
- EasyMock.expect(this.advancedCache.getConfiguration()).andReturn(configuration);
-
- EasyMock.replay(this.advancedCache);
-
- Configuration result = this.cache.getConfiguration();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(configuration, result);
- }
-
- @Test
- public void startBatch()
- {
- EasyMock.expect(this.advancedCache.startBatch()).andReturn(true);
-
- EasyMock.replay(this.advancedCache);
-
- boolean result = this.cache.startBatch();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void endBatch()
- {
- this.advancedCache.endBatch(true);
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.endBatch(true);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void getName()
- {
- String name = "name";
-
- EasyMock.expect(this.advancedCache.getName()).andReturn(name);
-
- EasyMock.replay(this.advancedCache);
-
- String result = this.cache.getName();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(name, result);
- }
-
- @Test
- public void getVersion()
- {
- String version = "name";
-
- EasyMock.expect(this.advancedCache.getVersion()).andReturn(version);
-
- EasyMock.replay(this.advancedCache);
-
- String result = this.cache.getVersion();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(version, result);
- }
-
- @Test
- public void getCacheManager()
- {
- CacheContainer result = this.cache.getCacheManager();
-
- Assert.assertSame(this.container, result);
- }
-
- @Test
- public void putLifespan()
- {
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit unit = TimeUnit.SECONDS;
- Object expected = new Object();
-
- EasyMock.expect(this.advancedCache.put(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(unit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.put(key, value, lifespan, unit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putIfAbsentLifespan()
- {
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit unit = TimeUnit.SECONDS;
- Object expected = new Object();
-
- EasyMock.expect(this.advancedCache.putIfAbsent(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(unit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.putIfAbsent(key, value, lifespan, unit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putAllLifespan()
- {
- Map<Object, Object> map = Collections.emptyMap();
- long lifespan = 1;
- TimeUnit unit = TimeUnit.SECONDS;
-
- this.advancedCache.putAll(EasyMock.same(map), EasyMock.eq(lifespan), EasyMock.same(unit));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.putAll(map, lifespan, unit);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void replaceLifespan()
- {
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit unit = TimeUnit.SECONDS;
- Object expected = new Object();
-
- EasyMock.expect(this.advancedCache.replace(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(unit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.replace(key, value, lifespan, unit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void replaceIfLifespan()
- {
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit unit = TimeUnit.SECONDS;
- Object oldValue = new Object();
-
- EasyMock.expect(this.advancedCache.replace(EasyMock.same(key), EasyMock.same(oldValue), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(unit))).andReturn(true);
-
- EasyMock.replay(this.advancedCache);
-
- boolean result = this.cache.replace(key, oldValue, value, lifespan, unit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void putTimeout()
- {
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdleTime = 2;
- TimeUnit maxIdleTimeUnit = TimeUnit.MILLISECONDS;
-
- Object expected = new Object();
-
- EasyMock.expect(this.advancedCache.put(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdleTime), EasyMock.same(maxIdleTimeUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.put(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putIfAbsentTimeout()
- {
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdleTime = 2;
- TimeUnit maxIdleTimeUnit = TimeUnit.MILLISECONDS;
-
- Object expected = new Object();
-
- EasyMock.expect(this.advancedCache.putIfAbsent(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdleTime), EasyMock.same(maxIdleTimeUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putAllTimeout()
- {
- Map<Object, Object> map = Collections.emptyMap();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdleTime = 2;
- TimeUnit maxIdleTimeUnit = TimeUnit.MILLISECONDS;
-
- this.advancedCache.putAll(EasyMock.same(map), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdleTime), EasyMock.same(maxIdleTimeUnit));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.putAll(map, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void replaceTimeout()
- {
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdleTime = 2;
- TimeUnit maxIdleTimeUnit = TimeUnit.MILLISECONDS;
-
- Object expected = new Object();
-
- EasyMock.expect(this.advancedCache.replace(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdleTime), EasyMock.same(maxIdleTimeUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.replace(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void replaceIfTimeout()
- {
- Object key = new Object();
- Object value = new Object();
- Object oldValue = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdleTime = 2;
- TimeUnit maxIdleTimeUnit = TimeUnit.MILLISECONDS;
-
- EasyMock.expect(this.advancedCache.replace(EasyMock.same(key), EasyMock.same(oldValue), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdleTime), EasyMock.same(maxIdleTimeUnit))).andReturn(true);
-
- EasyMock.replay(this.advancedCache);
-
- boolean result = this.cache.replace(key, oldValue, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void putAsync()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.putAsync(EasyMock.same(key), EasyMock.same(value))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.putAsync(key, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putAsyncLifespan()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit unit = TimeUnit.SECONDS;
-
- EasyMock.expect(this.advancedCache.putAsync(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(unit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.putAsync(key, value, lifespan, unit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putAsyncTimeout()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdle = 2;
- TimeUnit maxIdleUnit = TimeUnit.MILLISECONDS;
-
- EasyMock.expect(this.advancedCache.putAsync(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdle), EasyMock.same(maxIdleUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.putAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putAllAsync()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Void> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Map<Object, Object> map = Collections.emptyMap();
-
- EasyMock.expect(this.advancedCache.putAllAsync(EasyMock.same(map))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Void> result = this.cache.putAllAsync(map);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putAllAsyncLifespan()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Void> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Map<Object, Object> map = Collections.emptyMap();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
-
- EasyMock.expect(this.advancedCache.putAllAsync(EasyMock.same(map), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Void> result = this.cache.putAllAsync(map, lifespan, lifespanUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putAllAsyncTimeout()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Void> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Map<Object, Object> map = Collections.emptyMap();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdle = 2;
- TimeUnit maxIdleUnit = TimeUnit.MILLISECONDS;
-
- EasyMock.expect(this.advancedCache.putAllAsync(EasyMock.same(map), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdle), EasyMock.same(maxIdleUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Void> result = this.cache.putAllAsync(map, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void clearAsync()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Void> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- EasyMock.expect(this.advancedCache.clearAsync()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Void> result = this.cache.clearAsync();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putIfAbsentAsync()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.putIfAbsentAsync(EasyMock.same(key), EasyMock.same(value))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.putIfAbsentAsync(key, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putIfAbsentAsyncLifespan()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
-
- EasyMock.expect(this.advancedCache.putIfAbsentAsync(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.putIfAbsentAsync(key, value, lifespan, lifespanUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putIfAbsentAsyncTimeout()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdle = 2;
- TimeUnit maxIdleUnit = TimeUnit.MILLISECONDS;
-
- EasyMock.expect(this.advancedCache.putIfAbsentAsync(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdle), EasyMock.same(maxIdleUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.putIfAbsentAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void removeAsync()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
-
- EasyMock.expect(this.advancedCache.removeAsync(EasyMock.same(key))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.removeAsync(key);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void removeAsyncIf()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Boolean> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.removeAsync(EasyMock.same(key), EasyMock.same(value))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Boolean> result = this.cache.removeAsync(key, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void replaceAsync()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.replaceAsync(EasyMock.same(key), EasyMock.same(value))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.replaceAsync(key, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void replaceAsyncLifespan()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
-
- EasyMock.expect(this.advancedCache.replaceAsync(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.replaceAsync(key, value, lifespan, lifespanUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void replaceAsyncTimeout()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Object> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdle = 2;
- TimeUnit maxIdleUnit = TimeUnit.MILLISECONDS;
-
- EasyMock.expect(this.advancedCache.replaceAsync(EasyMock.same(key), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdle), EasyMock.same(maxIdleUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Object> result = this.cache.replaceAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void replaceAsyncIf()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Boolean> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object oldValue = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.replaceAsync(EasyMock.same(key), EasyMock.same(oldValue), EasyMock.same(value))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Boolean> result = this.cache.replaceAsync(key, oldValue, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void replaceAsyncIfLifespan()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Boolean> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object oldValue = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
-
- EasyMock.expect(this.advancedCache.replaceAsync(EasyMock.same(key), EasyMock.same(oldValue), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Boolean> result = this.cache.replaceAsync(key, oldValue, value, lifespan, lifespanUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void replaceAsyncIfTimeout()
- {
- @SuppressWarnings("unchecked")
- NotifyingFuture<Boolean> expected = EasyMock.createStrictMock(NotifyingFuture.class);
-
- Object key = new Object();
- Object oldValue = new Object();
- Object value = new Object();
- long lifespan = 1;
- TimeUnit lifespanUnit = TimeUnit.SECONDS;
- long maxIdle = 2;
- TimeUnit maxIdleUnit = TimeUnit.MILLISECONDS;
-
- EasyMock.expect(this.advancedCache.replaceAsync(EasyMock.same(key), EasyMock.same(oldValue), EasyMock.same(value), EasyMock.eq(lifespan), EasyMock.same(lifespanUnit), EasyMock.eq(maxIdle), EasyMock.same(maxIdleUnit))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- NotifyingFuture<Boolean> result = this.cache.replaceAsync(key, oldValue, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getAdvancedCache()
- {
- Assert.assertSame(this.cache, this.cache.getAdvancedCache());
- }
-
- @Test
- public void compact()
- {
- this.advancedCache.compact();
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.compact();
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void getStatus()
- {
- ComponentStatus expected = ComponentStatus.INITIALIZING;
-
- EasyMock.expect(this.advancedCache.getStatus()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- ComponentStatus result = this.cache.getStatus();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void keySet()
- {
- Set<Object> expected = Collections.emptySet();
-
- EasyMock.expect(this.advancedCache.keySet()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Set<Object> result = this.cache.keySet();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void values()
- {
- Collection<Object> expected = Collections.emptySet();
-
- EasyMock.expect(this.advancedCache.values()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Collection<Object> result = this.cache.values();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void entrySet()
- {
- Set<java.util.Map.Entry<Object, Object>> expected = Collections.emptySet();
-
- EasyMock.expect(this.advancedCache.entrySet()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Set<java.util.Map.Entry<Object, Object>> result = this.cache.entrySet();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putIfAbsent()
- {
- Object expected = new Object();
- Object key = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.putIfAbsent(EasyMock.same(key), EasyMock.same(value))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.putIfAbsent(key, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void removeIf()
- {
- Object key = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.remove(EasyMock.same(key), EasyMock.same(value))).andReturn(true);
-
- EasyMock.replay(this.advancedCache);
-
- boolean result = this.cache.remove(key, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void replaceIf()
- {
- Object key = new Object();
- Object oldValue = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.replace(EasyMock.same(key), EasyMock.same(oldValue), EasyMock.same(value))).andReturn(true);
-
- EasyMock.replay(this.advancedCache);
-
- boolean result = this.cache.replace(key, oldValue, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void replace()
- {
- Object expected = new Object();
- Object key = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.replace(EasyMock.same(key), EasyMock.same(value))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.replace(key, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void size()
- {
- EasyMock.expect(this.advancedCache.size()).andReturn(1);
-
- EasyMock.replay(this.advancedCache);
-
- int result = this.cache.size();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertEquals(1, result);
- }
-
- @Test
- public void isEmpty()
- {
- EasyMock.expect(this.advancedCache.isEmpty()).andReturn(true);
-
- EasyMock.replay(this.advancedCache);
-
- boolean result = this.cache.isEmpty();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void containsKey()
- {
- Object key = new Object();
-
- EasyMock.expect(this.advancedCache.containsKey(EasyMock.same(key))).andReturn(true);
-
- EasyMock.replay(this.advancedCache);
-
- boolean result = this.cache.containsKey(key);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void containsValue()
- {
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.containsValue(EasyMock.same(value))).andReturn(true);
-
- EasyMock.replay(this.advancedCache);
-
- boolean result = this.cache.containsValue(value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void get()
- {
- Object expected = new Object();
- Object key = new Object();
-
- EasyMock.expect(this.advancedCache.get(EasyMock.same(key))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.get(key);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void put()
- {
- Object expected = new Object();
- Object key = new Object();
- Object value = new Object();
-
- EasyMock.expect(this.advancedCache.put(EasyMock.same(key), EasyMock.same(value))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.put(key, value);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void remove()
- {
- Object expected = new Object();
- Object key = new Object();
-
- EasyMock.expect(this.advancedCache.remove(EasyMock.same(key))).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Object result = this.cache.remove(key);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void putAll()
- {
- Map<Object, Object> map = Collections.emptyMap();
-
- this.advancedCache.putAll(EasyMock.same(map));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.putAll(map);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void clear()
- {
- this.advancedCache.clear();
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.clear();
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void start()
- {
- this.advancedCache.start();
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.start();
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void stop()
- {
- this.advancedCache.stop();
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.stop();
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void addListener()
- {
- Object listener = new Object();
-
- this.advancedCache.addListener(EasyMock.same(listener));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.addListener(listener);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void removeListener()
- {
- Object listener = new Object();
-
- this.advancedCache.removeListener(EasyMock.same(listener));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.removeListener(listener);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void getListeners()
- {
- Set<Object> expected = Collections.emptySet();
-
- EasyMock.expect(this.advancedCache.getListeners()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Set<Object> result = this.cache.getListeners();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void withFlags()
- {
- Flag[] flags = new Flag[0];
-
- EasyMock.expect(this.advancedCache.withFlags(flags)).andReturn(this.advancedCache);
-
- EasyMock.replay(this.advancedCache);
-
- AdvancedCache<Object, Object> result = this.cache.withFlags(flags);
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(this.cache, result);
- }
-
- @Test
- public void addInterceptor()
- {
- CommandInterceptor interceptor = new CallInterceptor();
- int position = 1;
-
- this.advancedCache.addInterceptor(EasyMock.same(interceptor), EasyMock.eq(position));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.addInterceptor(interceptor, position);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void addInterceptorAfter()
- {
- CommandInterceptor interceptor = new CallInterceptor();
- Class<? extends CommandInterceptor> afterInterceptor = CallInterceptor.class;
-
- this.advancedCache.addInterceptorAfter(EasyMock.same(interceptor), EasyMock.same(afterInterceptor));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.addInterceptorAfter(interceptor, afterInterceptor);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void addInterceptorBefore()
- {
- CommandInterceptor interceptor = new CallInterceptor();
- Class<? extends CommandInterceptor> afterInterceptor = CallInterceptor.class;
-
- this.advancedCache.addInterceptorBefore(EasyMock.same(interceptor), EasyMock.same(afterInterceptor));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.addInterceptorBefore(interceptor, afterInterceptor);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void removeInterceptorPosition()
- {
- int position = 1;
-
- this.advancedCache.removeInterceptor(position);
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.removeInterceptor(position);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void removeInterceptor()
- {
- Class<? extends CommandInterceptor> interceptorType = CallInterceptor.class;
-
- this.advancedCache.removeInterceptor(interceptorType);
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.removeInterceptor(interceptorType);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void getInterceptorChain()
- {
- List<CommandInterceptor> expected = Collections.emptyList();
-
- EasyMock.expect(this.advancedCache.getInterceptorChain()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- List<CommandInterceptor> result = this.cache.getInterceptorChain();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getEvictionManager()
- {
- EvictionManager expected = EasyMock.createStrictMock(EvictionManager.class);
-
- EasyMock.expect(this.advancedCache.getEvictionManager()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- EvictionManager result = this.cache.getEvictionManager();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getComponentRegistry()
- {
- ComponentRegistry expected = new ComponentRegistry("test", new Configuration(), this.cache, new GlobalComponentRegistry(new GlobalConfiguration(), this.container));
-
- EasyMock.expect(this.advancedCache.getComponentRegistry()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- ComponentRegistry result = this.cache.getComponentRegistry();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getDistributionManager()
- {
- DistributionManager expected = EasyMock.createStrictMock(DistributionManager.class);
-
- EasyMock.expect(this.advancedCache.getDistributionManager()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- DistributionManager result = this.cache.getDistributionManager();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void lock()
- {
- Object key = new Object();
-
- this.advancedCache.lock(EasyMock.same(key));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.lock(key);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void lockMany()
- {
- Collection<Object> keys = Collections.emptyList();
-
- this.advancedCache.lock(EasyMock.same(keys));
-
- EasyMock.replay(this.advancedCache);
-
- this.cache.lock(keys);
-
- EasyMock.verify(this.advancedCache);
- }
-
- @Test
- public void getRpcManager()
- {
- RpcManager expected = EasyMock.createStrictMock(RpcManager.class);
-
- EasyMock.expect(this.advancedCache.getRpcManager()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- RpcManager result = this.cache.getRpcManager();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getBatchContainer()
- {
- BatchContainer expected = new BatchContainer();
-
- EasyMock.expect(this.advancedCache.getBatchContainer()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- BatchContainer result = this.cache.getBatchContainer();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getInvocationContextContainer()
- {
- InvocationContextContainer expected = EasyMock.createStrictMock(InvocationContextContainer.class);
-
- EasyMock.expect(this.advancedCache.getInvocationContextContainer()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- InvocationContextContainer result = this.cache.getInvocationContextContainer();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getDataContainer()
- {
- DataContainer expected = EasyMock.createStrictMock(DataContainer.class);
-
- EasyMock.expect(this.advancedCache.getDataContainer()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- DataContainer result = this.cache.getDataContainer();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getTransactionManager()
- {
- TransactionManager expected = EasyMock.createStrictMock(TransactionManager.class);
-
- EasyMock.expect(this.advancedCache.getTransactionManager()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- TransactionManager result = this.cache.getTransactionManager();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getStats()
- {
- Stats expected = EasyMock.createStrictMock(Stats.class);
-
- EasyMock.expect(this.advancedCache.getStats()).andReturn(expected);
-
- EasyMock.replay(this.advancedCache);
-
- Stats result = this.cache.getStats();
-
- EasyMock.verify(this.advancedCache);
-
- Assert.assertSame(expected, result);
- }
-}
Modified: projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerRegistryTest.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -22,7 +22,6 @@
package org.jboss.ha.ispn;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -35,12 +34,9 @@
import org.easymock.Capture;
import org.easymock.CaptureType;
import org.easymock.EasyMock;
-import org.infinispan.AdvancedCache;
import org.infinispan.config.Configuration;
import org.infinispan.config.GlobalConfiguration;
-import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.EmbeddedCacheManager;
-import org.jboss.ha.ispn.config.Alias;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfiguration;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationEntry;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationSource;
@@ -91,11 +87,13 @@
EasyMock.expect(factory.createCacheContainer(EasyMock.same(defaultConfig))).andReturn(defaultContainer);
EasyMock.expect(context.composeName("default", "java:CacheManager")).andReturn("java:CacheManager/default");
+ defaultContainer.start();
context.rebind(EasyMock.eq("java:CacheManager/default"), EasyMock.capture(capturedReferences));
EasyMock.expect(factory.createCacheContainer(EasyMock.same(otherConfig))).andReturn(otherContainer);
EasyMock.expect(context.composeName("other", "java:CacheManager")).andReturn("java:CacheManager/other");
+ otherContainer.start();
context.rebind(EasyMock.eq("java:CacheManager/other"), EasyMock.capture(capturedReferences));
EasyMock.replay(factory, source, context, defaultContainer, otherContainer);
@@ -117,23 +115,21 @@
RefAddr addr = reference.get("nns");
Assert.assertNotNull(addr);
Assert.assertEquals("java:CacheManager/default", addr.getContent());
- Assert.assertSame(registry.getCacheContainer("default"), NonSerializableFactory.lookup("java:CacheManager/default"));
+ Assert.assertSame(defaultContainer, NonSerializableFactory.lookup("java:CacheManager/default"));
reference = references.get(1);
addr = reference.get("nns");
Assert.assertNotNull(addr);
Assert.assertEquals("java:CacheManager/other", addr.getContent());
- Assert.assertSame(registry.getCacheContainer("other"), NonSerializableFactory.lookup("java:CacheManager/other"));
+ Assert.assertSame(otherContainer, NonSerializableFactory.lookup("java:CacheManager/other"));
+ Assert.assertSame(defaultContainer, registry.getCacheContainer());
+ Assert.assertSame(defaultContainer, registry.getCacheContainer(null));
+ Assert.assertSame(defaultContainer, registry.getCacheContainer("default"));
+ Assert.assertSame(defaultContainer, registry.getCacheContainer("unknown"));
+ Assert.assertSame(otherContainer, registry.getCacheContainer("other"));
+
EasyMock.reset(factory, source, context, defaultContainer, otherContainer);
-
- this.verifyContainer(defaultContainer, registry.getCacheContainer());
- this.verifyContainer(defaultContainer, registry.getCacheContainer(null));
- this.verifyContainer(defaultContainer, registry.getCacheContainer("default"));
- this.verifyContainer(defaultContainer, registry.getCacheContainer("unknown"));
- this.verifyContainer(otherContainer, registry.getCacheContainer("other"));
-
-
defaultContainer.stop();
context.unbind("java:CacheManager/default");
otherContainer.stop();
@@ -152,18 +148,6 @@
EasyMock.reset(factory, source, context, defaultContainer, otherContainer);
}
- private void verifyContainer(CacheContainer mockContainer, CacheContainer container)
- {
- mockContainer.start();
-
- EasyMock.replay(mockContainer);
-
- container.start();
-
- EasyMock.verify(mockContainer);
- EasyMock.reset(mockContainer);
- }
-
/**
* Test with custom default config and custom base jndi name
* @throws Exception
@@ -184,23 +168,15 @@
otherEntry.setId("other");
otherEntry.setConfiguration(otherConfig);
otherEntry.setJndiName("java:other");
+ otherEntry.setAliases(Arrays.asList("other.alias1", "other.alias2"));
- Alias otherAlias = new Alias();
- otherAlias.setName("legacy-other-cache");
- otherAlias.setTarget("other-cache");
- otherEntry.setAliases(Collections.singletonList(otherAlias));
-
CacheContainerConfiguration defaultConfig = new CacheContainerConfiguration(new GlobalConfiguration(), new Configuration());
CacheContainerRegistryConfigurationEntry defaultEntry = new CacheContainerRegistryConfigurationEntry();
defaultEntry.setId("default");
defaultEntry.setConfiguration(defaultConfig);
+ defaultEntry.setAliases(Arrays.asList("default.alias1", "default.alias2"));
- Alias defaultAlias = new Alias();
- defaultAlias.setName("legacy-default-cache");
- defaultAlias.setTarget("default-cache");
- defaultEntry.setAliases(Collections.singletonList(defaultAlias));
-
CacheContainerRegistryConfiguration configRegistry = new CacheContainerRegistryConfiguration();
configRegistry.setEntries(Arrays.asList(otherEntry, defaultEntry));
configRegistry.setDefaultEntry(defaultEntry);
@@ -214,11 +190,13 @@
EasyMock.expect(factory.createCacheContainer(EasyMock.same(otherConfig))).andReturn(otherContainer);
+ otherContainer.start();
context.rebind(EasyMock.eq("java:other"), EasyMock.capture(capturedReferences));
EasyMock.expect(factory.createCacheContainer(EasyMock.same(defaultConfig))).andReturn(defaultContainer);
EasyMock.expect(context.composeName("default", "java:Infinispan")).andReturn("java:Infinispan/default");
+ defaultContainer.start();
context.rebind(EasyMock.eq("java:Infinispan/default"), EasyMock.capture(capturedReferences));
EasyMock.replay(factory, provider, context, defaultContainer, otherContainer);
@@ -249,18 +227,16 @@
EasyMock.reset(factory, provider, context, defaultContainer, otherContainer);
- this.verifyContainer(defaultContainer, registry.getCacheContainer());
- this.verifyContainer(defaultContainer, registry.getCacheContainer(null));
- this.verifyContainer(defaultContainer, registry.getCacheContainer("default"));
- this.verifyContainer(defaultContainer, registry.getCacheContainer("unknown"));
- this.verifyContainer(otherContainer, registry.getCacheContainer("other"));
-
- this.verifyCacheAlias(defaultContainer, registry.getCacheContainer("default"), "default-cache", "default-cache");
- this.verifyCacheAlias(defaultContainer, registry.getCacheContainer("default"), "legacy-default-cache", "default-cache");
+ Assert.assertSame(defaultContainer, registry.getCacheContainer());
+ Assert.assertSame(defaultContainer, registry.getCacheContainer(null));
+ Assert.assertSame(defaultContainer, registry.getCacheContainer("default"));
+ Assert.assertSame(defaultContainer, registry.getCacheContainer("default.alias1"));
+ Assert.assertSame(defaultContainer, registry.getCacheContainer("default.alias2"));
+ Assert.assertSame(defaultContainer, registry.getCacheContainer("unknown"));
+ Assert.assertSame(otherContainer, registry.getCacheContainer("other"));
+ Assert.assertSame(otherContainer, registry.getCacheContainer("other.alias1"));
+ Assert.assertSame(otherContainer, registry.getCacheContainer("other.alias2"));
- this.verifyCacheAlias(otherContainer, registry.getCacheContainer("other"), "other-cache", "other-cache");
- this.verifyCacheAlias(otherContainer, registry.getCacheContainer("other"), "legacy-other-cache", "other-cache");
-
defaultContainer.stop();
context.unbind("java:Infinispan/default");
otherContainer.stop();
@@ -278,21 +254,4 @@
EasyMock.reset(factory, context, defaultContainer, otherContainer);
}
-
- private void verifyCacheAlias(CacheContainer mockContainer, CacheContainer container, String cacheName, String expectedCacheName)
- {
- @SuppressWarnings("unchecked")
- AdvancedCache<Object, Object> cache = EasyMock.createMock(AdvancedCache.class);
-
- EasyMock.expect(mockContainer.getCache(expectedCacheName)).andReturn(cache);
- EasyMock.expect(cache.getAdvancedCache()).andReturn(cache);
- cache.start();
-
- EasyMock.replay(mockContainer, cache);
-
- container.getCache(cacheName).start();
-
- EasyMock.verify(mockContainer, cache);
- EasyMock.reset(mockContainer, cache);
- }
}
Deleted: projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerTest.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerTest.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/DefaultCacheContainerTest.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -1,318 +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.ha.ispn;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.Assert;
-
-import org.easymock.EasyMock;
-import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
-import org.infinispan.config.GlobalConfiguration;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.infinispan.remoting.transport.Address;
-import org.junit.After;
-import org.junit.Test;
-
-/**
- * @author Paul Ferraro
- *
- */
-public class DefaultCacheContainerTest
-{
- private final EmbeddedCacheManager mock = EasyMock.createStrictMock(EmbeddedCacheManager.class);
- private final EmbeddedCacheManager container = new DefaultCacheContainer(this.mock, Collections.singletonMap("alias", "default"));
-
- @After
- public void reset()
- {
- EasyMock.reset(this.mock);
- }
-
- @Test
- public void getCache()
- {
- @SuppressWarnings("unchecked")
- Cache<Object, Object> cache = EasyMock.createMock(Cache.class);
-
- EasyMock.expect(this.mock.getCache()).andReturn(cache);
-
- EasyMock.replay(this.mock);
-
- Cache<Object, Object> result = this.container.getCache();
-
- EasyMock.verify(this.mock);
-
- Assert.assertNotSame(cache, result);
- Assert.assertSame(this.container, result.getCacheManager());
- }
-
- @Test
- public void getNamedCache()
- {
- @SuppressWarnings("unchecked")
- Cache<Object, Object> cache = EasyMock.createMock(Cache.class);
-
- EasyMock.expect(this.mock.getCache("test")).andReturn(cache);
-
- EasyMock.replay(this.mock);
-
- Cache<Object, Object> result = this.container.getCache("test");
-
- EasyMock.verify(this.mock);
-
- Assert.assertNotSame(cache, result);
- Assert.assertSame(this.container, result.getCacheManager());
- }
-
- @Test
- public void start()
- {
- this.mock.start();
-
- EasyMock.replay(this.mock);
-
- this.container.start();
-
- EasyMock.verify(this.mock);
- }
-
- @Test
- public void stop()
- {
- this.mock.start();
-
- EasyMock.replay(this.mock);
-
- this.container.start();
-
- EasyMock.verify(this.mock);
- }
-
- @Test
- public void addListener()
- {
- Object listener = new Object();
-
- this.mock.addListener(EasyMock.same(listener));
-
- EasyMock.replay(this.mock);
-
- this.container.addListener(listener);
-
- EasyMock.verify(this.mock);
- }
-
- @Test
- public void removeListener()
- {
- Object listener = new Object();
-
- this.mock.removeListener(EasyMock.same(listener));
-
- EasyMock.replay(this.mock);
-
- this.container.removeListener(listener);
-
- EasyMock.verify(this.mock);
- }
-
- @Test
- public void getListeners()
- {
- Set<Object> expected = Collections.emptySet();
-
- EasyMock.expect(this.mock.getListeners()).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- Set<Object> result = this.container.getListeners();
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void defineConfiguration()
- {
- Configuration expected = new Configuration();
- Configuration override = new Configuration();
-
- EasyMock.expect(this.mock.defineConfiguration(EasyMock.eq("test"), EasyMock.same(override))).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- Configuration result = this.container.defineConfiguration("test", override);
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void defineConfigurationFromTemplate()
- {
- Configuration expected = new Configuration();
- Configuration override = new Configuration();
-
- EasyMock.expect(this.mock.defineConfiguration(EasyMock.eq("test"), EasyMock.eq("template"), EasyMock.same(override))).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- Configuration result = this.container.defineConfiguration("test", "template", override);
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getClusterName()
- {
- String expected = "cluster";
-
- EasyMock.expect(this.mock.getClusterName()).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- String result = this.container.getClusterName();
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getMembers()
- {
- List<Address> expected = Collections.emptyList();
-
- EasyMock.expect(this.mock.getMembers()).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- List<Address> result = this.container.getMembers();
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getAddress()
- {
- Address expected = EasyMock.createMock(Address.class);
-
- EasyMock.expect(this.mock.getAddress()).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- Address result = this.container.getAddress();
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void isCoordinator()
- {
- EasyMock.expect(this.mock.isCoordinator()).andReturn(true);
-
- EasyMock.replay(this.mock);
-
- boolean result = this.container.isCoordinator();
-
- EasyMock.verify(this.mock);
-
- Assert.assertTrue(result);
- }
-
- @Test
- public void getStatus()
- {
- ComponentStatus expected = ComponentStatus.INITIALIZING;
-
- EasyMock.expect(this.mock.getStatus()).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- ComponentStatus result = this.container.getStatus();
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getGlobalConfiguration()
- {
- GlobalConfiguration expected = new GlobalConfiguration();
-
- EasyMock.expect(this.mock.getGlobalConfiguration()).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- GlobalConfiguration result = this.container.getGlobalConfiguration();
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getDefaultConfiguration()
- {
- Configuration expected = new Configuration();
-
- EasyMock.expect(this.mock.getDefaultConfiguration()).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- Configuration result = this.container.getDefaultConfiguration();
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-
- @Test
- public void getCacheNames()
- {
- Set<String> expected = Collections.emptySet();
-
- EasyMock.expect(this.mock.getCacheNames()).andReturn(expected);
-
- EasyMock.replay(this.mock);
-
- Set<String> result = this.container.getCacheNames();
-
- EasyMock.verify(this.mock);
-
- Assert.assertSame(expected, result);
- }
-}
Modified: projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/config/xml/XMLCacheManagerRegistryConfigurationSourceTest.java
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/config/xml/XMLCacheManagerRegistryConfigurationSourceTest.java 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/test/java/org/jboss/ha/ispn/config/xml/XMLCacheManagerRegistryConfigurationSourceTest.java 2010-08-26 18:56:46 UTC (rev 107813)
@@ -1,8 +1,9 @@
package org.jboss.ha.ispn.config.xml;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
-import org.jboss.ha.ispn.config.Alias;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfiguration;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationEntry;
import org.jboss.ha.ispn.config.CacheContainerRegistryConfigurationSource;
@@ -30,6 +31,8 @@
Assert.assertEquals("default", entry.getId());
Assert.assertNull(entry.getJndiName());
Assert.assertEquals(7, entry.getConfiguration().getNamedConfigurations().size());
+ Assert.assertNotNull(entry.getAliases());
+ Assert.assertEquals(Collections.emptyList(), entry.getAliases());
}
@Test
@@ -51,7 +54,7 @@
Assert.assertNull(entry.getJndiName());
Assert.assertNotSame(entry, registry.getDefaultEntry());
Assert.assertEquals(0, entry.getConfiguration().getNamedConfigurations().size());
- Assert.assertNull(entry.getAliases());
+ Assert.assertEquals(Collections.emptyList(), entry.getAliases());
entry = entries.get(1);
@@ -59,12 +62,7 @@
Assert.assertNull(entry.getJndiName());
Assert.assertSame(entry, registry.getDefaultEntry());
Assert.assertEquals(0, entry.getConfiguration().getNamedConfigurations().size());
- Assert.assertNotNull(entry.getAliases());
- Assert.assertEquals(2, entry.getAliases().size());
- Assert.assertEquals("alias1", entry.getAliases().get(0).getName());
- Assert.assertEquals("default", entry.getAliases().get(0).getTarget());
- Assert.assertEquals("alias2", entry.getAliases().get(1).getName());
- Assert.assertEquals("default", entry.getAliases().get(1).getTarget());
+ Assert.assertEquals(Arrays.asList("manager1.alias1", "manager1.alias2"), entry.getAliases());
entry = entries.get(2);
@@ -72,18 +70,13 @@
Assert.assertEquals("java:CacheManager", entry.getJndiName());
Assert.assertNotSame(entry, registry.getDefaultEntry());
Assert.assertEquals(0, entry.getConfiguration().getNamedConfigurations().size());
- Assert.assertNotNull(entry.getAliases());
- Assert.assertEquals(2, entry.getAliases().size());
- Assert.assertEquals("alias1", entry.getAliases().get(0).getName());
- Assert.assertEquals("default1", entry.getAliases().get(0).getTarget());
- Assert.assertEquals("alias2", entry.getAliases().get(1).getName());
- Assert.assertEquals("default2", entry.getAliases().get(1).getTarget());
+ Assert.assertEquals(Arrays.asList("manager2.alias1", "manager2.alias2"), entry.getAliases());
}
@Test
public void propertyReplacement() throws Exception
{
- String oldValue = System.setProperty("known", "expected");
+ String oldValue = System.setProperty("known", "alias1");
try
{
@@ -103,12 +96,7 @@
Assert.assertNull(entry.getJndiName());
Assert.assertSame(entry, registry.getDefaultEntry());
Assert.assertEquals(0, entry.getConfiguration().getNamedConfigurations().size());
- List<Alias> aliases = entry.getAliases();
- Assert.assertNotNull(aliases);
- Assert.assertEquals(1, aliases.size());
- Alias alias = aliases.get(0);
- Assert.assertEquals("expected", alias.getName());
- Assert.assertEquals("expected", alias.getTarget());
+ Assert.assertEquals(Arrays.asList("alias1", "expected"), entry.getAliases());
}
finally
{
Modified: projects/cluster/ha-server-ispn/trunk/src/test/resources/infinispan-configs-multiple.xml
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/resources/infinispan-configs-multiple.xml 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/test/resources/infinispan-configs-multiple.xml 2010-08-26 18:56:46 UTC (rev 107813)
@@ -4,13 +4,13 @@
<infinispan xmlns="urn:infinispan:config:4.0"/>
</infinispan-config>
<infinispan-config name="manager1">
- <alias name="alias1">default</alias>
- <alias name="alias2">default</alias>
+ <alias>manager1.alias1</alias>
+ <alias>manager1.alias2</alias>
<infinispan xmlns="urn:infinispan:config:4.0"/>
</infinispan-config>
<infinispan-config name="manager2" jndi-name="java:CacheManager">
- <alias name="alias1">default1</alias>
- <alias name="alias2">default2</alias>
+ <alias>manager2.alias1</alias>
+ <alias>manager2.alias2</alias>
<infinispan xmlns="urn:infinispan:config:4.0"/>
</infinispan-config>
</infinispan-configs>
\ No newline at end of file
Modified: projects/cluster/ha-server-ispn/trunk/src/test/resources/infinispan-configs-property-replacement.xml
===================================================================
--- projects/cluster/ha-server-ispn/trunk/src/test/resources/infinispan-configs-property-replacement.xml 2010-08-26 18:50:49 UTC (rev 107812)
+++ projects/cluster/ha-server-ispn/trunk/src/test/resources/infinispan-configs-property-replacement.xml 2010-08-26 18:56:46 UTC (rev 107813)
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<infinispan-configs default="manager" base-jndi-name="java:CacheContainer" xmlns="urn:jboss:infinispan-configs:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:infinispan-configs:1.0 ../../src/main/resources/infinispan-configs.xsd">
<infinispan-config name="manager">
- <alias name="${known:unexpected}">${unknown:expected}</alias>
+ <alias>${known:unexpected}</alias>
+ <alias>${unknown:expected}</alias>
<infinispan xmlns="urn:infinispan:config:4.0"/>
</infinispan-config>
</infinispan-configs>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list