@Test public void sessionCompletedIsIdempotent() { Runnable callback1 = Mockito.mock(Runnable.class); this.simpAttributes.registerDestructionCallback("name1", callback1); this.simpAttributes.sessionCompleted(); this.simpAttributes.sessionCompleted(); this.simpAttributes.sessionCompleted(); verify(callback1, times(1)).run(); }
@Test public void sessionCompleted() { Runnable callback1 = Mockito.mock(Runnable.class); Runnable callback2 = Mockito.mock(Runnable.class); this.simpAttributes.registerDestructionCallback("name1", callback1); this.simpAttributes.registerDestructionCallback("name2", callback2); this.simpAttributes.sessionCompleted(); verify(callback1, times(1)).run(); verify(callback2, times(1)).run(); }
@Test public void registerDestructionCallbackAfterSessionCompleted() { this.simpAttributes.sessionCompleted(); this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage(containsString("already completed")); this.simpAttributes.registerDestructionCallback("name1", Mockito.mock(Runnable.class)); }
@Override public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) { this.decoders.remove(session.getId()); Message<byte[]> message = createDisconnectMessage(session); SimpAttributes simpAttributes = SimpAttributes.fromMessage(message); try { SimpAttributesContextHolder.setAttributes(simpAttributes); if (this.eventPublisher != null) { Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionDisconnectEvent(this, message, session.getId(), closeStatus, user)); } outputChannel.send(message); } finally { this.stompAuthentications.remove(session.getId()); SimpAttributesContextHolder.resetAttributes(); simpAttributes.sessionCompleted(); } }
@Test public void registerDestructionCallback() { Runnable runnable = Mockito.mock(Runnable.class); this.scope.registerDestructionCallback("name", runnable); this.simpAttributes.sessionCompleted(); verify(runnable, times(1)).run(); }
@Override public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) { this.decoders.remove(session.getId()); Message<byte[]> message = createDisconnectMessage(session); SimpAttributes simpAttributes = SimpAttributes.fromMessage(message); try { SimpAttributesContextHolder.setAttributes(simpAttributes); if (this.eventPublisher != null) { Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionDisconnectEvent(this, message, session.getId(), closeStatus, user)); } outputChannel.send(message); } finally { this.stompAuthentications.remove(session.getId()); SimpAttributesContextHolder.resetAttributes(); simpAttributes.sessionCompleted(); } }
@Override public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) { this.decoders.remove(session.getId()); Message<byte[]> message = createDisconnectMessage(session); SimpAttributes simpAttributes = SimpAttributes.fromMessage(message); try { SimpAttributesContextHolder.setAttributes(simpAttributes); if (this.eventPublisher != null) { Principal user = getUser(session); publishEvent(this.eventPublisher, new SessionDisconnectEvent(this, message, session.getId(), closeStatus, user)); } outputChannel.send(message); } finally { this.stompAuthentications.remove(session.getId()); SimpAttributesContextHolder.resetAttributes(); simpAttributes.sessionCompleted(); } }