You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2011/06/05 07:36:26 UTC

svn commit: r1131813 - in /incubator/mesos/trunk/src: Makefile.in swig/java/TestExceptionExecutor.java swig/java/TestExceptionFramework.java swig/java/test_exception_framework

Author: benh
Date: Sun Jun  5 05:36:25 2011
New Revision: 1131813

URL: http://svn.apache.org/viewvc?rev=1131813&view=rev
Log:
A Java framework that throws an Exception to test Swig JNI patching.

Added:
    incubator/mesos/trunk/src/swig/java/TestExceptionExecutor.java
    incubator/mesos/trunk/src/swig/java/TestExceptionFramework.java
    incubator/mesos/trunk/src/swig/java/test_exception_framework   (with props)
Modified:
    incubator/mesos/trunk/src/Makefile.in

Modified: incubator/mesos/trunk/src/Makefile.in
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/Makefile.in?rev=1131813&r1=1131812&r2=1131813&view=diff
==============================================================================
--- incubator/mesos/trunk/src/Makefile.in (original)
+++ incubator/mesos/trunk/src/Makefile.in Sun Jun  5 05:36:25 2011
@@ -211,7 +211,7 @@ memhog: memhog.cpp $(NEXUS_LIB) third_pa
 memhog-executor: memhog_executor.cpp $(NEXUS_LIB) third_party/libprocess/libprocess.a
 	$(CXX) $(CXXFLAGS) -o $@ $< -L. $(LDFLAGS) -lnexus++ $(LIBS) 
 
-java: $(JAVA_LIB) swig/java/nexus.jar swig/java/TestFramework.class swig/java/TestExecutor.class
+java: $(JAVA_LIB) swig/java/nexus.jar swig/java/TestFramework.class swig/java/TestExecutor.class swig/java/TestExceptionFramework.class swig/java/TestExceptionExecutor.class
 
 python: $(PYTHON_LIB)
 
@@ -243,6 +243,16 @@ ifdef JAVA_HOME
 	$(JAVA_HOME)/bin/javac -cp swig/java/nexus.jar -sourcepath swig/java -d swig/java swig/java/TestExecutor.java
 endif
 
+swig/java/TestExceptionFramework.class: $(JAVA_LIB) swig/java/nexus.jar swig/java/TestExceptionFramework.java
+ifdef JAVA_HOME
+	$(JAVA_HOME)/bin/javac -cp swig/java/nexus.jar -sourcepath swig/java -d swig/java swig/java/TestExceptionFramework.java
+endif
+
+swig/java/TestExceptionExecutor.class: $(JAVA_LIB) swig/java/nexus.jar swig/java/TestExceptionExecutor.java
+ifdef JAVA_HOME
+	$(JAVA_HOME)/bin/javac -cp swig/java/nexus.jar -sourcepath swig/java -d swig/java swig/java/TestExceptionExecutor.java
+endif
+
 $(PYTHON_LIB): swig/nexus.i $(NEXUS_LIB)
 ifdef PYTHON_HEADERS
 	$(SWIG) -c++ -python -threads -I../include -o swig/python/nexus_wrap.cpp -outdir swig/python swig/nexus.i

Added: incubator/mesos/trunk/src/swig/java/TestExceptionExecutor.java
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/swig/java/TestExceptionExecutor.java?rev=1131813&view=auto
==============================================================================
--- incubator/mesos/trunk/src/swig/java/TestExceptionExecutor.java (added)
+++ incubator/mesos/trunk/src/swig/java/TestExceptionExecutor.java Sun Jun  5 05:36:25 2011
@@ -0,0 +1,24 @@
+import java.io.File;
+import nexus.*;
+
+public class TestExceptionExecutor extends Executor {
+  static {
+    System.loadLibrary("nexus");
+  }
+
+  @Override
+  public void launchTask(final ExecutorDriver d, final TaskDescription task) {
+    new Thread() { public void run() {
+      System.out.println("About to throw exception in launchTask");
+      int[] errorArray = {1,2};
+      int myInt = errorArray[2];
+      System.out.println("Running task " + task.getTaskId());
+    }}.start();
+  }
+
+  public static void main(String[] args) throws Exception {
+    TestExceptionExecutor exec = new TestExceptionExecutor();
+    ExecutorDriver driver = new NexusExecutorDriver(exec);
+    driver.run();
+  }
+}

