@Test public void testGetNotificationTimeout() { final AsyncResponse asyncResponse = mock( AsyncResponse.class ); NotificationRequestWrapper notificationRequestWrapper = new NotificationRequestWrapper(); NotificationRequest notificationRequest = new NotificationRequest(); notificationRequest.setNotificationType( "test-type" ); NotificationRequestEntry notificationRequestEntry = new NotificationRequestEntry( "test-id", 10L ); notificationRequest.setEntries( Arrays.asList( notificationRequestEntry ) ); notificationRequestWrapper.setRequests( Arrays.asList( notificationRequest ) ); doAnswer( new Answer<Void>() { @Override public Void answer( InvocationOnMock invocation ) throws Throwable { ( (TimeoutHandler) invocation.getArguments()[ 0 ] ).handleTimeout( asyncResponse ); ( (TimeoutHandler) invocation.getArguments()[ 0 ] ).handleTimeout( asyncResponse ); return null; } } ).when( asyncResponse ).setTimeoutHandler( any( TimeoutHandler.class ) ); service.getNotifications( asyncResponse, notificationRequestWrapper ); verify( asyncResponse, times( 1 ) ).resume( any( NotificationResponse.class ) ); }
@GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) public void webresource(@javax.ws.rs.PathParam("id") Long id, @Suspended final AsyncResponse response) throws IOException { // WebResource webResource = webResourceDataServiceDecorator.getWebResourceFullDeep(id); ObjectMapper mapper = new ObjectMapper(); response.setTimeoutHandler(new TimeoutHandler() { @Override public void handleTimeout(AsyncResponse asyncResponse) { LOGGER.error("Timout error in audit page"); AuditResult auditResult = new AuditResult(); auditResult.setMessage((String) messages.get("global.timeout.error")); asyncResponse.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(auditResult).build()); } }); //Time out is fixed to 60 seconds response.setTimeout(60, TimeUnit.SECONDS); // response.resume(mapper.writeValueAsString(webResource)); }
@Override public void setTimeoutHandler(TimeoutHandler handler) { throw new UnsupportedOperationException(); }
@Override public void setTimeoutHandler(TimeoutHandler handler) { // TODO Auto-generated method stub }
@Override public void setTimeoutHandler(final TimeoutHandler handler) { // Empty. }
/** * {@inheritDoc}. */ @Override public void setTimeoutHandler(final TimeoutHandler handler) { timeoutHandler = handler; }
@Override public void setTimeoutHandler(TimeoutHandler handler) { }