/** * 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); } }
/** * 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); } }