elek commented on a change in pull request #1050:
URL: https://github.com/apache/hadoop-ozone/pull/1050#discussion_r446104057



##########
File path: 
hadoop-hdds/test-utils/src/main/java/org/apache/hadoop/test/JacocoServer.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 org.apache.hadoop.test;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import org.jacoco.core.data.ExecutionDataWriter;
+import org.jacoco.core.runtime.RemoteControlReader;
+import org.jacoco.core.runtime.RemoteControlWriter;
+
+/**
+ * Simple TPC server to collect all the Jacoco coverage data.
+ */
+public final class JacocoServer {
+
+  private static int port = 6300;
+
+  private static String destinationFile = "/tmp/jacoco-combined.exec";
+
+  private JacocoServer() {
+  }
+
+  @SuppressWarnings("checkstyle:EmptyStatement")
+  public static void main(String[] args) throws IOException {
+    ExecutionDataWriter destination =
+        new ExecutionDataWriter(new FileOutputStream(destinationFile));
+    ServerSocket serverSocket = new ServerSocket(port);
+    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+      try {
+        destination.flush();
+        serverSocket.close();
+      } catch (Exception ex) {
+        ex.printStackTrace();
+      }
+    }));
+
+    while (true) {
+      final Socket socket = serverSocket.accept();
+      new Thread(() -> {
+        try {
+          RemoteControlWriter writer =
+              new RemoteControlWriter(socket.getOutputStream());
+          RemoteControlReader reader =
+              new RemoteControlReader(socket.getInputStream());
+          reader.setSessionInfoVisitor(destination::visitSessionInfo);
+          reader.setExecutionDataVisitor(destination::visitClassExecution);
+          while (reader.read()) {
+            ;//read until the end of the stream.
+          }
+          destination.flush();

Review comment:
       Thanks to investigate it. I uploaded a synchronized version. 
   
   The main problem is that the same functionality is written in Jacoco project 
under LGPL which couldn't be imported. I wrote my own version from scratch, and 
this mistake clearly proves that it's independent, as I added my own mistakes 
;-)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to