1 5 package com.opensymphony.oscache.plugins.clustersupport; 6 7 import com.opensymphony.oscache.base.*; 8 import com.opensymphony.oscache.base.events.CacheEntryEventListener; 9 10 import junit.framework.TestCase; 11 12 import java.util.Date ; 13 14 20 public abstract class BaseTestBroadcastingListener extends TestCase { 21 24 protected static AbstractBroadcastingListener listener = null; 25 26 29 protected static Cache cache = null; 30 31 36 int testsRemaining = 0; 37 38 41 private final String GROUP = "test group"; 42 43 46 private final String KEY = "Test clustersupport persistence listener key"; 47 48 public BaseTestBroadcastingListener(String str) { 49 super(str); 50 } 51 52 56 public void testListener() { 57 CacheEntry entry = new CacheEntry(KEY, null); 58 59 cache.putInCache(KEY, entry); 60 cache.putInCache(KEY, entry, new String [] {GROUP}); 61 cache.flushEntry(KEY); 62 cache.flushGroup(GROUP); 63 cache.flushAll(new Date ()); 64 65 } 67 68 72 public void setUp() { 73 if (listener == null) { 75 testsRemaining = countTestCases(); 77 listener = getListener(); 78 assertNotNull(listener); 79 80 cache = new Cache(true, false, false); 81 assertNotNull(cache); 82 83 try { 84 listener.initialize(cache, getConfig()); 85 } catch (InitializationException e) { 86 fail(e.getMessage()); 87 } 88 89 cache.addCacheEventListener(listener, CacheEntryEventListener.class); 90 } 91 } 92 93 96 protected void tearDown() throws Exception { 97 if (--testsRemaining == 0) { 98 try { 99 listener.finialize(); 100 listener = null; 101 } catch (FinalizationException e) { 102 fail(e.getMessage()); 103 } 104 } 105 } 106 107 111 abstract AbstractBroadcastingListener getListener(); 112 113 117 abstract Config getConfig(); 118 } 119 | Popular Tags |