incubator-bigtop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1371457 - in /incubator/bigtop/branches/branch-0.4: bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/ bigtop-tests/test-artifacts/hive/src/main/groovy/org/apache/bigtop/itest/hivesmoke/
Date Thu, 09 Aug 2012 20:35:06 GMT
Author: rvs
Date: Thu Aug  9 20:35:06 2012
New Revision: 1371457

URL: http://svn.apache.org/viewvc?rev=1371457&view=rev
Log:
BIGTOP-685. Provide a way to specify the parameters expected by a test (Wing Yew Poon via
Bruno Mahé)

Added:
    incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/ParameterSetter.java
    incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Parameters.java
    incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Property.java
    incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Variable.java
Modified:
    incubator/bigtop/branches/branch-0.4/bigtop-tests/test-artifacts/hive/src/main/groovy/org/apache/bigtop/itest/hivesmoke/TestJdbcDriver.java

Added: incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/ParameterSetter.java
URL: http://svn.apache.org/viewvc/incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/ParameterSetter.java?rev=1371457&view=auto
==============================================================================
--- incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/ParameterSetter.java
(added)
+++ incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/ParameterSetter.java
Thu Aug  9 20:35:06 2012
@@ -0,0 +1,75 @@
+/**
+ * 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.bigtop.itest;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+   Class containing utility methods for test classes to use (in a static
+   setup method) for obtaining the values of parameters passed in via
+   environment variables or system properties. The parameters are obtained
+   by introspecting the {@link org.apache.bigtop.itest.Parameters [Parameters]}
+   annotation of the test class.
+ */
+public class ParameterSetter {
+
+  public static void setEnv(Class target, String[] fieldNames)
+      throws NoSuchFieldException, IllegalAccessException {
+    Parameters params = (Parameters) target.getAnnotation(Parameters.class);
+    Variable[] vars = params.env();
+    assert vars.length == fieldNames.length;
+    for (int i = 0; i < vars.length; i++) {
+      Variable var = vars[i];
+      Field field = target.getField(fieldNames[i]);
+      String value = System.getenv(var.name());
+      if (value == null && var.required()) {
+	assertNotNull(var.name() + " is not set", value);
+      }
+      field.set(target, value);
+    }
+  }
+
+  public static void setProperties(Class target, String[] fieldNames)
+      throws NoSuchFieldException, IllegalAccessException {
+    Parameters params = (Parameters) target.getAnnotation(Parameters.class);
+    Property[] props = params.properties();
+    assert props.length == fieldNames.length;
+    for (int i = 0; i < props.length; i++) {
+      Property prop = props[i];
+      Field field = target.getField(fieldNames[i]);
+      Object value = null;
+      switch (prop.type()) {
+      case STRING:
+	value = System.getProperty(prop.name(), prop.defaultValue());
+	break;
+      case INT:
+	value = Integer.getInteger(prop.name(), prop.intValue());
+	break;
+      case LONG:
+	value = Long.getLong(prop.name(), prop.longValue());
+	break;
+      case BOOLEAN:
+	value = Boolean.getBoolean(prop.name());
+      }
+      field.set(target, value);
+    }
+  }
+}

Added: incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Parameters.java
URL: http://svn.apache.org/viewvc/incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Parameters.java?rev=1371457&view=auto
==============================================================================
--- incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Parameters.java
(added)
+++ incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Parameters.java
Thu Aug  9 20:35:06 2012
@@ -0,0 +1,35 @@
+/**
+ * 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.bigtop.itest;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Documented
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface Parameters {
+  Variable[] env();
+  Property[] properties();
+}

Added: incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Property.java
URL: http://svn.apache.org/viewvc/incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Property.java?rev=1371457&view=auto
==============================================================================
--- incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Property.java
(added)
+++ incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Property.java
Thu Aug  9 20:35:06 2012
@@ -0,0 +1,38 @@
+/**
+ * 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.bigtop.itest;
+
+/**
+   Specifies a parameter to be passed into a test via a system property.
+   The parameter may be a String, an int, a long, or a boolean. If the type
+   of the parameter is not specified, it defaults to String.
+   A default value (String value, int value, long value) may be specified
+   for the parameter if its type is not boolean; the default value of a
+   boolean parameter is false.
+*/
+public @interface Property {
+  public static enum Type {
+    STRING, INT, LONG, BOOLEAN;
+  }
+  String name();
+  Type type() default Type.STRING;
+  String defaultValue();
+  int intValue();
+  long longValue();
+}

