@Test public void getIdShouldReturnAndCacheCorrectValue() { final TransportMetadata metadata = context.mock(TransportMetadata.class, "metadata"); final IoServiceEx service = context.mock(IoServiceEx.class, "service"); ResourceAddressFactory addressFactory = ResourceAddressFactory.newResourceAddressFactory(); String addressURI = "ws: final SocketAddress address = addressFactory.newResourceAddress(addressURI); final Subject subject = new Subject(); final String expected = "wsn#23 127.0.0.1:2121"; AtomicReference<String> value = new AtomicReference<String>(); context.checking(new Expectations() { { oneOf(sessionEx).getAttribute(with(any(Object.class))); will(returnValue(null)); oneOf(sessionEx).getId(); will(returnValue(TEST_SESSION_NUMBER)); oneOf(sessionEx).getTransportMetadata(); will(returnValue(metadata)); oneOf(metadata).getName(); will(returnValue("wsn")); oneOf(sessionEx).getService(); will(returnValue(service)); oneOf(sessionEx).getLocalAddress(); will(returnValue(address)); oneOf(sessionEx).getSubject(); will(returnValue(subject)); oneOf(sessionEx).getRemoteAddress(); will(returnValue(address)); oneOf(sessionEx).setAttribute(with(any(Object.class)), with(any(String.class))); will(saveParameter(value, 1)); } }); assertEquals(expected, LoggingUtils.getId(sessionEx)); context.assertIsSatisfied(); context.checking(new Expectations() { { oneOf(sessionEx).getAttribute(with(any(Object.class))); will(returnValue(value.get())); } }); assertEquals(expected, LoggingUtils.getId(sessionEx)); }
public static String getId(IoSession session) { String result = LOG_ID_ATTRIBUTE.get(session); if (result == null) { result = session.getTransportMetadata().getName() + "#" + session.getId(); String user = LoggingUtils.getUserIdentifier(session); if (user != null) { result = result + " " + user; } LOG_ID_ATTRIBUTE.set(session, result); } return result; }
LoggingUtils { public static String getId(IoSession session) { String result = LOG_ID_ATTRIBUTE.get(session); if (result == null) { result = session.getTransportMetadata().getName() + "#" + session.getId(); String user = LoggingUtils.getUserIdentifier(session); if (user != null) { result = result + " " + user; } LOG_ID_ATTRIBUTE.set(session, result); } return result; } }
LoggingUtils { public static String getId(IoSession session) { String result = LOG_ID_ATTRIBUTE.get(session); if (result == null) { result = session.getTransportMetadata().getName() + "#" + session.getId(); String user = LoggingUtils.getUserIdentifier(session); if (user != null) { result = result + " " + user; } LOG_ID_ATTRIBUTE.set(session, result); } return result; } private  LoggingUtils(); }
LoggingUtils { public static String getId(IoSession session) { String result = LOG_ID_ATTRIBUTE.get(session); if (result == null) { result = session.getTransportMetadata().getName() + "#" + session.getId(); String user = LoggingUtils.getUserIdentifier(session); if (user != null) { result = result + " " + user; } LOG_ID_ATTRIBUTE.set(session, result); } return result; } private  LoggingUtils(); static String addSession(String message, IoSession session); static String getId(IoSession session); static void log(IoSession session, Throwable t); static void log(IoSession session, Logger logger, Throwable t); static void log(IoSession session, Logger logger, String message, Throwable t); }
LoggingUtils { public static String getId(IoSession session) { String result = LOG_ID_ATTRIBUTE.get(session); if (result == null) { result = session.getTransportMetadata().getName() + "#" + session.getId(); String user = LoggingUtils.getUserIdentifier(session); if (user != null) { result = result + " " + user; } LOG_ID_ATTRIBUTE.set(session, result); } return result; } private  LoggingUtils(); static String addSession(String message, IoSession session); static String getId(IoSession session); static void log(IoSession session, Throwable t); static void log(IoSession session, Logger logger, Throwable t); static void log(IoSession session, Logger logger, String message, Throwable t); static final String NETWORK_CONNECTIVITY_ERROR_MESSAGE; static final String EARLY_TERMINATION_OF_IOSESSION_MESSAGE; }