@Override public void copyLog(String cubeId, boolean follow, boolean stdout, boolean stderr, boolean timestamps, int tail, OutputStream outputStream) { Cube<?> cube = cubeRegistry.get().getCube(cubeId); Validate.notNull(cube, "Cube with id '" + cubeId + "' to get logs command does not exist."); if (cube.hasMetadata(CanCopyFromContainer.class)) { cube.getMetadata(CanCopyFromContainer.class).copyLog(follow, stdout, stderr, timestamps, tail, outputStream); } else { throw new IllegalArgumentException( "Cube " + cubeId + " does not provide the " + CanCopyFromContainer.class.getSimpleName() + " metadata"); } }
private void stopAndDestroyCubes(ConnectionMode connectionMode, TestClass testClass) { final CubeController cubeController = cubeControllerInstance.get(); final List<Cube<?>> byMetadata = cubeRegistryInstance.get().getByMetadata(IsContainerObject.class); byMetadata.stream() .filter( cube -> { // To support fork tests final Class<?> testJavaClass = testClass.getJavaClass(); return testJavaClass.equals(cube.getMetadata(IsContainerObject.class).getTestClass()); }) .filter(cube -> cube.getMetadata(IsContainerObject.class).getConnectionMode() == connectionMode) .forEach(cube -> { logger.fine(String.format("Stopping Container Object %s", cube.getId())); cubeController.stop(cube.getId()); cubeController.destroy(cube.getId()); cubeRegistryInstance.get().removeCube(cube.getId()); }); }
public void apply(Cube cube) { String[] scriptsToExecute = postProcessScript(this.chaosScriptContent); for (String scriptToExecute : scriptsToExecute) { if (cube.hasMetadata(CanExecuteProcessInContainer.class)) { final String[] command = scriptToExecute.split("\\s+"); final CanExecuteProcessInContainer executeProcess = (CanExecuteProcessInContainer) cube.getMetadata(CanExecuteProcessInContainer.class); executeProcess.exec(command); } } }
@Test public void shouldNotRemapContainerAddressToBootToDocker() { Map<String, String> containerConfig = new HashMap<String, String>(); containerConfig.put("myHost", "10.0.10.1"); when(containerDef.getContainerProperties()).thenReturn(containerConfig); when(cube.getMetadata(HasPortBindings.class)).thenReturn(hasPortBindings); bind(ApplicationScoped.class, OperatingSystemFamily.class, OperatingSystemFamily.MAC); fire(new BeforeSetup(deployableContainer)); verify(containerDef, times(0)).overrideProperty("myHost", "192.168.0.1"); } }
@Test public void should_not_remove_docker_image_as_not_built_by_cube() { DockerClientExecutor executor = Mockito.mock(DockerClientExecutor.class); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); CubeConfiguration cubeConfiguration = CubeConfiguration.fromMap(new HashMap<String, String>()); bind(ApplicationScoped.class, CubeConfiguration.class, cubeConfiguration); when(cube.getId()).thenReturn(CUBE_ID); when(cube.configuration()).thenReturn(dockerConfiguration.getDockerContainersContent().get(CUBE_ID));
@Test public void should_start_vnc_by_default() { when(seleniumContainers.getVncContainerName()).thenReturn("vnc"); when(cubeRegistry.getCube("vnc")).thenReturn(cube); VncRecorderLifecycleManager vncRecorderLifecycleManager = new VncRecorderLifecycleManager(); vncRecorderLifecycleManager.seleniumContainersInstance = new Instance<SeleniumContainers>() { @Override public SeleniumContainers get() { return seleniumContainers; } }; vncRecorderLifecycleManager.startRecording(null, CubeDroneConfiguration.fromMap(new HashMap<String, String>()), cubeRegistry); verify(cube).create(); verify(cube).start(); }
@Test // equal ports, different ip public void shouldUpdateWithIPFromDocker() throws Exception { Binding binding = new Binding(GATEWAY_IP); binding.addPortBinding(EXPOSED_PORT, EXPOSED_PORT); Mockito.when(cube.getMetadata(HasPortBindings.class)).thenReturn(new TestPortBindings(binding)); bind(ContainerScoped.class, Container.class, new ContainerImpl(CUBE_CONTAINER_NAME, deployableContainer, new ContainerDefImpl("arquillian.xml"))); ProtocolMetaData metadata = new ProtocolMetaData(); metadata.addContext(new HTTPContext(LOCALHOST, EXPOSED_PORT).add(new Servlet("A", "B"))); bind(DeploymentScoped.class, ProtocolMetaData.class, metadata); fire(metadata); ProtocolMetaData updated = getManager().getContext(DeploymentContext.class) .getObjectStore().get(ProtocolMetaData.class); Assert.assertEquals(EXPOSED_PORT.intValue(), updated.getContexts(HTTPContext.class).iterator().next().getPort()); Assert.assertEquals(GATEWAY_IP, updated.getContexts(HTTPContext.class).iterator().next().getHost()); assertEventFired(ProtocolMetaData.class, 1); // twice, but original fire is intercepted and never hit the Counter }
private void configureCube() throws IOException { cubeRegistry = new LocalCubeRegistry(); when(cube.getId()).thenReturn(CUBE_ID); cubeRegistry.addCube(cube); when(statistics.getNetworks()).thenReturn(getNetworks()); when(statistics.getMemoryStats()).thenReturn(getMemory()); when(statistics.getBlkioStats()).thenReturn(getIOStats()); when(dockerClientExecutor.statsContainer(CUBE_ID)).thenReturn(statistics); }
@Test public void should_stop_vnc_by_default() throws IOException, NoSuchMethodException { final File destination = temporaryFolder.newFolder("destination"); final File video = temporaryFolder.newFile("file.flv"); when(seleniumContainers.getVideoRecordingFile()).thenReturn(video.toPath()); when(after.getTestClass()).thenReturn(new TestClass(VncRecorderLifecycleManagerTest.class)); when(after.getTestMethod()).thenReturn( VncRecorderLifecycleManagerTest.class.getMethod("should_stop_vnc_by_default")); Map<String, String> conf = new HashMap<>(); conf.put("videoOutput", destination.getAbsolutePath()); TestResult testResult = TestResult.passed(); VncRecorderLifecycleManager vncRecorderLifecycleManager = new VncRecorderLifecycleManager(); vncRecorderLifecycleManager.vnc = cube; vncRecorderLifecycleManager.afterVideoRecordedEvent = event; vncRecorderLifecycleManager.stopRecording(after, testResult, CubeDroneConfiguration.fromMap(conf), seleniumContainers ); verify(cube).stop(); verify(cube).destroy(); }
@Before public void setup() { Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") Map<String, Object> content = (Map<String, Object>) yaml.load(CONTENT); when(cube.getId()).thenReturn(CUBE_ID); when(cube.configuration()).thenReturn(content); when(container.getName()).thenReturn(CUBE_ID); when(container.getDeployableContainer()).thenReturn(deployableContainer); when(deployableContainer.getConfigurationClass()).thenReturn(ContainerConfiguration.class); when(container.getContainerConfiguration()).thenReturn(containerDef); when(containerRegistry.getContainers()).thenReturn(Arrays.asList(container)); when(hasPortBindings.getContainerIP()).thenReturn("192.168.0.1"); registry = new LocalCubeRegistry(); registry.addCube(cube); bind(ApplicationScoped.class, CubeRegistry.class, registry); bind(ApplicationScoped.class, ContainerRegistry.class, containerRegistry); }
@Before public void setup() { when(cube.getId()).thenReturn(CUBE_ID); CubeRegistry registry = new LocalCubeRegistry(); registry.addCube(cube); bind(ApplicationScoped.class, CubeRegistry.class, registry); CubeConfiguration configuration = CubeConfiguration.fromMap(new HashMap<String, String>()); fire(configuration); }
@Before public void prepareCubeDockerConfiguration() { when(cubeDockerConfiguration.getDockerServerIp()).thenReturn(DOCKER_HOST); when(hasPortBindings.getInternalIP()).thenReturn("192.168.99.100"); when(cube.hasMetadata(HasPortBindings.class)).thenReturn(true); when(cube.getMetadata(HasPortBindings.class)).thenReturn(hasPortBindings); when(cubeRegistry.getCube("helloworld")).thenReturn(cube); dockerCubeCustomizableURLResourceProvider = new DockerCubeCustomizableURLResourceProvider(); dockerCubeCustomizableURLResourceProvider.cubeDockerConfigurationInstance = new Instance<CubeDockerConfiguration>() { @Override public CubeDockerConfiguration get() { return cubeDockerConfiguration; } }; dockerCubeCustomizableURLResourceProvider.grapheneConfiguration = new Instance<GrapheneConfiguration>() { @Override public GrapheneConfiguration get() { return grapheneConfiguration; } }; dockerCubeCustomizableURLResourceProvider.cubeRegistryInstance = new Instance<CubeRegistry>() { @Override public CubeRegistry get() { return cubeRegistry; } }; }
@Before @SuppressWarnings("unchecked") public void setup() { when(cube.getId()).thenReturn(CUBE_ID); when(container.getName()).thenReturn(CUBE_ID); when(container.getDeployableContainer()).thenReturn(deployableContainer); when(container.getContainerConfiguration()).thenReturn(containerDef); when(containerDef.getContainerProperties()).thenReturn(Collections.EMPTY_MAP); when(containerRegistry.getContainers()).thenReturn(Arrays.asList(container)); registry = new LocalCubeRegistry(); registry.addCube(cube); bind(ApplicationScoped.class, CubeRegistry.class, registry); bind(ApplicationScoped.class, ContainerRegistry.class, containerRegistry); bind(ApplicationScoped.class, CubeConfiguration.class, new CubeConfiguration()); }