JBoss Cache SVN: r7901 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-11 13:29:26 -0400 (Wed, 11 Mar 2009)
New Revision: 7901
Modified:
core/trunk/src/main/java/org/jboss/cache/Cache.java
core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
Log:
JBCACHE-1488 - getChildrenNames() to be moveed from CacheSPI to Cache
Modified: core/trunk/src/main/java/org/jboss/cache/Cache.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Cache.java 2009-03-11 17:25:40 UTC (rev 7900)
+++ core/trunk/src/main/java/org/jboss/cache/Cache.java 2009-03-11 17:29:26 UTC (rev 7901)
@@ -263,8 +263,24 @@
*/
Node<K, V> getNode(String fqn);
+ /**
+ * Returns all children of a given node. Returns an empty set if there are no children.
+ * The set is unmodifiable.
+ *
+ * @param fqn The fully qualified name of the node
+ * @return Set an unmodifiable set of children names, Object.
+ */
+ Set<Object> getChildrenNames(Fqn fqn);
/**
+ * Convenience method that takes a String representation of an Fqn. Otherwise identical to {@link #getChildrenNames(Fqn)}
+ *
+ * @param fqn as a string
+ * @return Set an unmodifiable set of children names, Object.
+ */
+ Set<String> getChildrenNames(String fqn);
+
+ /**
* Convenience method that allows for direct access to the data in a {@link Node}.
*
* @param fqn <b><i>absolute</i></b> {@link Fqn} to the {@link Node} to be accessed.
Modified: core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2009-03-11 17:25:40 UTC (rev 7900)
+++ core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2009-03-11 17:29:26 UTC (rev 7901)
@@ -296,23 +296,6 @@
boolean exists(String fqn);
/**
- * Returns all children of a given node. Returns an empty set if there are no children.
- * The set is unmodifiable.
- *
- * @param fqn The fully qualified name of the node
- * @return Set an unmodifiable set of children names, Object.
- */
- Set<Object> getChildrenNames(Fqn fqn);
-
- /**
- * Convenience method that takes a String representation of an Fqn. Otherwise identical to {@link #getChildrenNames(Fqn)}
- *
- * @param fqn as a string
- * @return Set an unmodifiable set of children names, Object.
- */
- Set<String> getChildrenNames(String fqn);
-
- /**
* Returns the component registry associated with this cache instance.
*
* @see org.jboss.cache.factories.ComponentRegistry
15 years, 9 months
JBoss Cache SVN: r7900 - in core/trunk/src: test/java/org/jboss/cache/eviction and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-11 13:25:40 -0400 (Wed, 11 Mar 2009)
New Revision: 7900
Added:
core/trunk/src/test/java/org/jboss/cache/eviction/RecursiveRootEvictionTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
Log:
JBCACHE-1490 Cache.evict(Fqn.ROOT, true) does not work
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java 2009-03-11 15:30:50 UTC (rev 7899)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java 2009-03-11 17:25:40 UTC (rev 7900)
@@ -91,7 +91,7 @@
public Object perform(InvocationContext ctx)
{
NodeSPI node = lookupForEviction(ctx, fqn);
- if (node == null || node.isDeleted() || node.isResident())
+ if ((node == null || node.isDeleted() || node.isResident()) && !recursiveEvictOnRoot(node))
{
return true;
}
@@ -110,6 +110,11 @@
}
}
+ private boolean recursiveEvictOnRoot(NodeSPI node)
+ {
+ return node == null && fqn.isRoot() && recursive && !nodesToEvict.isEmpty();
+ }
+
protected Collection<Fqn> getRecursiveEvictionNodes()
{
Collections.sort(nodesToEvict);
Added: core/trunk/src/test/java/org/jboss/cache/eviction/RecursiveRootEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RecursiveRootEvictionTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RecursiveRootEvictionTest.java 2009-03-11 17:25:40 UTC (rev 7900)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.cache.eviction;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.factories.UnitTestConfigurationFactory;
+import org.jboss.cache.loader.testloaders.DummyInMemoryCacheLoader;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.cache.util.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+
+@Test(groups = { "functional" }, testName = "eviction.RecursiveRootEvictionTest")
+public class RecursiveRootEvictionTest
+{
+ private CacheSPI<String, String> cache;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ UnitTestCacheFactory<String, String> factory = new UnitTestCacheFactory<String, String>();
+ Configuration conf = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
+ conf.setEvictionConfig(new EvictionConfig(new EvictionRegionConfig(Fqn.ROOT, new LRUAlgorithmConfig(1000000, 5000)), 200));
+ conf.setCacheLoaderConfig(buildCacheLoaderConfig());
+ conf.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache = (CacheSPI<String, String>) factory.createCache(conf, true, getClass());
+ }
+
+ private CacheLoaderConfig buildCacheLoaderConfig() throws IOException
+ {
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
+ iclc.setClassName(DummyInMemoryCacheLoader.class.getName());
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(iclc);
+ return cacheLoaderConfig;
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testNonrecursiveRootEviction()
+ {
+ cache.put(Fqn.fromElements("a", "a"), "x", "x");
+ cache.put(Fqn.fromElements("a", "b"), "x", "x");
+ cache.put(Fqn.fromElements("a", "c"), "x", "x");
+
+ assert cache.getNumberOfNodes() == 4;
+
+ cache.evict(Fqn.fromElements("a", "a"), false);
+ assert cache.getNumberOfNodes() == 3;
+ cache.evict(Fqn.fromElements("a", "b"), false);
+ assert cache.getNumberOfNodes() == 2;
+ cache.evict(Fqn.fromElements("a", "c"), false);
+ assert cache.getNumberOfNodes() == 1;
+ cache.evict(Fqn.fromElements("a"), false);
+
+ assert cache.getNumberOfNodes() == 0;
+ }
+
+ public void testRecursiveNonRootEviction()
+ {
+ cache.put(Fqn.fromElements("a", "a"), "x", "x");
+ cache.put(Fqn.fromElements("a", "b"), "x", "x");
+ cache.put(Fqn.fromElements("a", "c"), "x", "x");
+
+ cache.evict(Fqn.fromElements("a"), true);
+
+ assert cache.getNumberOfNodes() == 0;
+ }
+
+ public void testRecursiveRootEviction()
+ {
+ cache.put(Fqn.fromElements("a", "a"), "x", "x");
+ cache.put(Fqn.fromElements("a", "b"), "x", "x");
+ cache.put(Fqn.fromElements("a", "c"), "x", "x");
+
+ cache.evict(Fqn.ROOT, true);
+
+ assert cache.getNumberOfNodes() == 0;
+ }
+}
15 years, 9 months
JBoss Cache SVN: r7899 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-11 11:30:50 -0400 (Wed, 11 Mar 2009)
New Revision: 7899
Modified:
core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
Log:
Removed unnecessary scary logging
Modified: core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2009-03-11 10:04:36 UTC (rev 7898)
+++ core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2009-03-11 15:30:50 UTC (rev 7899)
@@ -162,10 +162,6 @@
public void setResident(boolean resident)
{
- if (resident)
- {
- log.trace("Someone is marking " + fqn + " as resident!", new Throwable());
- }
setFlag(RESIDENT, resident);
}
15 years, 9 months
JBoss Cache SVN: r7898 - core/trunk/src/main/java/org/jboss/cache/transaction.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-11 06:04:36 -0400 (Wed, 11 Mar 2009)
New Revision: 7898
Modified:
core/trunk/src/main/java/org/jboss/cache/transaction/GlobalTransaction.java
Log:
Reduced synchronization
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/GlobalTransaction.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/GlobalTransaction.java 2009-03-11 10:00:29 UTC (rev 7897)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/GlobalTransaction.java 2009-03-11 10:04:36 UTC (rev 7898)
@@ -28,6 +28,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.concurrent.atomic.AtomicLong;
/**
@@ -44,7 +45,7 @@
private static final long serialVersionUID = 8011434781266976149L;
- private static long sid = 0;
+ private static AtomicLong sid = new AtomicLong(0);
private Address addr = null;
private long id = -1;
@@ -63,14 +64,9 @@
private GlobalTransaction(Address addr)
{
this.addr = addr;
- id = newId();
+ id = sid.getAndIncrement();
}
- private static synchronized long newId()
- {
- return ++sid;
- }
-
public static GlobalTransaction create(Address addr)
{
return new GlobalTransaction(addr);
15 years, 9 months
JBoss Cache SVN: r7897 - core/branches/flat/src/main/java/org/horizon/transaction.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-03-11 06:00:29 -0400 (Wed, 11 Mar 2009)
New Revision: 7897
Modified:
core/branches/flat/src/main/java/org/horizon/transaction/GlobalTransaction.java
Log:
removed syncs on GTX
Modified: core/branches/flat/src/main/java/org/horizon/transaction/GlobalTransaction.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/transaction/GlobalTransaction.java 2009-03-10 21:24:47 UTC (rev 7896)
+++ core/branches/flat/src/main/java/org/horizon/transaction/GlobalTransaction.java 2009-03-11 10:00:29 UTC (rev 7897)
@@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.util.concurrent.atomic.AtomicLong;
/**
@@ -42,7 +43,7 @@
private static final long serialVersionUID = 8011434781266976149L;
- private static long sid = 0;
+ private static AtomicLong sid = new AtomicLong(0);
private Address addr = null;
private long id = -1;
@@ -59,13 +60,9 @@
private GlobalTransaction(Address addr) {
this.addr = addr;
- id = newId();
+ id = sid.getAndIncrement();
}
- private static synchronized long newId() {
- return ++sid;
- }
-
public static GlobalTransaction create(Address addr) {
return new GlobalTransaction(addr);
}
15 years, 9 months
JBoss Cache SVN: r7896 - in core/branches/flat/src: main/java/org/horizon/config/parsing and 6 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-03-10 17:24:47 -0400 (Tue, 10 Mar 2009)
New Revision: 7896
Added:
core/branches/flat/src/test/java/org/horizon/jmx/
core/branches/flat/src/test/java/org/horizon/jmx/JmxRegistrationManagerTest.java
core/branches/flat/src/test/java/org/horizon/jmx/ResourceDMBeanTest.java
Modified:
core/branches/flat/src/main/java/org/horizon/config/Configuration.java
core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java
core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java
core/branches/flat/src/main/java/org/horizon/jmx/PlatformMBeanServerRegistration.java
core/branches/flat/src/main/resources/schema/horizon-config-1.0.xsd
core/branches/flat/src/test/java/org/horizon/config/parsing/XmlFileParsingTest.java
core/branches/flat/src/test/resources/configs/named-cache-test.xml
Log:
ongoing JMX integration
Modified: core/branches/flat/src/main/java/org/horizon/config/Configuration.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/Configuration.java 2009-03-10 10:56:24 UTC (rev 7895)
+++ core/branches/flat/src/main/java/org/horizon/config/Configuration.java 2009-03-10 21:24:47 UTC (rev 7896)
@@ -43,6 +43,7 @@
// reference to a global configuration
private GlobalConfiguration globalConfiguration;
+ private String JmxNameBase;
public GlobalConfiguration getGlobalConfiguration() {
@@ -63,6 +64,25 @@
}
/**
+ * If JMX statistics are enabled then all 'published' JMX objects will appear under this name. This is optional, if
+ * not specified an object name will be created for you by default.
+ *
+ * @see javax.management.ObjectName
+ * @see #isExposeManagementStatistics()
+ */
+ public void setJmxNameBase(String jmxObjectName) {
+ testImmutability("JmxNameBase");
+ this.JmxNameBase = jmxObjectName;
+ }
+
+ /**
+ * @see #setJmxNameBase(String)
+ */
+ public String getJmxNameBase() {
+ return JmxNameBase;
+ }
+
+ /**
* Cache replication mode.
*/
public static enum CacheMode {
Modified: core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java 2009-03-10 10:56:24 UTC (rev 7895)
+++ core/branches/flat/src/main/java/org/horizon/config/parsing/XmlConfigurationParserImpl.java 2009-03-10 21:24:47 UTC (rev 7896)
@@ -291,6 +291,10 @@
// by default enable this since the element is present!
config.setExposeManagementStatistics(true);
}
+ String jmxNameBase = getAttributeValue(element, "jmxNameBase");
+ if (existsAttribute(jmxNameBase)) {
+ config.setJmxNameBase(jmxNameBase);
+ }
}
}
Modified: core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java 2009-03-10 10:56:24 UTC (rev 7895)
+++ core/branches/flat/src/main/java/org/horizon/jmx/JmxRegistrationManager.java 2009-03-10 21:24:47 UTC (rev 7896)
@@ -23,13 +23,12 @@
import org.horizon.AdvancedCache;
import org.horizon.CacheException;
-import org.horizon.config.Configuration;
import org.horizon.factories.ComponentRegistry;
import org.horizon.logging.Log;
import org.horizon.logging.LogFactory;
+import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
@@ -53,28 +52,13 @@
private static final Log log = LogFactory.getLog(JmxRegistrationManager.class);
- private static final String GENERAL_PREFIX = System.getProperty("horizon.jmx.prefix", "horizon:service=Horizon");
-
- /**
- * default ObjectName for clusterd caches. Cluster name should pe appended.
- */
- public static final String REPLICATED_CACHE_PREFIX = GENERAL_PREFIX + ",cluster=";
-
- /**
- * default ObjectName for non clustered caches. An unique identifier should be appended.
- */
- public static final String LOCAL_CACHE_PREFIX = GENERAL_PREFIX + ",uniqueId=";
-
- /**
- * Key for every Dynamic mbean added.
- */
- public static final String JMX_RESOURCE_KEY = ",jmx-resource=";
-
private MBeanServer mBeanServer;
private String objectNameBase;
private AdvancedCache cache;
+ public static final String CACHE_NAME_KEY = "cache-name";
+ public static final String JMX_RESOURCE_KEY = "jmx-resource";
/**
* C-tor.
@@ -83,39 +67,21 @@
* @param cache cache that needs to be monitored
* @param objectNameBase path in the MBeanServer where to register cache MBeans
*/
- public JmxRegistrationManager(MBeanServer mBeanServer, AdvancedCache cache, ObjectName objectNameBase) {
+ public JmxRegistrationManager(MBeanServer mBeanServer, AdvancedCache cache) {
this.mBeanServer = mBeanServer;
this.cache = cache;
- processBaseName(objectNameBase);
+ processBaseName();
}
/**
- * @throws IllegalArgumentException if the supplied objectNameBase name isn't valid
- */
- public JmxRegistrationManager(MBeanServer mBeanServer, AdvancedCache cache, String objectNameBase) {
- this.mBeanServer = mBeanServer;
- this.cache = cache;
- try {
- processBaseName(new ObjectName(objectNameBase));
- }
- catch (MalformedObjectNameException e) {
- throw new IllegalArgumentException("Invalid Object Name : " + objectNameBase, e);
- }
- }
-
- /**
* Defaults to platform to platform MBeanServer.
*
* @see java.lang.management.ManagementFactory#getPlatformMBeanServer()
* @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/mxbeans.html#mbean_s...">platform
* MBeanServer</a>
*/
- public JmxRegistrationManager(AdvancedCache cache, ObjectName objectNameBase) {
- this(ManagementFactory.getPlatformMBeanServer(), cache, objectNameBase);
- }
-
public JmxRegistrationManager(AdvancedCache cache) {
- this(cache, null);
+ this(ManagementFactory.getPlatformMBeanServer(), cache);
}
/**
@@ -128,7 +94,15 @@
String resourceName = resource.getObjectName();
ObjectName objectName = new ObjectName(getObjectName(resourceName));
if (!mBeanServer.isRegistered(objectName)) {
- mBeanServer.registerMBean(resource, objectName);
+ try {
+ mBeanServer.registerMBean(resource, objectName);
+ } catch (InstanceAlreadyExistsException e) {
+ //this might happen if multiple instances are trying to concurrently register same objectName
+ log.info("Could not register object with name:" + objectName + "(" + e.getMessage() + ")");
+ }
+ } else {
+ if (log.isInfoEnabled())
+ log.info("Could not register object with name: " + objectName);
}
}
}
@@ -169,22 +143,19 @@
return resourceDMBeans;
}
- private void processBaseName(ObjectName baseName) {
- if (baseName != null) {
- this.objectNameBase = baseName.getCanonicalName();
+ private void processBaseName() {
+ String base = cache.getConfiguration().getJmxNameBase();
+ if (base != null) {
+ objectNameBase = base;
+ if (log.isTraceEnabled()) log.trace("Using custom base name: '" + base + "'");
return;
}
- if (cache.getConfiguration().getCacheMode().equals(Configuration.CacheMode.LOCAL)) {
- objectNameBase = LOCAL_CACHE_PREFIX + ",instance=" + Integer.toHexString(System.identityHashCode(cache));
- } else //the cache is clustered
- {
- objectNameBase = REPLICATED_CACHE_PREFIX + cache.getConfiguration().getGlobalConfiguration().getClusterName();
- }
- objectNameBase = objectNameBase + ",cacheName=" + cache.getName();
+ objectNameBase = "horizon:" + CACHE_NAME_KEY + "=";
+ objectNameBase += cache.getName() + "(" + cache.getConfiguration().getCacheModeString().toLowerCase() + ")";
}
public String getObjectName(String resourceName) {
- return objectNameBase + JMX_RESOURCE_KEY + resourceName;
+ return objectNameBase + "," + JMX_RESOURCE_KEY + "=" + resourceName;
}
public String getObjectNameBase() {
Modified: core/branches/flat/src/main/java/org/horizon/jmx/PlatformMBeanServerRegistration.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/jmx/PlatformMBeanServerRegistration.java 2009-03-10 10:56:24 UTC (rev 7895)
+++ core/branches/flat/src/main/java/org/horizon/jmx/PlatformMBeanServerRegistration.java 2009-03-10 21:24:47 UTC (rev 7896)
@@ -34,7 +34,7 @@
* If {@link Configuration#isExposeManagementStatistics()} is true, then class will register all the MBeans from the
* ConfigurationRegistry to the pltform MBean server.
* <p/>
- * Note: to enable platform MBeanServer the following system property should be passet to the JVM:
+ * Note: to enable platform MBeanServer the following system property should be passet to the Sun JVM:
* <b>-Dcom.sun.management.jmxremote</b>.
*
* @author Mircea.Markus(a)jboss.com
Modified: core/branches/flat/src/main/resources/schema/horizon-config-1.0.xsd
===================================================================
--- core/branches/flat/src/main/resources/schema/horizon-config-1.0.xsd 2009-03-10 10:56:24 UTC (rev 7895)
+++ core/branches/flat/src/main/resources/schema/horizon-config-1.0.xsd 2009-03-10 21:24:47 UTC (rev 7896)
@@ -123,6 +123,7 @@
<xs:complexType name="jmxStatisticsType">
<xs:attribute name="enabled" type="tns:booleanType"/>
+ <xs:attribute name="jmxNameBase" type="xs:string"/>
</xs:complexType>
<xs:complexType name="lazyDeserialization">
Modified: core/branches/flat/src/test/java/org/horizon/config/parsing/XmlFileParsingTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/config/parsing/XmlFileParsingTest.java 2009-03-10 10:56:24 UTC (rev 7895)
+++ core/branches/flat/src/test/java/org/horizon/config/parsing/XmlFileParsingTest.java 2009-03-10 21:24:47 UTC (rev 7896)
@@ -111,6 +111,10 @@
assert tableManipulation.getDataColumnType().equals("BLOB");
assert tableManipulation.isDropTableOnExit();
assert !tableManipulation.isCreateTableOnStart();
+
+ c = namedCaches.get("withJmxEnabled");
+ assert c.isExposeManagementStatistics();
+ assert c.getJmxNameBase().equals("horizonDomain:aKey=aValue");
}
public void testConfigurationMerging() throws IOException {
Added: core/branches/flat/src/test/java/org/horizon/jmx/JmxRegistrationManagerTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/jmx/JmxRegistrationManagerTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/jmx/JmxRegistrationManagerTest.java 2009-03-10 21:24:47 UTC (rev 7896)
@@ -0,0 +1,163 @@
+package org.horizon.jmx;
+
+import org.horizon.AdvancedCache;
+import org.horizon.Cache;
+import org.horizon.config.Configuration;
+import org.horizon.config.GlobalConfiguration;
+import org.horizon.interceptors.CacheMgmtInterceptor;
+import org.horizon.manager.CacheManager;
+import org.horizon.manager.DefaultCacheManager;
+import org.horizon.test.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tester class for {@link JmxRegistrationManager}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
+ * @since 1.0
+ */
+@Test(groups = "functional", testName = "jmx.JmxRegistrationManagerTest")
+public class JmxRegistrationManagerTest {
+
+ private MBeanServer mBeanServer;
+ private List<CacheManager> cacheManagers = new ArrayList<CacheManager>();
+
+ @BeforeMethod
+ public void setUp() {
+ mBeanServer = MBeanServerFactory.createMBeanServer();
+// mBeanServer = ManagementFactory.getPlatformMBeanServer();
+ cacheManagers.clear();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ MBeanServerFactory.releaseMBeanServer(mBeanServer);
+ for (CacheManager cacheManager : cacheManagers) {
+ TestingUtil.killCacheManagers(cacheManager);
+ }
+ cacheManagers.clear();
+ }
+
+ public void testRegisterLocalCache() throws Exception {
+ CacheManager cm = TestingUtil.createLocalCacheManager();
+ cacheManagers.add(cm);
+ cm.start();
+ Configuration configuration = config();
+ configuration.setCacheMode(Configuration.CacheMode.LOCAL);
+ cm.defineCache("first", configuration);
+ Cache first = cm.getCache("first");
+
+ JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, (AdvancedCache) first);
+ regManager.registerAllMBeans();
+ String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
+ ObjectName name1 = new ObjectName(name);
+ assert mBeanServer.isRegistered(name1);
+ regManager.unregisterAllMBeans();
+ assert !mBeanServer.isRegistered(name1);
+ assertCorrectJmxName(name1, first);
+ }
+
+ public void testRegisterReplicatedCache() throws Exception {
+ GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
+ CacheManager cm = new DefaultCacheManager(globalConfiguration);
+ cacheManagers.add(cm);
+ cm.start();
+ Configuration configurationOverride = config();
+ configurationOverride.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ cm.defineCache("first", configurationOverride);
+ Cache first = cm.getCache("first");
+
+ JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, (AdvancedCache) first);
+ regManager.registerAllMBeans();
+ String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
+ ObjectName name1 = new ObjectName(name);
+ assertCorrectJmxName(name1, first);
+ assert mBeanServer.isRegistered(name1);
+ regManager.unregisterAllMBeans();
+ assert !mBeanServer.isRegistered(name1);
+ }
+
+ public void testLocalAndReplicatedCache() throws Exception {
+ GlobalConfiguration globalConfiguration = GlobalConfiguration.getClusteredDefault();
+ CacheManager cm = new DefaultCacheManager(globalConfiguration);
+ cacheManagers.add(cm);
+ cm.start();
+ Configuration replicated = config();
+ Configuration local = config();
+ replicated.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ local.setCacheMode(Configuration.CacheMode.LOCAL);
+ cm.defineCache("replicated", replicated);
+ cm.defineCache("local", local);
+ Cache replicatedCache = cm.getCache("replicated");
+ Cache localCache = cm.getCache("local");
+
+ JmxRegistrationManager replicatedRegManager = new JmxRegistrationManager(mBeanServer, (AdvancedCache) replicatedCache);
+ JmxRegistrationManager localRegManager = new JmxRegistrationManager(mBeanServer, (AdvancedCache) localCache);
+ replicatedRegManager.registerAllMBeans();
+ localRegManager.registerAllMBeans();
+
+ String replicatedtCMgmtIntName = replicatedRegManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
+ String localCMgmtIntName = localRegManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
+ ObjectName replObjectName = new ObjectName(replicatedtCMgmtIntName);
+ ObjectName localObjName = new ObjectName(localCMgmtIntName);
+ assertCorrectJmxName(replObjectName, replicatedCache);
+
+ assert mBeanServer.isRegistered(replObjectName);
+ assert mBeanServer.isRegistered(localObjName);
+ assert !localCMgmtIntName.equals(replicatedtCMgmtIntName);
+
+ replicatedRegManager.unregisterAllMBeans();
+ localRegManager.unregisterAllMBeans();
+ assert !mBeanServer.isRegistered(new ObjectName(localCMgmtIntName));
+ assert !mBeanServer.isRegistered(new ObjectName(replicatedtCMgmtIntName));
+ }
+
+ public void testCustomCacheName() throws Exception {
+ CacheManager cm = TestingUtil.createLocalCacheManager();
+ cacheManagers.add(cm);
+ cm.start();
+ Configuration configuration = config();
+ configuration.setJmxNameBase("mircea:aKey=aValue,secondKey=secondValue");
+ configuration.setCacheMode(Configuration.CacheMode.LOCAL);
+ cm.defineCache("first", configuration);
+ Cache cache = cm.getCache("first");
+
+ JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, (AdvancedCache) cache);
+ regManager.registerAllMBeans();
+
+ String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
+ ObjectName name1 = new ObjectName(name);
+ assert mBeanServer.isRegistered(name1);
+ regManager.unregisterAllMBeans();
+ assert !mBeanServer.isRegistered(name1);
+
+
+ assert name1.getDomain().equals("mircea");
+ assert name1.getKeyProperty("aKey").equals("aValue");
+ assert name1.getKeyProperty("secondKey").equals("secondValue");
+ assert name1.getKeyProperty(JmxRegistrationManager.JMX_RESOURCE_KEY) != null;
+ }
+
+ private void assertCorrectJmxName(ObjectName objectName, Cache cache) {
+ assert objectName.getKeyProperty(JmxRegistrationManager.CACHE_NAME_KEY).startsWith(cache.getName());
+ String cacheModeStr = cache.getConfiguration().getCacheModeString().toLowerCase();
+ assert objectName.getKeyProperty(JmxRegistrationManager.CACHE_NAME_KEY).contains(cacheModeStr);
+ assert objectName.getKeyProperty(JmxRegistrationManager.JMX_RESOURCE_KEY) != null;
+ }
+
+
+ private Configuration config() {
+ Configuration configuration = new Configuration();
+ configuration.setExposeManagementStatistics(true);
+ return configuration;
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/jmx/JmxRegistrationManagerTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: core/branches/flat/src/test/java/org/horizon/jmx/ResourceDMBeanTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/jmx/ResourceDMBeanTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/jmx/ResourceDMBeanTest.java 2009-03-10 21:24:47 UTC (rev 7896)
@@ -0,0 +1,35 @@
+package org.horizon.jmx;
+
+import org.horizon.jmx.annotations.ManagedOperation;
+import org.testng.annotations.Test;
+
+/**
+ * /** Tester class for {@link ResourceDMBean}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 1.0
+ */
+@Test(groups = "unit", testName = "jmx.ResourceDMBeanTest")
+public class ResourceDMBeanTest {
+
+ /**
+ * If we have a method in the base class that is annotated as @ManagedOperation, will this be seen the same way in
+ * the inherited class?
+ */
+ public void testInheritedMethod() {
+ Bbb bbb = new Bbb();
+ ResourceDMBean resourceDMBean = new ResourceDMBean(bbb);
+ assert resourceDMBean.isOperationRegistred("baseMethod");
+ }
+
+ static class Aaa {
+ @ManagedOperation
+ public void baseMethod() {
+ }
+ }
+
+ static class Bbb extends Aaa {
+ public void localMethod() {
+ }
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/jmx/ResourceDMBeanTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: core/branches/flat/src/test/resources/configs/named-cache-test.xml
===================================================================
--- core/branches/flat/src/test/resources/configs/named-cache-test.xml 2009-03-10 10:56:24 UTC (rev 7895)
+++ core/branches/flat/src/test/resources/configs/named-cache-test.xml 2009-03-10 21:24:47 UTC (rev 7896)
@@ -30,6 +30,7 @@
<default>
<locking concurrencyLevel="100" lockAcquisitionTimeout="1000"/>
+ <jmxStatistics enabled="false"/>
</default>
<namedCache name="transactional">
@@ -100,4 +101,11 @@
</loaders>
</namedCache>
+ <namedCache name="withJmxEnabled">
+ <clustering>
+ <async useReplQueue="true" replQueueInterval="100" replQueueMaxElements="200"/>
+ </clustering>
+ <jmxStatistics enabled="true" jmxNameBase="horizonDomain:aKey=aValue"/>
+ </namedCache>
+
</horizon>
15 years, 9 months
JBoss Cache SVN: r7895 - core/branches/flat/src/test/java/org/horizon/loader/jdbc.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-03-10 06:56:24 -0400 (Tue, 10 Mar 2009)
New Revision: 7895
Modified:
core/branches/flat/src/test/java/org/horizon/loader/jdbc/PooledConnectionFactoryTest.java
Log:
fixed UT
Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/PooledConnectionFactoryTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/PooledConnectionFactoryTest.java 2009-03-09 22:30:47 UTC (rev 7894)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/PooledConnectionFactoryTest.java 2009-03-10 10:56:24 UTC (rev 7895)
@@ -2,7 +2,6 @@
import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
import org.horizon.loader.jdbc.connectionfactory.PooledConnectionFactory;
-import org.horizon.loader.jdbc.UnitTestDatabaseManager;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -15,7 +14,7 @@
*
* @author
*/
-@Test(groups = "functional", testName = "loader.jdbc.PooledConnectionFactoryTest", enabled = false)
+@Test(groups = "functional", testName = "loader.jdbc.PooledConnectionFactoryTest")
public class PooledConnectionFactoryTest {
private PooledConnectionFactory factory;
15 years, 9 months
JBoss Cache SVN: r7894 - in core/branches/flat: src/main/java/org/horizon/loader/s3 and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: adriancole
Date: 2009-03-09 18:30:47 -0400 (Mon, 09 Mar 2009)
New Revision: 7894
Modified:
core/branches/flat/pom.xml
core/branches/flat/src/main/java/org/horizon/loader/s3/Jets3tS3Connection.java
Log:
updated to v0.7.0 jets3t
Modified: core/branches/flat/pom.xml
===================================================================
--- core/branches/flat/pom.xml 2009-03-09 22:10:53 UTC (rev 7893)
+++ core/branches/flat/pom.xml 2009-03-09 22:30:47 UTC (rev 7894)
@@ -69,7 +69,7 @@
<dependency>
<groupId>net.java.dev.jets3t</groupId>
<artifactId>jets3t</artifactId>
- <version>0.6.1</version>
+ <version>0.7.0</version>
<optional>true</optional>
</dependency>
Modified: core/branches/flat/src/main/java/org/horizon/loader/s3/Jets3tS3Connection.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/s3/Jets3tS3Connection.java 2009-03-09 22:10:53 UTC (rev 7893)
+++ core/branches/flat/src/main/java/org/horizon/loader/s3/Jets3tS3Connection.java 2009-03-09 22:30:47 UTC (rev 7894)
@@ -60,13 +60,7 @@
* @see org.jets3t.service.S3Service#createBucket(String)
*/
public S3Bucket getOrCreateBucket(String bucketName) throws S3ServiceException {
- /* version 0.7.0 supports the following
- return s3Service.getOrCreateBucket(config.getBucket()); */
- if (s3Service.isBucketAccessible(bucketName)) {
- return s3Service.getBucket(bucketName);
- } else {
- return s3Service.createBucket(bucketName);
- }
+ return s3Service.getOrCreateBucket(bucketName);
}
/**
15 years, 9 months
JBoss Cache SVN: r7893 - in core/branches/flat/src: test/java/org/horizon/api/tree and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2009-03-09 18:10:53 -0400 (Mon, 09 Mar 2009)
New Revision: 7893
Added:
core/branches/flat/src/test/java/org/horizon/atomic/AtomicHashMapConcurrencyTest.java
Modified:
core/branches/flat/src/main/java/org/horizon/tree/TreeCacheImpl.java
core/branches/flat/src/main/java/org/horizon/tree/TreeStructureSupport.java
core/branches/flat/src/test/java/org/horizon/api/tree/NodeMoveAPITest.java
Log:
fixed UT
Modified: core/branches/flat/src/main/java/org/horizon/tree/TreeCacheImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/tree/TreeCacheImpl.java 2009-03-09 15:02:01 UTC (rev 7892)
+++ core/branches/flat/src/main/java/org/horizon/tree/TreeCacheImpl.java 2009-03-09 22:10:53 UTC (rev 7893)
@@ -118,13 +118,17 @@
public boolean removeNode(Fqn fqn) {
if (fqn.isRoot()) return false;
startAtomic();
+ boolean result;
try {
+ if (trace) log.trace("About to remove node " + fqn);
Node<K, V> n = getNode(fqn.getParent());
- return n != null && n.removeChild(fqn.getLastElement());
+ result = n != null && n.removeChild(fqn.getLastElement());
}
finally {
endAtomic();
}
+ if (trace) log.trace("Node successfully removed");
+ return result;
}
public boolean removeNode(Fqn fqn, Options... options) {
@@ -202,10 +206,12 @@
return get(fqn, key);
}
- public void move(Fqn nodeToMove, Fqn newParent) throws NodeNotExistsException {
- if (nodeToMove == null || newParent == null) throw new NullPointerException("Cannot accept null parameters!");
+ public void move(Fqn nodeToMoveFqn, Fqn newParentFqn) throws NodeNotExistsException {
+ if (trace) log.trace("Moving node '" + nodeToMoveFqn + "' to '" + newParentFqn + "'");
+ if (nodeToMoveFqn == null || newParentFqn == null) throw new NullPointerException("Cannot accept null parameters!");
- if (nodeToMove.getParent().equals(newParent)) {
+ if (nodeToMoveFqn.getParent().equals(newParentFqn)) {
+ if (trace) log.trace("Not doing anything as this node is equal with its parent");
// moving onto self! Do nothing!
return;
}
@@ -213,30 +219,35 @@
// Depth first. Lets start with getting the node we want.
startAtomic();
try {
- Node node = getNode(nodeToMove);
- if (node == null) return; // nothing to do here!
- if (!exists(newParent)) {
+ Node nodeToMove = getNode(nodeToMoveFqn, Options.FORCE_WRITE_LOCK);
+ if (nodeToMove == null) {
+ if (trace) log.trace("Did not find the node that needs to be moved. Returning...");
+ return; // nothing to do here!
+ }
+ if (!exists(newParentFqn)) {
// then we need to silently create the new parent
- createNodeInCache(newParent);
+ createNodeInCache(newParentFqn);
+ if (trace) log.trace("The new parent ("+newParentFqn +") did not exists, was created");
}
// create an empty node for this new parent
- Fqn newFqn = Fqn.fromRelativeElements(newParent, nodeToMove.getLastElement());
+ Fqn newFqn = Fqn.fromRelativeElements(newParentFqn, nodeToMoveFqn.getLastElement());
createNodeInCache(newFqn);
Node newNode = getNode(newFqn);
- Map oldData = node.getData();
+ Map oldData = nodeToMove.getData();
if (oldData != null && !oldData.isEmpty()) newNode.putAll(oldData);
- for (Object child : node.getChildrenNames()) {
+ for (Object child : nodeToMove.getChildrenNames()) {
// move kids
- Fqn oldChildFqn = Fqn.fromRelativeElements(nodeToMove, child);
+ if (trace) log.trace("Moving child " + child);
+ Fqn oldChildFqn = Fqn.fromRelativeElements(nodeToMoveFqn, child);
move(oldChildFqn, newFqn);
}
-
- removeNode(nodeToMove);
+ removeNode(nodeToMoveFqn);
}
finally {
endAtomic();
}
+ log.trace("Successfully moved node '" + nodeToMoveFqn + "' to '" + newParentFqn + "'");
}
public void move(Fqn nodeToMove, Fqn newParent, Options... options) throws NodeNotExistsException {
Modified: core/branches/flat/src/main/java/org/horizon/tree/TreeStructureSupport.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/tree/TreeStructureSupport.java 2009-03-09 15:02:01 UTC (rev 7892)
+++ core/branches/flat/src/main/java/org/horizon/tree/TreeStructureSupport.java 2009-03-09 22:10:53 UTC (rev 7893)
@@ -29,8 +29,12 @@
import org.horizon.invocation.InvocationContextContainer;
import org.horizon.invocation.Options;
import org.horizon.lock.LockManager;
+import org.horizon.logging.Log;
+import org.horizon.logging.LogFactory;
public class TreeStructureSupport extends AutoBatchSupport {
+ private static Log log = LogFactory.getLog(TreeStructureSupport.class);
+
AtomicMapCache cache;
InvocationContextContainer icc;
@@ -70,6 +74,7 @@
}
cache.getAtomicMap(structureKey);
cache.getAtomicMap(dataKey);
+ if (log.isTraceEnabled()) log.trace("Created node " + fqn);
return true;
}
finally {
Modified: core/branches/flat/src/test/java/org/horizon/api/tree/NodeMoveAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/tree/NodeMoveAPITest.java 2009-03-09 15:02:01 UTC (rev 7892)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/NodeMoveAPITest.java 2009-03-09 22:10:53 UTC (rev 7893)
@@ -2,6 +2,7 @@
import org.horizon.api.mvcc.LockAssert;
import org.horizon.config.Configuration;
+import org.horizon.container.DataContainer;
import org.horizon.factories.ComponentRegistry;
import org.horizon.invocation.InvocationContextContainer;
import org.horizon.lock.LockManager;
@@ -12,8 +13,6 @@
import org.horizon.test.TestingUtil;
import org.horizon.tree.Fqn;
import org.horizon.tree.Node;
-import org.horizon.tree.NodeNotExistsException;
-import org.horizon.tree.TreeCache;
import org.horizon.tree.TreeCacheImpl;
import org.horizon.tree.TreeStructureSupport;
import static org.testng.AssertJUnit.*;
@@ -42,8 +41,9 @@
static final Fqn D_B_C = Fqn.fromRelativeFqn(D_B, C);
protected static final Object k = "key", vA = "valueA", vB = "valueB", vC = "valueC", vD = "valueD", vE = "valueE";
- TreeCache<Object, Object> treeCache;
+ TreeCacheImpl<Object, Object> treeCache;
TransactionManager tm;
+ DataContainer dc;
protected CacheManager createCacheManager() throws Exception {
CacheManager cm = TestingUtil.createLocalCacheManager();
@@ -55,6 +55,7 @@
cache = cm.getCache("test");
tm = TestingUtil.extractComponent(cache, TransactionManager.class);
treeCache = new TreeCacheImpl(cache);
+ dc = TestingUtil.extractComponent(cache, DataContainer.class);
return cm;
}
@@ -329,19 +330,9 @@
for (int counter = 0; counter < loops; counter++) {
- try {
- treeCache.move(NODE_X.getFqn(), NODES[rnd.nextInt(NODES.length)].getFqn());
- }
- catch (NodeNotExistsException e) {
- // this may happen ...
- }
+ treeCache.move(NODE_X.getFqn(), NODES[rnd.nextInt(NODES.length)].getFqn());
TestingUtil.sleepRandom(250);
- try {
- treeCache.move(NODE_Y.getFqn(), NODES[rnd.nextInt(NODES.length)].getFqn());
- }
- catch (NodeNotExistsException e) {
- // this may happen ...
- }
+ treeCache.move(NODE_Y.getFqn(), NODES[rnd.nextInt(NODES.length)].getFqn());
TestingUtil.sleepRandom(250);
}
}
Added: core/branches/flat/src/test/java/org/horizon/atomic/AtomicHashMapConcurrencyTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/atomic/AtomicHashMapConcurrencyTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/atomic/AtomicHashMapConcurrencyTest.java 2009-03-09 22:10:53 UTC (rev 7893)
@@ -0,0 +1,140 @@
+package org.horizon.atomic;
+
+import org.horizon.config.Configuration;
+import org.horizon.lock.TimeoutException;
+import org.horizon.manager.CacheManager;
+import org.horizon.manager.DefaultCacheManager;
+import org.horizon.test.TestingUtil;
+import org.horizon.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Tester class for AtomicMapCache.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+@Test(groups = "functional", testName = "atomic.AtomicHashMapConcurrencyTest")
+public class AtomicHashMapConcurrencyTest {
+
+ public static final String KEY = "key";
+ AtomicMapCache<String, String> cache;
+ TransactionManager tm;
+
+ enum Operation {
+ PUT,
+ COMMIT,
+ READ
+ }
+
+ @BeforeMethod
+ @SuppressWarnings("unchecked")
+ public void setUp() {
+ Configuration c = new Configuration();
+ c.setLockAcquisitionTimeout(500);
+ // these 2 need to be set to use the AtomicMapCache
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ c.setInvocationBatchingEnabled(true);
+ CacheManager cm = new DefaultCacheManager(c);
+ cache = (AtomicMapCache<String, String>) cm.getCache();
+ tm = TestingUtil.getTransactionManager(cache);
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ try {
+ tm.rollback();
+ } catch (Exception e) {
+ }
+ }
+
+ public void testConcurrentCreate() throws Exception {
+ tm.begin();
+ AtomicMap<Integer, String> atomicMap = cache.getAtomicMap(KEY, Integer.class, String.class);
+ OtherThread ot = new OtherThread();
+ ot.start();
+ Object response = ot.response.take();
+ assert response instanceof TimeoutException;
+ }
+
+ public void testConcurrentModifications() throws Exception {
+ AtomicMap<Integer, String> atomicMap = cache.getAtomicMap(KEY, Integer.class, String.class);
+ tm.begin();
+ atomicMap.put(1,"");
+ OtherThread ot = new OtherThread();
+ ot.start();
+ ot.toExecute.put(Operation.PUT);
+ Object response = ot.response.take();
+ assert response instanceof TimeoutException;
+ }
+
+ public void testReadAfterTxStarted() throws Exception {
+ AtomicMap<Integer, String> atomicMap = cache.getAtomicMap(KEY, Integer.class, String.class);
+ atomicMap.put(1, "existing");
+ tm.begin();
+ atomicMap.put(1,"newVal");
+ OtherThread ot = new OtherThread();
+ ot.start();
+ ot.toExecute.put(Operation.READ);
+ Object response = ot.response.take();
+ assert response.equals("existing");
+ tm.commit();
+ assert atomicMap.get(1).equals("newVal");
+ ot.toExecute.put(Operation.READ);
+ response = ot.response.take();
+ assert response.equals("newVal");
+ }
+
+ public class OtherThread extends Thread {
+
+ public OtherThread() {
+ super("OtherThread");
+ }
+
+ BlockingQueue response = new ArrayBlockingQueue(1);
+
+ BlockingQueue<Operation> toExecute = new ArrayBlockingQueue<Operation>(1);
+
+ @Override
+ public void run() {
+ try {
+ tm.begin();
+ AtomicMap<Integer, String> atomicMap = cache.getAtomicMap(KEY, Integer.class, String.class);
+ boolean notCommited = true;
+ while (notCommited) {
+ Operation op = toExecute.take();
+ switch (op) {
+ case PUT: {
+ atomicMap.put(1, "val");
+ response.put(new Object());
+ break;
+ }
+ case READ: {
+ String val = atomicMap.get(1);
+ response.put(String.valueOf(val));
+ break;
+ }
+ case COMMIT: {
+ tm.commit();
+ response.put(new Object());
+ notCommited = false;
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ try {
+ response.put(e);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ e.printStackTrace();
+ }
+ }
+ }
+}
Property changes on: core/branches/flat/src/test/java/org/horizon/atomic/AtomicHashMapConcurrencyTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
15 years, 9 months