use of org.atmosphere.cache.UUIDBroadcasterCache in project atmosphere by Atmosphere.
the class AtmosphereResourceStateRecoveryTest method longPollingAggregatedTest.
@Test(enabled = false)
public void longPollingAggregatedTest() throws ServletException, IOException, ExecutionException, InterruptedException {
final AtomicReference<Object> ref = new AtomicReference<Object>();
AtmosphereResourceImpl r = (AtmosphereResourceImpl) config.resourcesFactory().create(config, "1234567");
r.setBroadcaster(config.getBroadcasterFactory().lookup("/1", true));
recovery.configure(config);
recovery.inspect(r);
config.getBroadcasterFactory().lookup("/1", true).getBroadcasterConfig().setBroadcasterCache(new UUIDBroadcasterCache());
config.getBroadcasterFactory().lookup("/2", true).getBroadcasterConfig().setBroadcasterCache(new UUIDBroadcasterCache());
config.getBroadcasterFactory().lookup("/3", true).getBroadcasterConfig().setBroadcasterCache(new UUIDBroadcasterCache());
config.getBroadcasterFactory().lookup("/4", true).getBroadcasterConfig().setBroadcasterCache(new UUIDBroadcasterCache());
config.getBroadcasterFactory().lookup("/1", true).addAtmosphereResource(r);
config.getBroadcasterFactory().lookup("/2", true).addAtmosphereResource(r);
config.getBroadcasterFactory().lookup("/3", true).addAtmosphereResource(r);
config.getBroadcasterFactory().lookup("/4", true).addAtmosphereResource(r);
r.suspend();
config.metaBroadcaster().broadcastTo("/1", "Initialize Cache").get();
r.close();
AtmosphereResourceImpl r2 = (AtmosphereResourceImpl) config.resourcesFactory().create(config, "1234567");
// Set a different one to hit caching.
r2.setBroadcaster(config.getBroadcasterFactory().lookup("/*", true));
config.getBroadcasterFactory().lookup("/1", true).broadcast(("1")).get();
config.getBroadcasterFactory().lookup("/2", true).broadcast(("2")).get();
config.getBroadcasterFactory().lookup("/3", true).broadcast(("3")).get();
config.getBroadcasterFactory().lookup("/4", true).broadcast(("4")).get();
r2.transport(AtmosphereResource.TRANSPORT.LONG_POLLING).atmosphereHandler(new AtmosphereHandlerAdapter() {
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
ref.set(event.getMessage());
}
}).suspend();
recovery.inspect(r2);
assertTrue(List.class.isAssignableFrom(ref.get().getClass()));
assertEquals(List.class.cast(ref.get()).size(), 4);
StringBuilder b = new StringBuilder();
for (Object o : List.class.cast(ref.get())) {
b.append(o.toString());
}
assertEquals(b.toString(), "1234");
}
use of org.atmosphere.cache.UUIDBroadcasterCache in project atmosphere by Atmosphere.
the class UUIDBroadcasterCacheTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
config = new AtmosphereFramework().getAtmosphereConfig();
DefaultBroadcasterFactory factory = new DefaultBroadcasterFactory(DefaultBroadcaster.class, "NEVER", config);
broadcaster = factory.get(DefaultBroadcaster.class, "test");
config.framework().setBroadcasterFactory(factory);
broadcasterCache = new UUIDBroadcasterCache();
broadcaster.getBroadcasterConfig().setBroadcasterCache(broadcasterCache);
broadcasterCache.configure(config);
atmosphereHandler = new AR();
ar = new AtmosphereResourceImpl(config, broadcaster, mock(AtmosphereRequestImpl.class), AtmosphereResponseImpl.newInstance(), mock(Servlet30CometSupport.class), atmosphereHandler);
broadcaster.addAtmosphereResource(ar);
}
use of org.atmosphere.cache.UUIDBroadcasterCache in project atmosphere by Atmosphere.
the class BroadcasterCacheTest method testCloseExcludeCache.
@Test
public void testCloseExcludeCache() throws ExecutionException, InterruptedException, ServletException, IOException {
UUIDBroadcasterCache cache = new UUIDBroadcasterCache();
SimpleBroadcaster b = config.getBroadcasterFactory().lookup(SimpleBroadcaster.class, "uuidTest", true);
cache.configure(config);
b.getBroadcasterConfig().setBroadcasterCache(cache);
// Reset
b.removeAtmosphereResource(ar);
b.addAtmosphereResource(ar);
b.broadcast("foo").get();
ar.close();
b.removeAtmosphereResource(ar);
b.broadcast("raide").get();
assertEquals(cache.messages().isEmpty(), false);
List<Object> l = cache.retrieveFromCache(b.getID(), ar.uuid());
assertNotNull(l);
assertEquals(l.isEmpty(), false);
}
use of org.atmosphere.cache.UUIDBroadcasterCache in project atmosphere by Atmosphere.
the class BroadcasterCacheTest method testExcludeCache.
@Test
public void testExcludeCache() throws ExecutionException, InterruptedException, ServletException {
BroadcasterCache cache = new UUIDBroadcasterCache();
cache.configure(config);
AtmosphereResource r = config.resourcesFactory().create(broadcaster.getBroadcasterConfig().getAtmosphereConfig(), "1234567");
broadcaster.getBroadcasterConfig().setBroadcasterCache(cache);
broadcaster.addAtmosphereResource(r);
broadcaster.broadcast("foo").get();
broadcaster.removeAtmosphereResource(r);
broadcaster.broadcast("foo").get();
List<Object> l = cache.retrieveFromCache(broadcaster.getID(), r.uuid());
assertNotNull(l);
assertEquals(l.isEmpty(), false);
}
use of org.atmosphere.cache.UUIDBroadcasterCache in project atmosphere by Atmosphere.
the class BroadcasterCacheTest method testSuspendExcludeCache.
@Test
public void testSuspendExcludeCache() throws ExecutionException, InterruptedException, ServletException, IOException {
UUIDBroadcasterCache cache = new UUIDBroadcasterCache();
SimpleBroadcaster b = config.getBroadcasterFactory().lookup(SimpleBroadcaster.class, "uuidTest", true);
cache.configure(config);
b.getBroadcasterConfig().setBroadcasterCache(cache);
// Reset
b.removeAtmosphereResource(ar);
ar.suspend();
b.removeAtmosphereResource(ar);
b.broadcast("raide").get();
// Blocked by the cache because suspend has been called.
assertEquals(cache.messages().isEmpty(), true);
}
Aggregations