airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject [1/2] git commit: Fixing the test cases to stop threads properly
Date Thu, 17 Apr 2014 13:11:21 GMT
Repository: airavata
Updated Branches:
  refs/heads/master eeb2c0dc4 -> 9edda85fa


Fixing the test cases to stop threads properly


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/603897c6
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/603897c6
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/603897c6

Branch: refs/heads/master
Commit: 603897c636e7029607ae8c1141150a7b4f2c74a0
Parents: 3330060
Author: lahiru <lahiru@apache.org>
Authored: Thu Apr 17 09:08:14 2014 -0400
Committer: lahiru <lahiru@apache.org>
Committed: Thu Apr 17 09:08:14 2014 -0400

----------------------------------------------------------------------
 .../airavata/job/monitor/MonitorManager.java    | 26 ++++++++++++++++
 .../airavata/job/monitor/AMQPMonitorTest.java   |  5 +++-
 .../QstatMonitorTestWithMyProxyAuth.java        | 15 ++++++++++
 .../client/sample/OrchestratorClientSample.java |  6 ++--
 .../apache/airavata/job/AMQPMonitorTest.java    | 31 ++++++++++++++++----
 .../job/QstatMonitorTestWithMyProxyAuth.java    | 26 ++++++++++++----
 6 files changed, 95 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/603897c6/modules/gfac/gfac-monitor/src/main/java/org/apache/airavata/job/monitor/MonitorManager.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-monitor/src/main/java/org/apache/airavata/job/monitor/MonitorManager.java
b/modules/gfac/gfac-monitor/src/main/java/org/apache/airavata/job/monitor/MonitorManager.java
index 45b7230..8c916ef 100644
--- a/modules/gfac/gfac-monitor/src/main/java/org/apache/airavata/job/monitor/MonitorManager.java
+++ b/modules/gfac/gfac-monitor/src/main/java/org/apache/airavata/job/monitor/MonitorManager.java
@@ -217,6 +217,32 @@ public class MonitorManager {
         }
     }
 
