@@ -61,7 +61,7 @@ static SharedStorageBody.SharedStorageBodyResult sharedStorageBody(List<DataStre
61
61
62
62
BOperator bOp = new BOperator ();
63
63
SingleOutputStreamOperator <Long > afterBOp =
64
- data .transform ("b" , TypeInformation .of (Long .class ), bOp );
64
+ afterAOp .transform ("b" , TypeInformation .of (Long .class ), bOp );
65
65
66
66
Map <ItemDescriptor <?>, SharedStorageStreamOperator > ownerMap = new HashMap <>();
67
67
ownerMap .put (SUM , aOp );
@@ -89,7 +89,9 @@ public void testSharedStorage() throws Exception {
89
89
90
90
/** Operator A: add input elements to the shared {@link #SUM}. */
91
91
static class AOperator extends AbstractStreamOperator <Long >
92
- implements OneInputStreamOperator <Long , Long >, SharedStorageStreamOperator {
92
+ implements OneInputStreamOperator <Long , Long >,
93
+ SharedStorageStreamOperator ,
94
+ BoundedOneInput {
93
95
94
96
private final String sharedStorageAccessorID ;
95
97
private SharedStorageContext sharedStorageContext ;
@@ -115,15 +117,18 @@ public void processElement(StreamRecord<Long> element) throws Exception {
115
117
Long currentSum = getter .get (SUM );
116
118
setter .set (SUM , currentSum + element .getValue ());
117
119
});
118
- output .collect (element );
120
+ }
121
+
122
+ @ Override
123
+ public void endInput () throws Exception {
124
+ // Informs BOperator to get the value from shared {@link #SUM}.
125
+ output .collect (new StreamRecord <>(0L ));
119
126
}
120
127
}
121
128
122
129
/** Operator B: when input ends, get the value from shared {@link #SUM}. */
123
130
static class BOperator extends AbstractStreamOperator <Long >
124
- implements OneInputStreamOperator <Long , Long >,
125
- SharedStorageStreamOperator ,
126
- BoundedOneInput {
131
+ implements OneInputStreamOperator <Long , Long >, SharedStorageStreamOperator {
127
132
128
133
private final String sharedStorageAccessorID ;
129
134
private SharedStorageContext sharedStorageContext ;
@@ -143,10 +148,7 @@ public String getSharedStorageAccessorID() {
143
148
}
144
149
145
150
@ Override
146
- public void processElement (StreamRecord <Long > element ) throws Exception {}
147
-
148
- @ Override
149
- public void endInput () throws Exception {
151
+ public void processElement (StreamRecord <Long > element ) throws Exception {
150
152
sharedStorageContext .invoke (
151
153
(getter , setter ) -> {
152
154
output .collect (new StreamRecord <>(getter .get (SUM )));
0 commit comments