def test_read_handshake(self):
     handshake_dict = {
         "conf": {
             "topology.message.timeout.secs": 3,
             "topology.tick.tuple.freq.secs": 1,
             "topology.debug": True
         },
         "pidDir": ".",
         "context": {
             "task->component": {
                 "1": "example-spout",
                 "2": "__acker",
                 "3": "example-bolt1",
                 "4": "example-bolt2"
             },
             "taskid": 3,
             # Everything below this line is only available in Storm 0.10.0+
             "componentid": "example-bolt1",
             "stream->target->grouping": {
                 "default": {
                     "example-bolt2": {
                         "type": "SHUFFLE"
                     }
                 }
             },
             "streams": ["default"],
             "stream->outputfields": {"default": ["word"]},
             "source->stream->grouping": {
                 "example-spout": {
                     "default": {
                         "type": "FIELDS",
                         "fields": ["word"]
                     }
                 }
             },
             "source->stream->fields": {
                 "example-spout": {
                     "default": ["word"]
                 }
             }
         }
     }
     pid_dir = handshake_dict['pidDir']
     expected_conf = handshake_dict['conf']
     expected_context = handshake_dict['context']
     inputs = ["{}\n".format(json.dumps(handshake_dict)),
               "end\n"]
     component = Component(input_stream=BytesIO(''.join(inputs).encode('utf-8')),
                           output_stream=BytesIO())
     given_conf, given_context = component.read_handshake()
     pid_path = os.path.join(pid_dir, str(component.pid))
     self.assertTrue(os.path.exists(pid_path))
     os.remove(pid_path)
     self.assertEqual(given_conf, expected_conf)
     self.assertEqual(given_context, expected_context)
     self.assertEqual("{}\nend\n".format(json.dumps({"pid": component.pid})).encode('utf-8'),
                      component.output_stream.buffer.getvalue())
示例#2
0
 def test_read_handshake(self):
     handshake_dict = {
         "conf": {
             "topology.message.timeout.secs": 3,
             "topology.tick.tuple.freq.secs": 1,
             "topology.debug": True
         },
         "pidDir": ".",
         "context": {
             "task->component": {
                 "1": "example-spout",
                 "2": "__acker",
                 "3": "example-bolt1",
                 "4": "example-bolt2"
             },
             "taskid": 3,
             # Everything below this line is only available in Storm 0.11.0+
             "componentid": "example-bolt",
             "stream->target->grouping": {
                 "default": {
                     "example-bolt2": {
                         "type": "SHUFFLE"
                     }
                 }
             },
             "streams": ["default"],
             "stream->outputfields": {
                 "default": ["word"]
             },
             "source->stream->grouping": {
                 "example-spout": {
                     "default": {
                         "type": "FIELDS",
                         "fields": ["word"]
                     }
                 }
             }
         }
     }
     pid_dir = handshake_dict['pidDir']
     expected_conf = handshake_dict['conf']
     expected_context = handshake_dict['context']
     inputs = ["{}\n".format(json.dumps(handshake_dict)), "end\n"]
     component = Component(input_stream=StringIO(''.join(inputs)),
                           output_stream=BytesIO())
     given_conf, given_context = component.read_handshake()
     pid_path = os.path.join(pid_dir, str(component.pid))
     self.assertTrue(os.path.exists(pid_path))
     os.remove(pid_path)
     self.assertEqual(given_conf, expected_conf)
     self.assertEqual(given_context, expected_context)
     self.assertEqual(
         "{}\nend\n".format(json.dumps({"pid":
                                        component.pid})).encode('utf-8'),
         component.output_stream.getvalue())