Updated Branches:
  refs/heads/master 39010dbc5 -> 527113b40

SAMZA-49: Config.getShort returns a long.


Project: http://git-wip-us.apache.org/repos/asf/incubator-samza/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-samza/commit/527113b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-samza/tree/527113b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-samza/diff/527113b4

Branch: refs/heads/master
Commit: 527113b40b106927b775aaecdf73e5c6fcbcbff9
Parents: 39010db
Author: Garry Turkington <[email protected]>
Authored: Mon Dec 2 11:00:41 2013 -0800
Committer: Jakob Homan <[email protected]>
Committed: Mon Dec 2 11:00:41 2013 -0800

----------------------------------------------------------------------
 .../java/org/apache/samza/config/Config.java    |  4 +-
 .../org/apache/samza/config/TestConfig.java     | 59 ++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-samza/blob/527113b4/samza-api/src/main/java/org/apache/samza/config/Config.java
----------------------------------------------------------------------
diff --git a/samza-api/src/main/java/org/apache/samza/config/Config.java 
b/samza-api/src/main/java/org/apache/samza/config/Config.java
index b2f8805..c42c1c5 100644
--- a/samza-api/src/main/java/org/apache/samza/config/Config.java
+++ b/samza-api/src/main/java/org/apache/samza/config/Config.java
@@ -70,14 +70,14 @@ public abstract class Config implements Map<String, String> 
{
       throw new ConfigException("Missing key " + k + ".");
   }
 
-  public long getShort(String k, short defaultValue) {
+  public short getShort(String k, short defaultValue) {
     if (containsKey(k))
       return Short.parseShort(get(k));
     else
       return defaultValue;
   }
 
-  public long getShort(String k) {
+  public short getShort(String k) {
     if (containsKey(k))
       return Short.parseShort(get(k));
     else

http://git-wip-us.apache.org/repos/asf/incubator-samza/blob/527113b4/samza-api/src/test/java/org/apache/samza/config/TestConfig.java
----------------------------------------------------------------------
diff --git a/samza-api/src/test/java/org/apache/samza/config/TestConfig.java 
b/samza-api/src/test/java/org/apache/samza/config/TestConfig.java
new file mode 100644
index 0000000..e701296
--- /dev/null
+++ b/samza-api/src/test/java/org/apache/samza/config/TestConfig.java
@@ -0,0 +1,59 @@
+/*
+ * 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
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.samza.config;
+
+import org.junit.Assert.* ;
+import org.junit.Test ;
+import java.util.Map ;
+import java.util.HashMap ;
+
+public class TestConfig {
+  // Utility methods to make it easier to tell the class of a primitive via 
overloaded args
+  Class getClass(long l) {
+    return Long.class ;
+  }
+
+  Class getClass(short s) {
+    return Short.class ;
+  }
+
+  @Test
+  public void testgetShortAndLong(){
+    Map<String, String> m = new HashMap<String, String>() { {
+      put("testkey", "11") ;
+    } } ;
+
+    MapConfig mc = new MapConfig(m) ;
+    short defaultShort=0 ;
+    long defaultLong=0 ;
+
+    Class c1 = getClass(mc.getShort("testkey")) ;
+    assert(c1 == Short.class) ;
+
+    Class c2 = getClass(mc.getShort("testkey", defaultShort)) ;
+    assert(c2 == Short.class) ;
+
+    Class c3 = getClass(mc.getLong("testkey")) ;
+    assert(c3 == Long.class) ;
+
+    Class c4 = getClass(mc.getLong("testkey", defaultLong)) ;
+    assert(c4 == Long.class) ;
+  }
+}

Reply via email to