@Override public DatagramSocketImpl createDatagramSocketImpl() { return new DirectDatagramSocketImpl(); } }
@Override protected void bind(int lport, InetAddress laddr) throws SocketException { LOGGER.log(Level.FINE, "binding to port {0}, address {1}", new Object[] { lport, laddr }); int port = bind(lport); synchronized (this) { this.localPort = port; this.localAddress = laddr; } setOption(SocketOptions.SO_BINDADDR, laddr); }
/** * Get socket timeout. * * @return timeout in milliseconds. 0, doen't wait. * @throws SocketException not used */ private int getSoTimeout() throws SocketException { Object option = getOption(SocketOptions.SO_TIMEOUT); if (option instanceof Integer) { return ((Integer) option).intValue(); } else { return 0; } }
/** * Close network after testing. * * Ensure, that all sockets are closed. Reset network configuration to their * defaults. * * @see #DEFAULT_FORMATTER * @see #DEFAULT_DELAY_IN_MILLIS */ protected void closeNetwork() { if (Mode.DIRECT == usedMode) { if (!DirectDatagramSocketImpl.isEmpty()) { Description description; synchronized (RULES_STACK) { description = this.description; } LOGGER.log(Level.INFO, "Test {0} did not close all DatagramSockets!", description); DirectDatagramSocketImpl.clearAll(); } DirectDatagramSocketImpl.configure(DEFAULT_FORMATTER, DEFAULT_DELAY_IN_MILLIS); } }
addr = this.localAddress; final int timeout = getSoTimeout(); final Setup currentSetup = setup.get(); final DatagramExchange exchange;
/** * Initialize network for testing. * * Configure network using * {@link DirectDatagramSocketImpl#configure(DatagramFormatter, int)}, if * {@link #usedMode} is {@link Mode#DIRECT}. * * @param outerScope true, if called from the outer most rule. Usually the * rule is used as class rule and my use nested method rules. If * that's the case, outerScope is true for the class rule and * false for the method rule. If only method rules are used, it's * always true. If true, all open DIRECT sockets are cleaned up * and warnings are logged. This indicator is introduced to cover * situations, where the class setup starts a server, which is * then reused by several tests. */ protected void initNetwork(boolean outerScope) { if (Mode.DIRECT == usedMode) { if (outerScope && !DirectDatagramSocketImpl.isEmpty()) { LOGGER.info("Previous test did not call ''closeNetwork()''!"); DirectDatagramSocketImpl.clearAll(); } DirectDatagramSocketImpl.configure(formatter, delayInMillis); } }