WorkspacePVCCleaner { @Inject public void subscribe(EventService eventService) { if (pvcEnabled) { eventService.subscribe( event -> { final Workspace workspace = event.getWorkspace(); try { strategy.cleanup(workspace); } catch (InfrastructureException ex) { LOG.error( "Failed to cleanup workspace '{}' data. Cause: {}", workspace.getId(), ex.getMessage()); } }, WorkspaceRemovedEvent.class); } } @Inject  WorkspacePVCCleaner(
      @Named("che.infra.kubernetes.pvc.enabled") boolean pvcEnabled,
      WorkspaceVolumesStrategy pvcStrategy); @Inject void subscribe(EventService eventService);  }
@Test public void testDoNotSubscribesCleanerWhenPVCDisabled() throws Exception { workspacePVCCleaner = spy(new WorkspacePVCCleaner(false, pvcStrategy)); workspacePVCCleaner.subscribe(eventService); verify(eventService, never()).subscribe(any(), eq(WorkspaceRemovedEvent.class)); }
@Test public void testSubscribesDeleteKubernetesOnWorkspaceRemove() throws Exception { workspacePVCCleaner.subscribe(eventService); verify(eventService).subscribe(any(), eq(WorkspaceRemovedEvent.class)); }
@Test public void testInvokeCleanupWhenWorkspaceRemovedEventPublished() throws Exception { workspacePVCCleaner.subscribe(eventService); eventService.publish(event); verify(pvcStrategy).cleanup(workspace); }
@Test public void testDoNotRethrowExceptionWhenErrorOnCleanupOccurs() throws Exception { doThrow(InfrastructureException.class).when(pvcStrategy).cleanup(workspace); workspacePVCCleaner.subscribe(eventService); eventService.publish(event); verify(pvcStrategy).cleanup(workspace); }