You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by GitBox <gi...@apache.org> on 2018/12/27 20:28:58 UTC

[GitHub] nwangtw closed pull request #3134: Refactor StreamletShadow class to be more general

nwangtw closed pull request #3134: Refactor StreamletShadow class to be more general
URL: https://github.com/apache/incubator-heron/pull/3134
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/heron/api/src/java/org/apache/heron/streamlet/impl/StreamletImpl.java b/heron/api/src/java/org/apache/heron/streamlet/impl/StreamletImpl.java
index c05c654567..3afa54996e 100644
--- a/heron/api/src/java/org/apache/heron/streamlet/impl/StreamletImpl.java
+++ b/heron/api/src/java/org/apache/heron/streamlet/impl/StreamletImpl.java
@@ -231,9 +231,12 @@ public int getNumPartitions() {
 
     Set<String> availableIds = getAvailableStreamIds();
     if (availableIds.contains(streamId)) {
-      StreamletShadow<R> shadow = new StreamletShadow<R>(this);
-      shadow.setStreamId(streamId);
-      return shadow;
+      return new StreamletShadow<R>(this) {
+        @Override
+        public String getStreamId() {
+          return streamId;
+        }
+      };
     } else {
       throw new RuntimeException(
           String.format("Stream id %s is not available in %s. Available ids are: %s.",
diff --git a/heron/api/src/java/org/apache/heron/streamlet/impl/StreamletShadow.java b/heron/api/src/java/org/apache/heron/streamlet/impl/StreamletShadow.java
index 56d0c64482..fad23ded58 100644
--- a/heron/api/src/java/org/apache/heron/streamlet/impl/StreamletShadow.java
+++ b/heron/api/src/java/org/apache/heron/streamlet/impl/StreamletShadow.java
@@ -53,20 +53,9 @@
  */
 public class StreamletShadow<R> extends StreamletImpl<R> {
   private StreamletImpl<R> real;
-  // Extra properties for a Streamlet object
-  protected String streamId;
 
   public StreamletShadow(StreamletImpl<R> real) {
     this.real = real;
-    this.streamId = real.getStreamId();
-  }
-
-  /**
-   * Sets the stream id of this Streamlet.
-   * @param streamId the stream id for this streamlet.
-   */
-  public void setStreamId(String streamId) {
-    this.streamId = streamId;
   }
 
   /**
@@ -75,7 +64,7 @@ public void setStreamId(String streamId) {
    */
   @Override
   public String getStreamId() {
-    return streamId;
+    return real.getStreamId();
   }
 
   /*
diff --git a/heron/api/tests/java/org/apache/heron/streamlet/impl/StreamletShadowTest.java b/heron/api/tests/java/org/apache/heron/streamlet/impl/StreamletShadowTest.java
index 4cc70d2ada..fbbd803c1a 100644
--- a/heron/api/tests/java/org/apache/heron/streamlet/impl/StreamletShadowTest.java
+++ b/heron/api/tests/java/org/apache/heron/streamlet/impl/StreamletShadowTest.java
@@ -56,13 +56,20 @@ public void testConstruction() {
     assertEquals(shadow.getStreamId(), "real_stream");
 
     // set a different stream id
-    shadow.setStreamId("shadow_stream");
+    StreamletShadow<Double> shadow2 = new StreamletShadow(mockReal) {
+      @Override
+      public String getStreamId() {
+        return "shadow_stream";
+      }
+    };
+    assertEquals(shadow.getName(), "real_name");
+    assertEquals(shadow.getNumPartitions(), 1);
     assertEquals(shadow.getStreamId(), "shadow_stream");
 
     // addChild call should be forwarded to the real object
     verify(mockReal, never()).addChild(mockChild);
     shadow.addChild(mockChild);
-    verify(mockReal, times(1)).addChild(mockChild);
+    shadow2.addChild(mockChild);
+    verify(mockReal, times(2)).addChild(mockChild);
   }
-
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services