Search in sources :

Example 26 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.

the class KubernetesInternalRuntimeTest method shouldReturnFalseIfAllPodsExistOnRuntimeConsistencyChecking.

@Test
public void shouldReturnFalseIfAllPodsExistOnRuntimeConsistencyChecking() throws Exception {
    // given
    KubernetesMachineImpl machine1 = new KubernetesMachineImpl(WORKSPACE_ID, "machine1", "pod1", "container 1", null, emptyMap(), emptyMap());
    KubernetesMachineImpl machine2 = new KubernetesMachineImpl(WORKSPACE_ID, "machine2", "pod1", "container 2", null, emptyMap(), emptyMap());
    KubernetesMachineImpl machine3 = new KubernetesMachineImpl(WORKSPACE_ID, "machine3", "pod2", "container 1", null, emptyMap(), emptyMap());
    machinesCache.put(IDENTITY, machine1);
    machinesCache.put(IDENTITY, machine2);
    machinesCache.put(IDENTITY, machine3);
    doReturn(Optional.empty()).when(deployments).get(anyString());
    // when
    boolean isConsistent = internalRuntime.isConsistent();
    // then
    assertFalse(isConsistent);
}
Also used : KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Test(org.testng.annotations.Test)

Example 27 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.

the class KubernetesInternalRuntimeTest method shouldReturnTrueIfAllPodsExistOnRuntimeConsistencyChecking.

@Test
public void shouldReturnTrueIfAllPodsExistOnRuntimeConsistencyChecking() throws Exception {
    // given
    KubernetesMachineImpl machine1 = new KubernetesMachineImpl(WORKSPACE_ID, "machine1", "pod1", "container 1", null, emptyMap(), emptyMap());
    KubernetesMachineImpl machine2 = new KubernetesMachineImpl(WORKSPACE_ID, "machine2", "pod1", "container 2", null, emptyMap(), emptyMap());
    KubernetesMachineImpl machine3 = new KubernetesMachineImpl(WORKSPACE_ID, "machine3", "pod2", "container 1", null, emptyMap(), emptyMap());
    machinesCache.put(IDENTITY, machine1);
    machinesCache.put(IDENTITY, machine2);
    machinesCache.put(IDENTITY, machine3);
    doReturn(Optional.of(mock(Pod.class))).when(deployments).get(anyString());
    // when
    boolean isConsistent = internalRuntime.isConsistent();
    // then
    assertTrue(isConsistent);
}
Also used : KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Test(org.testng.annotations.Test)

Example 28 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.

the class KubernetesMachinesCacheTest method shouldUpdateMachineStatus.

@Test
public void shouldUpdateMachineStatus() throws Exception {
    // given
    RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
    KubernetesMachineImpl machine = machines[0];
    String machineName = machine.getName();
    // when
    machineCache.updateMachineStatus(runtimeId, machineName, MachineStatus.RUNNING);
    // then
    Optional<KubernetesMachineImpl> machineOpt = machineCache.getMachines(runtimeId).entrySet().stream().filter(e -> e.getKey().equals(machineName)).map(Map.Entry::getValue).findAny();
    assertTrue(machineOpt.isPresent());
    assertEquals(machineOpt.get().getStatus(), MachineStatus.RUNNING);
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test)

Example 29 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.

the class KubernetesMachinesCacheTest method shouldThrowExceptionIfMachineIsAlreadyInCacheOnTryToPutMachine.

@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Machine is already in cache")
public void shouldThrowExceptionIfMachineIsAlreadyInCacheOnTryToPutMachine() throws Exception {
    // given
    KubernetesMachineImpl machine = createMachine(workspaces[1].getId(), machines[0].getName(), MachineStatus.RUNNING, ImmutableMap.of("myServer", createServer(ServerStatus.RUNNING)));
    // when
    machineCache.put(runtimeStates[1].getRuntimeId(), machine);
}
Also used : KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Test(org.testng.annotations.Test)

Example 30 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project devspaces-images by redhat-developer.

the class KubernetesMachinesCacheTest method shouldThrowExceptionWhenServerWasNotFoundOnStatusUpdating.

@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Server with name 'non-existing' was not found")
public void shouldThrowExceptionWhenServerWasNotFoundOnStatusUpdating() throws Exception {
    // given
    RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
    KubernetesMachineImpl machine = machines[0];
    // when
    machineCache.updateServerStatus(runtimeId, machine.getName(), "non-existing", ServerStatus.RUNNING);
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Test(org.testng.annotations.Test)

Aggregations

KubernetesMachineImpl (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl)38 Test (org.testng.annotations.Test)20 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)12 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)8 KubernetesMachineCache (org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesMachineCache)8 KubernetesRuntimeStateCache (org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesRuntimeStateCache)8 KubernetesRuntimeState (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState)8 KubernetesServerImpl (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl)8 TypeLiteral (com.google.inject.TypeLiteral)6 AccountImpl (org.eclipse.che.account.spi.AccountImpl)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)6 PersistTestModuleBuilder (org.eclipse.che.commons.test.db.PersistTestModuleBuilder)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)6 DBInitializer (org.eclipse.che.core.db.DBInitializer)6 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)6 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)6 AccountDao (org.eclipse.che.account.spi.AccountDao)3 JpaAccountDao (org.eclipse.che.account.spi.jpa.JpaAccountDao)3 JpaUserDevfileDao (org.eclipse.che.api.devfile.server.jpa.JpaUserDevfileDao)3