@Test public void notFoundTest() { for (int i = 0; i < 10; i++) { BroadcasterFactory.getDefault().get(String.valueOf(i)); } AtmosphereResource r = AtmosphereResourceFactory.getDefault() .create( mock(AtmosphereConfig.class), BroadcasterFactory.getDefault().lookup("1"), AtmosphereResponse.newInstance().request(AtmosphereRequest.create()), mock(AsyncSupport.class), mock(AtmosphereHandler.class)); assertNotNull(r); assertNull(AtmosphereResourceFactory.getDefault().find(r.uuid())); }
public void cancel() throws IOException { if (!isCancelled.getAndSet(true)) { logger.trace("Cancelling {}", uuid); if (config.getBroadcasterFactory().getDefault() != null) { config.getBroadcasterFactory().getDefault().removeAllAtmosphereResource(this); if (transport.equals(TRANSPORT.WEBSOCKET)) { String parentUUID = (String) req.getAttribute(SUSPENDED_ATMOSPHERE_RESOURCE_UUID); AtmosphereResource p = AtmosphereResourceFactory.getDefault().find(parentUUID); if (p != null) { config.getBroadcasterFactory().getDefault().removeAllAtmosphereResource(p); } } } asyncSupport.complete(this); SessionTimeoutSupport.restoreTimeout(req); action.type(Action.TYPE.CANCELLED); if (asyncSupport != null) asyncSupport.action(this); // We must close the underlying WebSocket as well. if (AtmosphereResponse.class.isAssignableFrom(response.getClass())) { AtmosphereResponse.class.cast(response).close(); AtmosphereResponse.class.cast(response).destroy(); } if (AtmosphereRequest.class.isAssignableFrom(req.getClass())) { AtmosphereRequest.class.cast(req).destroy(); } req.removeAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE); event.destroy(); } }
@Test public void findTest() { Broadcaster b1 = BroadcasterFactory.getDefault().get("b1"); Broadcaster b2 = BroadcasterFactory.getDefault().get("b2"); AtmosphereResource r = AtmosphereResourceFactory.getDefault() .create( mock(AtmosphereConfig.class), b1, AtmosphereResponse.newInstance().request(AtmosphereRequest.create()), mock(AsyncSupport.class), mock(AtmosphereHandler.class)); assertNotNull(r); b2.addAtmosphereResource(r); assertNotNull(AtmosphereResourceFactory.getDefault().find(r.uuid())); }
@Test public void createTest() { AtmosphereResource r = AtmosphereResourceFactory.getDefault() .create( mock(AtmosphereConfig.class), mock(Broadcaster.class), AtmosphereResponse.newInstance().request(AtmosphereRequest.create()), mock(AsyncSupport.class), mock(AtmosphereHandler.class)); assertNotNull(r); }