[jbosscache-commits] JBoss Cache SVN: r7619 - in core/branches/flat/src: main/java/org/horizon/commands/read and 3 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Jan 30 19:34:44 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-01-30 19:34:44 -0500 (Fri, 30 Jan 2009)
New Revision: 7619

Added:
   core/branches/flat/src/test/java/org/horizon/notifications/cachelistener/CacheNotifierTest.java
   core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierTest.java
Removed:
   core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerTest.java
   core/branches/flat/src/test/java/org/horizon/notifications/CacheManagerNotifierTest.java
Modified:
   core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java
   core/branches/flat/src/main/java/org/horizon/commands/read/GetKeyValueCommand.java
Log:
Started work on notifications

Modified: core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java	2009-01-31 00:32:22 UTC (rev 7618)
+++ core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java	2009-01-31 00:34:44 UTC (rev 7619)
@@ -37,7 +37,7 @@
 import org.horizon.commands.write.ReplaceCommand;
 import org.horizon.container.DataContainer;
 import org.horizon.factories.annotations.Inject;
-import org.horizon.notifications.CacheNotifier;
+import org.horizon.notifications.cachelistener.CacheNotifier;
 import org.horizon.remoting.transport.Address;
 import org.horizon.transaction.GlobalTransaction;
 

Modified: core/branches/flat/src/main/java/org/horizon/commands/read/GetKeyValueCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/read/GetKeyValueCommand.java	2009-01-31 00:32:22 UTC (rev 7618)
+++ core/branches/flat/src/main/java/org/horizon/commands/read/GetKeyValueCommand.java	2009-01-31 00:34:44 UTC (rev 7619)
@@ -26,7 +26,7 @@
 import org.horizon.context.InvocationContext;
 import org.horizon.logging.Log;
 import org.horizon.logging.LogFactory;
