use of org.eclipse.che.commons.observability.NoopExecutorServiceWrapper in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntimeTest method setup.
@BeforeMethod
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
runtimeStatesCache = new MapBasedRuntimeStateCache();
machinesCache = new MapBasedMachinesCache();
eventPublisher = new RuntimeEventsPublisher(eventService);
serverResolverFactory = new KubernetesServerResolverFactory(pathTransformInverter, "che-host", MULTI_HOST_STRATEGY, WorkspaceExposureType.NATIVE.getConfigValue());
startSynchronizer = spy(new StartSynchronizer(eventService, 5, IDENTITY));
when(startSynchronizerFactory.create(any())).thenReturn(startSynchronizer);
internalRuntime = new KubernetesInternalRuntime<>(13, 5, new URLRewriter.NoOpURLRewriter(), unrecoverablePodEventListenerFactory, serverCheckerFactory, volumesStrategy, probesScheduler, workspaceProbesFactory, eventPublisher, new KubernetesSharedPool(new NoopExecutorServiceWrapper()), runtimeStatesCache, machinesCache, startSynchronizerFactory, ImmutableSet.of(internalEnvironmentProvisioner), kubernetesEnvironmentProvisioner, toolingProvisioner, runtimeHangingDetector, previewUrlCommandProvisioner, secretAsContainerResourceProvisioner, serverResolverFactory, runtimeCleaner, cheNamespace, tracer, context, namespace);
when(context.getEnvironment()).thenReturn(k8sEnv);
when(context.getRuntime()).thenReturn(internalRuntime);
when(serverCheckerFactory.create(any(), anyString(), any())).thenReturn(serversChecker);
when(context.getIdentity()).thenReturn(IDENTITY);
doNothing().when(namespace).cleanUp();
when(namespace.services()).thenReturn(services);
when(namespace.ingresses()).thenReturn(ingresses);
when(namespace.deployments()).thenReturn(deployments);
when(namespace.secrets()).thenReturn(secrets);
when(namespace.configMaps()).thenReturn(configMaps);
doReturn(ImmutableMap.of(M1_NAME, mock(InternalMachineConfig.class), M2_NAME, mock(InternalMachineConfig.class))).when(k8sEnv).getMachines();
final Map<String, Service> allServices = ImmutableMap.of(SERVICE_NAME, mockService());
final Ingress ingress = mockIngress();
final Map<String, Ingress> allIngresses = ImmutableMap.of(INGRESS_NAME, ingress);
when(services.create(any())).thenAnswer(a -> a.getArguments()[0]);
when(ingresses.create(any())).thenAnswer(a -> a.getArguments()[0]);
when(ingresses.wait(anyString(), anyLong(), any(), any())).thenReturn(ingress);
when(deployments.deploy(any(Pod.class))).thenAnswer(inv -> inv.getArgument(0));
when(deployments.deploy(any(Deployment.class))).thenAnswer(inv -> {
Deployment d = inv.getArgument(0);
Pod pod = new Pod();
pod.setSpec(d.getSpec().getTemplate().getSpec());
pod.setMetadata(d.getSpec().getTemplate().getMetadata());
return pod;
});
when(k8sEnv.getServices()).thenReturn(allServices);
when(k8sEnv.getIngresses()).thenReturn(allIngresses);
when(k8sEnv.getPodsCopy()).thenReturn(podsMap);
when(k8sEnv.getCommands()).thenReturn(new ArrayList<>(singletonList(envCommand)));
when(deployments.waitRunningAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
when(serversChecker.startAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
}
use of org.eclipse.che.commons.observability.NoopExecutorServiceWrapper in project devspaces-images by redhat-developer.
the class JpaEntitiesCascadeRemovalTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
injector = Guice.createInjector(Stage.PRODUCTION, new AbstractModule() {
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(new JpaPersistModule("main"));
bind(H2JpaCleaner.class).toInstance(new H2JpaCleaner(server));
bind(EventService.class).in(Singleton.class);
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(DBInitializer.class).asEagerSingleton();
install(new InitModule(PostConstruct.class));
install(new UserJpaModule());
install(new AccountModule());
install(new SshJpaModule());
install(new FactoryJpaModule());
install(new OrganizationJpaModule());
install(new MultiuserWorkspaceJpaModule());
install(new MachineAuthModule());
install(new DevfileModule());
install(new MultiuserUserDevfileJpaModule());
bind(ExecutorServiceWrapper.class).to(NoopExecutorServiceWrapper.class);
bind(FreeResourcesLimitDao.class).to(JpaFreeResourcesLimitDao.class);
bind(RemoveFreeResourcesLimitSubscriber.class).asEagerSingleton();
// initialize empty binder
Multibinder.newSetBinder(binder(), WorkspaceAttributeValidator.class);
bind(WorkspaceManager.class);
bind(WorkspaceLockService.class).to(DefaultWorkspaceLockService.class);
bind(WorkspaceStatusCache.class).to(DefaultWorkspaceStatusCache.class);
bind(RuntimeInfrastructure.class).toInstance(mock(RuntimeInfrastructure.class));
MapBinder.newMapBinder(binder(), String.class, InternalEnvironmentFactory.class);
bind(PermissionsManager.class);
bind(PermissionChecker.class).to(PermissionCheckerImpl.class);
bind(AccountManager.class);
bind(Boolean.class).annotatedWith(Names.named("che.workspace.auto_snapshot")).toInstance(false);
bind(Boolean.class).annotatedWith(Names.named("che.workspace.auto_restore")).toInstance(false);
bind(Boolean.class).annotatedWith(Names.named("che.devworkspaces.enabled")).toInstance(false);
bind(WorkspaceSharedPool.class).toInstance(new WorkspaceSharedPool("cached", null, null, new NoopExecutorServiceWrapper()));
bind(String[].class).annotatedWith(Names.named("che.auth.reserved_user_names")).toInstance(new String[0]);
bind(RemoveOrganizationOnLastUserRemovedEventSubscriber.class).asEagerSingleton();
Multibinder.newSetBinder(binder(), ResourceLockKeyProvider.class);
Multibinder.newSetBinder(binder(), ResourceUsageTracker.class);
MapBinder.newMapBinder(binder(), String.class, AvailableResourcesProvider.class);
bind(String.class).annotatedWith(Names.named("che.workspace.plugin_registry_url")).toInstance("");
bind(String.class).annotatedWith(Names.named("che.factory.scm_file_fetcher_limit_bytes")).toInstance("1024");
MapBinder.newMapBinder(binder(), String.class, ChePluginsApplier.class);
Multibinder.newSetBinder(binder(), ResourceType.class).addBinding().to(RamResourceType.class);
Multibinder.newSetBinder(binder(), ResourcesProvider.class).addBinding().toInstance((accountId) -> singletonList(new ProvidedResourcesImpl("test", null, accountId, -1L, -1L, singletonList(new ResourceImpl(RamResourceType.ID, 1024, RamResourceType.UNIT)))));
bindConstant().annotatedWith(Names.named("che.workspace.probe_pool_size")).to(1);
// setup bindings for the devfile that would otherwise be read from the config
bindConstant().annotatedWith(Names.named("che.workspace.devfile.default_editor")).to("default/editor/0.0.1");
bindConstant().annotatedWith(Names.named("che.websocket.endpoint")).to("che.websocket.endpoint");
bind(String.class).annotatedWith(Names.named("che.workspace.devfile.default_editor.plugins")).toInstance("default/plugin/0.0.1");
bind(String.class).annotatedWith(Names.named("che.workspace.devfile.async.storage.plugin")).toInstance("");
}
});
eventService = injector.getInstance(EventService.class);
accountDao = injector.getInstance(AccountDao.class);
accountManager = injector.getInstance(AccountManager.class);
userDao = injector.getInstance(UserDao.class);
userManager = injector.getInstance(UserManager.class);
preferenceDao = injector.getInstance(PreferenceDao.class);
profileDao = injector.getInstance(ProfileDao.class);
sshDao = injector.getInstance(SshDao.class);
workspaceDao = injector.getInstance(WorkspaceDao.class);
factoryDao = injector.getInstance(FactoryDao.class);
workerDao = injector.getInstance(WorkerDao.class);
userDevfileDao = injector.getInstance(UserDevfileDao.class);
userDevfilePermissionDao = injector.getInstance(UserDevfilePermissionDao.class);
signatureKeyDao = injector.getInstance(SignatureKeyDao.class);
freeResourcesLimitDao = injector.getInstance(FreeResourcesLimitDao.class);
organizationManager = injector.getInstance(OrganizationManager.class);
memberDao = injector.getInstance(MemberDao.class);
organizationResourcesDistributor = injector.getInstance(OrganizationResourcesDistributor.class);
h2JpaCleaner = injector.getInstance(H2JpaCleaner.class);
}
use of org.eclipse.che.commons.observability.NoopExecutorServiceWrapper in project devspaces-images by redhat-developer.
the class CascadeRemovalTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
server = H2DBTestServer.startDefault();
injector = Guice.createInjector(Stage.PRODUCTION, new AbstractModule() {
@Override
protected void configure() {
install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(AccountImpl.class, UserImpl.class, ProfileImpl.class, PreferenceEntity.class, WorkspaceImpl.class, WorkspaceConfigImpl.class, WorkspaceActivity.class, ProjectConfigImpl.class, EnvironmentImpl.class, MachineConfigImpl.class, SourceStorageImpl.class, ServerConfigImpl.class, CommandImpl.class, RecipeImpl.class, SshPairImpl.class, VolumeImpl.class, ActionImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class, ComponentImpl.class, DevfileImpl.class, EndpointImpl.class, EntrypointImpl.class, EnvImpl.class, ProjectImpl.class, SourceImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class, KubernetesRuntimeState.class, KubernetesRuntimeCommandImpl.class, KubernetesMachineImpl.class, KubernetesMachineImpl.MachineId.class, KubernetesServerImpl.class, KubernetesServerImpl.ServerId.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").addClass(SerializableConverter.class).setExceptionHandler(H2ExceptionHandler.class).build());
bind(EventService.class).in(Singleton.class);
install(new InitModule(PostConstruct.class));
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(DBInitializer.class).asEagerSingleton();
bind(String[].class).annotatedWith(Names.named("che.auth.reserved_user_names")).toInstance(new String[0]);
bind(Long.class).annotatedWith(Names.named("che.limits.workspace.idle.timeout")).toInstance(100000L);
bind(Long.class).annotatedWith(Names.named("che.limits.workspace.run.timeout")).toInstance(0L);
bind(UserManager.class);
bind(AccountManager.class);
install(new UserJpaModule());
install(new AccountModule());
install(new SshJpaModule());
install(new WorkspaceJpaModule());
install(new WorkspaceActivityModule());
install(new JpaKubernetesRuntimeCacheModule());
bind(ExecutorServiceWrapper.class).to(NoopExecutorServiceWrapper.class);
// initialize empty binder
Multibinder.newSetBinder(binder(), WorkspaceAttributeValidator.class);
bind(WorkspaceManager.class);
RuntimeInfrastructure infra = mock(RuntimeInfrastructure.class);
doReturn(emptySet()).when(infra).getRecipeTypes();
bind(RuntimeInfrastructure.class).toInstance(infra);
WorkspaceRuntimes wR = spy(new WorkspaceRuntimes(mock(EventService.class), emptyMap(), infra, mock(WorkspaceSharedPool.class), mock(WorkspaceDao.class), mock(DBInitializer.class), mock(ProbeScheduler.class), new DefaultWorkspaceStatusCache(), new DefaultWorkspaceLockService(), mock(DevfileConverter.class), false));
when(wR.hasRuntime(anyString())).thenReturn(false);
bind(WorkspaceRuntimes.class).toInstance(wR);
bind(AccountManager.class);
bind(WorkspaceSharedPool.class).toInstance(new WorkspaceSharedPool("cached", null, null, new NoopExecutorServiceWrapper()));
MapBinder.newMapBinder(binder(), String.class, ComponentIntegrityValidator.class).addBinding("kubernetes").toInstance(mock(ComponentIntegrityValidator.class));
}
});
eventService = injector.getInstance(EventService.class);
accountDao = injector.getInstance(AccountDao.class);
userDao = injector.getInstance(UserDao.class);
userManager = injector.getInstance(UserManager.class);
accountManager = injector.getInstance(AccountManager.class);
preferenceDao = injector.getInstance(PreferenceDao.class);
profileDao = injector.getInstance(ProfileDao.class);
sshDao = injector.getInstance(SshDao.class);
workspaceDao = injector.getInstance(WorkspaceDao.class);
workspaceActivityDao = injector.getInstance(WorkspaceActivityDao.class);
k8sRuntimes = injector.getInstance(KubernetesRuntimeStateCache.class);
k8sMachines = injector.getInstance(KubernetesMachineCache.class);
}
Aggregations