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:46:43 UTC

svn commit: r1131900 - in /incubator/mesos/trunk/src: ./ tests/ tests/external/SampleFrameworks/

Author: benh
Date: Sun Jun  5 05:46:42 2011
New Revision: 1131900

URL: http://svn.apache.org/viewvc?rev=1131900&view=rev
Log:
Added some tests for framework initialization through command line arguments

Added:
    incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkCmdlineParsing.sh   (with props)
    incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidCmdline.sh   (with props)
    incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidEnv.sh   (with props)
Modified:
    incubator/mesos/trunk/src/local.cpp
    incubator/mesos/trunk/src/nexus_local.cpp
    incubator/mesos/trunk/src/nexus_local.hpp
    incubator/mesos/trunk/src/nexus_sched.cpp
    incubator/mesos/trunk/src/test_framework.cpp
    incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp

Modified: incubator/mesos/trunk/src/local.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/local.cpp?rev=1131900&r1=1131899&r2=1131900&view=diff
==============================================================================
--- incubator/mesos/trunk/src/local.cpp (original)
+++ incubator/mesos/trunk/src/local.cpp Sun Jun  5 05:46:42 2011
@@ -34,10 +34,7 @@ int main (int argc, char **argv)
 {
   Configurator conf;
   conf.addOption<int>("port", 'p', "Port to listen on", 50010);
-  conf.addOption<int>("slaves", 's', "Number of slaves", 1);
-  Logging::registerOptions(&conf);
-  Master::registerOptions(&conf);
-  Slave::registerOptions(&conf);
+  local::registerOptions(&conf);
 
   if (argc == 2 && string("--help") == argv[1]) {
     usage(argv[0], conf);

Modified: incubator/mesos/trunk/src/nexus_local.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_local.cpp?rev=1131900&r1=1131899&r2=1131900&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_local.cpp (original)
+++ incubator/mesos/trunk/src/nexus_local.cpp Sun Jun  5 05:46:42 2011
@@ -8,6 +8,7 @@
 
 #include "configurator.hpp"
 #include "foreach.hpp"
+#include "logging.hpp"
 #include "nexus_local.hpp"
 #include "process_based_isolation_module.hpp"
 
@@ -41,6 +42,15 @@ static map<IsolationModule*, Slave*> sla
 static MasterDetector *detector = NULL;
 
 
+void registerOptions(Configurator* conf)
+{
+  conf->addOption<int>("slaves", 's', "Number of slaves", 1);
+  Logging::registerOptions(conf);
+  Master::registerOptions(conf);
+  Slave::registerOptions(conf);
+}
+
+
 PID launch(int numSlaves, int32_t cpus, int64_t mem,
 	   bool initLogging, bool quiet)
 {

Modified: incubator/mesos/trunk/src/nexus_local.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_local.hpp?rev=1131900&r1=1131899&r2=1131900&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_local.hpp (original)
+++ incubator/mesos/trunk/src/nexus_local.hpp Sun Jun  5 05:46:42 2011
@@ -1,15 +1,17 @@
-#ifndef LOCAL_HPP
-#define LOCAL_HPP
+#ifndef __NEXUS_LOCAL_HPP__
+#define __NEXUS_LOCAL_HPP__
 
 // Include the master and slave headers here so that the nexus_sched
 // library will re-compile when they are changed.
 #include "master.hpp"
 #include "slave.hpp"
 
-#include "params.hpp"
+#include "configurator.hpp"
 
 namespace nexus { namespace internal { namespace local {
 
+void registerOptions(Configurator* conf);
+
 PID launch(int numSlaves, int32_t cpus, int64_t mem,
 	   bool initLogging, bool quiet);
 
@@ -19,4 +21,4 @@ void shutdown();
 
 }}}
 
-#endif /* LOCAL_HPP */
+#endif /* __NEXUS_LOCAL_HPP__ */

Modified: incubator/mesos/trunk/src/nexus_sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_sched.cpp?rev=1131900&r1=1131899&r2=1131900&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_sched.cpp (original)
+++ incubator/mesos/trunk/src/nexus_sched.cpp Sun Jun  5 05:46:42 2011
@@ -23,10 +23,11 @@
 #include "fatal.hpp"
 #include "hash_pid.hpp"
 #include "lock.hpp"
+#include "logging.hpp"
+#include "master_detector.hpp"
 #include "messages.hpp"
 #include "nexus_local.hpp"
 #include "nexus_sched.hpp"
-#include "master_detector.hpp"
 
 #define REPLY_TIMEOUT 20
 
@@ -43,6 +44,8 @@ using boost::unordered_map;
 
 using namespace nexus;
 using namespace nexus::internal;
+using nexus::internal::master::Master;
+using nexus::internal::slave::Slave;
 
 
 namespace nexus { namespace internal {
@@ -410,6 +413,7 @@ NexusSchedulerDriver::NexusSchedulerDriv
 					   FrameworkID fid)
 {
   Configurator configurator;
+  local::registerOptions(&configurator);
   Params* conf;
   try {
     conf = new Params(configurator.load());
@@ -428,6 +432,7 @@ NexusSchedulerDriver::NexusSchedulerDriv
 					   FrameworkID fid)
 {
   Configurator configurator;
+  local::registerOptions(&configurator);
   try {
     conf = new Params(configurator.load(params));
   } catch (ConfigurationException& e) {
@@ -445,6 +450,7 @@ NexusSchedulerDriver::NexusSchedulerDriv
 					   FrameworkID fid)
 {
   Configurator configurator;
+  local::registerOptions(&configurator);
   try {
     conf = new Params(configurator.load(argc, argv, false));
   } catch (ConfigurationException& e) {

Modified: incubator/mesos/trunk/src/test_framework.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/test_framework.cpp?rev=1131900&r1=1131899&r2=1131900&view=diff
==============================================================================
--- incubator/mesos/trunk/src/test_framework.cpp (original)
+++ incubator/mesos/trunk/src/test_framework.cpp Sun Jun  5 05:46:42 2011
@@ -70,6 +70,7 @@ void slave_lost(nexus_sched *sched, slav
 void error(nexus_sched *sched, int code, const char *message)
 {
   cout << "Error from Nexus: " << message << endl;
+  exit(code);
 }
 
 
@@ -97,21 +98,36 @@ int main(int argc, char **argv)
   string executor = string(buf) + "/test-executor";
   sched.executor_name = executor.c_str();
 
+  if (argc == 2 && string("--help") == argv[0]) {
+    cerr << "Usage: " << argv[0] << " MASTER_URL" << endl
+         << "  OR   " << argv[0] << " --url=URL [OPTIONS]" << endl;
+    exit(1);
+  }
+
   if (nexus_sched_init(&sched) < 0) {
     perror("nexus_sched_init");
-    return -1;
+    exit(1);
   }
 
-  if (nexus_sched_reg(&sched, argv[1]) < 0) {
-    perror("nexus_sched_reg");
-    return -1;
+  if (argc == 1 && strlen(argv[1]) > 0 && argv[1][0] != '-') {
+    // Initialize with master URL alone
+    if (nexus_sched_reg(&sched, argv[1]) < 0) {
+      perror("nexus_sched_reg");
+      exit(1);
+    }
+  } else {
+    // Initialize by parsing command line
+    if (nexus_sched_reg_with_cmdline(&sched, argc, argv) < 0) {
+      perror("nexus_sched_reg");
+      exit(1);
+    }
   }
 
   nexus_sched_join(&sched);
 
   if (nexus_sched_destroy(&sched) < 0) {
     perror("nexus_sched_destroy");
-    return -1;
+    exit(1);
   }
 
   return 0;

Added: incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkCmdlineParsing.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkCmdlineParsing.sh?rev=1131900&view=auto
==============================================================================
--- incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkCmdlineParsing.sh (added)
+++ incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkCmdlineParsing.sh Sun Jun  5 05:46:42 2011
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# Check that the C test framework executes without crashing (returns 0).
+exec $MESOS_HOME/test-framework --url=local --slaves=3

Propchange: incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkCmdlineParsing.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidCmdline.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidCmdline.sh?rev=1131900&view=auto
==============================================================================
--- incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidCmdline.sh (added)
+++ incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidCmdline.sh Sun Jun  5 05:46:42 2011
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Run the C framework with an invalid slaves parameter (not an integer)
+# and check that it reports the error.
+$MESOS_HOME/test-framework --url=local --slaves=blah > framework.out 2>&1
+if grep -e "Configuration error" framework.out; then
+  exit 0
+else
+  exit 1
+fi

Propchange: incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidCmdline.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidEnv.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidEnv.sh?rev=1131900&view=auto
==============================================================================
--- incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidEnv.sh (added)
+++ incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidEnv.sh Sun Jun  5 05:46:42 2011
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Run the C framework with an invalid slaves parameter (not an integer)
+# set through the environment, and check that it reports the error.
+MESOS_SLAVES=blah $MESOS_HOME/test-framework local > framework.out 2>&1
+if grep -e "Configuration error" framework.out; then
+  exit 0
+else
+  exit 1
+fi

Propchange: incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFrameworkInvalidEnv.sh
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp?rev=1131900&r1=1131899&r2=1131900&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp (original)
+++ incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp Sun Jun  5 05:46:42 2011
@@ -12,3 +12,8 @@ TEST_EXTERNAL(SampleFrameworks, CppFrame
 #ifdef MESOS_HAS_PYTHON
   TEST_EXTERNAL(SampleFrameworks, PythonFramework)
 #endif
+
+// Some tests for command-line and environment configuration
+TEST_EXTERNAL(SampleFrameworks, CFrameworkCmdlineParsing)
+TEST_EXTERNAL(SampleFrameworks, CFrameworkInvalidCmdline)
+TEST_EXTERNAL(SampleFrameworks, CFrameworkInvalidEnv)