private Cube<?> resolveMainCube(CubeRegistry cubeRegistry) { Cube<?> cube = null; if (this.configuration.isContainerlessDockerSet()) { String containerlessDocker = this.configuration.getContainerlessDocker(); cube = cubeRegistry.getCube(containerlessDocker); if (cube == null) { // Is there a way to ignore it? Or we should throw an exception? throw new IllegalArgumentException("No Containerless Docker container configured in extension with id " + containerlessDocker); } } else { List<Cube<?>> cubes = cubeRegistry.getCubes(); if (cubes.size() == 1) { cube = cubes.get(0); } else { throw new IllegalArgumentException( "More than one container eligible for being the main instance. Use containerlessDocker property to set one."); } } return cube; }
public void attachShutDownHookForceStopDockerContainers(@Observes(precedence = 200) BeforeSuite event, final CubeRegistry cubeRegistry) { Runtime.getRuntime().addShutdownHook(new Thread(() -> { final List<Cube<?>> cubes = cubeRegistry.getCubes(); for (Cube cube : cubes) { try { cube.stop(); } catch (final Throwable e) { Logger.getLogger(ForceStopDockerContainersShutdownHook.class.getName()).log(Level.WARNING, "Failed to stop container: " + cube.getId(), e); } finally { try { cube.destroy(); } catch (final Throwable ignore) { //no-op } } } })); } }
public void attachShutDownHookForceStopDockerContainers(@Observes(precedence = 200) BeforeSuite event, final CubeRegistry cubeRegistry) { Runtime.getRuntime().addShutdownHook(new Thread(() -> { final List<Cube<?>> cubes = cubeRegistry.getCubes(); for (Cube cube : cubes) { try { cube.stop(); } catch (final Throwable e) { Logger.getLogger(ForceStopDockerContainersShutdownHook.class.getName()).log(Level.WARNING, "Failed to stop container: " + cube.getId(), e); } finally { try { cube.destroy(); } catch (final Throwable ignore) { //no-op } } } })); } }
@Test public void shouldGetAllCubes() throws Exception { // given: List<String> cubeIds = Arrays.asList("tomcat1", "tomcat2", "tomcat_46fd2cc1-0084-42a8-9ffd-35f305a08dcc"); for (String cubeId : cubeIds) { Cube cube = createCubeMock(cubeId); cubeRegistry.addCube(cube); } // when: List<Cube<?>> cubes = cubeRegistry.getCubes(); // then: Assert.assertEquals(cubeIds.size(), cubes.size()); }