[jbosscache-commits] JBoss Cache SVN: r6323 - in pojo/trunk: src/test/java/org/jboss/cache/pojo/notification and 1 other directory.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Fri Jul 18 00:18:10 EDT 2008
Author: jason.greene at jboss.com
Date: 2008-07-18 00:18:10 -0400 (Fri, 18 Jul 2008)
New Revision: 6323
Modified:
pojo/trunk/pom.xml
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/Listener.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/MapTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ObjectTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedListTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedMapTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedObjectTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedSetTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/SetTest.java
Log:
Update to CR6
Fix state transfer race in notification tests
Modified: pojo/trunk/pom.xml
===================================================================
--- pojo/trunk/pom.xml 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/pom.xml 2008-07-18 04:18:10 UTC (rev 6323)
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<jbosscache-pojo-version>2.2.0-SNAPSHOT</jbosscache-pojo-version>
- <jbosscache-core-version>2.2.0.CR5</jbosscache-core-version>
+ <jbosscache-core-version>2.2.0.CR6</jbosscache-core-version>
<jboss.aop.version>2.0.0.CR14</jboss.aop.version>
</properties>
<parent>
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListTest.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListTest.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -118,7 +118,7 @@
// List Attach
attach = takeNotification(AttachedEvent.class);
assertEquals(list, attach.getSource());
-
+ //cache.detach("a");
}
@SuppressWarnings("unchecked")
@@ -129,8 +129,8 @@
List<String> list = new ArrayList<String>();
list.add(test1);
- cache.attach("a", list);
- list = (List<String>) cache.find("a");
+ cache.attach("b", list);
+ list = (List<String>) cache.find("b");
list.set(0, test2);
// String attach
@@ -160,6 +160,7 @@
assertEquals(ListModifiedEvent.Operation.SET, modify.getOperation());
assertEquals(test2, modify.getValue());
assertEquals(0, modify.getIndex());
+ //cache.detach("b");
}
@SuppressWarnings("unchecked")
@@ -171,8 +172,8 @@
List<String> list = new ArrayList<String>();
list.add(test1);
list.add(test2);
- cache.attach("a", list);
- list = (List<String>) cache.find("a");
+ cache.attach("c", list);
+ list = (List<String>) cache.find("c");
list.remove(1);
// String attach
@@ -208,6 +209,7 @@
// String detach
DetachedEvent detach = takeNotification(DetachedEvent.class);
assertEquals(test2, detach.getSource());
+ //cache.detach("c");
}
public void testObjectListAdd() throws Exception
@@ -225,7 +227,7 @@
list.add(taiwanese);
test.setLanguages(list);
- cache.attach("a", test);
+ cache.attach("d", test);
// String attach
AttachedEvent attach = takeNotification(AttachedEvent.class);
@@ -254,6 +256,8 @@
// Person Attach
attach = takeNotification(AttachedEvent.class);
assertEquals(test, attach.getSource());
+
+ //cache.detach("d");
}
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/Listener.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/Listener.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/Listener.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -22,11 +22,9 @@
package org.jboss.cache.pojo.notification;
-import java.util.LinkedList;
-import java.util.Queue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
-import net.jcip.annotations.NotThreadSafe;
-
import org.jboss.cache.pojo.notification.annotation.Attached;
import org.jboss.cache.pojo.notification.annotation.Detached;
import org.jboss.cache.pojo.notification.annotation.FieldModified;
@@ -39,20 +37,27 @@
// $Id$
/**
- * A recoding Listener for notification test package. This is not thread safe, just for testing.
+ * A recoding Listener for notification test package.
*
* @author Jason T. Greene
*/
@PojoCacheListener
- at NotThreadSafe
public class Listener
{
- private Queue<Event> events = new LinkedList<Event>();
+ private BlockingQueue<Event> events = new LinkedBlockingQueue<Event>();
@SuppressWarnings("unchecked")
public <T extends Event> T take(Class<T> t)
{
- Event notification = events.remove();
+ Event notification;
+ try
+ {
+ notification = events.take();
+ }
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException(e);
+ }
if (!t.isInstance(notification))
throw new IllegalStateException("Expected notification type: " + t.getSimpleName() + " but was: " + notification.getClass().getSimpleName());
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/MapTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/MapTest.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/MapTest.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -51,7 +51,6 @@
protected PojoCache cache;
protected Listener listener = new Listener();
-
@BeforeMethod(alwaysRun = true)
protected void setUp() throws Exception
{
@@ -122,6 +121,8 @@
attach = takeNotification(AttachedEvent.class);
assertEquals(map, attach.getSource());
+ //cache.detach("a");
+
}
@SuppressWarnings("unchecked")
@@ -135,8 +136,8 @@
Map<String, String> map = new LinkedHashMap<String, String>();
map.put(key1, test1);
map.put(key2, test2);
- cache.attach("a", map);
- map = (Map<String, String>) cache.find("a");
+ cache.attach("b", map);
+ map = (Map<String, String>) cache.find("b");
map.remove(key2);
// String attach
@@ -172,6 +173,8 @@
// String detach
DetachedEvent detach = takeNotification(DetachedEvent.class);
assertEquals(test2, detach.getSource());
+
+ //cache.detach("b");
}
public void testObjectMapAdd() throws Exception
@@ -189,7 +192,7 @@
map.put(key1, drumming);
map.put(key2, engineering);
test.setHobbies(map);
- cache.attach("a", test);
+ cache.attach("c", test);
// String attach
AttachedEvent attach = takeNotification(AttachedEvent.class);
@@ -218,6 +221,8 @@
// Person Attach
attach = takeNotification(AttachedEvent.class);
assertEquals(test, attach.getSource());
+
+ //cache.detach("c");
}
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ObjectTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ObjectTest.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ObjectTest.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -34,7 +34,7 @@
public class ObjectTest
{
protected PojoCache cache;
- protected Listener listener;
+ protected Listener listener = new Listener();
@BeforeMethod(alwaysRun = true)
@@ -45,7 +45,6 @@
cache = PojoCacheFactory.createCache(configFile, toStart);
cache.start();
- listener = new Listener();
cache.addListener(listener);
}
@@ -69,6 +68,7 @@
protected void tearDown() throws Exception
{
cache.stop();
+ listener.clear();
}
public void testAttachNotification() throws Exception
@@ -79,6 +79,7 @@
cache.attach("/a", test);
AttachedEvent attach = takeNotification(AttachedEvent.class);
assertEquals(test, attach.getSource());
+ //cache.detach("/a");
}
public void testAttachNotification2() throws Exception
@@ -88,7 +89,7 @@
test.setAge(10);
Address addr = new Address();
test.setAddress(addr);
- cache.attach("/a", test);
+ cache.attach("/b", test);
// Address Attach
AttachedEvent attach = takeNotification(AttachedEvent.class);
@@ -97,6 +98,7 @@
// Person Attach
attach = takeNotification(AttachedEvent.class);
assertEquals(test, attach.getSource());
+ //cache.detach("/b");
}
public void testDetachNotification() throws Exception
@@ -104,14 +106,14 @@
Person test = new Person();
test.setName("Ben");
test.setAge(10);
- cache.attach("/a", test);
+ cache.attach("/c", test);
// Person Attach
AttachedEvent attach = takeNotification(AttachedEvent.class);
Object attached = attach.getSource();
assertEquals(test, attached);
- cache.detach("/a");
+ cache.detach("/c");
// Person Detach
DetachedEvent detach = takeNotification(DetachedEvent.class);
@@ -123,7 +125,7 @@
Person test = new Person();
test.setName("Ben");
test.setAge(10);
- cache.attach("/a", test);
+ cache.attach("/d", test);
// Person Attach
AttachedEvent attach = takeNotification(AttachedEvent.class);
@@ -152,5 +154,7 @@
assertEquals(test, modify.getSource());
assertEquals(test.getClass().getDeclaredField("address"), modify.getField());
assertEquals(addr, modify.getValue());
+
+ //cache.detach("/d");
}
}
\ No newline at end of file
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedListTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedListTest.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedListTest.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -25,6 +25,7 @@
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertSame;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.pojo.PojoCache;
@@ -49,9 +50,13 @@
@BeforeMethod(alwaysRun = true)
protected void setUp() throws Exception
{
- cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config.setFetchInMemoryState(false);
+ Configuration config2 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config2.setFetchInMemoryState(false);
+ cache = PojoCacheFactory.createCache(config, false);
cache.start();
- listenerCache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ listenerCache = PojoCacheFactory.createCache(config2, false);
listenerCache.start();
listenerCache.addListener(listener);
}
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedMapTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedMapTest.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedMapTest.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -25,6 +25,7 @@
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertSame;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.pojo.PojoCache;
@@ -49,11 +50,13 @@
@BeforeMethod(alwaysRun = true)
protected void setUp() throws Exception
{
- super.setUp();
-
- cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config.setFetchInMemoryState(false);
+ Configuration config2 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config2.setFetchInMemoryState(false);
+ cache = PojoCacheFactory.createCache(config, false);
cache.start();
- listenerCache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ listenerCache = PojoCacheFactory.createCache(config2, false);
listenerCache.start();
listenerCache.addListener(listener);
}
@@ -61,9 +64,9 @@
@AfterMethod(alwaysRun = true)
protected void tearDown() throws Exception
{
- super.tearDown();
cache.stop();
listenerCache.stop();
+ listener.clear();
}
protected void verifyNotification(Event notification)
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedObjectTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedObjectTest.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedObjectTest.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -25,6 +25,7 @@
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertSame;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.pojo.PojoCache;
@@ -49,11 +50,14 @@
@BeforeMethod(alwaysRun = true)
protected void setUp() throws Exception
{
- cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config.setFetchInMemoryState(false);
+ Configuration config2 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config2.setFetchInMemoryState(false);
+ cache = PojoCacheFactory.createCache(config, false);
cache.start();
- listenerCache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ listenerCache = PojoCacheFactory.createCache(config2, false);
listenerCache.start();
- listener = new Listener();
listenerCache.addListener(listener);
}
@AfterMethod(alwaysRun = true)
@@ -61,6 +65,7 @@
{
cache.stop();
listenerCache.stop();
+ listener.clear();
}
protected void verifyNotification(Event notification)
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedSetTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedSetTest.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ReplicatedSetTest.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -25,6 +25,7 @@
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertSame;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.pojo.PojoCache;
@@ -42,18 +43,20 @@
* @author Jason T. Greene
*/
@Test(groups = {"functional"})
-public class ReplicatedSetTest extends ListTest
+public class ReplicatedSetTest extends SetTest
{
private PojoCache listenerCache;
@BeforeMethod(alwaysRun = true)
protected void setUp() throws Exception
{
- super.setUp();
-
- cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config.setFetchInMemoryState(false);
+ Configuration config2 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config2.setFetchInMemoryState(false);
+ cache = PojoCacheFactory.createCache(config, false);
cache.start();
- listenerCache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ listenerCache = PojoCacheFactory.createCache(config2, false);
listenerCache.start();
listenerCache.addListener(listener);
}
@@ -61,9 +64,9 @@
@AfterMethod(alwaysRun = true)
protected void tearDown() throws Exception
{
- super.tearDown();
cache.stop();
listenerCache.stop();
+ listener.clear();
}
protected void verifyNotification(Event notification)
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/SetTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/SetTest.java 2008-07-17 16:08:09 UTC (rev 6322)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/SetTest.java 2008-07-18 04:18:10 UTC (rev 6323)
@@ -46,10 +46,10 @@
* @author Jason T. Greene
*/
@Test(groups = {"functional"})
-public class SetTest
+public class SetTest
{
- private PojoCache cache;
- private Listener listener = new Listener();
+ protected PojoCache cache;
+ protected Listener listener = new Listener();
@BeforeMethod(alwaysRun = true)
@@ -66,6 +66,7 @@
protected void tearDown() throws Exception
{
cache.stop();
+ listener.clear();
}
private <T extends Event> T takeNotification(Class<T> clazz)
@@ -114,8 +115,9 @@
// Set Attach
attach = takeNotification(AttachedEvent.class);
- assertSame(set, attach.getSource());
+ assertEquals(set, attach.getSource());
+ //cache.detach("a");
}
@SuppressWarnings("unchecked")
@@ -127,9 +129,9 @@
Set<String> set = new LinkedHashSet<String>();
set.add(test1);
set.add(test2);
- cache.attach("a", set);
+ cache.attach("b", set);
- set = (Set<String>) cache.find("a");
+ set = (Set<String>) cache.find("b");
set.remove(test2);
// String attach
@@ -152,7 +154,7 @@
// Set Attach
attach = takeNotification(AttachedEvent.class);
- assertSame(set, attach.getSource());
+ assertEquals(set, attach.getSource());
// Set remove
modify = takeNotification(SetModifiedEvent.class);
@@ -162,6 +164,8 @@
// String detach
DetachedEvent detach = takeNotification(DetachedEvent.class);
assertEquals(test2, detach.getSource());
+
+ //cache.detach("b");
}
public void testObjectSetAdd() throws Exception
@@ -177,7 +181,7 @@
set.add(drumming);
set.add(engineering);
test.setSkills(set);
- cache.attach("a", test);
+ cache.attach("c", test);
// String attach
AttachedEvent attach = takeNotification(AttachedEvent.class);
@@ -204,7 +208,7 @@
// Person Attach
attach = takeNotification(AttachedEvent.class);
assertEquals(test, attach.getSource());
+
+ //cache.detach("c");
}
-
-
}
More information about the jbosscache-commits
mailing list