You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by bo...@apache.org on 2018/06/01 13:27:43 UTC

[1/2] storm git commit: STORM-3087: Make FluxBuilder.canInvokeWithArgs check whether the actual argument type is assignable to Number before deciding that a method with a primitive parameter can be invoked

Repository: storm
Updated Branches:
  refs/heads/master 3356f1f76 -> 0bc4e26d1


STORM-3087: Make FluxBuilder.canInvokeWithArgs check whether the actual argument type is assignable to Number before deciding that a method with a primitive parameter can be invoked


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/1ebdf301
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/1ebdf301
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/1ebdf301

Branch: refs/heads/master
Commit: 1ebdf301edbd3bac1ff9416d971ee6e7738891ce
Parents: 64af629
Author: Stig Rohde Døssing <sr...@apache.org>
Authored: Mon May 28 22:47:15 2018 +0200
Committer: Stig Rohde Døssing <sr...@apache.org>
Committed: Mon May 28 22:48:33 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/storm/flux/FluxBuilder.java |  6 ++-
 .../java/org/apache/storm/flux/TCKTest.java     | 39 +++++++++++---
 .../org/apache/storm/flux/test/TestBolt.java    |  4 ++
 .../configs/bad_static_factory_test.yaml        | 56 ++++++++++++++++++++
 4 files changed, 96 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/1ebdf301/flux/flux-core/src/main/java/org/apache/storm/flux/FluxBuilder.java
