From 5cbaf1d0c489aaff22f52addb1b419bb5c3993a8 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Fri, 31 May 2024 15:31:32 +0100 Subject: [PATCH 1/6] feat: configure ydoc main --- .../src/main/java/org/enso/ydoc/Main.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java index d4049aea33a2..6dc33efa45fb 100644 --- a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java +++ b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java @@ -4,6 +4,9 @@ public class Main { + private static final String YDOC_HOST="YDOC_HOST"; + private static final String YDOC_PORT="YDOC_PORT"; + private static final Semaphore lock = new Semaphore(0); private Main() {} @@ -15,7 +18,19 @@ public static void main(String[] args) throws Exception { Sampling.init(); - try (var ydoc = Ydoc.builder().build()) { + var ydocHost = System.getenv(YDOC_HOST); + var ydocPort = System.getenv(YDOC_PORT); + + var builder = Ydoc.builder(); + if (ydocHost != null) { + builder.hostname(ydocHost); + } + if (ydocPort != null) { + var port = Integer.parseInt(ydocPort); + builder.port(port); + } + + try (var ydoc = builder.build()) { ydoc.start(); lock.acquire(); } From a089341bb6eeffa6adb87d3a03aea8630ad20824 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 23 May 2024 13:04:56 +0100 Subject: [PATCH 2/6] DRAFT: init test --- .../src/test/java/org/enso/ydoc/YdocTest.java | 39 +++++++++++++++++-- .../src/test/resources/logback-test.xml | 2 +- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java index f2140526d0c2..a3f11aad42db 100644 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java @@ -6,10 +6,14 @@ import io.helidon.webserver.websocket.WsRouting; import io.helidon.websocket.WsListener; import io.helidon.websocket.WsSession; + +import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -18,7 +22,7 @@ public class YdocTest { private static final int WEB_SERVER_PORT = 44556; - private static final String YDOC_URL = "ws://localhost:1234/project/index"; + private static final String YDOC_URL = "ws://localhost:1234/project/"; private static final String WEB_SERVER_URL = "ws://127.0.0.1:" + WEB_SERVER_PORT; private Ydoc ydoc; @@ -35,6 +39,10 @@ private static WebServer startWebSocketServer(ExecutorService executor) { return ws; } + private static String ydocUrl(Object doc) { + return YDOC_URL + doc + "?ls=" + WEB_SERVER_URL; + } + @Before public void setup() { webServerExecutor = Executors.newSingleThreadExecutor(); @@ -46,21 +54,25 @@ public void setup() { public void tearDown() throws Exception { ls.stop(); webServerExecutor.shutdownNow(); + webServerExecutor.awaitTermination(3, TimeUnit.SECONDS); ydoc.close(); } @Test public void connect() throws Exception { var queue = new LinkedBlockingQueue(); - var url = YDOC_URL + "?ls=" + WEB_SERVER_URL; + var projectId = new UUID(0, 1); ydoc.start(); var ws = WsClient.builder().build(); - ws.connect(url, new TestWsListener(queue)); + ws.connect(ydocUrl("index"), new TestWsListener(queue)); var msg = queue.take(); Assert.assertArrayEquals(new byte[] {0, 0, 1, 0}, msg.readBytes()); + + //WsClient.builder().build().connect(ydocUrl(projectId), new TestWsListener(queue)); + Thread.sleep(10000); } private static final class TestWsListener implements WsListener { @@ -73,11 +85,32 @@ private static final class TestWsListener implements WsListener { @Override public void onMessage(WsSession session, BufferData buffer, boolean last) { + System.out.println(buffer.debugDataHex(true)); messages.add(buffer); } + + @Override + public void onMessage(WsSession session, String text, boolean last) { + System.out.println("!!!!!!!!!!C onMessage" + text); + } } private static final class WebServerWsListener implements WsListener { + + private static final String INIT_PROTOCOL_CONNECTION_REQUEST = "session/initProtocolConnection"; + private static final String INIT_PROTOCOL_CONNECTION_RESPONSE = + """ +{"jsonrpc":"2.0","id":"0","result":{"ensoVersion":"0.0.0-dev","currentEdition":"0.0.0-dev","contentRoots":[{"type":"Project","id":"c0223c1f-18c5-45bb-a175-70b933caa357"},{"type":"Home","id":"638ae233-03a5-4d15-bd4b-9ef159180917"},{"type":"FileSystemRoot","id":"6173bd12-5570-46fd-8423-902c161b9f8b","path":"/"}]}}"""; + WebServerWsListener() {} + + @Override + public void onMessage(WsSession session, String text, boolean last) { + System.out.println("!!!!!!!S onMessage " + text); + if (text.contains(INIT_PROTOCOL_CONNECTION_REQUEST)) { + session.send(INIT_PROTOCOL_CONNECTION_RESPONSE, true); + } + } } + } diff --git a/lib/java/ydoc-server/src/test/resources/logback-test.xml b/lib/java/ydoc-server/src/test/resources/logback-test.xml index 3ce331ce1a62..29389ba9cce1 100644 --- a/lib/java/ydoc-server/src/test/resources/logback-test.xml +++ b/lib/java/ydoc-server/src/test/resources/logback-test.xml @@ -11,7 +11,7 @@ - + From b29faa4ce5c3cd943991ab8245836c79a0641774 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Fri, 31 May 2024 20:11:28 +0100 Subject: [PATCH 3/6] DRAFT: init test success --- build.sbt | 17 ++-- .../src/main/java/org/enso/ydoc/Main.java | 4 +- .../src/test/java/org/enso/ydoc/YdocTest.java | 95 ++++++++++++++++--- .../java/org/enso/ydoc/jsonrpc/Request.java | 5 + .../java/org/enso/ydoc/jsonrpc/Response.java | 14 +++ .../enso/ydoc/jsonrpc/model/ContentRoot.java | 10 ++ .../org/enso/ydoc/jsonrpc/model/FilePath.java | 6 ++ .../ydoc/jsonrpc/model/FileSystemObject.java | 8 ++ .../ydoc/jsonrpc/model/WriteCapability.java | 6 ++ .../ydoc/jsonrpc/result/FileListResult.java | 6 ++ .../result/InitProtocolConnectionResult.java | 7 ++ .../org/enso/ydoc/jsonrpc/result/Result.java | 3 + .../jsonrpc/result/TextOpenFileResult.java | 29 ++++++ .../src/test/resources/logback-test.xml | 2 +- 14 files changed, 187 insertions(+), 25 deletions(-) create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Request.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Response.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/ContentRoot.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/FilePath.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/FileSystemObject.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/WriteCapability.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/FileListResult.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/InitProtocolConnectionResult.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/Result.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/TextOpenFileResult.java diff --git a/build.sbt b/build.sbt index 19d794495235..82f7df841a1f 100644 --- a/build.sbt +++ b/build.sbt @@ -1250,14 +1250,15 @@ lazy val `ydoc-server` = project (`profiling-utils` / Compile / productDirectories).value.head ), libraryDependencies ++= Seq( - "org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion % "provided", - "org.graalvm.polyglot" % "inspect" % graalMavenPackagesVersion % "runtime", - "org.graalvm.polyglot" % "js" % graalMavenPackagesVersion % "runtime", - "org.slf4j" % "slf4j-api" % slf4jVersion, - "io.helidon.webclient" % "helidon-webclient-websocket" % helidonVersion, - "io.helidon.webserver" % "helidon-webserver-websocket" % helidonVersion, - "junit" % "junit" % junitVersion % Test, - "com.github.sbt" % "junit-interface" % junitIfVersion % Test + "org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion % "provided", + "org.graalvm.polyglot" % "inspect" % graalMavenPackagesVersion % "runtime", + "org.graalvm.polyglot" % "js" % graalMavenPackagesVersion % "runtime", + "org.slf4j" % "slf4j-api" % slf4jVersion, + "io.helidon.webclient" % "helidon-webclient-websocket" % helidonVersion, + "io.helidon.webserver" % "helidon-webserver-websocket" % helidonVersion, + "junit" % "junit" % junitVersion % Test, + "com.github.sbt" % "junit-interface" % junitIfVersion % Test, + "com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion % Test ) ) // `Compile/run` settings are necessary for the `run` task to work. diff --git a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java index 6dc33efa45fb..74dd559dc9ce 100644 --- a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java +++ b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java @@ -4,8 +4,8 @@ public class Main { - private static final String YDOC_HOST="YDOC_HOST"; - private static final String YDOC_PORT="YDOC_PORT"; + private static final String YDOC_HOST = "YDOC_HOST"; + private static final String YDOC_PORT = "YDOC_PORT"; private static final Semaphore lock = new Semaphore(0); diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java index a3f11aad42db..431c5c674f98 100644 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java @@ -1,19 +1,29 @@ package org.enso.ydoc; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import io.helidon.common.buffers.BufferData; import io.helidon.webclient.websocket.WsClient; import io.helidon.webserver.WebServer; import io.helidon.webserver.websocket.WsRouting; import io.helidon.websocket.WsListener; import io.helidon.websocket.WsSession; - +import java.util.List; import java.util.UUID; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; - +import org.enso.ydoc.jsonrpc.Request; +import org.enso.ydoc.jsonrpc.Response; +import org.enso.ydoc.jsonrpc.model.ContentRoot; +import org.enso.ydoc.jsonrpc.model.FilePath; +import org.enso.ydoc.jsonrpc.model.FileSystemObject; +import org.enso.ydoc.jsonrpc.model.WriteCapability; +import org.enso.ydoc.jsonrpc.result.FileListResult; +import org.enso.ydoc.jsonrpc.result.InitProtocolConnectionResult; +import org.enso.ydoc.jsonrpc.result.TextOpenFileResult; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -25,6 +35,8 @@ public class YdocTest { private static final String YDOC_URL = "ws://localhost:1234/project/"; private static final String WEB_SERVER_URL = "ws://127.0.0.1:" + WEB_SERVER_PORT; + private static final UUID PROJECT_ID = new UUID(0, 1); + private Ydoc ydoc; private ExecutorService webServerExecutor; private WebServer ls; @@ -61,17 +73,27 @@ public void tearDown() throws Exception { @Test public void connect() throws Exception { var queue = new LinkedBlockingQueue(); - var projectId = new UUID(0, 1); ydoc.start(); var ws = WsClient.builder().build(); ws.connect(ydocUrl("index"), new TestWsListener(queue)); - var msg = queue.take(); - Assert.assertArrayEquals(new byte[] {0, 0, 1, 0}, msg.readBytes()); + var ok1 = queue.take(); + Assert.assertArrayEquals(new byte[] {0, 0, 1, 0}, ok1.readBytes()); + + var buffer = queue.take(); + buffer.skip(32); + var uuidString = buffer.readString(36); + System.out.println("UUID_STRING='" + uuidString + "'"); + var uuid = UUID.fromString(uuidString); + System.out.println("UUID='" + uuid + "'"); + + WsClient.builder().build().connect(ydocUrl(uuid), new TestWsListener(queue)); + + var ok2 = queue.take(); + Assert.assertArrayEquals(new byte[] {0, 0, 1, 0}, ok2.readBytes()); - //WsClient.builder().build().connect(ydocUrl(projectId), new TestWsListener(queue)); Thread.sleep(10000); } @@ -85,7 +107,8 @@ private static final class TestWsListener implements WsListener { @Override public void onMessage(WsSession session, BufferData buffer, boolean last) { - System.out.println(buffer.debugDataHex(true)); + System.out.println("!!!!!!!!!!C onMessage\n" + buffer.debugDataHex(true)); + messages.add(buffer); } @@ -97,20 +120,64 @@ public void onMessage(WsSession session, String text, boolean last) { private static final class WebServerWsListener implements WsListener { - private static final String INIT_PROTOCOL_CONNECTION_REQUEST = "session/initProtocolConnection"; - private static final String INIT_PROTOCOL_CONNECTION_RESPONSE = - """ -{"jsonrpc":"2.0","id":"0","result":{"ensoVersion":"0.0.0-dev","currentEdition":"0.0.0-dev","contentRoots":[{"type":"Project","id":"c0223c1f-18c5-45bb-a175-70b933caa357"},{"type":"Home","id":"638ae233-03a5-4d15-bd4b-9ef159180917"},{"type":"FileSystemRoot","id":"6173bd12-5570-46fd-8423-902c161b9f8b","path":"/"}]}}"""; + private static final String METHOD_INIT_PROTOCOL_CONNECTION = "session/initProtocolConnection"; + private static final String METHOD_CAPABILITY_ACQUIRE = "capability/acquire"; + private static final String METHOD_FILE_LIST = "file/list"; + private static final String METHOD_TEXT_OPEN_FILE = "text/openFile"; + + private static final ObjectMapper objectMapper = new ObjectMapper(); WebServerWsListener() {} @Override public void onMessage(WsSession session, String text, boolean last) { System.out.println("!!!!!!!S onMessage " + text); - if (text.contains(INIT_PROTOCOL_CONNECTION_REQUEST)) { - session.send(INIT_PROTOCOL_CONNECTION_RESPONSE, true); + try { + var request = objectMapper.readValue(text, Request.class); + + Response jsonRpcResponse = null; + + switch (request.method()) { + case METHOD_INIT_PROTOCOL_CONNECTION -> { + var contentRoots = + List.of( + new ContentRoot("Project", PROJECT_ID), + new ContentRoot("Home", new UUID(0, 2)), + new ContentRoot("FileSystemRoot", new UUID(0, 3), "/")); + var initProtocolConnectionResult = + new InitProtocolConnectionResult("0.0.0-dev", "0.0.0-dev", contentRoots); + jsonRpcResponse = new Response(request.id(), initProtocolConnectionResult); + } + case METHOD_CAPABILITY_ACQUIRE -> jsonRpcResponse = Response.ok(request.id()); + case METHOD_FILE_LIST -> { + var paths = + List.of( + FileSystemObject.file("Main.enso", new FilePath(PROJECT_ID, List.of("src")))); + var fileListResult = new FileListResult(paths); + jsonRpcResponse = new Response(request.id(), fileListResult); + } + case METHOD_TEXT_OPEN_FILE -> { + var options = + new WriteCapability.Options(new FilePath(PROJECT_ID, List.of("src", "Main.enso"))); + var writeCapability = new WriteCapability("text/canEdit", options); + var textOpenFileResult = + new TextOpenFileResult( + writeCapability, TextOpenFileResult.CONTENT, TextOpenFileResult.VERSION); + jsonRpcResponse = new Response(request.id(), textOpenFileResult); + } + } + + if (jsonRpcResponse != null) { + var response = objectMapper.writeValueAsString(jsonRpcResponse); + System.out.println("SENDING " + response); + session.send(response, true); + } else { + System.out.println("UNKNOWN REQUEST"); + } + } catch (JsonProcessingException e) { + e.printStackTrace(); + throw new RuntimeException(e); } } } - } diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Request.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Request.java new file mode 100644 index 000000000000..661a31120b7b --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Request.java @@ -0,0 +1,5 @@ +package org.enso.ydoc.jsonrpc; + +import com.fasterxml.jackson.databind.JsonNode; + +public record Request(String jsonrpc, String id, String method, JsonNode params) {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Response.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Response.java new file mode 100644 index 000000000000..0e8dd5b8e802 --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Response.java @@ -0,0 +1,14 @@ +package org.enso.ydoc.jsonrpc; + +import org.enso.ydoc.jsonrpc.result.Result; + +public record Response(String jsonrpc, String id, Result result) { + + public Response(String id, Result result) { + this("2.0", id, result); + } + + public static Response ok(String id) { + return new Response(id, null); + } +} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/ContentRoot.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/ContentRoot.java new file mode 100644 index 000000000000..74fc9d13efc8 --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/ContentRoot.java @@ -0,0 +1,10 @@ +package org.enso.ydoc.jsonrpc.model; + +import java.util.UUID; + +public record ContentRoot(String type, UUID id, String path) { + + public ContentRoot(String type, UUID id) { + this(type, id, null); + } +} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/FilePath.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/FilePath.java new file mode 100644 index 000000000000..b1bff5849d8c --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/FilePath.java @@ -0,0 +1,6 @@ +package org.enso.ydoc.jsonrpc.model; + +import java.util.List; +import java.util.UUID; + +public record FilePath(UUID rootId, List segments) {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/FileSystemObject.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/FileSystemObject.java new file mode 100644 index 000000000000..4fdfbe2a6a8f --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/FileSystemObject.java @@ -0,0 +1,8 @@ +package org.enso.ydoc.jsonrpc.model; + +public record FileSystemObject(String type, String name, FilePath path) { + + public static FileSystemObject file(String name, FilePath path) { + return new FileSystemObject("File", name, path); + } +} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/WriteCapability.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/WriteCapability.java new file mode 100644 index 000000000000..abce6fef3a45 --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/WriteCapability.java @@ -0,0 +1,6 @@ +package org.enso.ydoc.jsonrpc.model; + +public record WriteCapability(String method, Options registerOptions) { + + public record Options(FilePath path) {} +} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/FileListResult.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/FileListResult.java new file mode 100644 index 000000000000..2e920d30e0e0 --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/FileListResult.java @@ -0,0 +1,6 @@ +package org.enso.ydoc.jsonrpc.result; + +import java.util.List; +import org.enso.ydoc.jsonrpc.model.FileSystemObject; + +public record FileListResult(List paths) implements Result {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/InitProtocolConnectionResult.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/InitProtocolConnectionResult.java new file mode 100644 index 000000000000..eb85724c369f --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/InitProtocolConnectionResult.java @@ -0,0 +1,7 @@ +package org.enso.ydoc.jsonrpc.result; + +import java.util.List; +import org.enso.ydoc.jsonrpc.model.ContentRoot; + +public record InitProtocolConnectionResult( + String ensoVersion, String currentEdition, List contentRoots) implements Result {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/Result.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/Result.java new file mode 100644 index 000000000000..b491e4be90fd --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/Result.java @@ -0,0 +1,3 @@ +package org.enso.ydoc.jsonrpc.result; + +public interface Result {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/TextOpenFileResult.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/TextOpenFileResult.java new file mode 100644 index 000000000000..d04552c707c0 --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/TextOpenFileResult.java @@ -0,0 +1,29 @@ +package org.enso.ydoc.jsonrpc.result; + +import org.enso.ydoc.jsonrpc.model.WriteCapability; + +public record TextOpenFileResult( + WriteCapability writeCapability, String content, String currentVersion) implements Result { + + public static final String CONTENT = + "from Standard.Base import all\n" + + "from Standard.Table import all\n" + + "from Standard.Database import all\n" + + "from Standard.AWS import all\n" + + "import Standard.Visualization\n" + + "import Standard.Visualization.Warnings\n" + + "from Standard.Base.Errors.Common import Dry_Run_Operation\n\n" + + "type Student\n" + + " Value id region\n\n" + + "main =\n" + + " my_op = 226\n" + + " operator47321 = 'east'\n" + + " operator76980 = Student.Value my_op operator47321\n" + + " operator91574 = 0\n" + + " operator34358 = operator47321.take (Index_Sub_Range.By_Index [0," + + " operator91574])\n\n\n\n" + + "#### METADATA ####\n" + + "[[{\"index\":{\"value\":0},\"size\":{\"value\":4}},\"7f508138-95e6-40c9-a663-68f496d577f2\"],[{\"index\":{\"value\":0},\"size\":{\"value\":29}},\"389fe7a5-e59b-440a-8801-e0bd86716094\"],[{\"index\":{\"value\":0},\"size\":{\"value\":497}},\"59a4052a-e0eb-4eba-8ce4-4d930bd86e84\"],[{\"index\":{\"value\":5},\"size\":{\"value\":8}},\"c6f0de99-3bd3-459d-a69b-5fc774dd1e3f\"],[{\"index\":{\"value\":5},\"size\":{\"value\":13}},\"05827411-7354-478b-99d8-8370dadd560b\"],[{\"index\":{\"value\":13},\"size\":{\"value\":1}},\"72f9678a-e186-42f9-81f5-29a9a785f854\"],[{\"index\":{\"value\":14},\"size\":{\"value\":4}},\"8abd24ea-b1cb-4c10-ad16-5a190f7ed0c7\"],[{\"index\":{\"value\":19},\"size\":{\"value\":6}},\"756c7965-a2df-4e6a-8b1c-5d0eb9112ac8\"],[{\"index\":{\"value\":26},\"size\":{\"value\":3}},\"6c235dfc-9fb6-4bc9-a46f-2504cd3f37e4\"],[{\"index\":{\"value\":30},\"size\":{\"value\":4}},\"64907585-db55-491d-8125-0d8ee95adafd\"],[{\"index\":{\"value\":30},\"size\":{\"value\":30}},\"bdd4b4cc-9c1e-4554-b0fb-3f73dcd5a590\"],[{\"index\":{\"value\":35},\"size\":{\"value\":8}},\"7e7bb9b4-8e9b-4700-9dcd-83c353800da5\"],[{\"index\":{\"value\":35},\"size\":{\"value\":14}},\"524bafb6-d3ca-4ee5-b8de-84b5c47ca87b\"],[{\"index\":{\"value\":43},\"size\":{\"value\":1}},\"eaf5c36a-c388-47ce-9285-5a3bf8c8bfd6\"],[{\"index\":{\"value\":44},\"size\":{\"value\":5}},\"7173f374-5f53-462b-ab1b-f7b1845d729b\"],[{\"index\":{\"value\":50},\"size\":{\"value\":6}},\"94eac4fd-71cb-41e6-aa17-5da97b7059ab\"],[{\"index\":{\"value\":57},\"size\":{\"value\":3}},\"d96ece64-9552-4d83-a792-139f91926041\"],[{\"index\":{\"value\":61},\"size\":{\"value\":4}},\"357a38f5-543b-4c53-a419-5de8a8da5829\"],[{\"index\":{\"value\":61},\"size\":{\"value\":33}},\"9f6ae949-410b-48e6-bb75-84d4ba8a1989\"],[{\"index\":{\"value\":66},\"size\":{\"value\":8}},\"f4726e40-dd5b-49a0-aa2a-6cea6df88d5d\"],[{\"index\":{\"value\":66},\"size\":{\"value\":17}},\"539b4dcf-4487-49b6-9c90-6ae58d51c2db\"],[{\"index\":{\"value\":74},\"size\":{\"value\":1}},\"66329d8b-90f1-4b08-bb35-edb3b1492619\"],[{\"index\":{\"value\":75},\"size\":{\"value\":8}},\"8fdf4ee7-2e74-4cac-b9b9-4230183f91c5\"],[{\"index\":{\"value\":84},\"size\":{\"value\":6}},\"66c04eab-d5a3-489a-a04a-77afadf45e84\"],[{\"index\":{\"value\":91},\"size\":{\"value\":3}},\"dbcfdae9-dddc-4f6c-b08f-2d04a7be0180\"],[{\"index\":{\"value\":95},\"size\":{\"value\":4}},\"c566151f-b355-42e7-85cd-dbbeb25608e4\"],[{\"index\":{\"value\":95},\"size\":{\"value\":28}},\"f9b37b67-fb54-4e47-8281-e922edb4c5d3\"],[{\"index\":{\"value\":100},\"size\":{\"value\":8}},\"6cf398f8-d0c9-42fa-a6e6-e740de11562f\"],[{\"index\":{\"value\":100},\"size\":{\"value\":12}},\"28e4d0e3-7da4-4ee2-94c7-d9a7c692f8de\"],[{\"index\":{\"value\":108},\"size\":{\"value\":1}},\"ad7da09d-d75b-4bea-b1b2-0534b46eefc2\"],[{\"index\":{\"value\":109},\"size\":{\"value\":3}},\"bdc65807-0438-4296-8b1f-1fab3a885c17\"],[{\"index\":{\"value\":113},\"size\":{\"value\":6}},\"b78ca3c2-670e-4caf-9c69-c0a2b385a4f3\"],[{\"index\":{\"value\":120},\"size\":{\"value\":3}},\"e860e397-968c-47ab-949e-103be48da20e\"],[{\"index\":{\"value\":124},\"size\":{\"value\":6}},\"1097e484-331e-4470-b204-0abf25bad184\"],[{\"index\":{\"value\":124},\"size\":{\"value\":29}},\"d49e0fe3-a638-4d7e-ba58-12db7abad20f\"],[{\"index\":{\"value\":131},\"size\":{\"value\":8}},\"c9411433-5e73-4927-9175-15d3b1ccb0ef\"],[{\"index\":{\"value\":131},\"size\":{\"value\":22}},\"b53ad817-ea4c-491e-aaf8-49967e22aff6\"],[{\"index\":{\"value\":139},\"size\":{\"value\":1}},\"26172f9f-9786-44d9-9261-1032ba96caa6\"],[{\"index\":{\"value\":140},\"size\":{\"value\":13}},\"3b662906-1887-4dd6-a0e2-a222ace135ce\"],[{\"index\":{\"value\":154},\"size\":{\"value\":6}},\"f0d6c0b3-0461-4a2b-a7f8-435fdc729eea\"],[{\"index\":{\"value\":154},\"size\":{\"value\":38}},\"7c45872c-22b4-4f37-bcd7-b3791408f737\"],[{\"index\":{\"value\":161},\"size\":{\"value\":8}},\"21152f0d-4222-48e4-9376-a2a28f8f6be6\"],[{\"index\":{\"value\":161},\"size\":{\"value\":22}},\"1cb71d49-a06d-4dd9-bc1b-54603b416601\"],[{\"index\":{\"value\":161},\"size\":{\"value\":31}},\"faa46cf2-3e90-44ed-9d9e-77b7f874b338\"],[{\"index\":{\"value\":169},\"size\":{\"value\":1}},\"af0e4f34-0ffb-4ab6-9108-2daca0c4f8ba\"],[{\"index\":{\"value\":170},\"size\":{\"value\":13}},\"830d73c2-1898-41a9-8046-22d86f159ef0\"],[{\"index\":{\"value\":183},\"size\":{\"value\":1}},\"3c9b8a49-a4ab-41d5-8c5f-019bc2d5a9b2\"],[{\"index\":{\"value\":184},\"size\":{\"value\":8}},\"29f35cf2-d79d-44d0-96d0-79b11589726c\"],[{\"index\":{\"value\":193},\"size\":{\"value\":4}},\"08856917-449d-40bd-a94c-0dd97acb6adc\"],[{\"index\":{\"value\":193},\"size\":{\"value\":57}},\"478005ac-f0ca-497a-b298-554bd64946a9\"],[{\"index\":{\"value\":198},\"size\":{\"value\":8}},\"c11511ce-252c-4b84-9f61-dfa5544d4916\"],[{\"index\":{\"value\":198},\"size\":{\"value\":13}},\"dbae65a1-bdca-44b0-a497-7934d1e42616\"],[{\"index\":{\"value\":198},\"size\":{\"value\":20}},\"355392ad-8c81-4304-a6d0-2bbf3690da0c\"],[{\"index\":{\"value\":198},\"size\":{\"value\":27}},\"0720ccb5-ebd3-4c29-8113-0aa1f251e873\"],[{\"index\":{\"value\":206},\"size\":{\"value\":1}},\"25fd7465-6369-4b6e-a6f5-ccf382b59794\"],[{\"index\":{\"value\":207},\"size\":{\"value\":4}},\"10046e78-5164-407c-adef-2ab11ce77b4c\"],[{\"index\":{\"value\":211},\"size\":{\"value\":1}},\"45edeab2-9567-4079-8179-cc15474d3ae0\"],[{\"index\":{\"value\":212},\"size\":{\"value\":6}},\"7a09de10-35e2-45e0-9eb8-f79fa054b733\"],[{\"index\":{\"value\":218},\"size\":{\"value\":1}},\"4004f059-8c02-42c3-8a0a-2a0b2e1a03cb\"],[{\"index\":{\"value\":219},\"size\":{\"value\":6}},\"1b04c19d-cdf0-4661-8f4e-d980cf12c996\"],[{\"index\":{\"value\":226},\"size\":{\"value\":6}},\"57a8a12a-62d9-4bc3-8a49-a1cafc99966c\"],[{\"index\":{\"value\":233},\"size\":{\"value\":17}},\"60fd6a1c-7ada-4546-ae20-e1f8b432b4fd\"],[{\"index\":{\"value\":252},\"size\":{\"value\":4}},\"d60938a3-b4f4-43cd-95f9-dc8dd68206dd\"],[{\"index\":{\"value\":252},\"size\":{\"value\":32}},\"8479091c-9232-49d6-b375-32f89693c389\"],[{\"index\":{\"value\":257},\"size\":{\"value\":7}},\"fceba8f9-af4d-484f-98f9-775d2e3e10e4\"],[{\"index\":{\"value\":264},\"size\":{\"value\":1}},\"147655e9-3368-453a-be03-2a3999e00cb1\"],[{\"index\":{\"value\":269},\"size\":{\"value\":5}},\"f8134346-2c23-43e7-aff0-7cae2361367a\"],[{\"index\":{\"value\":269},\"size\":{\"value\":15}},\"e3315ef2-d0ec-43b1-b8f6-5b436054aaee\"],[{\"index\":{\"value\":275},\"size\":{\"value\":2}},\"bc7205c4-68bf-461e-a1ba-31400b9337ff\"],[{\"index\":{\"value\":278},\"size\":{\"value\":6}},\"78870c05-9117-4e24-bf77-a72e7aef9c18\"],[{\"index\":{\"value\":286},\"size\":{\"value\":4}},\"517c743f-c775-4031-8f87-222d0f0a365f\"],[{\"index\":{\"value\":286},\"size\":{\"value\":210}},\"929ad6f1-e3cf-4cd4-8cb7-d919a191ccd1\"],[{\"index\":{\"value\":291},\"size\":{\"value\":1}},\"9d5b4cfa-ef7a-4f07-9cca-b904de56f431\"],[{\"index\":{\"value\":292},\"size\":{\"value\":204}},\"2ab319a4-0a89-44e1-a59a-77216559a778\"],[{\"index\":{\"value\":297},\"size\":{\"value\":5}},\"52c9426a-17d3-40e2-8423-7a1ffdd95123\"],[{\"index\":{\"value\":297},\"size\":{\"value\":11}},\"8ef8639a-e900-4aff-aeda-6bf1164d6773\"],[{\"index\":{\"value\":303},\"size\":{\"value\":1}},\"aa9d543a-91b3-411f-ab6c-d5b98bb3369d\"],[{\"index\":{\"value\":305},\"size\":{\"value\":3}},\"016c8065-1b96-4612-a70c-a4bf7c9df2c3\"],[{\"index\":{\"value\":313},\"size\":{\"value\":13}},\"6a574885-2c78-43ea-b5ca-f8057b0738a6\"],[{\"index\":{\"value\":313},\"size\":{\"value\":22}},\"3bbd70b1-c7a2-45f9-806f-a30e9800af75\"],[{\"index\":{\"value\":327},\"size\":{\"value\":1}},\"396c59db-f42e-47ba-8191-5b666f399866\"],[{\"index\":{\"value\":329},\"size\":{\"value\":1}},\"7dd7148b-fc9c-4ca3-b54d-49aaf9d719be\"],[{\"index\":{\"value\":329},\"size\":{\"value\":6}},\"b2d8cdd6-cb21-4d39-979f-5d3543533885\"],[{\"index\":{\"value\":330},\"size\":{\"value\":4}},\"72f10c8f-0da1-498c-950a-dcd0445914c7\"],[{\"index\":{\"value\":334},\"size\":{\"value\":1}},\"243d8ac4-e8f9-4759-9fcd-6b75eee57980\"],[{\"index\":{\"value\":340},\"size\":{\"value\":13}},\"6e95b94e-eef4-4ee3-b9cd-da48d5efc88e\"],[{\"index\":{\"value\":340},\"size\":{\"value\":49}},\"f5d12a49-8070-4c5b-8569-3c896bb44820\"],[{\"index\":{\"value\":354},\"size\":{\"value\":1}},\"9e2b672b-38a9-4703-b3e7-733e50f724d0\"],[{\"index\":{\"value\":356},\"size\":{\"value\":7}},\"4667cc6f-7574-4181-a88b-7e9e01f534b9\"],[{\"index\":{\"value\":356},\"size\":{\"value\":13}},\"718dc070-2cd2-4ba6-91df-43909cb6630d\"],[{\"index\":{\"value\":356},\"size\":{\"value\":19}},\"aca33e8a-3e71-4e9b-bec2-2456b30016d1\"],[{\"index\":{\"value\":356},\"size\":{\"value\":33}},\"8928757b-9c83-4385-b8a1-2116e4a48572\"],[{\"index\":{\"value\":363},\"size\":{\"value\":1}},\"20e7d598-ae0c-4e99-ab73-f1e951df40e6\"],[{\"index\":{\"value\":364},\"size\":{\"value\":5}},\"63aea777-30b8-4cac-8120-d36a87c14699\"],[{\"index\":{\"value\":370},\"size\":{\"value\":5}},\"ca2e0ecc-ca50-41bd-8dce-413ceff13fe6\"],[{\"index\":{\"value\":376},\"size\":{\"value\":13}},\"fa66f697-e334-4b3e-a446-4e3dd219a816\"],[{\"index\":{\"value\":394},\"size\":{\"value\":13}},\"53c85179-01b3-45f7-9a64-141b28a51bf0\"],[{\"index\":{\"value\":394},\"size\":{\"value\":17}},\"b4a90be4-5fbf-425c-aef9-feda20de5b3e\"],[{\"index\":{\"value\":408},\"size\":{\"value\":1}},\"967ca125-4e15-49b3-a915-58e26e74b4b2\"],[{\"index\":{\"value\":410},\"size\":{\"value\":1}},\"69b37f53-acf3-4afd-91c9-98c384912707\"],[{\"index\":{\"value\":416},\"size\":{\"value\":13}},\"2e16b3da-d091-430b-94e6-2ca47cb4d575\"],[{\"index\":{\"value\":416},\"size\":{\"value\":80}},\"27a65c26-9814-43a3-8855-5c4461a9c050\"],[{\"index\":{\"value\":430},\"size\":{\"value\":1}},\"52e26deb-0a13-4d95-8b07-72156880b306\"],[{\"index\":{\"value\":432},\"size\":{\"value\":13}},\"a5139627-05a8-4838-b171-02666c62c348\"],[{\"index\":{\"value\":432},\"size\":{\"value\":18}},\"2a70b8fa-5569-4d7f-b41b-489f689cc165\"],[{\"index\":{\"value\":432},\"size\":{\"value\":64}},\"8df4a011-54db-4c3b-b1c5-fb7027d93ab2\"],[{\"index\":{\"value\":445},\"size\":{\"value\":1}},\"78daa642-63b5-4576-bcab-9ce44ac7f992\"],[{\"index\":{\"value\":446},\"size\":{\"value\":4}},\"1ac9930b-19bf-4c4a-9ad6-0b44a30fb0a4\"],[{\"index\":{\"value\":451},\"size\":{\"value\":1}},\"611f20c7-9cd1-41e5-aca1-41e98dcbe39e\"],[{\"index\":{\"value\":451},\"size\":{\"value\":45}},\"adc7c9a4-26ee-40f3-be1d-92315160d33f\"],[{\"index\":{\"value\":452},\"size\":{\"value\":15}},\"a221414a-6c82-49f9-9291-fa47e020d41e\"],[{\"index\":{\"value\":452},\"size\":{\"value\":24}},\"ea4ee13c-d57f-4ea8-8c9b-859606775bb8\"],[{\"index\":{\"value\":452},\"size\":{\"value\":43}},\"bdcd2298-ff93-4d38-8168-a65c25a80575\"],[{\"index\":{\"value\":467},\"size\":{\"value\":1}},\"bc931ceb-ed88-4fa5-b890-d4eaad686535\"],[{\"index\":{\"value\":468},\"size\":{\"value\":8}},\"3d6ffb97-15c4-45a0-9bb0-e497a7538967\"],[{\"index\":{\"value\":477},\"size\":{\"value\":1}},\"702a1abd-1743-4da6-9e06-833e82142c42\"],[{\"index\":{\"value\":477},\"size\":{\"value\":18}},\"0a4ba14c-0a3f-49d2-8949-fb0020841647\"],[{\"index\":{\"value\":478},\"size\":{\"value\":1}},\"eca28d4b-96a9-4c60-a95a-4b77db63caf7\"],[{\"index\":{\"value\":479},\"size\":{\"value\":1}},\"9f7ddaf2-2f80-4d73-a2db-937502b31d36\"],[{\"index\":{\"value\":481},\"size\":{\"value\":13}},\"c7dcf3df-eca3-4519-a0fc-e6a74264e0b2\"],[{\"index\":{\"value\":494},\"size\":{\"value\":1}},\"8dc38e9c-3ac0-4574-993d-e27e83426844\"],[{\"index\":{\"value\":495},\"size\":{\"value\":1}},\"ba0c6ae6-2926-433d-af9f-a26baf82fba4\"]]\n" + + "{\"ide\":{\"node\":{\"016c8065-1b96-4612-a70c-a4bf7c9df2c3\":{\"position\":{\"vector\":[55,-107]}},\"b2d8cdd6-cb21-4d39-979f-5d3543533885\":{\"position\":{\"vector\":[284,-107]}},\"8928757b-9c83-4385-b8a1-2116e4a48572\":{\"position\":{\"vector\":[55,-192]}},\"69b37f53-acf3-4afd-91c9-98c384912707\":{\"position\":{\"vector\":[559,-107]}},\"8df4a011-54db-4c3b-b1c5-fb7027d93ab2\":{\"position\":{\"vector\":[323,-220]},\"visualization\":{\"show\":true,\"fullscreen\":false}}},\"import\":{},\"project\":null}}"; + public static final String VERSION = "8f2d9d1598a16d51cc8ce160ebfa3a82efcfde91cd6bea502e235aa1"; +} diff --git a/lib/java/ydoc-server/src/test/resources/logback-test.xml b/lib/java/ydoc-server/src/test/resources/logback-test.xml index 29389ba9cce1..3ce331ce1a62 100644 --- a/lib/java/ydoc-server/src/test/resources/logback-test.xml +++ b/lib/java/ydoc-server/src/test/resources/logback-test.xml @@ -11,7 +11,7 @@ - + From b1e0e65d9a0d5879eb83615e1eb25c04618f5b23 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Mon, 3 Jun 2024 17:42:34 +0100 Subject: [PATCH 4/6] feat: ydoc initialization test --- .../src/test/java/org/enso/ydoc/YdocTest.java | 118 +++++++++++------- .../org/enso/ydoc/jsonrpc/JsonRpcRequest.java | 5 + .../enso/ydoc/jsonrpc/JsonRpcResponse.java | 16 +++ .../java/org/enso/ydoc/jsonrpc/Request.java | 5 - .../java/org/enso/ydoc/jsonrpc/Response.java | 14 --- .../{ => model}/result/FileListResult.java | 2 +- .../result/InitProtocolConnectionResult.java | 2 +- .../ydoc/jsonrpc/model/result/Result.java | 3 + .../model/result/TextOpenFileResult.java | 6 + .../org/enso/ydoc/jsonrpc/result/Result.java | 3 - .../jsonrpc/result/TextOpenFileResult.java | 29 ----- 11 files changed, 107 insertions(+), 96 deletions(-) create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/JsonRpcRequest.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/JsonRpcResponse.java delete mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Request.java delete mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Response.java rename lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/{ => model}/result/FileListResult.java (78%) rename lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/{ => model}/result/InitProtocolConnectionResult.java (83%) create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/Result.java create mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/TextOpenFileResult.java delete mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/Result.java delete mode 100644 lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/TextOpenFileResult.java diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java index 431c5c674f98..ef0c1e725633 100644 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java @@ -15,19 +15,21 @@ import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import org.enso.ydoc.jsonrpc.Request; -import org.enso.ydoc.jsonrpc.Response; +import org.enso.ydoc.jsonrpc.JsonRpcRequest; +import org.enso.ydoc.jsonrpc.JsonRpcResponse; import org.enso.ydoc.jsonrpc.model.ContentRoot; import org.enso.ydoc.jsonrpc.model.FilePath; import org.enso.ydoc.jsonrpc.model.FileSystemObject; import org.enso.ydoc.jsonrpc.model.WriteCapability; -import org.enso.ydoc.jsonrpc.result.FileListResult; -import org.enso.ydoc.jsonrpc.result.InitProtocolConnectionResult; -import org.enso.ydoc.jsonrpc.result.TextOpenFileResult; +import org.enso.ydoc.jsonrpc.model.result.FileListResult; +import org.enso.ydoc.jsonrpc.model.result.InitProtocolConnectionResult; +import org.enso.ydoc.jsonrpc.model.result.TextOpenFileResult; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class YdocTest { @@ -35,14 +37,14 @@ public class YdocTest { private static final String YDOC_URL = "ws://localhost:1234/project/"; private static final String WEB_SERVER_URL = "ws://127.0.0.1:" + WEB_SERVER_PORT; - private static final UUID PROJECT_ID = new UUID(0, 1); + private static final Logger log = LoggerFactory.getLogger(YdocTest.class); private Ydoc ydoc; private ExecutorService webServerExecutor; private WebServer ls; private static WebServer startWebSocketServer(ExecutorService executor) { - var routing = WsRouting.builder().endpoint("/", new WebServerWsListener()); + var routing = WsRouting.builder().endpoint("/", new LanguageServerConnection()); var ws = WebServer.builder().host("localhost").port(WEB_SERVER_PORT).addRouting(routing).build(); @@ -51,7 +53,7 @@ private static WebServer startWebSocketServer(ExecutorService executor) { return ws; } - private static String ydocUrl(Object doc) { + private static String ydocUrl(String doc) { return YDOC_URL + doc + "?ls=" + WEB_SERVER_URL; } @@ -65,118 +67,148 @@ public void setup() { @After public void tearDown() throws Exception { ls.stop(); - webServerExecutor.shutdownNow(); - webServerExecutor.awaitTermination(3, TimeUnit.SECONDS); + webServerExecutor.shutdown(); + var stopped = webServerExecutor.awaitTermination(3, TimeUnit.SECONDS); + if (!stopped) { + var pending = webServerExecutor.shutdownNow(); + log.error("Executor pending [{}] tasks: [{}].", pending.size(), pending); + } ydoc.close(); } @Test - public void connect() throws Exception { + public void initialize() throws Exception { var queue = new LinkedBlockingQueue(); ydoc.start(); var ws = WsClient.builder().build(); - ws.connect(ydocUrl("index"), new TestWsListener(queue)); + ws.connect(ydocUrl("index"), new DashboardConnection(queue)); var ok1 = queue.take(); - Assert.assertArrayEquals(new byte[] {0, 0, 1, 0}, ok1.readBytes()); + Assert.assertTrue(ok1.debugDataHex(), BufferDataUtil.isOk(ok1)); var buffer = queue.take(); - buffer.skip(32); - var uuidString = buffer.readString(36); - System.out.println("UUID_STRING='" + uuidString + "'"); - var uuid = UUID.fromString(uuidString); - System.out.println("UUID='" + uuid + "'"); - - WsClient.builder().build().connect(ydocUrl(uuid), new TestWsListener(queue)); + var uuid = BufferDataUtil.readUUID(buffer); + WsClient.builder().build().connect(ydocUrl(uuid.toString()), new DashboardConnection(queue)); var ok2 = queue.take(); - Assert.assertArrayEquals(new byte[] {0, 0, 1, 0}, ok2.readBytes()); + Assert.assertTrue(ok2.debugDataHex(), BufferDataUtil.isOk(ok2)); + } + + private static final class BufferDataUtil { - Thread.sleep(10000); + private static final int UUID_BYTES = 36; + private static final int SUFFIX_BYTES = 3; + + private static boolean isOk(BufferData data) { + return data.readInt16() == 0; + } + + private static UUID readUUID(BufferData data) { + try { + data.skip(data.available() - UUID_BYTES - SUFFIX_BYTES); + var uuidString = data.readString(36); + return UUID.fromString(uuidString); + } catch (Exception e) { + log.error("Failed to read UUID of\n{}", data.debugDataHex()); + throw e; + } + } } - private static final class TestWsListener implements WsListener { + private static final class DashboardConnection implements WsListener { + + private static final Logger log = LoggerFactory.getLogger(DashboardConnection.class); private final BlockingQueue messages; - TestWsListener(BlockingQueue messages) { + private DashboardConnection(BlockingQueue messages) { this.messages = messages; } @Override public void onMessage(WsSession session, BufferData buffer, boolean last) { - System.out.println("!!!!!!!!!!C onMessage\n" + buffer.debugDataHex(true)); + log.debug("Got message\n{}", buffer.debugDataHex()); messages.add(buffer); } @Override public void onMessage(WsSession session, String text, boolean last) { - System.out.println("!!!!!!!!!!C onMessage" + text); + log.error("Got unexpected message [{}].", text); } } - private static final class WebServerWsListener implements WsListener { + private static final class LanguageServerConnection implements WsListener { private static final String METHOD_INIT_PROTOCOL_CONNECTION = "session/initProtocolConnection"; private static final String METHOD_CAPABILITY_ACQUIRE = "capability/acquire"; private static final String METHOD_FILE_LIST = "file/list"; private static final String METHOD_TEXT_OPEN_FILE = "text/openFile"; + private static final UUID PROJECT_ROOT_ID = new UUID(0, 1); + + private static final Logger log = LoggerFactory.getLogger(LanguageServerConnection.class); + private static final ObjectMapper objectMapper = new ObjectMapper(); - WebServerWsListener() {} + private LanguageServerConnection() {} @Override public void onMessage(WsSession session, String text, boolean last) { - System.out.println("!!!!!!!S onMessage " + text); + log.debug("Got message [{}].", text); + try { - var request = objectMapper.readValue(text, Request.class); + var request = objectMapper.readValue(text, JsonRpcRequest.class); - Response jsonRpcResponse = null; + JsonRpcResponse jsonRpcResponse = null; switch (request.method()) { case METHOD_INIT_PROTOCOL_CONNECTION -> { var contentRoots = List.of( - new ContentRoot("Project", PROJECT_ID), + new ContentRoot("Project", PROJECT_ROOT_ID), new ContentRoot("Home", new UUID(0, 2)), new ContentRoot("FileSystemRoot", new UUID(0, 3), "/")); var initProtocolConnectionResult = new InitProtocolConnectionResult("0.0.0-dev", "0.0.0-dev", contentRoots); - jsonRpcResponse = new Response(request.id(), initProtocolConnectionResult); + jsonRpcResponse = new JsonRpcResponse(request.id(), initProtocolConnectionResult); } - case METHOD_CAPABILITY_ACQUIRE -> jsonRpcResponse = Response.ok(request.id()); + case METHOD_CAPABILITY_ACQUIRE -> jsonRpcResponse = JsonRpcResponse.ok(request.id()); case METHOD_FILE_LIST -> { var paths = List.of( - FileSystemObject.file("Main.enso", new FilePath(PROJECT_ID, List.of("src")))); + FileSystemObject.file( + "Main.enso", new FilePath(PROJECT_ROOT_ID, List.of("src")))); var fileListResult = new FileListResult(paths); - jsonRpcResponse = new Response(request.id(), fileListResult); + jsonRpcResponse = new JsonRpcResponse(request.id(), fileListResult); } case METHOD_TEXT_OPEN_FILE -> { var options = - new WriteCapability.Options(new FilePath(PROJECT_ID, List.of("src", "Main.enso"))); + new WriteCapability.Options( + new FilePath(PROJECT_ROOT_ID, List.of("src", "Main.enso"))); var writeCapability = new WriteCapability("text/canEdit", options); var textOpenFileResult = new TextOpenFileResult( - writeCapability, TextOpenFileResult.CONTENT, TextOpenFileResult.VERSION); - jsonRpcResponse = new Response(request.id(), textOpenFileResult); + writeCapability, + "main =", + "e5aeae8609bd90f94941d4227e6ec1e0f069d3318fb7bd93ffe4d391"); + jsonRpcResponse = new JsonRpcResponse(request.id(), textOpenFileResult); } } if (jsonRpcResponse != null) { var response = objectMapper.writeValueAsString(jsonRpcResponse); - System.out.println("SENDING " + response); + + log.debug("Sending [{}].", response); session.send(response, true); } else { - System.out.println("UNKNOWN REQUEST"); + log.error("Unknown request."); } } catch (JsonProcessingException e) { - e.printStackTrace(); - throw new RuntimeException(e); + log.error("Failed to parse JSON.", e); + Assert.fail(e.getMessage()); } } } diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/JsonRpcRequest.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/JsonRpcRequest.java new file mode 100644 index 000000000000..c28722cfda6d --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/JsonRpcRequest.java @@ -0,0 +1,5 @@ +package org.enso.ydoc.jsonrpc; + +import com.fasterxml.jackson.databind.JsonNode; + +public record JsonRpcRequest(String jsonrpc, String id, String method, JsonNode params) {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/JsonRpcResponse.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/JsonRpcResponse.java new file mode 100644 index 000000000000..f446e2fc4c56 --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/JsonRpcResponse.java @@ -0,0 +1,16 @@ +package org.enso.ydoc.jsonrpc; + +import org.enso.ydoc.jsonrpc.model.result.Result; + +public record JsonRpcResponse(String jsonrpc, String id, Result result) { + + private static final String JSONRPC_VERSION_2_0 = "2.0"; + + public JsonRpcResponse(String id, Result result) { + this(JSONRPC_VERSION_2_0, id, result); + } + + public static JsonRpcResponse ok(String id) { + return new JsonRpcResponse(id, null); + } +} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Request.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Request.java deleted file mode 100644 index 661a31120b7b..000000000000 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Request.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.enso.ydoc.jsonrpc; - -import com.fasterxml.jackson.databind.JsonNode; - -public record Request(String jsonrpc, String id, String method, JsonNode params) {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Response.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Response.java deleted file mode 100644 index 0e8dd5b8e802..000000000000 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/Response.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.enso.ydoc.jsonrpc; - -import org.enso.ydoc.jsonrpc.result.Result; - -public record Response(String jsonrpc, String id, Result result) { - - public Response(String id, Result result) { - this("2.0", id, result); - } - - public static Response ok(String id) { - return new Response(id, null); - } -} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/FileListResult.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/FileListResult.java similarity index 78% rename from lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/FileListResult.java rename to lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/FileListResult.java index 2e920d30e0e0..92e8da00dd69 100644 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/FileListResult.java +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/FileListResult.java @@ -1,4 +1,4 @@ -package org.enso.ydoc.jsonrpc.result; +package org.enso.ydoc.jsonrpc.model.result; import java.util.List; import org.enso.ydoc.jsonrpc.model.FileSystemObject; diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/InitProtocolConnectionResult.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/InitProtocolConnectionResult.java similarity index 83% rename from lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/InitProtocolConnectionResult.java rename to lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/InitProtocolConnectionResult.java index eb85724c369f..3a0dad0d39a1 100644 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/InitProtocolConnectionResult.java +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/InitProtocolConnectionResult.java @@ -1,4 +1,4 @@ -package org.enso.ydoc.jsonrpc.result; +package org.enso.ydoc.jsonrpc.model.result; import java.util.List; import org.enso.ydoc.jsonrpc.model.ContentRoot; diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/Result.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/Result.java new file mode 100644 index 000000000000..f94dd6f49306 --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/Result.java @@ -0,0 +1,3 @@ +package org.enso.ydoc.jsonrpc.model.result; + +public interface Result {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/TextOpenFileResult.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/TextOpenFileResult.java new file mode 100644 index 000000000000..88c2317672d5 --- /dev/null +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/model/result/TextOpenFileResult.java @@ -0,0 +1,6 @@ +package org.enso.ydoc.jsonrpc.model.result; + +import org.enso.ydoc.jsonrpc.model.WriteCapability; + +public record TextOpenFileResult( + WriteCapability writeCapability, String content, String currentVersion) implements Result {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/Result.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/Result.java deleted file mode 100644 index b491e4be90fd..000000000000 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/Result.java +++ /dev/null @@ -1,3 +0,0 @@ -package org.enso.ydoc.jsonrpc.result; - -public interface Result {} diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/TextOpenFileResult.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/TextOpenFileResult.java deleted file mode 100644 index d04552c707c0..000000000000 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/jsonrpc/result/TextOpenFileResult.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.enso.ydoc.jsonrpc.result; - -import org.enso.ydoc.jsonrpc.model.WriteCapability; - -public record TextOpenFileResult( - WriteCapability writeCapability, String content, String currentVersion) implements Result { - - public static final String CONTENT = - "from Standard.Base import all\n" - + "from Standard.Table import all\n" - + "from Standard.Database import all\n" - + "from Standard.AWS import all\n" - + "import Standard.Visualization\n" - + "import Standard.Visualization.Warnings\n" - + "from Standard.Base.Errors.Common import Dry_Run_Operation\n\n" - + "type Student\n" - + " Value id region\n\n" - + "main =\n" - + " my_op = 226\n" - + " operator47321 = 'east'\n" - + " operator76980 = Student.Value my_op operator47321\n" - + " operator91574 = 0\n" - + " operator34358 = operator47321.take (Index_Sub_Range.By_Index [0," - + " operator91574])\n\n\n\n" - + "#### METADATA ####\n" - + "[[{\"index\":{\"value\":0},\"size\":{\"value\":4}},\"7f508138-95e6-40c9-a663-68f496d577f2\"],[{\"index\":{\"value\":0},\"size\":{\"value\":29}},\"389fe7a5-e59b-440a-8801-e0bd86716094\"],[{\"index\":{\"value\":0},\"size\":{\"value\":497}},\"59a4052a-e0eb-4eba-8ce4-4d930bd86e84\"],[{\"index\":{\"value\":5},\"size\":{\"value\":8}},\"c6f0de99-3bd3-459d-a69b-5fc774dd1e3f\"],[{\"index\":{\"value\":5},\"size\":{\"value\":13}},\"05827411-7354-478b-99d8-8370dadd560b\"],[{\"index\":{\"value\":13},\"size\":{\"value\":1}},\"72f9678a-e186-42f9-81f5-29a9a785f854\"],[{\"index\":{\"value\":14},\"size\":{\"value\":4}},\"8abd24ea-b1cb-4c10-ad16-5a190f7ed0c7\"],[{\"index\":{\"value\":19},\"size\":{\"value\":6}},\"756c7965-a2df-4e6a-8b1c-5d0eb9112ac8\"],[{\"index\":{\"value\":26},\"size\":{\"value\":3}},\"6c235dfc-9fb6-4bc9-a46f-2504cd3f37e4\"],[{\"index\":{\"value\":30},\"size\":{\"value\":4}},\"64907585-db55-491d-8125-0d8ee95adafd\"],[{\"index\":{\"value\":30},\"size\":{\"value\":30}},\"bdd4b4cc-9c1e-4554-b0fb-3f73dcd5a590\"],[{\"index\":{\"value\":35},\"size\":{\"value\":8}},\"7e7bb9b4-8e9b-4700-9dcd-83c353800da5\"],[{\"index\":{\"value\":35},\"size\":{\"value\":14}},\"524bafb6-d3ca-4ee5-b8de-84b5c47ca87b\"],[{\"index\":{\"value\":43},\"size\":{\"value\":1}},\"eaf5c36a-c388-47ce-9285-5a3bf8c8bfd6\"],[{\"index\":{\"value\":44},\"size\":{\"value\":5}},\"7173f374-5f53-462b-ab1b-f7b1845d729b\"],[{\"index\":{\"value\":50},\"size\":{\"value\":6}},\"94eac4fd-71cb-41e6-aa17-5da97b7059ab\"],[{\"index\":{\"value\":57},\"size\":{\"value\":3}},\"d96ece64-9552-4d83-a792-139f91926041\"],[{\"index\":{\"value\":61},\"size\":{\"value\":4}},\"357a38f5-543b-4c53-a419-5de8a8da5829\"],[{\"index\":{\"value\":61},\"size\":{\"value\":33}},\"9f6ae949-410b-48e6-bb75-84d4ba8a1989\"],[{\"index\":{\"value\":66},\"size\":{\"value\":8}},\"f4726e40-dd5b-49a0-aa2a-6cea6df88d5d\"],[{\"index\":{\"value\":66},\"size\":{\"value\":17}},\"539b4dcf-4487-49b6-9c90-6ae58d51c2db\"],[{\"index\":{\"value\":74},\"size\":{\"value\":1}},\"66329d8b-90f1-4b08-bb35-edb3b1492619\"],[{\"index\":{\"value\":75},\"size\":{\"value\":8}},\"8fdf4ee7-2e74-4cac-b9b9-4230183f91c5\"],[{\"index\":{\"value\":84},\"size\":{\"value\":6}},\"66c04eab-d5a3-489a-a04a-77afadf45e84\"],[{\"index\":{\"value\":91},\"size\":{\"value\":3}},\"dbcfdae9-dddc-4f6c-b08f-2d04a7be0180\"],[{\"index\":{\"value\":95},\"size\":{\"value\":4}},\"c566151f-b355-42e7-85cd-dbbeb25608e4\"],[{\"index\":{\"value\":95},\"size\":{\"value\":28}},\"f9b37b67-fb54-4e47-8281-e922edb4c5d3\"],[{\"index\":{\"value\":100},\"size\":{\"value\":8}},\"6cf398f8-d0c9-42fa-a6e6-e740de11562f\"],[{\"index\":{\"value\":100},\"size\":{\"value\":12}},\"28e4d0e3-7da4-4ee2-94c7-d9a7c692f8de\"],[{\"index\":{\"value\":108},\"size\":{\"value\":1}},\"ad7da09d-d75b-4bea-b1b2-0534b46eefc2\"],[{\"index\":{\"value\":109},\"size\":{\"value\":3}},\"bdc65807-0438-4296-8b1f-1fab3a885c17\"],[{\"index\":{\"value\":113},\"size\":{\"value\":6}},\"b78ca3c2-670e-4caf-9c69-c0a2b385a4f3\"],[{\"index\":{\"value\":120},\"size\":{\"value\":3}},\"e860e397-968c-47ab-949e-103be48da20e\"],[{\"index\":{\"value\":124},\"size\":{\"value\":6}},\"1097e484-331e-4470-b204-0abf25bad184\"],[{\"index\":{\"value\":124},\"size\":{\"value\":29}},\"d49e0fe3-a638-4d7e-ba58-12db7abad20f\"],[{\"index\":{\"value\":131},\"size\":{\"value\":8}},\"c9411433-5e73-4927-9175-15d3b1ccb0ef\"],[{\"index\":{\"value\":131},\"size\":{\"value\":22}},\"b53ad817-ea4c-491e-aaf8-49967e22aff6\"],[{\"index\":{\"value\":139},\"size\":{\"value\":1}},\"26172f9f-9786-44d9-9261-1032ba96caa6\"],[{\"index\":{\"value\":140},\"size\":{\"value\":13}},\"3b662906-1887-4dd6-a0e2-a222ace135ce\"],[{\"index\":{\"value\":154},\"size\":{\"value\":6}},\"f0d6c0b3-0461-4a2b-a7f8-435fdc729eea\"],[{\"index\":{\"value\":154},\"size\":{\"value\":38}},\"7c45872c-22b4-4f37-bcd7-b3791408f737\"],[{\"index\":{\"value\":161},\"size\":{\"value\":8}},\"21152f0d-4222-48e4-9376-a2a28f8f6be6\"],[{\"index\":{\"value\":161},\"size\":{\"value\":22}},\"1cb71d49-a06d-4dd9-bc1b-54603b416601\"],[{\"index\":{\"value\":161},\"size\":{\"value\":31}},\"faa46cf2-3e90-44ed-9d9e-77b7f874b338\"],[{\"index\":{\"value\":169},\"size\":{\"value\":1}},\"af0e4f34-0ffb-4ab6-9108-2daca0c4f8ba\"],[{\"index\":{\"value\":170},\"size\":{\"value\":13}},\"830d73c2-1898-41a9-8046-22d86f159ef0\"],[{\"index\":{\"value\":183},\"size\":{\"value\":1}},\"3c9b8a49-a4ab-41d5-8c5f-019bc2d5a9b2\"],[{\"index\":{\"value\":184},\"size\":{\"value\":8}},\"29f35cf2-d79d-44d0-96d0-79b11589726c\"],[{\"index\":{\"value\":193},\"size\":{\"value\":4}},\"08856917-449d-40bd-a94c-0dd97acb6adc\"],[{\"index\":{\"value\":193},\"size\":{\"value\":57}},\"478005ac-f0ca-497a-b298-554bd64946a9\"],[{\"index\":{\"value\":198},\"size\":{\"value\":8}},\"c11511ce-252c-4b84-9f61-dfa5544d4916\"],[{\"index\":{\"value\":198},\"size\":{\"value\":13}},\"dbae65a1-bdca-44b0-a497-7934d1e42616\"],[{\"index\":{\"value\":198},\"size\":{\"value\":20}},\"355392ad-8c81-4304-a6d0-2bbf3690da0c\"],[{\"index\":{\"value\":198},\"size\":{\"value\":27}},\"0720ccb5-ebd3-4c29-8113-0aa1f251e873\"],[{\"index\":{\"value\":206},\"size\":{\"value\":1}},\"25fd7465-6369-4b6e-a6f5-ccf382b59794\"],[{\"index\":{\"value\":207},\"size\":{\"value\":4}},\"10046e78-5164-407c-adef-2ab11ce77b4c\"],[{\"index\":{\"value\":211},\"size\":{\"value\":1}},\"45edeab2-9567-4079-8179-cc15474d3ae0\"],[{\"index\":{\"value\":212},\"size\":{\"value\":6}},\"7a09de10-35e2-45e0-9eb8-f79fa054b733\"],[{\"index\":{\"value\":218},\"size\":{\"value\":1}},\"4004f059-8c02-42c3-8a0a-2a0b2e1a03cb\"],[{\"index\":{\"value\":219},\"size\":{\"value\":6}},\"1b04c19d-cdf0-4661-8f4e-d980cf12c996\"],[{\"index\":{\"value\":226},\"size\":{\"value\":6}},\"57a8a12a-62d9-4bc3-8a49-a1cafc99966c\"],[{\"index\":{\"value\":233},\"size\":{\"value\":17}},\"60fd6a1c-7ada-4546-ae20-e1f8b432b4fd\"],[{\"index\":{\"value\":252},\"size\":{\"value\":4}},\"d60938a3-b4f4-43cd-95f9-dc8dd68206dd\"],[{\"index\":{\"value\":252},\"size\":{\"value\":32}},\"8479091c-9232-49d6-b375-32f89693c389\"],[{\"index\":{\"value\":257},\"size\":{\"value\":7}},\"fceba8f9-af4d-484f-98f9-775d2e3e10e4\"],[{\"index\":{\"value\":264},\"size\":{\"value\":1}},\"147655e9-3368-453a-be03-2a3999e00cb1\"],[{\"index\":{\"value\":269},\"size\":{\"value\":5}},\"f8134346-2c23-43e7-aff0-7cae2361367a\"],[{\"index\":{\"value\":269},\"size\":{\"value\":15}},\"e3315ef2-d0ec-43b1-b8f6-5b436054aaee\"],[{\"index\":{\"value\":275},\"size\":{\"value\":2}},\"bc7205c4-68bf-461e-a1ba-31400b9337ff\"],[{\"index\":{\"value\":278},\"size\":{\"value\":6}},\"78870c05-9117-4e24-bf77-a72e7aef9c18\"],[{\"index\":{\"value\":286},\"size\":{\"value\":4}},\"517c743f-c775-4031-8f87-222d0f0a365f\"],[{\"index\":{\"value\":286},\"size\":{\"value\":210}},\"929ad6f1-e3cf-4cd4-8cb7-d919a191ccd1\"],[{\"index\":{\"value\":291},\"size\":{\"value\":1}},\"9d5b4cfa-ef7a-4f07-9cca-b904de56f431\"],[{\"index\":{\"value\":292},\"size\":{\"value\":204}},\"2ab319a4-0a89-44e1-a59a-77216559a778\"],[{\"index\":{\"value\":297},\"size\":{\"value\":5}},\"52c9426a-17d3-40e2-8423-7a1ffdd95123\"],[{\"index\":{\"value\":297},\"size\":{\"value\":11}},\"8ef8639a-e900-4aff-aeda-6bf1164d6773\"],[{\"index\":{\"value\":303},\"size\":{\"value\":1}},\"aa9d543a-91b3-411f-ab6c-d5b98bb3369d\"],[{\"index\":{\"value\":305},\"size\":{\"value\":3}},\"016c8065-1b96-4612-a70c-a4bf7c9df2c3\"],[{\"index\":{\"value\":313},\"size\":{\"value\":13}},\"6a574885-2c78-43ea-b5ca-f8057b0738a6\"],[{\"index\":{\"value\":313},\"size\":{\"value\":22}},\"3bbd70b1-c7a2-45f9-806f-a30e9800af75\"],[{\"index\":{\"value\":327},\"size\":{\"value\":1}},\"396c59db-f42e-47ba-8191-5b666f399866\"],[{\"index\":{\"value\":329},\"size\":{\"value\":1}},\"7dd7148b-fc9c-4ca3-b54d-49aaf9d719be\"],[{\"index\":{\"value\":329},\"size\":{\"value\":6}},\"b2d8cdd6-cb21-4d39-979f-5d3543533885\"],[{\"index\":{\"value\":330},\"size\":{\"value\":4}},\"72f10c8f-0da1-498c-950a-dcd0445914c7\"],[{\"index\":{\"value\":334},\"size\":{\"value\":1}},\"243d8ac4-e8f9-4759-9fcd-6b75eee57980\"],[{\"index\":{\"value\":340},\"size\":{\"value\":13}},\"6e95b94e-eef4-4ee3-b9cd-da48d5efc88e\"],[{\"index\":{\"value\":340},\"size\":{\"value\":49}},\"f5d12a49-8070-4c5b-8569-3c896bb44820\"],[{\"index\":{\"value\":354},\"size\":{\"value\":1}},\"9e2b672b-38a9-4703-b3e7-733e50f724d0\"],[{\"index\":{\"value\":356},\"size\":{\"value\":7}},\"4667cc6f-7574-4181-a88b-7e9e01f534b9\"],[{\"index\":{\"value\":356},\"size\":{\"value\":13}},\"718dc070-2cd2-4ba6-91df-43909cb6630d\"],[{\"index\":{\"value\":356},\"size\":{\"value\":19}},\"aca33e8a-3e71-4e9b-bec2-2456b30016d1\"],[{\"index\":{\"value\":356},\"size\":{\"value\":33}},\"8928757b-9c83-4385-b8a1-2116e4a48572\"],[{\"index\":{\"value\":363},\"size\":{\"value\":1}},\"20e7d598-ae0c-4e99-ab73-f1e951df40e6\"],[{\"index\":{\"value\":364},\"size\":{\"value\":5}},\"63aea777-30b8-4cac-8120-d36a87c14699\"],[{\"index\":{\"value\":370},\"size\":{\"value\":5}},\"ca2e0ecc-ca50-41bd-8dce-413ceff13fe6\"],[{\"index\":{\"value\":376},\"size\":{\"value\":13}},\"fa66f697-e334-4b3e-a446-4e3dd219a816\"],[{\"index\":{\"value\":394},\"size\":{\"value\":13}},\"53c85179-01b3-45f7-9a64-141b28a51bf0\"],[{\"index\":{\"value\":394},\"size\":{\"value\":17}},\"b4a90be4-5fbf-425c-aef9-feda20de5b3e\"],[{\"index\":{\"value\":408},\"size\":{\"value\":1}},\"967ca125-4e15-49b3-a915-58e26e74b4b2\"],[{\"index\":{\"value\":410},\"size\":{\"value\":1}},\"69b37f53-acf3-4afd-91c9-98c384912707\"],[{\"index\":{\"value\":416},\"size\":{\"value\":13}},\"2e16b3da-d091-430b-94e6-2ca47cb4d575\"],[{\"index\":{\"value\":416},\"size\":{\"value\":80}},\"27a65c26-9814-43a3-8855-5c4461a9c050\"],[{\"index\":{\"value\":430},\"size\":{\"value\":1}},\"52e26deb-0a13-4d95-8b07-72156880b306\"],[{\"index\":{\"value\":432},\"size\":{\"value\":13}},\"a5139627-05a8-4838-b171-02666c62c348\"],[{\"index\":{\"value\":432},\"size\":{\"value\":18}},\"2a70b8fa-5569-4d7f-b41b-489f689cc165\"],[{\"index\":{\"value\":432},\"size\":{\"value\":64}},\"8df4a011-54db-4c3b-b1c5-fb7027d93ab2\"],[{\"index\":{\"value\":445},\"size\":{\"value\":1}},\"78daa642-63b5-4576-bcab-9ce44ac7f992\"],[{\"index\":{\"value\":446},\"size\":{\"value\":4}},\"1ac9930b-19bf-4c4a-9ad6-0b44a30fb0a4\"],[{\"index\":{\"value\":451},\"size\":{\"value\":1}},\"611f20c7-9cd1-41e5-aca1-41e98dcbe39e\"],[{\"index\":{\"value\":451},\"size\":{\"value\":45}},\"adc7c9a4-26ee-40f3-be1d-92315160d33f\"],[{\"index\":{\"value\":452},\"size\":{\"value\":15}},\"a221414a-6c82-49f9-9291-fa47e020d41e\"],[{\"index\":{\"value\":452},\"size\":{\"value\":24}},\"ea4ee13c-d57f-4ea8-8c9b-859606775bb8\"],[{\"index\":{\"value\":452},\"size\":{\"value\":43}},\"bdcd2298-ff93-4d38-8168-a65c25a80575\"],[{\"index\":{\"value\":467},\"size\":{\"value\":1}},\"bc931ceb-ed88-4fa5-b890-d4eaad686535\"],[{\"index\":{\"value\":468},\"size\":{\"value\":8}},\"3d6ffb97-15c4-45a0-9bb0-e497a7538967\"],[{\"index\":{\"value\":477},\"size\":{\"value\":1}},\"702a1abd-1743-4da6-9e06-833e82142c42\"],[{\"index\":{\"value\":477},\"size\":{\"value\":18}},\"0a4ba14c-0a3f-49d2-8949-fb0020841647\"],[{\"index\":{\"value\":478},\"size\":{\"value\":1}},\"eca28d4b-96a9-4c60-a95a-4b77db63caf7\"],[{\"index\":{\"value\":479},\"size\":{\"value\":1}},\"9f7ddaf2-2f80-4d73-a2db-937502b31d36\"],[{\"index\":{\"value\":481},\"size\":{\"value\":13}},\"c7dcf3df-eca3-4519-a0fc-e6a74264e0b2\"],[{\"index\":{\"value\":494},\"size\":{\"value\":1}},\"8dc38e9c-3ac0-4574-993d-e27e83426844\"],[{\"index\":{\"value\":495},\"size\":{\"value\":1}},\"ba0c6ae6-2926-433d-af9f-a26baf82fba4\"]]\n" - + "{\"ide\":{\"node\":{\"016c8065-1b96-4612-a70c-a4bf7c9df2c3\":{\"position\":{\"vector\":[55,-107]}},\"b2d8cdd6-cb21-4d39-979f-5d3543533885\":{\"position\":{\"vector\":[284,-107]}},\"8928757b-9c83-4385-b8a1-2116e4a48572\":{\"position\":{\"vector\":[55,-192]}},\"69b37f53-acf3-4afd-91c9-98c384912707\":{\"position\":{\"vector\":[559,-107]}},\"8df4a011-54db-4c3b-b1c5-fb7027d93ab2\":{\"position\":{\"vector\":[323,-220]},\"visualization\":{\"show\":true,\"fullscreen\":false}}},\"import\":{},\"project\":null}}"; - public static final String VERSION = "8f2d9d1598a16d51cc8ce160ebfa3a82efcfde91cd6bea502e235aa1"; -} From 7f05940b3f4941049eee7c07b4e358965c6c0b36 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Tue, 4 Jun 2024 17:53:58 +0100 Subject: [PATCH 5/6] update: review comments --- lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java | 4 ++-- .../ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java index 74dd559dc9ce..3ad70ebd45ec 100644 --- a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java +++ b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java @@ -4,8 +4,8 @@ public class Main { - private static final String YDOC_HOST = "YDOC_HOST"; - private static final String YDOC_PORT = "YDOC_PORT"; + private static final String YDOC_HOST = "ENSO_YDOC_HOST"; + private static final String YDOC_PORT = "ENSO_YDOC_PORT"; private static final Semaphore lock = new Semaphore(0); diff --git a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java index ef0c1e725633..0f55d564c023 100644 --- a/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java +++ b/lib/java/ydoc-server/src/test/java/org/enso/ydoc/YdocTest.java @@ -108,7 +108,7 @@ private static boolean isOk(BufferData data) { private static UUID readUUID(BufferData data) { try { data.skip(data.available() - UUID_BYTES - SUFFIX_BYTES); - var uuidString = data.readString(36); + var uuidString = data.readString(UUID_BYTES); return UUID.fromString(uuidString); } catch (Exception e) { log.error("Failed to read UUID of\n{}", data.debugDataHex()); From 8e2ce8c829e7b0062df30de24bde2632fb00c5ca Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Tue, 4 Jun 2024 17:55:40 +0100 Subject: [PATCH 6/6] misc: cleanup --- .../ydoc-server/src/main/java/org/enso/ydoc/Main.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java index 3ad70ebd45ec..6481afd25360 100644 --- a/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java +++ b/lib/java/ydoc-server/src/main/java/org/enso/ydoc/Main.java @@ -4,8 +4,8 @@ public class Main { - private static final String YDOC_HOST = "ENSO_YDOC_HOST"; - private static final String YDOC_PORT = "ENSO_YDOC_PORT"; + private static final String ENSO_YDOC_HOST = "ENSO_YDOC_HOST"; + private static final String ENSO_YDOC_PORT = "ENSO_YDOC_PORT"; private static final Semaphore lock = new Semaphore(0); @@ -18,8 +18,8 @@ public static void main(String[] args) throws Exception { Sampling.init(); - var ydocHost = System.getenv(YDOC_HOST); - var ydocPort = System.getenv(YDOC_PORT); + var ydocHost = System.getenv(ENSO_YDOC_HOST); + var ydocPort = System.getenv(ENSO_YDOC_PORT); var builder = Ydoc.builder(); if (ydocHost != null) {