Author: manik.surtani(a)jboss.com
Date: 2008-08-05 06:50:47 -0400 (Tue, 05 Aug 2008)
New Revision: 6509
Modified:
core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java
Log:
Notifier fixes
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2008-08-05
10:42:48 UTC (rev 6508)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2008-08-05
10:50:47 UTC (rev 6509)
@@ -122,34 +122,28 @@
listenersMap.put(NodeInvalidated.class, nodeInvalidatedListeners);
}
- public NotifierImpl(Cache cache)
- {
- this();
- this.cache = cache;
- }
-
@Inject
- private void injectDependencies(CacheSPI cache, Configuration config)
+ void injectDependencies(CacheSPI cache, Configuration config)
{
this.cache = cache;
this.config = config;
}
@Stop
- private void stop()
+ void stop()
{
syncProcessor.shutdownNow();
asyncProcessor.shutdownNow();
}
@Destroy
- protected void destroy()
+ void destroy()
{
removeAllCacheListeners();
}
@Start
- protected void start()
+ void start()
{
useMarshalledValueMaps = config.isUseLazyDeserialization();
syncProcessor = new WithinThreadExecutor();
Modified:
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java 2008-08-05
10:42:48 UTC (rev 6508)
+++
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java 2008-08-05
10:50:47 UTC (rev 6509)
@@ -1,7 +1,8 @@
package org.jboss.cache.notifications;
-import org.jboss.cache.Cache;
-import org.jboss.cache.DefaultCacheFactory;
+import static org.easymock.EasyMock.createNiceMock;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.CacheStarted;
import org.jboss.cache.notifications.annotation.CacheStopped;
@@ -9,6 +10,7 @@
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.notifications.event.NodeMovedEvent;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -28,10 +30,18 @@
@BeforeMethod(alwaysRun = true)
public void setUp()
{
- Cache c = new DefaultCacheFactory<Object, Object>().createCache(false);
- n = new NotifierImpl(c);
+ n = new NotifierImpl();
+ n.injectDependencies(createNiceMock(CacheSPI.class), new Configuration());
+ n.start();
}
+ @AfterMethod
+ public void tearDown()
+ {
+ n.stop();
+ n.destroy();
+ }
+
public void testControl()
{
Object l = new TestControlListener();
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java 2008-08-05
10:42:48 UTC (rev 6508)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java 2008-08-05
10:50:47 UTC (rev 6509)
@@ -1,14 +1,16 @@
package org.jboss.cache.notifications;
import static org.easymock.EasyMock.createNiceMock;
-import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.invocation.LegacyInvocationContext;
import org.jboss.cache.notifications.annotation.*;
import org.jboss.cache.notifications.event.*;
import org.jgroups.View;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -26,7 +28,6 @@
public class NotifierTest
{
private NotifierImpl notifier;
- private Cache cache;
private InvocationContext ctx;
private AllEventsListener allEventsListener;
private Fqn fqn = Fqn.fromString("/a/b/c");
@@ -34,13 +35,21 @@
@BeforeMethod
public void setUp()
{
- cache = createNiceMock(Cache.class);
- notifier = new NotifierImpl(cache);
+ notifier = new NotifierImpl();
+ notifier.injectDependencies(createNiceMock(CacheSPI.class), new Configuration());
+ notifier.start();
ctx = new LegacyInvocationContext(null);
allEventsListener = new AllEventsListener();
notifier.addCacheListener(allEventsListener);
}
+ @AfterMethod
+ public void tearDown()
+ {
+ notifier.stop();
+ notifier.destroy();
+ }
+
public void testNotifyNodeCreated()
{
assert allEventsListener.nodeCreatedEvent == null;
@@ -60,7 +69,7 @@
public void testNotifyNodeModified()
{
assert allEventsListener.nodeModifiedEvent == null;
- Map expected = new HashMap();
+ Map<String, String> expected = new HashMap<String, String>();
expected.put("k", "v");
notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA,
expected, ctx);
assert allEventsListener.nodeModifiedEvent != null;
@@ -71,7 +80,7 @@
public void testNotifyNodeRemoved()
{
assert allEventsListener.nodeRemoveEvent == null;
- Map data = new HashMap();
+ Map<String, String> data = new HashMap<String, String>();
data.put("k", "v");
notifier.notifyNodeRemoved(fqn, true, data, ctx);
assert allEventsListener.nodeRemoveEvent != null;
@@ -110,7 +119,7 @@
public void testNotifyNodeLoaded()
{
assert allEventsListener.nodeLoadedEvent == null;
- Map expected = new HashMap();
+ Map<String, String> expected = new HashMap<String, String>();
expected.put("key", "value");
notifier.notifyNodeLoaded(fqn, true, expected, ctx);
assert allEventsListener.nodeLoadedEvent != null;
@@ -122,7 +131,7 @@
public void testNotifyNodeActivated()
{
assert allEventsListener.nodeActivatedEvent == null;
- Map expected = new HashMap();
+ Map<String, String> expected = new HashMap<String, String>();
expected.put("key", "value");
notifier.notifyNodeActivated(fqn, true, expected, ctx);
assert allEventsListener.nodeActivatedEvent != null;
@@ -134,7 +143,7 @@
public void testNotifyNodePassivated()
{
assert allEventsListener.nodePassivatedEvent == null;
- Map expected = new HashMap();
+ Map<String, String> expected = new HashMap<String, String>();
expected.put("key", "value");
notifier.notifyNodePassivated(fqn, true, expected, ctx);
assert allEventsListener.nodePassivatedEvent != null;