Added: incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Variable.java
URL: http://svn.apache.org/viewvc/incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Variable.java?rev=1371457&view=auto
==============================================================================
--- incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Variable.java
(added)
+++ incubator/bigtop/branches/branch-0.4/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/Variable.java
Thu Aug  9 20:35:06 2012
@@ -0,0 +1,30 @@
+/**
+ * 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.bigtop.itest;
+
+/**
+   Specifies a parameter to be passed into a test via an environment variable.
+   The parameter is a String.
+   By default, the parameter is required. If it is required and a non-null value
+   cannot be found for it, an exception may be thrown.
+*/
+public @interface Variable {
+  String name();
+  boolean required() default true;
+}

Modified: incubator/bigtop/branches/branch-0.4/bigtop-tests/test-artifacts/hive/src/main/groovy/org/apache/bigtop/itest/hivesmoke/TestJdbcDriver.java
URL: http://svn.apache.org/viewvc/incubator/bigtop/branches/branch-0.4/bigtop-tests/test-artifacts/hive/src/main/groovy/org/apache/bigtop/itest/hivesmoke/TestJdbcDriver.java?rev=1371457&r1=1371456&r2=1371457&view=diff
==============================================================================
--- incubator/bigtop/branches/branch-0.4/bigtop-tests/test-artifacts/hive/src/main/groovy/org/apache/bigtop/itest/hivesmoke/TestJdbcDriver.java
(original)
+++ incubator/bigtop/branches/branch-0.4/bigtop-tests/test-artifacts/hive/src/main/groovy/org/apache/bigtop/itest/hivesmoke/TestJdbcDriver.java
Thu Aug  9 20:35:06 2012
@@ -36,8 +36,16 @@ import org.junit.Test;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
 
+import org.apache.bigtop.itest.Parameters;
+import org.apache.bigtop.itest.ParameterSetter;
+import org.apache.bigtop.itest.Property;
 import org.apache.bigtop.itest.shell.Shell;
 
+@Parameters(
+  properties = {
+    @Property(name="hiveserver.startup.wait", type=Property.Type.INT, intValue=1000)
+  },
+  env = {})
 public class TestJdbcDriver {
 
   public static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
@@ -45,10 +53,13 @@ public class TestJdbcDriver {
   public static Shell sh = new Shell("/bin/bash -s");
   public static String testDir = "/tmp/hive-jdbc." + (new Date().getTime());
   public static String hiveserver_pid;
+  public static int hiveserver_startup_wait;
   private Connection con;
 
   @BeforeClass
-  public static void setUp() throws ClassNotFoundException, InterruptedException {
+  public static void setUp() throws ClassNotFoundException, InterruptedException, NoSuchFieldException,
IllegalAccessException {
+    ParameterSetter.setProperties(TestJdbcDriver.class, new String[] {"hiveserver_startup_wait"});
+    System.out.println("hiveserver_startup_wait: " + hiveserver_startup_wait);
     Class.forName(driverName);
     sh.exec("hadoop fs -mkdir " + testDir);
     assertTrue("Could not create test directory", sh.getRet() == 0);
@@ -57,15 +68,7 @@ public class TestJdbcDriver {
     // start hiveserver in background and remember the pid
     sh.exec("(HIVE_PORT=10000 hive --service hiveserver > /dev/null 2>&1 &
echo $! ) 2> /dev/null");
     hiveserver_pid = sh.getOut().get(0);
-    String hiveserver_startup_wait = System.getProperty("hiveserver.startup.wait");
-    int wait;
-    try {
-      wait = Integer.parseInt(hiveserver_startup_wait);
-    }
-    catch (Exception e) {
-      wait = 1000; // default
-    }
-    Thread.sleep(wait); // allow time for hiveserver to be up
+    Thread.sleep(hiveserver_startup_wait); // allow time for hiveserver to be up
   }
 
   @Before



Mime
View raw message