+    /**
+     * This method should be invoked before adding any elements to monitorQueue
+     * In this method we assume that we give higher preference to Push
+     * Monitorig mechanism if there's any configured, otherwise Pull
+     * monitoring will be launched.
+     * Ex: If there's a reasource which doesn't support Push, we have
+     * to live with Pull MOnitoring.
+     *
+     * @throws AiravataMonitorException
+     */
+    public void stopMonitor() throws AiravataMonitorException {
+        //no push monitor is configured so we launch pull monitor
+        int index = 0;
+        if(localJobMonitor != null){
+            (new Thread(localJobMonitor)).stop();
+        }
+
+        for (PullMonitor monitor : pullMonitors) {
+            (new Thread(monitor)).stop();
+        }
+
+        //todo fix this
+        for (PushMonitor monitor : pushMonitors) {
+            (new Thread(monitor)).stop();
+        }
+    }
     /* getter setters for the private variables */
 
     public List<PullMonitor> getPullMonitors() {

http://git-wip-us.apache.org/repos/asf/airavata/blob/603897c6/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/AMQPMonitorTest.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/AMQPMonitorTest.java
b/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/AMQPMonitorTest.java
index 43ec28b..65ab8d0 100644
--- a/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/AMQPMonitorTest.java
+++ b/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/AMQPMonitorTest.java
@@ -49,6 +49,8 @@ public class AMQPMonitorTest {
     private String pbsFilePath;
     private String workingDirectory;
     private HostDescription hostDescription;
+    private String proxyFilePath;
+
 
     @Before
     public void setUp() throws Exception {
@@ -61,6 +63,7 @@ public class AMQPMonitorTest {
         myProxyPassword = System.getProperty("myproxy.password");
         workingDirectory = System.getProperty("gsi.working.directory");
         certificateLocation = System.getProperty("trusted.cert.location");
+        proxyFilePath = System.getProperty("proxy.file.path");
         System.setProperty("connection.name", "xsede");
         if (myProxyUserName == null || myProxyPassword == null || workingDirectory == null)
{
             System.out.println(">>>>>> Please run tests with my proxy user
name and password. " +
@@ -71,7 +74,7 @@ public class AMQPMonitorTest {
         monitorManager = new MonitorManager();
         AMQPMonitor amqpMonitor = new
                 AMQPMonitor(monitorManager.getMonitorPublisher(),
-                monitorManager.getPushQueue(), monitorManager.getFinishQueue(),"/Users/lahirugunathilake/Downloads/x509up_u503876","xsede",
+                monitorManager.getPushQueue(), monitorManager.getFinishQueue(),proxyFilePath,"xsede",
                 Arrays.asList("info1.dyn.teragrid.org,info2.dyn.teragrid.org".split(",")));
         try {
             monitorManager.addPushMonitor(amqpMonitor);

http://git-wip-us.apache.org/repos/asf/airavata/blob/603897c6/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/QstatMonitorTestWithMyProxyAuth.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/QstatMonitorTestWithMyProxyAuth.java
b/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/QstatMonitorTestWithMyProxyAuth.java
index 53abae3..f8360ba 100644
--- a/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/QstatMonitorTestWithMyProxyAuth.java
+++ b/modules/gfac/gfac-monitor/src/test/java/org/apache/airavata/job/monitor/QstatMonitorTestWithMyProxyAuth.java
@@ -20,6 +20,7 @@
 */
 package org.apache.airavata.job.monitor;
 
+import com.google.common.eventbus.Subscribe;
 import org.apache.airavata.commons.gfac.type.HostDescription;
 import org.apache.airavata.gsi.ssh.api.Cluster;
 import org.apache.airavata.gsi.ssh.api.SSHApiException;
@@ -31,8 +32,10 @@ import org.apache.airavata.gsi.ssh.impl.authentication.MyProxyAuthenticationInfo
 import org.apache.airavata.gsi.ssh.util.CommonUtils;
 import org.apache.airavata.job.monitor.exception.AiravataMonitorException;
 import org.apache.airavata.job.monitor.impl.pull.qstat.QstatMonitor;
+import org.apache.airavata.job.monitor.state.JobStatus;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.schemas.gfac.GsisshHostType;
+import org.junit.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
@@ -71,6 +74,8 @@ public class QstatMonitorTestWithMyProxyAuth {
         monitorManager = new MonitorManager(RegistryFactory.getLoggingRegistry());
         QstatMonitor qstatMonitor = new
                 QstatMonitor(monitorManager.getPullQueue(), monitorManager.getMonitorPublisher());
+
+        monitorManager.getMonitorPublisher().registerListener(this);
         try {
             monitorManager.addPullMonitor(qstatMonitor);
             monitorManager.launchMonitor();
@@ -147,4 +152,14 @@ public class QstatMonitorTestWithMyProxyAuth {
             e.printStackTrace();
         }
     }
+
+    @Subscribe
+    public void testCaseShutDown(JobStatus status) {
+        Assert.assertNotNull(status.getState());
+        try {
+            monitorManager.stopMonitor();
+        } catch (AiravataMonitorException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/603897c6/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
b/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
index 3a5fc55..abde87a 100644
--- a/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
+++ b/modules/orchestrator/orchestrator-client-sdks/src/main/java/org/apache/airavata/orchestrator/client/sample/OrchestratorClientSample.java
@@ -116,13 +116,13 @@ public class OrchestratorClientSample {
                     try {
                         expId = (String) registry.add(ParentDataType.EXPERIMENT, simpleExperiment);
                     } catch (Exception e) {
-                        e.printStackTrace();  //To change body of catch statement use File
| Settings | File Templates.
+                        e.printStackTrace();
                     }
 
                     try {
                         orchestratorClient.launchExperiment(expId);
                     } catch (TException e) {
-                        e.printStackTrace();  //To change body of catch statement use File
| Settings | File Templates.
+                        e.printStackTrace();
                     }
                 }
             };
@@ -130,7 +130,7 @@ public class OrchestratorClientSample {
             try {
                 thread.join();
             } catch (InterruptedException e) {
-                e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+                e.printStackTrace();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/603897c6/tools/job-monitor/src/test/java/org/apache/airavata/job/AMQPMonitorTest.java
----------------------------------------------------------------------
diff --git a/tools/job-monitor/src/test/java/org/apache/airavata/job/AMQPMonitorTest.java
b/tools/job-monitor/src/test/java/org/apache/airavata/job/AMQPMonitorTest.java
index 0452c35..aa42a9d 100644
--- a/tools/job-monitor/src/test/java/org/apache/airavata/job/AMQPMonitorTest.java
+++ b/tools/job-monitor/src/test/java/org/apache/airavata/job/AMQPMonitorTest.java
@@ -21,6 +21,7 @@
 package org.apache.airavata.job;
 
 import com.google.common.eventbus.EventBus;
+import com.google.common.eventbus.Subscribe;
 import org.apache.airavata.commons.gfac.type.HostDescription;
 import org.apache.airavata.gsi.ssh.api.Cluster;
 import org.apache.airavata.gsi.ssh.api.SSHApiException;
@@ -34,10 +35,13 @@ import org.apache.airavata.job.monitor.UserMonitorData;
 import org.apache.airavata.job.monitor.event.MonitorPublisher;
 import org.apache.airavata.job.monitor.exception.AiravataMonitorException;
 import org.apache.airavata.job.monitor.impl.push.amqp.AMQPMonitor;
+import org.apache.airavata.job.monitor.state.JobStatus;
 import org.apache.airavata.schemas.gfac.GsisshHostType;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import javax.validation.constraints.AssertTrue;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -58,6 +62,7 @@ public class AMQPMonitorTest {
     private BlockingQueue<MonitorID> finishQueue;
     private BlockingQueue<MonitorID> pushQueue;
     private Thread pushThread;
+    private String proxyFilePath;
     @Before
     public void setUp() throws Exception {
 //        System.setProperty("myproxy.username", "ogce");
@@ -65,10 +70,12 @@ public class AMQPMonitorTest {
 //        System.setProperty("basedir", "/Users/lahirugunathilake/work/airavata/sandbox/gsissh");
 //        System.setProperty("gsi.working.directory", "/home/ogce");
 //        System.setProperty("trusted.cert.location", "/Users/lahirugunathilake/Downloads/certificates");
+//        System.setProperty("proxy.file.path", "/Users/lahirugunathilake/Downloads/x509up_u503876");
         myProxyUserName = System.getProperty("myproxy.username");
         myProxyPassword = System.getProperty("myproxy.password");
         workingDirectory = System.getProperty("gsi.working.directory");
         certificateLocation = System.getProperty("trusted.cert.location");
+        proxyFilePath = System.getProperty("proxy.file.path");
         System.setProperty("connection.name", "xsede");
         if (myProxyUserName == null || myProxyPassword == null || workingDirectory == null)
{
             System.out.println(">>>>>> Please run tests with my proxy user
name and password. " +
@@ -80,9 +87,10 @@ public class AMQPMonitorTest {
         pushQueue = new LinkedBlockingQueue<MonitorID>();
         finishQueue = new LinkedBlockingQueue<MonitorID>();
 
+
         AMQPMonitor amqpMonitor = new
                 AMQPMonitor(monitorPublisher,
-                pushQueue, finishQueue,"/Users/lahirugunathilake/Downloads/x509up_u503876","xsede",
+                pushQueue, finishQueue,proxyFilePath,"xsede",
                 Arrays.asList("info1.dyn.teragrid.org,info2.dyn.teragrid.org".split(",")));
         try {
             pushThread = (new Thread(amqpMonitor));
@@ -147,12 +155,25 @@ public class AMQPMonitorTest {
             e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
         }
         try {
-            pushThread.join(5000);
-            Iterator<MonitorID> iterator = pushQueue.iterator();
-            MonitorID next = iterator.next();
-            org.junit.Assert.assertNotNull(next.getStatus());
+            pushThread.join();
         } catch (InterruptedException e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
         }
+        class InnerClassAMQP{
+            @Subscribe
+            private void getStatus(JobStatus status){
+                Assert.assertNotNull(status);
+                pushThread.interrupt();
+            }
+        }
+        monitorPublisher.registerListener(new InnerClassAMQP());
+//        try {
+//            pushThread.join(5000);
+//            Iterator<MonitorID> iterator = pushQueue.iterator();
+//            MonitorID next = iterator.next();
+//            org.junit.Assert.assertNotNull(next.getStatus());
+//        } catch (Exception e) {
+//            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+//        }
     }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/603897c6/tools/job-monitor/src/test/java/org/apache/airavata/job/QstatMonitorTestWithMyProxyAuth.java
----------------------------------------------------------------------
diff --git a/tools/job-monitor/src/test/java/org/apache/airavata/job/QstatMonitorTestWithMyProxyAuth.java
b/tools/job-monitor/src/test/java/org/apache/airavata/job/QstatMonitorTestWithMyProxyAuth.java
index af429a3..c086c65 100644
--- a/tools/job-monitor/src/test/java/org/apache/airavata/job/QstatMonitorTestWithMyProxyAuth.java
+++ b/tools/job-monitor/src/test/java/org/apache/airavata/job/QstatMonitorTestWithMyProxyAuth.java
@@ -21,6 +21,7 @@
 package org.apache.airavata.job;
 
 import com.google.common.eventbus.EventBus;
+import com.google.common.eventbus.Subscribe;
 import org.apache.airavata.commons.gfac.type.HostDescription;
 import org.apache.airavata.gsi.ssh.api.Cluster;
 import org.apache.airavata.gsi.ssh.api.SSHApiException;
@@ -34,7 +35,9 @@ import org.apache.airavata.job.monitor.MonitorID;
 import org.apache.airavata.job.monitor.UserMonitorData;
 import org.apache.airavata.job.monitor.event.MonitorPublisher;
 import org.apache.airavata.job.monitor.impl.pull.qstat.QstatMonitor;
+import org.apache.airavata.job.monitor.state.JobStatus;
 import org.apache.airavata.schemas.gfac.GsisshHostType;
+import org.junit.Assert;
 import org.testng.annotations.Test;
 
 import java.io.File;
@@ -73,6 +76,16 @@ public class QstatMonitorTestWithMyProxyAuth {
         }
 
         monitorPublisher =  new MonitorPublisher(new EventBus());
+        class InnerClassQstat {
+
+            @Subscribe
+            private void getStatus(JobStatus status) {
+                Assert.assertNotNull(status);
+                System.out.println(status.getState().toString());
+                monitorThread.interrupt();
+            }
+        }
+        monitorPublisher.registerListener(this);
         pullQueue = new LinkedBlockingQueue<UserMonitorData>();
         QstatMonitor qstatMonitor = new
                 QstatMonitor(pullQueue, monitorPublisher);
@@ -140,13 +153,16 @@ public class QstatMonitorTestWithMyProxyAuth {
             }
         }
         try {
-            monitorThread.join(5000);
-            Iterator<UserMonitorData> iterator = pullQueue.iterator();
-            UserMonitorData next = iterator.next();
-            MonitorID monitorID = next.getHostMonitorData().get(0).getMonitorIDs().get(0);
-            org.junit.Assert.assertNotNull(monitorID.getStatus());
+
+            monitorThread.join();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
+
+    @Subscribe
+    public void testCaseShutDown(JobStatus status) {
+        Assert.assertNotNull(status.getState());
+        monitorThread.stop();
+    }
 }


Mime
View raw message