Added: incubator/mesos/trunk/src/swig/java/TestExceptionFramework.java
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/swig/java/TestExceptionFramework.java?rev=1131813&view=auto
==============================================================================
--- incubator/mesos/trunk/src/swig/java/TestExceptionFramework.java (added)
+++ incubator/mesos/trunk/src/swig/java/TestExceptionFramework.java Sun Jun  5 05:36:25 2011
@@ -0,0 +1,90 @@
+import java.io.File;
+import nexus.*;
+
+public class TestExceptionFramework {
+  static {
+    System.loadLibrary("nexus");
+  }
+
+  static class MyScheduler extends Scheduler {
+    int launchedTasks = 0;
+    int finishedTasks = 0;
+    final int totalTasks = 5;
+
+    @Override
+    public String getFrameworkName(SchedulerDriver d) {
+      System.out.println("About to throw exception in getFrameworkName");
+      int[] errorArray = {1,2};
+      int myInt = errorArray[2];
+      return "TestException Framework";
+    }
+
+    @Override
+    public ExecutorInfo getExecutorInfo(SchedulerDriver d) {
+      try {
+        return new ExecutorInfo(
+            new File("./test_executor").getCanonicalPath(),
+            new byte[0]);
+      } catch (Exception e) {
+        e.printStackTrace();
+        System.exit(1);
+        return null;
+      }
+    }
+
+    @Override
+    public void registered(SchedulerDriver d, String fid) {
+      System.out.println("Registered! FID = " + fid);
+    }
+
+    @Override
+    public void resourceOffer(SchedulerDriver d,
+                              String oid,
+                              SlaveOfferVector offers) {
+      System.out.println("Got offer offer " + oid);
+      TaskDescriptionVector tasks = new TaskDescriptionVector();
+      if (launchedTasks < totalTasks) {
+        SlaveOffer offer = offers.get(0);
+        int taskId = launchedTasks++;
+        StringMap taskParams = new StringMap();
+        taskParams.set("cpus", "1");
+        taskParams.set("mem", "134217728");
+        System.out.println("Launching task " + taskId);
+        tasks.add(new TaskDescription(launchedTasks,
+                                      offer.getSlaveId(),
+                                      "task " + taskId,
+                                      taskParams,
+                                      new byte[0]));
+	launchedTasks++;
+      }
+      StringMap params = new StringMap();
+      params.set("timeout", "1");
+      d.replyToOffer(oid, tasks, params);
+    }
+
+    @Override
+    public void statusUpdate(SchedulerDriver d, TaskStatus status) {
+      System.out.println("Status update: task " + status.getTaskId() +
+                         " is in state " + status.getState());
+      if (status.getState() == TaskState.TASK_FINISHED) {
+        finishedTasks++;
+        System.out.println("Finished tasks: " + finishedTasks);
+        if (finishedTasks == totalTasks)
+          d.stop();
+      }
+    }
+
+    @Override
+    public void error(SchedulerDriver d, int code, String message) {
+      System.out.println("Error: " + message);
+    }
+  }
+
+  public static void main(String[] args) throws Exception {
+    new NexusSchedulerDriver(new MyScheduler(), args[0]).run();
+    // TODO: Java should just exit here, and it does so on Linux, but
+    // it doesn't on OS X. We should figure out why. It may have to do
+    // with the libprocess threads being around and not being marked
+    // as daemon threads by the JVM.
+  }
+}

Added: incubator/mesos/trunk/src/swig/java/test_exception_framework
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/swig/java/test_exception_framework?rev=1131813&view=auto
==============================================================================
--- incubator/mesos/trunk/src/swig/java/test_exception_framework (added)
+++ incubator/mesos/trunk/src/swig/java/test_exception_framework Sun Jun  5 05:36:25 2011
@@ -0,0 +1,4 @@
+#!/bin/sh
+FWDIR=`dirname $0`
+cd $FWDIR
+exec java -cp .:nexus.jar -Djava.library.path=. TestExceptionFramework $@

Propchange: incubator/mesos/trunk/src/swig/java/test_exception_framework
------------------------------------------------------------------------------
    svn:executable = *