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));
}
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()));
}
Aggregations