Skip to content

Commit

Permalink
fix: can't stop dev on component after switching to a different proje…
Browse files Browse the repository at this point in the history
…ct (#728)

Signed-off-by: Stephane Bouchet <[email protected]>
  • Loading branch information
sbouchet authored Mar 19, 2024
1 parent 1fb9954 commit 0ff5281
Show file tree
Hide file tree
Showing 38 changed files with 867 additions and 1,045 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.jboss.tools.intellij.openshift.utils.odo.Odo;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class OdoCluster {

Expand All @@ -25,7 +24,7 @@ public class OdoCluster {

private static final String CLUSTER_PASSWORD = System.getenv("CLUSTER_PASSWORD");

public boolean login(Odo odo) throws ExecutionException, InterruptedException, IOException {
public boolean login(Odo odo) throws IOException {
if (CLUSTER_URL != null && !odo.getMasterUrl().toString().startsWith(CLUSTER_URL)) {
odo.login(CLUSTER_URL, CLUSTER_USER, CLUSTER_PASSWORD.toCharArray(), null);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class OdoCliComponentTest extends OdoCliTest {
private String component;
private String service;

private final boolean projectCreationSkipped = true;

public OdoCliComponentTest(ComponentFeature feature) {
this.feature = feature;
}
Expand All @@ -56,8 +54,8 @@ public void initTestEnv() {

@After
public void cleanUp() throws IOException {
if (odo.isStarted(project, COMPONENT_PATH, component, ComponentFeature.DEV)) {
odo.stop(project, COMPONENT_PATH, component, ComponentFeature.DEV);
if (odo.isStarted(COMPONENT_PATH, ComponentFeature.DEV)) {
odo.stop(COMPONENT_PATH, component, ComponentFeature.DEV);
}
if (project.equals(odo.getCurrentNamespace())) {
odo.deleteProject(project);
Expand Down Expand Up @@ -101,33 +99,33 @@ public void checkCreateComponentAndLinkService() throws IOException, ExecutionEx
assertEquals(1, deployedServices.size());
Service deployedService = deployedServices.get(0);
assertNotNull(deployedService);
Binding binding = odo.link(project, COMPONENT_PATH, component, deployedService.getKind() + "/" + deployedService.getName());
Binding binding = odo.link(COMPONENT_PATH, deployedService.getKind() + "/" + deployedService.getName());
assertNotNull(binding);
}

@Test
public void checkCreateComponentAndListURLs() throws IOException, ExecutionException, InterruptedException {
Assume.assumeTrue(feature != null);
createComponent(project, component, feature);
List<URL> urls = odo.listURLs(project, COMPONENT_PATH, component);
List<URL> urls = odo.listURLs(COMPONENT_PATH);
assertEquals(1, urls.size());
}

@Test
public void checkCreateComponentAndDebug() throws IOException, ExecutionException, InterruptedException {
Assume.assumeTrue(feature != null);
createComponent(project, component, feature);
odo.start(project, COMPONENT_PATH, component, ComponentFeature.DEV, null, null);
List<URL> urls = odo.listURLs(project, COMPONENT_PATH, component);
odo.start(COMPONENT_PATH, component, ComponentFeature.DEV, null, null);
List<URL> urls = odo.listURLs(COMPONENT_PATH);
assertEquals(odo.isOpenShift() ? 2 : 1, urls.size());
int debugPort;
try (ServerSocket serverSocket = new ServerSocket(0)) {
debugPort = serverSocket.getLocalPort();
}
ExecHelper.submit(() -> {
try {
odo.debug(project, COMPONENT_PATH, component, debugPort);
DebugStatus status = odo.debugStatus(project, COMPONENT_PATH, component);
odo.debug(COMPONENT_PATH, debugPort);
DebugStatus status = odo.debugStatus(COMPONENT_PATH);
assertEquals(DebugStatus.RUNNING, status);
} catch (IOException e) {
fail("Should not raise Exception");
Expand All @@ -138,7 +136,7 @@ public void checkCreateComponentAndDebug() throws IOException, ExecutionExceptio
@Test
public void checkCreateComponentStarter() throws IOException, ExecutionException, InterruptedException {
createProject(project);
odo.createComponent(project, "java-springboot", REGISTRY_NAME, component,
odo.createComponent("java-springboot", REGISTRY_NAME, component,
Files.newTemporaryFolder().getAbsolutePath(), null, "springbootproject");
List<Component> components = odo.getComponents(project);
assertNotNull(components);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import com.redhat.devtools.intellij.common.utils.MessagesHelper;
import org.apache.commons.io.FileUtils;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationRootNodeOdo;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.utils.ToolFactory;

import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.awaitility.Awaitility.await;
import static org.awaitility.Awaitility.with;
import static org.mockito.Mockito.mock;


public abstract class OdoCliTest extends BasePlatformTestCase {
Expand All @@ -39,6 +43,8 @@ public abstract class OdoCliTest extends BasePlatformTestCase {

protected Odo odo;

private final OdoProcessHelper processHelper = new OdoProcessHelper();

protected Random random = new Random();

protected static final String PROJECT_PREFIX = "prj";
Expand All @@ -61,13 +67,13 @@ public abstract class OdoCliTest extends BasePlatformTestCase {
protected void setUp() throws Exception {
super.setUp();
previousTestDialog = MessagesHelper.setTestDialog(TestDialog.OK);
odo = ToolFactory.getInstance().createOdo(getProject()).get();
odo = getOdo().get();
if (odo.listDevfileRegistries().stream().noneMatch(c -> c.getName().equals(REGISTRY_NAME)))
odo.createDevfileRegistry(REGISTRY_NAME, REGISTRY_URL, null);

if (CLUSTER_URL != null && !odo.getMasterUrl().toString().startsWith(CLUSTER_URL)) {
odo.login(CLUSTER_URL, CLUSTER_USER, CLUSTER_PASSWORD.toCharArray(), null);
odo = ToolFactory.getInstance().createOdo(getProject()).get();
odo = getOdo().get();
}
}

Expand All @@ -78,19 +84,24 @@ protected void tearDown() throws Exception {
super.tearDown();
}

private CompletableFuture<Odo> getOdo() {
return ToolFactory.getInstance().createOdo(getProject())
.thenApply(odoDelegate -> new ApplicationRootNodeOdo(odoDelegate, mock(ApplicationsRootNode.class), processHelper));
}

protected void createProject(String project) throws IOException, ExecutionException, InterruptedException {
odo.createProject(project);
odo = ToolFactory.getInstance().createOdo(getProject()).get();
odo = getOdo().get();
}

protected void createComponent(String project, String component, ComponentFeature feature) throws IOException, ExecutionException, InterruptedException {
createProject(project);
cleanLocalProjectDirectory();
odo.createComponent(project, "java-springboot", REGISTRY_NAME, component,
odo.createComponent("java-springboot", REGISTRY_NAME, component,
new File(COMPONENT_PATH).getAbsolutePath(), null, null);
if (feature != null) {
AtomicBoolean started = new AtomicBoolean();
odo.start(project, new File(COMPONENT_PATH).getAbsolutePath(), component, feature, started::getAndSet, null);
odo.start(new File(COMPONENT_PATH).getAbsolutePath(), component, feature, started::getAndSet, null);
await().atMost(15, TimeUnit.MINUTES).untilTrue(started);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void before() throws MalformedURLException {
}

@Test
public void getCurrentNamespace_should_return_client_namespace() throws IOException {
public void getCurrentNamespace_should_return_client_namespace() {
// given
final String currentNamespace = "luke skywalker";
doReturn(currentNamespace)
Expand All @@ -78,7 +78,7 @@ public void getCurrentNamespace_should_return_client_namespace() throws IOExcept
}

@Test
public void getCurrentNamespace_should_return_default_if_there_is_no_client_namespace() throws IOException {
public void getCurrentNamespace_should_return_default_if_there_is_no_client_namespace() {
// given
doReturn(null)
.when(kubernetesClient).getNamespace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public void setTelemetrySender(TelemetrySender telemetrySender) {
this.telemetrySender = telemetrySender;
}

public abstract String getTelemetryActionName();

public void sendTelemetryResults(TelemetryService.TelemetryResult result) {
telemetrySender.sendTelemetryResults(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
sendTelemetryResults(TelemetryService.TelemetryResult.ABORTED);
return;
}
odo.deleteBinding(node.getParent().getNamespace(), node.getParent().getComponent().getPath(),
node.getParent().getComponent().getName(),node.getBinding().getName());
odo.deleteBinding(node.getParent().getComponent().getPath(), node.getBinding().getName());
NodeUtils.fireModified(node.getParent());
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
} catch (IOException e) {
Expand Down
Loading

0 comments on commit 0ff5281

Please sign in to comment.