Search in sources :

Example 6 with CacheMessage

use of org.atmosphere.cache.CacheMessage in project atmosphere by Atmosphere.

the class BroadcasterCacheTest method testEmptyRejectedCache.

@Test
public void testEmptyRejectedCache() throws ExecutionException, InterruptedException, ServletException {
    final CountDownLatch latch = new CountDownLatch(1);
    broadcaster.getBroadcasterConfig().setBroadcasterCache(new AbstractBroadcasterCache() {

        @Override
        public CacheMessage addToCache(String id, String uuid, BroadcastMessage e) {
            CacheMessage c = put(e, System.nanoTime(), uuid, broadcaster.getID());
            cachedMessage.set(messages);
            latch.countDown();
            return c;
        }

        @Override
        public List<Object> retrieveFromCache(String id, String uuid) {
            return Collections.<Object>emptyList();
        }
    }).getBroadcasterCache().inspector(new BroadcasterCacheInspector() {

        @Override
        public boolean inspect(BroadcastMessage message) {
            return false;
        }
    });
    broadcaster.broadcast("foo", ar);
    latch.await(10, TimeUnit.SECONDS);
    assertEquals(cachedMessage.get().size(), 0);
}
Also used : CacheMessage(org.atmosphere.cache.CacheMessage) AbstractBroadcasterCache(org.atmosphere.cache.AbstractBroadcasterCache) BroadcastMessage(org.atmosphere.cache.BroadcastMessage) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) BroadcasterCacheInspector(org.atmosphere.cache.BroadcasterCacheInspector) Test(org.testng.annotations.Test)

Aggregations

BroadcastMessage (org.atmosphere.cache.BroadcastMessage)6 CacheMessage (org.atmosphere.cache.CacheMessage)6 List (java.util.List)5 AbstractBroadcasterCache (org.atmosphere.cache.AbstractBroadcasterCache)5 Test (org.testng.annotations.Test)5 BroadcasterCacheInspector (org.atmosphere.cache.BroadcasterCacheInspector)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Servlet30CometSupport (org.atmosphere.container.Servlet30CometSupport)1 AR (org.atmosphere.runtime.BroadcasterCacheTest.AR)1