Search in sources :

Example 61 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class EnvironmentParserTest method shouldOverrideMemoryLimitFromExtendedMachineInComposeEnv.

@Test
public void shouldOverrideMemoryLimitFromExtendedMachineInComposeEnv() throws Exception {
    // given
    HashMap<String, ExtendedMachineImpl> machines = new HashMap<>();
    machines.put("machine1", new ExtendedMachineImpl(emptyList(), emptyMap(), singletonMap("memoryLimitBytes", "101010")));
    machines.put("machine2", new ExtendedMachineImpl(emptyList(), emptyMap(), emptyMap()));
    EnvironmentImpl environment = new EnvironmentImpl(new EnvironmentRecipeImpl("compose", "application/x-yaml", "content", null), machines);
    CheServicesEnvironmentImpl cheEnv = new CheServicesEnvironmentImpl();
    cheEnv.getServices().put("machine1", new CheServiceImpl());
    cheEnv.getServices().put("machine2", new CheServiceImpl());
    when(envParser.parse(environment)).thenReturn(cheEnv);
    // when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    // then
    assertEquals(cheServicesEnvironment, cheEnv);
    assertEquals(cheServicesEnvironment.getServices().get("machine1").getMemLimit().longValue(), 101010L);
    assertEquals(cheServicesEnvironment.getServices().get("machine2").getMemLimit(), null);
}
Also used : HashMap(java.util.HashMap) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) Test(org.testng.annotations.Test)

Example 62 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class EnvironmentParserTest method shouldThrowExceptionInCaseFailedParseMemoryLimit.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Value of attribute 'memoryLimitBytes' of machine 'machine1' is illegal")
public void shouldThrowExceptionInCaseFailedParseMemoryLimit() throws ServerException {
    HashMap<String, ExtendedMachineImpl> machines = new HashMap<>();
    machines.put("machine1", new ExtendedMachineImpl(emptyList(), emptyMap(), singletonMap("memoryLimitBytes", "here should be memory size number")));
    EnvironmentImpl environment = new EnvironmentImpl(new EnvironmentRecipeImpl("compose", "application/x-yaml", "content", null), machines);
    CheServicesEnvironmentImpl cheEnv = new CheServicesEnvironmentImpl();
    cheEnv.getServices().put("machine1", new CheServiceImpl());
    when(envParser.parse(environment)).thenReturn(cheEnv);
    // when
    parser.parse(environment);
}
Also used : HashMap(java.util.HashMap) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) Test(org.testng.annotations.Test)

Example 63 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class DefaultServicesStartStrategyTest method shouldOrderServicesWithVolumesFrom.

@Test
public void shouldOrderServicesWithVolumesFrom() throws Exception {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("second", new CheServiceImpl().withVolumesFrom(singletonList("first")));
    composeEnvironment.getServices().put("third", new CheServiceImpl().withVolumesFrom(asList("first", "second")));
    composeEnvironment.getServices().put("first", new CheServiceImpl().withVolumesFrom(emptyList()));
    composeEnvironment.getServices().put("forth", new CheServiceImpl().withVolumesFrom(singletonList("third")));
    composeEnvironment.getServices().put("fifth", new CheServiceImpl().withVolumesFrom(asList("forth", "first")));
    List<String> expected = asList("first", "second", "third", "forth", "fifth");
    // when
    List<String> actual = strategy.order(composeEnvironment);
    // then
    assertEquals(actual, expected);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 64 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class DefaultServicesStartStrategyTest method testOrderingOfServicesWithoutDependencies.

@Test
public void testOrderingOfServicesWithoutDependencies() throws Exception {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("second", new CheServiceImpl());
    composeEnvironment.getServices().put("third", new CheServiceImpl());
    composeEnvironment.getServices().put("first", new CheServiceImpl());
    String[] expected = new String[] { "first", "second", "third" };
    // when
    String[] actual = strategy.order(composeEnvironment).toArray(new String[composeEnvironment.getServices().size()]);
    // then
    assertEqualsNoOrder(actual, expected);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 65 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class DefaultServicesStartStrategyTest method shouldFailIfDependsOnFieldContainsNonExistingService.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Dependency 'fifth' in machine 'second' points to unknown machine.")
public void shouldFailIfDependsOnFieldContainsNonExistingService() throws Exception {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("second", new CheServiceImpl().withDependsOn(singletonList("fifth")));
    composeEnvironment.getServices().put("third", new CheServiceImpl());
    composeEnvironment.getServices().put("first", new CheServiceImpl());
    // when
    strategy.order(composeEnvironment);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Aggregations

CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)93 Test (org.testng.annotations.Test)63 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)46 Matchers.anyString (org.mockito.Matchers.anyString)32 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)28 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)24 Map (java.util.Map)18 Machine (org.eclipse.che.api.core.model.machine.Machine)17 CreateContainerParams (org.eclipse.che.plugin.docker.client.params.CreateContainerParams)17 ServerException (org.eclipse.che.api.core.ServerException)16 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)16 IOException (java.io.IOException)14 List (java.util.List)14 ServerConf (org.eclipse.che.api.core.model.machine.ServerConf)14 Collections.singletonMap (java.util.Collections.singletonMap)13 Set (java.util.Set)13 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)13 Instance (org.eclipse.che.api.machine.server.spi.Instance)13 EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)13