Skip to content

Commit

Permalink
Update unit test framework to make better use of generics
Browse files Browse the repository at this point in the history
  • Loading branch information
maniksurtani authored and galderz committed Dec 7, 2010
1 parent bcf4258 commit aa1889f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
Expand Up @@ -136,20 +136,35 @@ protected EmbeddedCacheManager addClusterEnabledCacheManager() {
}

/**
* Creates a new cache manager, starts it, and adds it to the list of known cache managers on the current thread.
* Uses a default clustered cache manager global config.
* Creates a new non-transactional cache manager, starts it, and adds it to the list of known cache managers on the
* current thread. Uses a default clustered cache manager global config.
*
* @param defaultConfig default cfg to use
* @return the new CacheManager
*/
protected EmbeddedCacheManager addClusterEnabledCacheManager(Configuration defaultConfig) {
EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(defaultConfig);
return addClusterEnabledCacheManager(defaultConfig, false);
}

/**
* Creates a new optionally transactional cache manager, starts it, and adds it to the list of known cache managers on
* the current thread. Uses a default clustered cache manager global config.
*
* @param defaultConfig default cfg to use
* @param transactional if true, the configuration will be decorated with necessary transactional settings
* @return the new CacheManager
*/
protected EmbeddedCacheManager addClusterEnabledCacheManager(Configuration defaultConfig, boolean transactional) {
EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(defaultConfig, transactional);
cacheManagers.add(cm);
return cm;
}

/**
* Creates a new cache manager, starts it, and adds it to the list of known cache managers on the current thread.
* @param mode cache mode to use
* @param transactional if true, the configuration will be decorated with necessary transactional settings
* @return an embedded cache manager
*/
protected EmbeddedCacheManager addClusterEnabledCacheManager(Configuration.CacheMode mode, boolean transactional) {
Configuration configuration = getDefaultClusteredConfig(mode, transactional);
Expand All @@ -165,6 +180,10 @@ protected void createCluster(Configuration config, int count) {
for (int i = 0; i < count; i++) addClusterEnabledCacheManager(config);
}

protected void createCluster(Configuration config, boolean transactional, int count) {
for (int i = 0; i < count; i++) addClusterEnabledCacheManager(config, transactional);
}

protected void createCluster(Configuration.CacheMode mode, int count) {
for (int i = 0; i < count; i++) addClusterEnabledCacheManager(mode, true);
}
Expand Down Expand Up @@ -291,15 +310,20 @@ public AdvancedCache advancedCache(int i, String cacheName) {
return cache(i, cacheName).getAdvancedCache();
}

public List<Cache> caches(String name) {
List<Cache> result = new ArrayList<Cache>();
public <K, V> List<Cache<K, V>> caches(String name) {
List<Cache<K, V>> result = new ArrayList<Cache<K, V>>();
for (EmbeddedCacheManager ecm : cacheManagers) {
result.add(name == null? ecm.getCache() : ecm.getCache(name));
Cache<K, V> c;
if (name == null)
c = ecm.getCache();
else
c = ecm.getCache(name);
result.add(c);
}
return result;
}

public List<Cache> caches() {
public <K, V> List<Cache<K, V>> caches() {
return caches(null);
}

Expand Down
Expand Up @@ -130,11 +130,16 @@ public static EmbeddedCacheManager createClusteredCacheManager() {
* Creates an cache manager that does support clustering with a given default cache configuration.
*/
public static EmbeddedCacheManager createClusteredCacheManager(Configuration defaultCacheConfig) {
return createClusteredCacheManager(defaultCacheConfig, false);
}

public static EmbeddedCacheManager createClusteredCacheManager(Configuration defaultCacheConfig, boolean transactional) {
GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
globalConfiguration.setTransportNodeName(perThreadCacheManagers.get().getNextCacheName());
amendMarshaller(globalConfiguration);
minimizeThreads(globalConfiguration);
amendTransport(globalConfiguration);
if (transactional) amendJTA(defaultCacheConfig);
return newDefaultCacheManager(true, globalConfiguration, defaultCacheConfig, false);
}

Expand Down

0 comments on commit aa1889f

Please sign in to comment.