This is an automated email from the ASF dual-hosted git repository.

baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new c7c3540285 [MINOR] More sleep to monitoring tests
c7c3540285 is described below

commit c7c35402859dae8bfa441a5204576d381261d739
Author: baunsgaard <[email protected]>
AuthorDate: Fri Nov 11 15:52:48 2022 +0100

    [MINOR] More sleep to monitoring tests
    
    try number 3 to make the monitoring tests consistently run.
    The PR contains discussions to make it more stable via callback
    or polling strategies. But both are currently not implemented.
    
    To make the test run on the short term, i have simply increased the
    sleep time to wait from 5 to 10 sec for the monitoring service to startup.
    
    Closes #1728
---
 .../org/apache/sysds/test/AutomatedTestBase.java   |  2 +-
 .../FederatedCoordinatorIntegrationCRUDTest.java   | 19 ++++-
 .../monitoring/FederatedMonitoringTestBase.java    | 94 +++++++++-------------
 3 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/src/test/java/org/apache/sysds/test/AutomatedTestBase.java 
b/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
index 02b09b3045..a815c2c14b 100644
--- a/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
+++ b/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
@@ -123,7 +123,7 @@ public abstract class AutomatedTestBase {
 
        // ms wait time 
        public static final int FED_WORKER_WAIT = 1000; 
-       public static final int FED_MONITOR_WAIT = 5000; 
+       public static final int FED_MONITOR_WAIT = 10000; 
        public static final int FED_WORKER_WAIT_S = 50;
        
 
diff --git 
a/src/test/java/org/apache/sysds/test/functions/federated/monitoring/FederatedCoordinatorIntegrationCRUDTest.java
 
b/src/test/java/org/apache/sysds/test/functions/federated/monitoring/FederatedCoordinatorIntegrationCRUDTest.java
index 203f41d841..41dfe503c6 100644
--- 
a/src/test/java/org/apache/sysds/test/functions/federated/monitoring/FederatedCoordinatorIntegrationCRUDTest.java
+++ 
b/src/test/java/org/apache/sysds/test/functions/federated/monitoring/FederatedCoordinatorIntegrationCRUDTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.sysds.test.functions.federated.monitoring;
 
+import static org.junit.Assert.fail;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.HttpStatus;
 import 
org.apache.sysds.runtime.controlprogram.federated.monitoring.models.CoordinatorModel;
@@ -43,10 +45,19 @@ public class FederatedCoordinatorIntegrationCRUDTest 
extends FederatedMonitoring
 
        @Test
        public void testCoordinatorAddedForMonitoring() {
-               var addedCoordinators = addEntities(1, Entity.COORDINATOR);
-               var firstCoordinatorStatus = 
addedCoordinators.get(0).statusCode();
-
-               Assert.assertEquals("Added coordinator status code", 
HttpStatus.SC_OK, firstCoordinatorStatus);
+               int firstCoordinatorStatus = addEntities(1, 
Entity.COORDINATOR).get(0).statusCode();
+               int retry = 0;
+               while(HttpStatus.SC_OK !=firstCoordinatorStatus && retry < 3){
+                       try{
+                               Thread.sleep(1000* (retry + 1));
+                       }
+                       catch(Exception e){
+                               fail(e.getMessage());
+                       }
+                       retry++;
+                       firstCoordinatorStatus = addEntities(1, 
Entity.COORDINATOR).get(0).statusCode();
+               }
+               Assert.assertEquals("Added coordinator status code was wrong", 
HttpStatus.SC_OK, firstCoordinatorStatus);
        }
 
        @Test
diff --git 
a/src/test/java/org/apache/sysds/test/functions/federated/monitoring/FederatedMonitoringTestBase.java
 
b/src/test/java/org/apache/sysds/test/functions/federated/monitoring/FederatedMonitoringTestBase.java
index eca19d8edb..769e144cc3 100644
--- 
a/src/test/java/org/apache/sysds/test/functions/federated/monitoring/FederatedMonitoringTestBase.java
+++ 
b/src/test/java/org/apache/sysds/test/functions/federated/monitoring/FederatedMonitoringTestBase.java
@@ -47,9 +47,7 @@ public abstract class FederatedMonitoringTestBase extends 
MultiTenantTestBase {
        private static final String STATISTICS_MAIN_PATH = "/statistics";
 
        public enum Entity {
-               WORKER,
-               COORDINATOR,
-               STATISTICS
+               WORKER, COORDINATOR, STATISTICS
        }
 
        @Override
@@ -58,7 +56,7 @@ public abstract class FederatedMonitoringTestBase extends 
MultiTenantTestBase {
        // ensure that the processes are killed - even if the test throws an 
exception
        @After
        public void stopMonitoringProcesses() {
-               if (monitoringProcess != null) {
+               if(monitoringProcess != null) {
                        monitoringProcess.destroyForcibly();
                }
        }
@@ -74,43 +72,40 @@ public abstract class FederatedMonitoringTestBase extends 
MultiTenantTestBase {
        }
 
        protected List<HttpResponse<?>> addEntities(int count, Entity entity) {
-               String uriStr = MAIN_URI + ":" + monitoringPort + 
WORKER_MAIN_PATH;
-               String name = "Worker";
+               try {
+                       String uriStr = MAIN_URI + ":" + monitoringPort + 
WORKER_MAIN_PATH;
+                       String name = "Worker";
 
-               if (entity == Entity.COORDINATOR) {
-                       uriStr = MAIN_URI + ":" + monitoringPort + 
COORDINATOR_MAIN_PATH;
-                       name = "Coordinator";
-               }
+                       if(entity == Entity.COORDINATOR) {
+                               uriStr = MAIN_URI + ":" + monitoringPort + 
COORDINATOR_MAIN_PATH;
+                               name = "Coordinator";
+                       }
 
-               List<HttpResponse<?>> responses = new ArrayList<>();
-               try {
+                       List<HttpResponse<?>> responses = new ArrayList<>();
                        ObjectMapper objectMapper = new ObjectMapper();
-                       for (int i = 0; i < count; i++) {
+                       for(int i = 0; i < count; i++) {
                                String requestBody = "";
 
-                               if (entity == Entity.WORKER) {
-                                       requestBody = objectMapper
-                                                       
.writerWithDefaultPrettyPrinter()
-                                                       .writeValueAsString(new 
WorkerModel((i + 1L), name, "localhost"));
-                               } else if (entity == Entity.COORDINATOR) {
+                               if(entity == Entity.WORKER) {
+                                       requestBody = 
objectMapper.writerWithDefaultPrettyPrinter()
+                                               .writeValueAsString(new 
WorkerModel((i + 1L), name, "localhost"));
+                               }
+                               else if(entity == Entity.COORDINATOR) {
                                        CoordinatorModel model = new 
CoordinatorModel(i + 1L, name, "localhost", 4242L);
                                        model.generateMonitoringKey();
 
-                                       requestBody = objectMapper
-                                                       
.writerWithDefaultPrettyPrinter()
-                                                       
.writeValueAsString(model);
+                                       requestBody = 
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(model);
                                }
                                var client = HttpClient.newHttpClient();
-                               var request = 
HttpRequest.newBuilder(URI.create(uriStr))
-                                       .header("accept", "application/json")
-                                       
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
-                                       .build();
+                               var request = 
HttpRequest.newBuilder(URI.create(uriStr)).header("accept", "application/json")
+                                       
.POST(HttpRequest.BodyPublishers.ofString(requestBody)).build();
                                responses.add(client.send(request, 
HttpResponse.BodyHandlers.ofString()));
                        }
 
                        return responses;
                }
-               catch (IOException | InterruptedException e) {
+               catch(Exception e) {
+                       e.printStackTrace();
                        throw new RuntimeException(e);
                }
        }
@@ -118,7 +113,7 @@ public abstract class FederatedMonitoringTestBase extends 
MultiTenantTestBase {
        protected HttpResponse<?> updateEntity(BaseModel editModel, Entity 
entity) {
                String uriStr = MAIN_URI + ":" + monitoringPort + 
WORKER_MAIN_PATH + "/" + editModel.id;
 
-               if (entity == Entity.COORDINATOR) {
+               if(entity == Entity.COORDINATOR) {
                        uriStr = MAIN_URI + ":" + monitoringPort + 
COORDINATOR_MAIN_PATH + "/" + editModel.id;
                }
 
@@ -126,28 +121,24 @@ public abstract class FederatedMonitoringTestBase extends 
MultiTenantTestBase {
                        ObjectMapper objectMapper = new ObjectMapper();
                        String requestBody = "";
 
-                       if (entity == Entity.WORKER) {
-                               requestBody = objectMapper
-                                               
.writerWithDefaultPrettyPrinter()
-                                               .writeValueAsString(new 
WorkerModel(editModel.id, ((WorkerModel) editModel).name, ((WorkerModel) 
editModel).address));
-                       } else if (entity == Entity.COORDINATOR) {
-                               CoordinatorModel model = new CoordinatorModel(
-                                               editModel.id, 
((CoordinatorModel)editModel).name,((CoordinatorModel)editModel).host, 
((CoordinatorModel)editModel).processId);
+                       if(entity == Entity.WORKER) {
+                               requestBody = 
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(
+                                       new WorkerModel(editModel.id, 
((WorkerModel) editModel).name, ((WorkerModel) editModel).address));
+                       }
+                       else if(entity == Entity.COORDINATOR) {
+                               CoordinatorModel model = new 
CoordinatorModel(editModel.id, ((CoordinatorModel) editModel).name,
+                                       ((CoordinatorModel) editModel).host, 
((CoordinatorModel) editModel).processId);
                                model.generateMonitoringKey();
 
-                               requestBody = objectMapper
-                                       .writerWithDefaultPrettyPrinter()
-                                       .writeValueAsString(model);
+                               requestBody = 
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(model);
                        }
                        var client = HttpClient.newHttpClient();
-                       var request = HttpRequest.newBuilder(URI.create(uriStr))
-                               .header("accept", "application/json")
-                               
.PUT(HttpRequest.BodyPublishers.ofString(requestBody))
-                               .build();
+                       var request = 
HttpRequest.newBuilder(URI.create(uriStr)).header("accept", "application/json")
+                               
.PUT(HttpRequest.BodyPublishers.ofString(requestBody)).build();
 
                        return client.send(request, 
HttpResponse.BodyHandlers.ofString());
                }
-               catch (IOException | InterruptedException e) {
+               catch(IOException | InterruptedException e) {
                        throw new RuntimeException(e);
                }
        }
@@ -155,20 +146,17 @@ public abstract class FederatedMonitoringTestBase extends 
MultiTenantTestBase {
        protected HttpResponse<?> removeEntity(Long id, Entity entity) {
                String uriStr = MAIN_URI + ":" + monitoringPort + 
WORKER_MAIN_PATH + "/" + id;
 
-               if (entity == Entity.COORDINATOR) {
+               if(entity == Entity.COORDINATOR) {
                        uriStr = MAIN_URI + ":" + monitoringPort + 
COORDINATOR_MAIN_PATH + "/" + id;
                }
 
                try {
                        var client = HttpClient.newHttpClient();
-                       var request = HttpRequest.newBuilder(URI.create(uriStr))
-                               .header("accept", "application/json")
-                               .DELETE()
-                               .build();
+                       var request = 
HttpRequest.newBuilder(URI.create(uriStr)).header("accept", 
"application/json").DELETE().build();
 
                        return client.send(request, 
HttpResponse.BodyHandlers.ofString());
                }
-               catch (IOException | InterruptedException e) {
+               catch(IOException | InterruptedException e) {
                        throw new RuntimeException(e);
                }
        }
@@ -176,22 +164,20 @@ public abstract class FederatedMonitoringTestBase extends 
MultiTenantTestBase {
        protected HttpResponse<?> getEntities(Entity entity) {
                String uriStr = MAIN_URI + ":" + monitoringPort + 
WORKER_MAIN_PATH;
 
-               if (entity == Entity.COORDINATOR) {
+               if(entity == Entity.COORDINATOR) {
                        uriStr = MAIN_URI + ":" + monitoringPort + 
COORDINATOR_MAIN_PATH;
                }
 
-               if (entity == Entity.STATISTICS) {
+               if(entity == Entity.STATISTICS) {
                        uriStr = MAIN_URI + ":" + monitoringPort + 
STATISTICS_MAIN_PATH + "/1";
                }
 
                try {
                        var client = HttpClient.newHttpClient();
-                       var request = HttpRequest.newBuilder(URI.create(uriStr))
-                               .header("accept", "application/json")
-                               .GET().build();
+                       var request = 
HttpRequest.newBuilder(URI.create(uriStr)).header("accept", 
"application/json").GET().build();
                        return client.send(request, 
HttpResponse.BodyHandlers.ofString());
                }
-               catch (IOException | InterruptedException e) {
+               catch(IOException | InterruptedException e) {
                        throw new RuntimeException(e);
                }
        }

Reply via email to