Search in sources :

Example 21 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class SnapshotDaoTest method shouldSaveSnapshot.

@Test(dependsOnMethods = "shouldGetSnapshotById")
public void shouldSaveSnapshot() throws Exception {
    final SnapshotImpl newSnapshot = createSnapshot("new-snapshot", workspaces[0].getId(), "env-name", "machine-name");
    snapshotDao.saveSnapshot(newSnapshot);
    assertEquals(snapshotDao.getSnapshot(newSnapshot.getId()), new SnapshotImpl(newSnapshot));
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Test(org.testng.annotations.Test)

Example 22 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class SnapshotDaoTest method shouldGetSnapshotById.

@Test
public void shouldGetSnapshotById() throws Exception {
    final SnapshotImpl snapshot = snapshots[0];
    assertEquals(snapshotDao.getSnapshot(snapshot.getId()), snapshot);
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Test(org.testng.annotations.Test)

Example 23 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironmentWithRecover.

@Test
public void shouldBeAbleToStartEnvironmentWithRecover() throws Exception {
    // given
    SnapshotImpl snapshot = mock(SnapshotImpl.class);
    MachineSourceImpl machineSource = new MachineSourceImpl("image", "registry.com/snapshot123:latest@sha256:abc1234567890", null);
    when(snapshotDao.getSnapshot(anyString(), anyString(), anyString())).thenReturn(snapshot);
    when(snapshot.getMachineSource()).thenReturn(machineSource);
    // given
    EnvironmentImpl env = createEnv();
    String envName = "env-1";
    String workspaceId = "wsId";
    List<Instance> expectedMachines = new ArrayList<>();
    when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
        Object[] arguments = invocationOnMock.getArguments();
        String machineName = (String) arguments[3];
        boolean isDev = (boolean) arguments[4];
        CheServiceImpl service = (CheServiceImpl) arguments[6];
        Machine machine = createMachine(workspaceId, envName, service, machineName, isDev);
        NoOpMachineInstance instance = spy(new NoOpMachineInstance(machine));
        expectedMachines.add(instance);
        return instance;
    });
    when(environmentParser.parse(env)).thenReturn(createCheServicesEnv());
    // when
    List<Instance> machines = engine.start(workspaceId, envName, env, true, messageConsumer);
    // then
    assertEquals(machines, expectedMachines);
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), anyString(), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertEquals(actualService.getImage(), "registry.com/snapshot123:latest");
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ArrayList(java.util.ArrayList) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Test(org.testng.annotations.Test)

Example 24 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class WorkspaceManagerTest method shouldBeAbleToCreateSnapshot.

@Test
public void shouldBeAbleToCreateSnapshot() throws Exception {
    // then
    WorkspaceImpl workspace = createAndMockWorkspace();
    mockRuntime(workspace, RUNNING);
    SnapshotImpl oldSnapshot = mock(SnapshotImpl.class);
    when(snapshotDao.getSnapshot(eq(workspace.getId()), eq(workspace.getConfig().getDefaultEnv()), anyString())).thenReturn(oldSnapshot);
    // when
    workspaceManager.createSnapshot(workspace.getId());
    // then
    verify(runtimes).snapshotAsync(workspace.getId());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Test(org.testng.annotations.Test)

Example 25 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class WorkspaceManagerTest method shouldRecoverWorkspaceWhenRecoverParameterIsNullAndAutoRestoreAttributeIsSetAndSnapshotExists.

@Test
public void shouldRecoverWorkspaceWhenRecoverParameterIsNullAndAutoRestoreAttributeIsSetAndSnapshotExists() throws Exception {
    final WorkspaceImpl workspace = createAndMockWorkspace();
    workspace.getAttributes().put(AUTO_RESTORE_FROM_SNAPSHOT, "true");
    mockStart(workspace);
    SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setEnvName("env").setDev(true).setMachineName("machine1").setWorkspaceId(workspace.getId()).setType("docker").setMachineSource(new MachineSourceImpl("image"));
    SnapshotImpl snapshot1 = snapshotBuilder.build();
    SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
    when(snapshotDao.findSnapshots(workspace.getId())).thenReturn(asList(snapshot1, snapshot2));
    workspaceManager.startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), null);
    verify(runtimes).startAsync(workspace, workspace.getConfig().getDefaultEnv(), true);
    assertNotNull(workspace.getAttributes().get(UPDATED_ATTRIBUTE_NAME));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Test(org.testng.annotations.Test)

Aggregations

SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)31 Test (org.testng.annotations.Test)22 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)13 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)10 NotFoundException (org.eclipse.che.api.core.NotFoundException)6 ServerException (org.eclipse.che.api.core.ServerException)5 SnapshotException (org.eclipse.che.api.machine.server.exception.SnapshotException)4 Instance (org.eclipse.che.api.machine.server.spi.Instance)4 ArrayList (java.util.ArrayList)3 ConflictException (org.eclipse.che.api.core.ConflictException)3 Workspace (org.eclipse.che.api.core.model.workspace.Workspace)3 EnvironmentException (org.eclipse.che.api.environment.server.exception.EnvironmentException)3 EnvironmentNotRunningException (org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException)3 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)3 SnapshotDao (org.eclipse.che.api.machine.server.spi.SnapshotDao)3 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)3 Matchers.anyString (org.mockito.Matchers.anyString)3 TypeLiteral (com.google.inject.TypeLiteral)2 Transactional (com.google.inject.persist.Transactional)2 IOException (java.io.IOException)2