-import org.horizon.notifications.CacheNotifier;
+import org.horizon.notifications.cachelistener.CacheNotifier;
 
 /**
  * // TODO: MANIK: Document this

Deleted: core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerTest.java	2009-01-31 00:32:22 UTC (rev 7618)
+++ core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerTest.java	2009-01-31 00:34:44 UTC (rev 7619)
@@ -1,211 +0,0 @@
-package org.horizon.notifications;
-
-import static org.easymock.EasyMock.*;
-import org.horizon.Cache;
-import org.horizon.config.Configuration;
-import org.horizon.context.InvocationContext;
-import org.horizon.lock.IsolationLevel;
-import org.horizon.manager.CacheManager;
-import org.horizon.manager.DefaultCacheManager;
-import org.horizon.notifications.cachelistener.CacheNotifier;
-import org.horizon.transaction.DummyTransactionManagerLookup;
-import org.horizon.util.TestingUtil;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
- at Test(groups = "functional", sequential = true)
-public class CacheListenerTest {
-   private Cache<Object, Object> cache;
-   private TransactionManager tm;
-   private CacheNotifier mockNotifier;
-   private CacheNotifier origNotifier;
-
-   @BeforeMethod(alwaysRun = true)
-   public void setUp() throws Exception {
-      Configuration c = new Configuration();
-      c.setCacheMode(Configuration.CacheMode.LOCAL);
-      c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
-      c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
-
-      CacheManager cm = new DefaultCacheManager(c);
-
-      cache = cm.getCache();
-      tm = TestingUtil.getTransactionManager(cache);
-      mockNotifier = createMock(CacheNotifier.class);
-      origNotifier = TestingUtil.replaceComponent(cache, CacheNotifier.class, mockNotifier, true);
-   }
-
-   @AfterMethod(alwaysRun = true)
-   public void tearDown() throws Exception {
-      TestingUtil.replaceComponent(cache, CacheNotifier.class, origNotifier, true);
-      TestingUtil.killCaches(cache);
-   }
-
-   private void initCacheData(Object key, Object value) {
-      initCacheData(Collections.singletonMap(key, value));
-   }
-
-   private void initCacheData(Map data) {
-      mockNotifier.notifyCacheEntryCreated(anyObject(), anyBoolean(), isA(InvocationContext.class));
-      expectLastCall().anyTimes();
-      mockNotifier.notifyCacheEntryModified(anyObject(), anyObject(), anyBoolean(), isA(InvocationContext.class));
-      expectLastCall().anyTimes();
-      replay(mockNotifier);
-      cache.putAll(data);
-      verify(mockNotifier);
-
-      // now reset the mock
-      reset(mockNotifier);
-   }
-
-   private void expectSingleEntryCreated(Object key, Object value) {
-      mockNotifier.notifyCacheEntryCreated(eq(key), eq(true), isA(InvocationContext.class));
-      expectLastCall().once();
-      mockNotifier.notifyCacheEntryCreated(eq(key), eq(false), isA(InvocationContext.class));
-      expectLastCall().once();
-      mockNotifier.notifyCacheEntryModified(eq(key), isNull(), eq(true), isA(InvocationContext.class));
-      expectLastCall().once();
-      mockNotifier.notifyCacheEntryModified(eq(key), eq(value), eq(false), isA(InvocationContext.class));
-      expectLastCall().once();
-   }
-
-   private void expectTransactionBoundaries(boolean successful) {
-      mockNotifier.notifyTransactionRegistered(isA(Transaction.class), isA(InvocationContext.class));
-      expectLastCall().once();
-      mockNotifier.notifyTransactionCompleted(isA(Transaction.class), eq(successful), isA(InvocationContext.class));
-      expectLastCall().once();
-   }
-
-
-   // simple tests first
-
-   public void testCreation() throws Exception {
-      expectSingleEntryCreated("key", "value");
-      replay(mockNotifier);
-      cache.put("key", "value");
-      verify(mockNotifier);
-   }
-
-   public void testOnlyModification() throws Exception {
-      initCacheData("key", "value");
-
-      mockNotifier.notifyCacheEntryModified(eq("key"), eq("value"), eq(true), isA(InvocationContext.class));
-      expectLastCall().once();
-      mockNotifier.notifyCacheEntryModified(eq("key"), eq("value2"), eq(false), isA(InvocationContext.class));
-      expectLastCall().once();
-
-      replay(mockNotifier);
-      cache.put("key", "value2");
-      verify(mockNotifier);
-   }
-
-   public void testNonexistentRemove() throws Exception {
-      cache.remove("doesNotExist");
-      replay(mockNotifier);
-      verify(mockNotifier);
-   }
-
-   public void testRemoveData() throws Exception {
-      Map data = new HashMap();
-      data.put("key", "value");
-      data.put("key2", "value2");
-      initCacheData(data);
-
-      mockNotifier.notifyCacheEntryRemoved(eq("key2"), eq("value2"), eq(true), isA(InvocationContext.class));
-      expectLastCall().once();
-      mockNotifier.notifyCacheEntryRemoved(eq("key2"), isNull(), eq(false), isA(InvocationContext.class));
-      expectLastCall().once();
-      replay(mockNotifier);
-
-      cache.remove("key2");
-
-      verify(mockNotifier);
-   }
-
-   public void testPutMap() throws Exception {
-      Map<Object, Object> data = new HashMap<Object, Object>();
-      data.put("key", "value");
-      data.put("key2", "value2");
-      expectSingleEntryCreated("key", "value");
-      expectSingleEntryCreated("key2", "value2");
-
-      replay(mockNotifier);
-
-      cache.putAll(data);
-      verify(mockNotifier);
-   }
-
-   // -- now the transactional ones
-
-   public void testTxNonexistentRemove() throws Exception {
-      expectTransactionBoundaries(true);
-      replay(mockNotifier);
-      tm.begin();
-      cache.remove("doesNotExist");
-      tm.commit();
-      verify(mockNotifier);
-   }
-
-   public void testTxCreationCommit() throws Exception {
-      expectTransactionBoundaries(true);
-      expectSingleEntryCreated("key", "value");
-      replay(mockNotifier);
-      tm.begin();
-      cache.put("key", "value");
-      tm.commit();
-      verify(mockNotifier);
-   }
-
-   public void testTxCreationRollback() throws Exception {
-      expectTransactionBoundaries(false);
-      expectSingleEntryCreated("key", "value");
-      replay(mockNotifier);
-      tm.begin();
-      cache.put("key", "value");
-      tm.rollback();
-      verify(mockNotifier);
-   }
-
-   public void testTxOnlyModification() throws Exception {
-      initCacheData("key", "value");
-      expectTransactionBoundaries(true);
-      mockNotifier.notifyCacheEntryModified(eq("key"), eq("value"), eq(true), isA(InvocationContext.class));
-      expectLastCall().once();
-      mockNotifier.notifyCacheEntryModified(eq("key"), eq("value2"), eq(false), isA(InvocationContext.class));
-      expectLastCall().once();
-
-      replay(mockNotifier);
-
-      tm.begin();
-      cache.put("key", "value2");
-      tm.commit();
-
-      verify(mockNotifier);
-   }
-
-   public void testTxRemoveData() throws Exception {
-      Map data = new HashMap();
-      data.put("key", "value");
-      data.put("key2", "value2");
-      initCacheData(data);
-      expectTransactionBoundaries(true);
-      mockNotifier.notifyCacheEntryRemoved(eq("key2"), eq("value2"), eq(true), isA(InvocationContext.class));
-      expectLastCall().once();
-      mockNotifier.notifyCacheEntryRemoved(eq("key2"), isNull(), eq(false), isA(InvocationContext.class));
-      expectLastCall().once();
-      replay(mockNotifier);
-
-      tm.begin();
-      cache.remove("key2");
-      tm.commit();
-
-      verify(mockNotifier);
-   }
-}

Deleted: core/branches/flat/src/test/java/org/horizon/notifications/CacheManagerNotifierTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/notifications/CacheManagerNotifierTest.java	2009-01-31 00:32:22 UTC (rev 7618)
+++ core/branches/flat/src/test/java/org/horizon/notifications/CacheManagerNotifierTest.java	2009-01-31 00:34:44 UTC (rev 7619)
@@ -1,70 +0,0 @@
-package org.horizon.notifications;
-
-import static org.easymock.EasyMock.*;
-import org.horizon.BaseClusteredTest;
-import org.horizon.Cache;
-import org.horizon.config.Configuration;
-import org.horizon.config.GlobalConfiguration;
-import org.horizon.manager.CacheManager;
-import org.horizon.notifications.cachemanagerlistener.CacheManagerNotifier;
-import org.horizon.remoting.transport.Address;
-import org.horizon.util.TestingUtil;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
- at Test(groups = "unit", sequential = true, testName = "notifications.CacheManagerNotifierTest")
-public class CacheManagerNotifierTest extends BaseClusteredTest {
-   public void testViewChange() {
-      CacheManager cm1 = addClusterEnabledCacheManager();
-      CacheManager cm2 = addClusterEnabledCacheManager();
-      Configuration c = new Configuration();
-      c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
-      defineCacheOnAllManagers("cache", c);
-
-      Cache c1 = cm1.getCache("cache");
-
-      // this will mean only 1 cache in the cluster so far
-      assert cm1.getMembers().size() == 1;
-      Address myAddress = cm1.getAddress();
-      assert cm1.getMembers().contains(myAddress);
-
-      // now attach a mock notifier
-      CacheManagerNotifier mockNotifier = createMock(CacheManagerNotifier.class);
-      CacheManagerNotifier origNotifier = TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, mockNotifier, true);
-      try {
-         mockNotifier.notifyViewChange(isA(List.class), eq(myAddress));
-         replay(mockNotifier);
-         // start a second cache.
-         Cache c2 = cm2.getCache("cache");
-         TestingUtil.blockUntilViewsReceived(60000, cm1, cm2);
-         verify(mockNotifier);
-
-      } finally {
-         TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, origNotifier, true);
-      }
-   }
-
-   public void testCacheStartedAndStopped() {
-      CacheManager cm1 = addCacheManager(GlobalConfiguration.getNonClusteredDefault());
-      Cache defCache = cm1.getCache();
-      CacheManagerNotifier mockNotifier = createMock(CacheManagerNotifier.class);
-      CacheManagerNotifier origNotifier = TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, mockNotifier, true);
-      try {
-         cm1.defineCache("testCache", new Configuration());
-         mockNotifier.notifyCacheStarted("testCache");
-         replay(mockNotifier);
-         // start a second cache.
-         Cache testCache = cm1.getCache("testCache");
-         verify(mockNotifier);
-
-         reset(mockNotifier);
-         mockNotifier.notifyCacheStopped("testCache");
-         replay(mockNotifier);
-         testCache.stop();
-         verify(mockNotifier);
-      } finally {
-         TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, origNotifier, true);
-      }
-   }
-}

Copied: core/branches/flat/src/test/java/org/horizon/notifications/cachelistener/CacheNotifierTest.java (from rev 7618, core/branches/flat/src/test/java/org/horizon/notifications/CacheListenerTest.java)
===================================================================
--- core/branches/flat/src/test/java/org/horizon/notifications/cachelistener/CacheNotifierTest.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/notifications/cachelistener/CacheNotifierTest.java	2009-01-31 00:34:44 UTC (rev 7619)
@@ -0,0 +1,210 @@
+package org.horizon.notifications.cachelistener;
+
+import static org.easymock.EasyMock.*;
+import org.horizon.Cache;
+import org.horizon.config.Configuration;
+import org.horizon.context.InvocationContext;
+import org.horizon.lock.IsolationLevel;
+import org.horizon.manager.CacheManager;
+import org.horizon.manager.DefaultCacheManager;
+import org.horizon.transaction.DummyTransactionManagerLookup;
+import org.horizon.util.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+ at Test(groups = "functional", sequential = true)
+public class CacheNotifierTest {
+   private Cache<Object, Object> cache;
+   private TransactionManager tm;
+   private CacheNotifier mockNotifier;
+   private CacheNotifier origNotifier;
+
+   @BeforeMethod(alwaysRun = true)
+   public void setUp() throws Exception {
+      Configuration c = new Configuration();
+      c.setCacheMode(Configuration.CacheMode.LOCAL);
+      c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+      c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+
+      CacheManager cm = new DefaultCacheManager(c);
+
+      cache = cm.getCache();
+      tm = TestingUtil.getTransactionManager(cache);
+      mockNotifier = createMock(CacheNotifier.class);
+      origNotifier = TestingUtil.replaceComponent(cache, CacheNotifier.class, mockNotifier, true);
+   }
+
+   @AfterMethod(alwaysRun = true)
+   public void tearDown() throws Exception {
+      TestingUtil.replaceComponent(cache, CacheNotifier.class, origNotifier, true);
+      TestingUtil.killCaches(cache);
+   }
+
+   private void initCacheData(Object key, Object value) {
+      initCacheData(Collections.singletonMap(key, value));
+   }
+
+   private void initCacheData(Map data) {
+      mockNotifier.notifyCacheEntryCreated(anyObject(), anyBoolean(), isA(InvocationContext.class));
+      expectLastCall().anyTimes();
+      mockNotifier.notifyCacheEntryModified(anyObject(), anyObject(), anyBoolean(), isA(InvocationContext.class));
+      expectLastCall().anyTimes();
+      replay(mockNotifier);
+      cache.putAll(data);
+      verify(mockNotifier);
+
+      // now reset the mock
+      reset(mockNotifier);
+   }
+
+   private void expectSingleEntryCreated(Object key, Object value) {
+      mockNotifier.notifyCacheEntryCreated(eq(key), eq(true), isA(InvocationContext.class));
+      expectLastCall().once();
+      mockNotifier.notifyCacheEntryCreated(eq(key), eq(false), isA(InvocationContext.class));
+      expectLastCall().once();
+      mockNotifier.notifyCacheEntryModified(eq(key), isNull(), eq(true), isA(InvocationContext.class));
+      expectLastCall().once();
+      mockNotifier.notifyCacheEntryModified(eq(key), eq(value), eq(false), isA(InvocationContext.class));
+      expectLastCall().once();
+   }
+
+   private void expectTransactionBoundaries(boolean successful) {
+      mockNotifier.notifyTransactionRegistered(isA(Transaction.class), isA(InvocationContext.class));
+      expectLastCall().once();
+      mockNotifier.notifyTransactionCompleted(isA(Transaction.class), eq(successful), isA(InvocationContext.class));
+      expectLastCall().once();
+   }
+
+
+   // simple tests first
+
+   public void testCreation() throws Exception {
+      expectSingleEntryCreated("key", "value");
+      replay(mockNotifier);
+      cache.put("key", "value");
+      verify(mockNotifier);
+   }
+
+   public void testOnlyModification() throws Exception {
+      initCacheData("key", "value");
+
+      mockNotifier.notifyCacheEntryModified(eq("key"), eq("value"), eq(true), isA(InvocationContext.class));
+      expectLastCall().once();
+      mockNotifier.notifyCacheEntryModified(eq("key"), eq("value2"), eq(false), isA(InvocationContext.class));
+      expectLastCall().once();
+
+      replay(mockNotifier);
+      cache.put("key", "value2");
+      verify(mockNotifier);
+   }
+
+   public void testNonexistentRemove() throws Exception {
+      cache.remove("doesNotExist");
+      replay(mockNotifier);
+      verify(mockNotifier);
+   }
+
+   public void testRemoveData() throws Exception {
+      Map data = new HashMap();
+      data.put("key", "value");
+      data.put("key2", "value2");
+      initCacheData(data);
+
+      mockNotifier.notifyCacheEntryRemoved(eq("key2"), eq("value2"), eq(true), isA(InvocationContext.class));
+      expectLastCall().once();
+      mockNotifier.notifyCacheEntryRemoved(eq("key2"), isNull(), eq(false), isA(InvocationContext.class));
+      expectLastCall().once();
+      replay(mockNotifier);
+
+      cache.remove("key2");
+
+      verify(mockNotifier);
+   }
+
+   public void testPutMap() throws Exception {
+      Map<Object, Object> data = new HashMap<Object, Object>();
+      data.put("key", "value");
+      data.put("key2", "value2");
+      expectSingleEntryCreated("key", "value");
+      expectSingleEntryCreated("key2", "value2");
+
+      replay(mockNotifier);
+
+      cache.putAll(data);
+      verify(mockNotifier);
+   }
+
+   // -- now the transactional ones
+
+   public void testTxNonexistentRemove() throws Exception {
+      expectTransactionBoundaries(true);
+      replay(mockNotifier);
+      tm.begin();
+      cache.remove("doesNotExist");
+      tm.commit();
+      verify(mockNotifier);
+   }
+
+   public void testTxCreationCommit() throws Exception {
+      expectTransactionBoundaries(true);
+      expectSingleEntryCreated("key", "value");
+      replay(mockNotifier);
+      tm.begin();
+      cache.put("key", "value");
+      tm.commit();
+      verify(mockNotifier);
+   }
+
+   public void testTxCreationRollback() throws Exception {
+      expectTransactionBoundaries(false);
+      expectSingleEntryCreated("key", "value");
+      replay(mockNotifier);
+      tm.begin();
+      cache.put("key", "value");
+      tm.rollback();
+      verify(mockNotifier);
+   }
+
+   public void testTxOnlyModification() throws Exception {
+      initCacheData("key", "value");
+      expectTransactionBoundaries(true);
+      mockNotifier.notifyCacheEntryModified(eq("key"), eq("value"), eq(true), isA(InvocationContext.class));
+      expectLastCall().once();
+      mockNotifier.notifyCacheEntryModified(eq("key"), eq("value2"), eq(false), isA(InvocationContext.class));
+      expectLastCall().once();
+
+      replay(mockNotifier);
+
+      tm.begin();
+      cache.put("key", "value2");
+      tm.commit();
+
+      verify(mockNotifier);
+   }
+
+   public void testTxRemoveData() throws Exception {
+      Map data = new HashMap();
+      data.put("key", "value");
+      data.put("key2", "value2");
+      initCacheData(data);
+      expectTransactionBoundaries(true);
+      mockNotifier.notifyCacheEntryRemoved(eq("key2"), eq("value2"), eq(true), isA(InvocationContext.class));
+      expectLastCall().once();
+      mockNotifier.notifyCacheEntryRemoved(eq("key2"), isNull(), eq(false), isA(InvocationContext.class));
+      expectLastCall().once();
+      replay(mockNotifier);
+
+      tm.begin();
+      cache.remove("key2");
+      tm.commit();
+
+      verify(mockNotifier);
+   }
+}

Copied: core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierTest.java (from rev 7618, core/branches/flat/src/test/java/org/horizon/notifications/CacheManagerNotifierTest.java)
===================================================================
--- core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierTest.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/notifications/cachemanagerlistener/CacheManagerNotifierTest.java	2009-01-31 00:34:44 UTC (rev 7619)
@@ -0,0 +1,70 @@
+package org.horizon.notifications.cachemanagerlistener;
+
+import static org.easymock.EasyMock.*;
+import org.horizon.BaseClusteredTest;
+import org.horizon.Cache;
+import org.horizon.config.Configuration;
+import org.horizon.config.GlobalConfiguration;
+import org.horizon.manager.CacheManager;
+import org.horizon.notifications.cachemanagerlistener.CacheManagerNotifier;
+import org.horizon.remoting.transport.Address;
+import org.horizon.util.TestingUtil;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+ at Test(groups = "unit", sequential = true, testName = "notifications.CacheManagerNotifierTest")
+public class CacheManagerNotifierTest extends BaseClusteredTest {
+   public void testViewChange() {
+      CacheManager cm1 = addClusterEnabledCacheManager();
+      CacheManager cm2 = addClusterEnabledCacheManager();
+      Configuration c = new Configuration();
+      c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+      defineCacheOnAllManagers("cache", c);
+
+      Cache c1 = cm1.getCache("cache");
+
+      // this will mean only 1 cache in the cluster so far
+      assert cm1.getMembers().size() == 1;
+      Address myAddress = cm1.getAddress();
+      assert cm1.getMembers().contains(myAddress);
+
+      // now attach a mock notifier
+      CacheManagerNotifier mockNotifier = createMock(CacheManagerNotifier.class);
+      CacheManagerNotifier origNotifier = TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, mockNotifier, true);
+      try {
+         mockNotifier.notifyViewChange(isA(List.class), eq(myAddress));
+         replay(mockNotifier);
+         // start a second cache.
+         Cache c2 = cm2.getCache("cache");
+         TestingUtil.blockUntilViewsReceived(60000, cm1, cm2);
+         verify(mockNotifier);
+
+      } finally {
+         TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, origNotifier, true);
+      }
+   }
+
+   public void testCacheStartedAndStopped() {
+      CacheManager cm1 = addCacheManager(GlobalConfiguration.getNonClusteredDefault());
+      Cache defCache = cm1.getCache();
+      CacheManagerNotifier mockNotifier = createMock(CacheManagerNotifier.class);
+      CacheManagerNotifier origNotifier = TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, mockNotifier, true);
+      try {
+         cm1.defineCache("testCache", new Configuration());
+         mockNotifier.notifyCacheStarted("testCache");
+         replay(mockNotifier);
+         // start a second cache.
+         Cache testCache = cm1.getCache("testCache");
+         verify(mockNotifier);
+
+         reset(mockNotifier);
+         mockNotifier.notifyCacheStopped("testCache");
+         replay(mockNotifier);
+         testCache.stop();
+         verify(mockNotifier);
+      } finally {
+         TestingUtil.replaceComponent(cm1, CacheManagerNotifier.class, origNotifier, true);
+      }
+   }
+}




More information about the jbosscache-commits mailing list