private void notifySessions(final KieServerControllerEvent event) { final KieServerControllerNotification notification = new KieServerControllerNotification(event); LOGGER.debug("Sending notification to all Web Socket sessions"); manager.broadcastObject(notification); }
@Test public void testBroadcast() throws Exception { final RemoteEndpoint.Basic endpoint = mock(RemoteEndpoint.Basic.class); when(session.getBasicRemote()).thenReturn(endpoint); when(session.isOpen()).thenReturn(true); manager.addSession(session); final KieServerControllerNotification notification = new KieServerControllerNotification(); manager.broadcastObject(notification); verify(endpoint, timeout(TIMEOUT)).sendObject(notification); }
@Test public void testRemoveSessionWithMessageInProgress() throws Exception { final RemoteEndpoint.Basic endpoint = mock(RemoteEndpoint.Basic.class); doThrow(new IOException()).when(endpoint).sendObject(any()); when(session.getBasicRemote()).thenReturn(endpoint); when(session.isOpen()).thenReturn(true); manager.addSession(session); final KieServerControllerNotification notification = new KieServerControllerNotification(); manager.broadcastObject(notification); final ExecutorService executor = manager.getExecutorsBySession().get(session); manager.removeSession(session); //Wait for complete shutdown Thread.sleep(500); assertTrue(executor.isShutdown()); assertTrue(executor.isTerminated()); }
@Test public void testBroadcastWithEncodeException() throws Exception { final RemoteEndpoint.Basic endpoint = mock(RemoteEndpoint.Basic.class); doThrow(new EncodeException(null, "encode error")).when(endpoint).sendObject(any()); when(session.getBasicRemote()).thenReturn(endpoint); when(session.isOpen()).thenReturn(true); manager.addSession(session); final KieServerControllerNotification notification = new KieServerControllerNotification(); manager.broadcastObject(notification); verify(endpoint, timeout(TIMEOUT)).sendObject(notification); } }