Search in sources :

Example 21 with InternalEnvironment

use of org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment in project devspaces-images by redhat-developer.

the class WorkspaceRuntimesTest method shouldRecoverEachRuntimeOnlyOnce.

@Test
public void shouldRecoverEachRuntimeOnlyOnce() throws Exception {
    // Given
    Set<RuntimeIdentity> identities = generateRuntimeIdentitySet(200);
    doReturn(identities).when(infrastructure).getIdentities();
    for (RuntimeIdentity identity : identities) {
        mockWorkspaceWithDevfile(identity);
        RuntimeContext context = mockContext(identity);
        when(context.getRuntime()).thenReturn(new TestInternalRuntime(context, emptyMap(), WorkspaceStatus.STARTING));
        doReturn(context).when(infrastructure).prepare(eq(identity), any());
    }
    when(statuses.get(anyString())).thenReturn(WorkspaceStatus.STARTING);
    InternalEnvironment internalEnvironment = mock(InternalEnvironment.class);
    doReturn(internalEnvironment).when(testEnvFactory).create(any(Environment.class));
    CountDownLatch finishLatch = new CountDownLatch(1);
    WorkspaceRuntimes runtimesSpy = spy(runtimes);
    // When
    WorkspaceRuntimes.RecoverRuntimesTask recoverRuntimesTask = runtimesSpy.new RecoverRuntimesTask(identities);
    new Thread(() -> {
        recoverRuntimesTask.run();
        finishLatch.countDown();
    }).start();
    // simulate all WorkspaceManager methods that uses WorkspaceManager.normalizeState
    new Thread(() -> {
        List<RuntimeIdentity> runtimeIdentities = new ArrayList<>(identities);
        Collections.shuffle(runtimeIdentities);
        for (RuntimeIdentity runtimeIdentity : runtimeIdentities) {
            if (finishLatch.getCount() > 0) {
                try {
                    runtimesSpy.injectRuntime(WorkspaceImpl.builder().setId(runtimeIdentity.getWorkspaceId()).build());
                } catch (ServerException e) {
                    fail(e.getMessage());
                }
            } else {
                break;
            }
        }
    }).start();
    finishLatch.await();
    // Then
    verify(runtimesSpy, Mockito.times(identities.size())).recoverOne(any(RuntimeInfrastructure.class), any(RuntimeIdentity.class));
}
Also used : RuntimeInfrastructure(org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure) ServerException(org.eclipse.che.api.core.ServerException) CountDownLatch(java.util.concurrent.CountDownLatch) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) Environment(org.eclipse.che.api.core.model.workspace.config.Environment) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) Test(org.testng.annotations.Test)

Example 22 with InternalEnvironment

use of org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment in project devspaces-images by redhat-developer.

the class WorkspaceRuntimesTest method runtimeIsNotRecoveredIfInfraPreparationFailed.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Couldn't recover runtime 'workspace123:my-env'. Error: oops!")
public void runtimeIsNotRecoveredIfInfraPreparationFailed() throws Exception {
    RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
    mockWorkspaceWithConfig(identity);
    InternalEnvironment internalEnvironment = mock(InternalEnvironment.class);
    doReturn(internalEnvironment).when(testEnvFactory).create(any(Environment.class));
    doThrow(new InfrastructureException("oops!")).when(infrastructure).prepare(eq(identity), any(InternalEnvironment.class));
    // try recover
    runtimes.recoverOne(infrastructure, identity);
    assertFalse(runtimes.hasRuntime(identity.getWorkspaceId()));
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) Environment(org.eclipse.che.api.core.model.workspace.config.Environment) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

Aggregations

InternalEnvironment (org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment)22 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)14 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)14 RuntimeContext (org.eclipse.che.api.workspace.server.spi.RuntimeContext)12 Test (org.testng.annotations.Test)12 RuntimeIdentityImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl)10 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)10 ServerException (org.eclipse.che.api.core.ServerException)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 ArrayList (java.util.ArrayList)4 Collections.emptyList (java.util.Collections.emptyList)4 List (java.util.List)4 ConflictException (org.eclipse.che.api.core.ConflictException)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 ValidationException (org.eclipse.che.api.core.ValidationException)4 WorkspaceStatus (org.eclipse.che.api.core.model.workspace.WorkspaceStatus)4 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)4 InternalEnvironmentFactory (org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironmentFactory)4 Beta (com.google.common.annotations.Beta)2