Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve robustness against wrong call order (#165) #166

Merged
merged 1 commit into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ private final class CamelServerRunnable implements Runnable {
@Override
public void run() {
LOGGER.info("Starting Camel Language Server...");
while (!shutdown && parentProcessStillRunning()) {
while (!shutdown && parentProcessStillRunning() && !Thread.currentThread().isInterrupted()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
Thread.currentThread().interrupt();
}
}
LOGGER.info("Camel Language Server - Client vanished...");
if (!Thread.currentThread().isInterrupted()) {
LOGGER.info("Camel Language Server - Client vanished...");
}
}
}

Expand Down Expand Up @@ -106,7 +108,11 @@ protected boolean parentProcessStillRunning() {
*/
public void stopServer() {
LOGGER.info("Stopping language server");
runner.interrupt();
if (runner != null) {
runner.interrupt();
} else {
LOGGER.info("Request to stop the server has been received but it wasn't started.");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.cameltooling.lsp.internal;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -38,6 +54,7 @@
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.TextDocumentService;
import org.junit.After;

public abstract class AbstractCamelLanguageServerTest {

Expand All @@ -47,10 +64,18 @@ public abstract class AbstractCamelLanguageServerTest {
protected static final String DUMMY_URI = "dummyUri";
private String extensionUsed;
protected PublishDiagnosticsParams lastPublishedDiagnostics;
private CamelLanguageServer camelLanguageServer;

public AbstractCamelLanguageServerTest() {
super();
}

@After
public void tearDown() {
if (camelLanguageServer != null) {
camelLanguageServer.stopServer();
}
}

protected CompletionItem createExpectedAhcCompletionItem(int lineStart, int characterStart, int lineEnd, int characterEnd) {
CompletionItem expectedAhcCompletioncompletionItem = new CompletionItem("ahc:httpUri");
Expand Down Expand Up @@ -94,8 +119,9 @@ protected CamelLanguageServer initializeLanguageServer(String text, String suffi
InitializeParams params = new InitializeParams();
params.setProcessId(new Random().nextInt());
params.setRootUri(getTestResource("/workspace/").toURI().toString());
CamelLanguageServer camelLanguageServer = new CamelLanguageServer();
camelLanguageServer = new CamelLanguageServer();
camelLanguageServer.connect(new DummyLanguageClient());
camelLanguageServer.startServer();
CompletableFuture<InitializeResult> initialize = camelLanguageServer.initialize(params);

assertThat(initialize).isCompleted();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.cameltooling.lsp.internal;

import org.junit.Test;

public class CamelLanguageServerRobustnesstest {

@Test
public void testStopWithoutErrorIfStopCalledWithoutConnection() throws Exception {
new CamelLanguageServer().stopServer();
}

}