def test_creds(self): creds_file = os.environ['EVENTSTREAMS_CREDENTIALS'] with open(creds_file) as data_file: credentials = json.load(data_file) topo = Topology() evstr.subscribe(topo, 'T1', CommonSchema.String, credentials=credentials) evstr.subscribe(topo, 'T1', CommonSchema.String, credentials='eventstreams')
def test_string(self): n = 107 topo = Topology() add_mh_toolkit(topo) add_pip_toolkits(topo) uid = str(uuid.uuid4()) s = topo.source(StringData(uid, n)).as_string() evstr.publish(s, 'MH_TEST') print('test_string') r = evstr.subscribe(topo, 'MH_TEST', CommonSchema.String) r = r.filter(lambda t: t.startswith(uid)) expected = list(StringData(uid, n, False)()) tester = Tester(topo) tester.contents(r, expected) tester.tuple_count(r, n) tester.test(self.test_ctxtype, self.test_config)
def test_string_creds(self): n = 107 creds_file = os.environ['EVENTSTREAMS_CREDENTIALS'] with open(creds_file) as data_file: credentials = json.load(data_file) topo = Topology() add_mh_toolkit(topo) add_pip_toolkits(topo) uid = str(uuid.uuid4()) s = topo.source(StringData(uid, n)).as_string() print('test_string_creds') evstr.publish(s, 'MH_TEST', credentials=credentials) r = evstr.subscribe(topo, 'MH_TEST', CommonSchema.String, credentials=credentials) r = r.filter(lambda t: t.startswith(uid)) expected = list(StringData(uid, n, False)()) tester = Tester(topo) tester.contents(r, expected) tester.tuple_count(r, n) tester.test(self.test_ctxtype, self.test_config)
def test_schemas_ok(self): topo = Topology() evstr.subscribe(topo, 'T1', CommonSchema.String) evstr.subscribe(topo, 'T1', CommonSchema.Json) evstr.subscribe(topo, 'T1', MsgSchema.StringMessage) evstr.subscribe(topo, 'T1', MsgSchema.BinaryMessage) evstr.subscribe(topo, 'T1', MsgSchema.StringMessageMeta) evstr.subscribe(topo, 'T1', MsgSchema.BinaryMessageMeta)
schema=Schema.StringMessage) # assume, we have created an application configuration with name 'messagehub' eventStreamsSink = evst.publish(sensorStream, topic=event_streams_topic, credentials='messagehub', name="SensorPublish") # # the consumer side # # subscribe, create a consumer group with 3 consumers consumerSchema = Schema.StringMessageMeta received = evst.subscribe( topology, topic=event_streams_topic, schema=consumerSchema, group='my_consumer_group', credentials='messagehub', name="SensorSubscribe").set_parallel(3).end_parallel() # start a different parallel region partitioned by message key, # so that each key always goes into the same parallel channel receivedParallelPartitioned = received.parallel( 5, routing=Routing.HASH_PARTITIONED, func=lambda x: string_hashcode(x['key'])) # schema extension, here we use the Python 2.7, 3 way flattenedSchema = consumerSchema.extend( StreamSchema('tuple<rstring sensor_id, float64 value, int64 ts>'))