/** * {@inheritDoc} */ @Override protected void tearDown() { // Reset context classloader. See the comment in setUp(). if (getTestData().containerType == ContainerType.EMBEDDED) { Thread.currentThread().setContextClassLoader(null); } // Stop any local container that is still running if (this.container != null && this.container.getType().isLocal()) { LocalContainer container = (LocalContainer) this.container; if (container.getState().isStarted() || container.getState().isStarting()) { getLogger().info( "Container is in the [" + container.getState() + "] state" + ", shutting it down now", this.getClass().getName()); container.stop(); } } getLogger().info("Ending test [" + getName() + "]", this.getClass().getName()); }
/** * Stops this cargo container */ public void stop() { if (!container.getState().isStarted()) { throw new IllegalArgumentException("Container " + description + " failed to stop because it is currently " + container.getState()); } container.stop(); }
/** * The container's port for the specified port type */ public String getPort(String portType) { LocalConfiguration config = getConfiguration(); config.applyPortOffset(); if (!container.getState().isStarted()) throw new IllegalStateException( "Container is not started, thus a port has not yet been assigned to the container."); return config.getPropertyValue(portType); }
if (container.getState().isStarted()) throw new IllegalArgumentException("Container " + description + " failed to start because it is currently " + container.getState());
/** * Get the indexes of all active containers */ private ArrayList<Integer> getActiveContainerIndexes() { return getContainerIndexesWithState(State.STARTED.toString()); }
/** * Get all inactive containers */ private ArrayList<ServerContainer> getInactiveContainers() { ArrayList<ServerContainer> inactiveContainers = getContainersWithState(State.STOPPED.toString()); inactiveContainers.addAll(getContainersWithState(State.UNKNOWN.toString())); return inactiveContainers; } }
/** * Get all active containers */ private ArrayList<ServerContainer> getActiveContainers() { return getContainersWithState(State.STARTED.toString()); }
/** * Get the positions of the containers with the given container state * * @param state A string representing the Cargo state a container is in. The possible states can * be found in as static variables in the {@link State} class. */ public ArrayList<Integer> getContainerIndexesWithState(String state) { if (!(state.equals(State.STARTED.toString()) || state.equals(State.STOPPED.toString()) || state.equals(State.STARTING.toString()) || state.equals(State.STOPPING.toString()) || state.equals(State.UNKNOWN.toString()))) { throw new IllegalArgumentException( "State must be one of the 5 specified cargo state strings (stopped, started, starting, stopping, or unknown). State given was: " + state); } ArrayList<Integer> indexes = new ArrayList<>(); for (int i = 0; i < numContainers(); i++) { if (getContainer(i).getState().toString().equals(state)) indexes.add(i); } return indexes; }