Skip to content

Commit

Permalink
Better test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
maniksurtani committed Feb 16, 2011
1 parent 23d95f0 commit 815d803
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static void waitForRehashToComplete(Cache... caches) {
log.error(message);
throw new RuntimeException(message);
}
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(1));
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(10));
}
log.trace("Node " + dmi.rpcManager.getAddress() + " finished rehash task.");
}
Expand Down Expand Up @@ -277,27 +277,49 @@ protected static String safeType(Object o) {
return o.getClass().getSimpleName();
}

protected void assertIsInL1(Cache<?, ?> cache, Object key) {
public static void assertIsInL1(Cache<?, ?> cache, Object key) {
DataContainer dc = cache.getAdvancedCache().getDataContainer();
InternalCacheEntry ice = dc.get(key);
assert ice != null : "Entry for key [" + key + "] should be in L1 on cache at [" + addressOf(cache) + "]!";
assert !(ice instanceof ImmortalCacheEntry) : "Entry for key [" + key + "] should have a lifespan on cache at [" + addressOf(cache) + "]!";
}

protected void assertIsNotInL1(Cache<?, ?> cache, Object key) {
public static void assertIsNotInL1(Cache<?, ?> cache, Object key) {
DataContainer dc = cache.getAdvancedCache().getDataContainer();
InternalCacheEntry ice = dc.get(key);
assert ice == null : "Entry for key [" + key + "] should not be in data container at all on cache at [" + addressOf(cache) + "]!";
}

protected void assertIsInContainerImmortal(Cache<?, ?> cache, Object key) {
public static void assertIsInContainerImmortal(Cache<?, ?> cache, Object key) {
Log log = LogFactory.getLog(BaseDistFunctionalTest.class);
DataContainer dc = cache.getAdvancedCache().getDataContainer();
InternalCacheEntry ice = dc.get(key);
if (ice == null) {
String msg = "Entry for key [" + key + "] should be in data container on cache at [" + addressOf(cache) + "]!";
log.fatal(msg);
assert false : msg;
}

if (!(ice instanceof ImmortalCacheEntry)) {
String msg = "Entry for key [" + key + "] on cache at [" + addressOf(cache) + "] should be immortal but was [" + ice + "]!";
log.fatal(msg);
assert false : msg;
}
}

public static void assertIsInL1OrNull(Cache<?, ?> cache, Object key) {
Log log = LogFactory.getLog(BaseDistFunctionalTest.class);
DataContainer dc = cache.getAdvancedCache().getDataContainer();
InternalCacheEntry ice = dc.get(key);
assert ice != null : "Entry for key [" + key + "] should be in data container on cache at [" + addressOf(cache) + "]!";
assert ice instanceof ImmortalCacheEntry : "Entry for key [" + key + "] on cache at [" + addressOf(cache) + "] should be immortal but was [" + ice + "]!";
if (ice instanceof ImmortalCacheEntry) {
String msg = "Entry for key [" + key + "] on cache at [" + addressOf(cache) + "] should be mortal or null but was [" + ice + "]!";
log.fatal(msg);
assert false : msg;
}
}

protected static boolean isOwner(Cache<?, ?> c, Object key) {

public static boolean isOwner(Cache<?, ?> c, Object key) {
DistributionManager dm = c.getAdvancedCache().getDistributionManager();
List<Address> ownerAddresses = dm.locate(key);
for (Address a : ownerAddresses) {
Expand All @@ -306,17 +328,17 @@ protected static boolean isOwner(Cache<?, ?> c, Object key) {
return false;
}

protected static boolean isFirstOwner(Cache<?, ?> c, Object key) {
public static boolean isFirstOwner(Cache<?, ?> c, Object key) {
DistributionManager dm = c.getAdvancedCache().getComponentRegistry().getComponent(DistributionManager.class);
List<Address> ownerAddresses = dm.locate(key);
return addressOf(c).equals(ownerAddresses.get(0));
}

protected Cache<Object, String>[] getOwners(Object key) {
public Cache<Object, String>[] getOwners(Object key) {
return getOwners(key, 2);
}

protected Cache<Object, String>[] getOwners(Object key, int expectedNumberOwners) {
public Cache<Object, String>[] getOwners(Object key, int expectedNumberOwners) {
Cache<Object, String>[] owners = new Cache[expectedNumberOwners];
int i = 0;
for (Cache<Object, String> c : caches) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand Down Expand Up @@ -135,7 +132,6 @@ public static EmbeddedCacheManager createClusteredCacheManager(Configuration def

public static EmbeddedCacheManager createClusteredCacheManager(Configuration defaultCacheConfig, boolean transactional) {
GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
globalConfiguration.setTransportNodeName(perThreadCacheManagers.get().getNextCacheName());
amendMarshaller(globalConfiguration);
minimizeThreads(globalConfiguration);
amendTransport(globalConfiguration);
Expand Down Expand Up @@ -288,6 +284,7 @@ private static void amendTransport(GlobalConfiguration configuration) {
}
newTransportProps.put(JGroupsTransport.CONFIGURATION_STRING, JGroupsConfigBuilder.getJGroupsConfig());
configuration.setTransportProperties(newTransportProps);
configuration.setTransportNodeName(perThreadCacheManagers.get().getNextCacheName());
}
}

Expand Down

0 comments on commit 815d803

Please sign in to comment.