SessionListListener implements HttpSessionListener, SessionListService { public SessionListResponse listSessions(final String nodeName) { LOGGER.debug("listSessions(\"{}\") called", nodeName); Objects.requireNonNull(nodeName); final SessionListResponse sessionList; if (NodeCallUtil.shouldExecuteLocally(nodeInfo, nodeName)) { sessionList = listSessionsOnThisNode(); } else { final String url = NodeCallUtil.getBaseEndpointUrl(nodeInfo, nodeService, nodeName) + ResourcePaths.buildAuthenticatedApiPath( SessionResource.BASE_PATH, SessionResource.LIST_PATH_PART); try { LOGGER.debug("Sending request to {} for node {}", url, nodeName); final Response response = webTargetFactory.create(url) .queryParam(SessionResource.NODE_NAME_PARAM, nodeName) .request(MediaType.APPLICATION_JSON) .get(); if (response.getStatus() != 200) { throw new WebApplicationException(response); } sessionList = response.readEntity(SessionListResponse.class); } catch (Throwable e) { throw NodeCallUtil.handleExceptionsOnNodeCall(nodeName, url, e); } } return sessionList; } @Inject  SessionListListener(final NodeInfo nodeInfo,
                        final NodeService nodeService,
                        final TaskContextFactory taskContextFactory,
                        final WebTargetFactory webTargetFactory); @Override void sessionCreated(final HttpSessionEvent event); @Override void sessionDestroyed(final HttpSessionEvent event); SessionListResponse listSessions(final String nodeName); SessionListResponse listSessions();  }
@Test void listSessions() throws InterruptedException { initNodes(); SessionListService sessionListService1 = sessionListServiceMap.get("node1"); SessionListResponse sessionListResponse = sessionListService1.listSessions(); Thread.sleep(50); Assertions.assertThat(getRequestEvents("node1")) .hasSize(0); Assertions.assertThat(getRequestEvents("node2")) .hasSize(1); Assertions.assertThat(getRequestEvents("node3")) .hasSize(0); }
@Test void testListSessions_oneNode() throws InterruptedException { initNodes(); SessionListService sessionListService1 = sessionListServiceMap.get("node1"); SessionListResponse sessionListResponse = sessionListService1.listSessions("node2"); Thread.sleep(50); Assertions.assertThat(getRequestEvents("node1")) .hasSize(0); Assertions.assertThat(getRequestEvents("node2")) .hasSize(1); Assertions.assertThat(getRequestEvents("node3")) .hasSize(0); }