Search in sources :

Example 31 with KubernetesRuntimeState

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project che-server by eclipse-che.

the class KubernetesRuntimeStateCacheTest method shouldNotUpdateStatusIfPreviousValueDoesNotMatchesPredicate.

@Test(dependsOnMethods = "shouldReturnRuntimeStatus")
public void shouldNotUpdateStatusIfPreviousValueDoesNotMatchesPredicate() throws Exception {
    // given
    KubernetesRuntimeState stateToUpdate = runtimesStates[0];
    // when
    boolean isUpdated = runtimesStatesCache.updateStatus(stateToUpdate.getRuntimeId(), s -> s == WorkspaceStatus.STARTING, WorkspaceStatus.STOPPED);
    // then
    assertFalse(isUpdated);
    Optional<WorkspaceStatus> updatedStatusOpt = runtimesStatesCache.getStatus(stateToUpdate.getRuntimeId());
    assertTrue(updatedStatusOpt.isPresent());
    assertEquals(updatedStatusOpt.get(), WorkspaceStatus.RUNNING);
    assertEquals(stateToUpdate.getStatus(), WorkspaceStatus.RUNNING);
}
Also used : KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) Test(org.testng.annotations.Test)

Example 32 with KubernetesRuntimeState

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project che-server by eclipse-che.

the class KubernetesRuntimeStateCacheTest method shouldRemoveRuntimeState.

@Test(dependsOnMethods = "shouldReturnEmptyOptionalIfRuntimeStateIsNotFound")
public void shouldRemoveRuntimeState() throws Exception {
    // given
    KubernetesRuntimeState runtimeState = createRuntimeState(workspaces[0]);
    RuntimeIdentity toRemove = runtimeState.getRuntimeId();
    // when
    runtimesStatesCache.remove(toRemove);
    // then
    assertFalse(runtimesStatesCache.get(toRemove).isPresent());
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) Test(org.testng.annotations.Test)

Example 33 with KubernetesRuntimeState

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project che-server by eclipse-che.

the class KubernetesRuntimeStateCacheTest method shouldReturnRuntimeStateByRuntimeId.

@Test
public void shouldReturnRuntimeStateByRuntimeId() throws Exception {
    // given
    KubernetesRuntimeState expectedState = runtimesStates[1];
    // when
    Optional<KubernetesRuntimeState> fetchedOpt = runtimesStatesCache.get(expectedState.getRuntimeId());
    // then
    assertTrue(fetchedOpt.isPresent());
    assertEquals(expectedState, fetchedOpt.get());
}
Also used : KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) Test(org.testng.annotations.Test)

Example 34 with KubernetesRuntimeState

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project che-server by eclipse-che.

the class KubernetesRuntimeStateCacheTest method shouldPutRuntimeState.

@Test(dependsOnMethods = "shouldReturnRuntimeStateByRuntimeId")
public void shouldPutRuntimeState() throws Exception {
    // given
    KubernetesRuntimeState runtimeState = createRuntimeState(workspaces[2]);
    // when
    boolean isInserted = runtimesStatesCache.putIfAbsent(runtimeState);
    // then
    assertTrue(isInserted);
    Optional<KubernetesRuntimeState> fetchedState = runtimesStatesCache.get(runtimeState.getRuntimeId());
    assertTrue(fetchedState.isPresent());
    assertEquals(runtimeState, fetchedState.get());
}
Also used : KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) Test(org.testng.annotations.Test)

Example 35 with KubernetesRuntimeState

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project che-server by eclipse-che.

the class KubernetesRuntimeStateCacheTest method shouldUpdateStatus.

@Test(dependsOnMethods = "shouldReturnRuntimeStatus")
public void shouldUpdateStatus() throws Exception {
    // given
    KubernetesRuntimeState stateToUpdate = runtimesStates[0];
    // when
    runtimesStatesCache.updateStatus(stateToUpdate.getRuntimeId(), WorkspaceStatus.STOPPED);
    // then
    Optional<WorkspaceStatus> updatedStatusOpt = runtimesStatesCache.getStatus(stateToUpdate.getRuntimeId());
    assertTrue(updatedStatusOpt.isPresent());
    assertEquals(updatedStatusOpt.get(), WorkspaceStatus.STOPPED);
    assertNotEquals(stateToUpdate, WorkspaceStatus.STOPPED);
}
Also used : KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) Test(org.testng.annotations.Test)

Aggregations

KubernetesRuntimeState (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState)48 Test (org.testng.annotations.Test)34 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)8 TypeLiteral (com.google.inject.TypeLiteral)6 AccountImpl (org.eclipse.che.account.spi.AccountImpl)6 WorkspaceStatus (org.eclipse.che.api.core.model.workspace.WorkspaceStatus)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)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 KubernetesMachineCache (org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesMachineCache)6 KubernetesRuntimeStateCache (org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesRuntimeStateCache)6 KubernetesMachineImpl (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl)6 KubernetesServerImpl (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl)6 AccountDao (org.eclipse.che.account.spi.AccountDao)4 JpaAccountDao (org.eclipse.che.account.spi.jpa.JpaAccountDao)4 JpaUserDevfileDao (org.eclipse.che.api.devfile.server.jpa.JpaUserDevfileDao)4 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)4