----------------------------------------------------------------------
diff --git a/flux/flux-core/src/main/java/org/apache/storm/flux/FluxBuilder.java b/flux/flux-core/src/main/java/org/apache/storm/flux/FluxBuilder.java
index e511add..3e5fbe0 100644
--- a/flux/flux-core/src/main/java/org/apache/storm/flux/FluxBuilder.java
+++ b/flux/flux-core/src/main/java/org/apache/storm/flux/FluxBuilder.java
@@ -557,7 +557,7 @@ public class FluxBuilder {
         for (Method method : methods) {
             Class[] paramClasses = method.getParameterTypes();
             if (paramClasses.length == args.size() && method.getName().equals(methodName)) {
-                LOG.debug("found constructor with same number of args..");
+                LOG.debug("found method with same number of args.");
                 boolean invokable = false;
                 if (args.size() == 0) {
                     // it's a method with zero args
@@ -698,6 +698,10 @@ public class FluxBuilder {
                 LOG.debug("Yes, assignment is possible.");
             } else if (isPrimitiveNumber(paramType) || Number.class.isAssignableFrom(paramType)
                     && Number.class.isAssignableFrom(objectType)) {
+                LOG.debug("Param is a number, checking whether argument can be coerced");
+                if (!Number.class.isAssignableFrom(objectType)) {
+                    return false;
+                }
                 LOG.debug("Yes, assignment is possible.");
             } else if (paramType.isEnum() && objectType.equals(String.class)) {
                 LOG.debug("Yes, will convert a String to enum");

http://git-wip-us.apache.org/repos/asf/storm/blob/1ebdf301/flux/flux-core/src/test/java/org/apache/storm/flux/TCKTest.java
----------------------------------------------------------------------
diff --git a/flux/flux-core/src/test/java/org/apache/storm/flux/TCKTest.java b/flux/flux-core/src/test/java/org/apache/storm/flux/TCKTest.java
index 4d1b220..90613c9 100644
--- a/flux/flux-core/src/test/java/org/apache/storm/flux/TCKTest.java
+++ b/flux/flux-core/src/test/java/org/apache/storm/flux/TCKTest.java
@@ -31,8 +31,14 @@ import static org.junit.Assert.*;
 
 import java.util.Collections;
 import java.util.Properties;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
 
 public class TCKTest {
+    
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+    
     @Test
     public void testTCK() throws Exception {
         TopologyDef topologyDef = FluxParser.parseResource("/configs/tck.yaml", false, true, null, false);
@@ -53,14 +59,16 @@ public class TCKTest {
         topology.validate();
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testBadShellComponents() throws Exception {
         TopologyDef topologyDef = FluxParser.parseResource("/configs/bad_shell_test.yaml", false, true, null, false);
         Config conf = FluxBuilder.buildConfig(topologyDef);
         ExecutionContext context = new ExecutionContext(topologyDef, conf);
-        StormTopology topology = FluxBuilder.buildTopology(context);
-        assertNotNull(topology);
-        topology.validate();
+        
+        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expectMessage("Unable to find configuration method");
+        
+        FluxBuilder.buildTopology(context);
     }
 
     @Test
@@ -115,14 +123,16 @@ public class TCKTest {
         topology.validate();
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testBadHbase() throws Exception {
         TopologyDef topologyDef = FluxParser.parseResource("/configs/bad_hbase.yaml", false, true, null, false);
         Config conf = FluxBuilder.buildConfig(topologyDef);
         ExecutionContext context = new ExecutionContext(topologyDef, conf);
-        StormTopology topology = FluxBuilder.buildTopology(context);
-        assertNotNull(topology);
-        topology.validate();
+        
+        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expectMessage("Couldn't find a suitable constructor");
+        
+        FluxBuilder.buildTopology(context);
     }
 
     @Test
@@ -266,4 +276,17 @@ public class TCKTest {
                is(context.getTopologyDef().getConfig().get("list.property.target")));
 
     }
+    
+    @Test
+    public void testTopologyWithInvalidStaticFactoryArgument() throws Exception {
+        //STORM-3087.
+        TopologyDef topologyDef = FluxParser.parseResource("/configs/bad_static_factory_test.yaml", false, true, null, false);
+        Config conf = FluxBuilder.buildConfig(topologyDef);
+        ExecutionContext context = new ExecutionContext(topologyDef, conf);
+        
+        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expectMessage("Couldn't find a suitable static method");
+        
+        FluxBuilder.buildTopology(context);
+    }
 }

http://git-wip-us.apache.org/repos/asf/storm/blob/1ebdf301/flux/flux-core/src/test/java/org/apache/storm/flux/test/TestBolt.java
----------------------------------------------------------------------
diff --git a/flux/flux-core/src/test/java/org/apache/storm/flux/test/TestBolt.java b/flux/flux-core/src/test/java/org/apache/storm/flux/test/TestBolt.java
index 373553f..45f0a18 100644
--- a/flux/flux-core/src/test/java/org/apache/storm/flux/test/TestBolt.java
+++ b/flux/flux-core/src/test/java/org/apache/storm/flux/test/TestBolt.java
@@ -148,4 +148,8 @@ public class TestBolt extends BaseBasicBolt {
     public static TestBolt newInstance(TestEnum te){
         return new TestBolt(te);
     }
+    
+    public static TestBolt newLongInstance(long l) {
+        return new TestBolt(l);
+    }
 }

http://git-wip-us.apache.org/repos/asf/storm/blob/1ebdf301/flux/flux-core/src/test/resources/configs/bad_static_factory_test.yaml
----------------------------------------------------------------------
diff --git a/flux/flux-core/src/test/resources/configs/bad_static_factory_test.yaml b/flux/flux-core/src/test/resources/configs/bad_static_factory_test.yaml
new file mode 100644
index 0000000..5f9b9d8
--- /dev/null
+++ b/flux/flux-core/src/test/resources/configs/bad_static_factory_test.yaml
@@ -0,0 +1,56 @@
+# 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.
+---
+name: "yaml-topology"
+
+#
+config:
+  topology.workers: 1
+  # ...
+
+# spout definitions
+spouts:
+  - id: "spout-1"
+    className: "org.apache.storm.testing.TestWordSpout"
+    parallelism: 1
+    # ...
+
+# bolt definitions
+bolts:
+  - id: "bolt-1"
+    className: "org.apache.storm.flux.test.TestBolt"
+    factory: "newLongInstance"
+    factoryArgs:
+      - "This is not a valid parameter, so should trigger an error"
+    parallelism: 1
+#stream definitions
+# stream definitions define connections between spouts and bolts.
+# note that such connections can be cyclical
+streams:
+  - name: "spout-1 --> bolt-1" # name isn't used (placeholder for logging, UI, etc.)
+#    id: "connection-1"
+    from: "spout-1"
+    to: "bolt-1"
+    grouping:
+      type: SHUFFLE
+
+
+
+
+
+
+
+


[2/2] storm git commit: Merge branch 'STORM-3087' of https://github.com/srdo/storm into STORM-3087

Posted by bo...@apache.org.
Merge branch 'STORM-3087' of https://github.com/srdo/storm into STORM-3087

STORM-3087: Make FluxBuilder.canInvokeWithArgs check whether the actual
argument type is assignable to Number before deciding that a method with
a primitive parameter can be invoked.

This clsoes #2695


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/0bc4e26d
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/0bc4e26d
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/0bc4e26d

Branch: refs/heads/master
Commit: 0bc4e26d1897fdc58d6b5ae77142384a1ecc8495
Parents: 3356f1f 1ebdf30
Author: Robert Evans <ev...@yahoo-inc.com>
Authored: Fri Jun 1 08:06:31 2018 -0500
Committer: Robert Evans <ev...@yahoo-inc.com>
Committed: Fri Jun 1 08:06:31 2018 -0500

----------------------------------------------------------------------
 .../java/org/apache/storm/flux/FluxBuilder.java |  6 ++-
 .../java/org/apache/storm/flux/TCKTest.java     | 39 +++++++++++---
 .../org/apache/storm/flux/test/TestBolt.java    |  4 ++
 .../configs/bad_static_factory_test.yaml        | 56 ++++++++++++++++++++
 4 files changed, 96 insertions(+), 9 deletions(-)
----------------------------------------------------------------------