@@ -79,11 +79,10 @@ def graph(count: int):
79
79
}
80
80
81
81
topic = f"test.metadata.{ os .getpid ()} "
82
- _precreate_topic (topic )
83
82
subKey = "foo"
84
83
pubKey = ["mapped_a" , "mapped_b" , "mapped_c" ]
85
84
86
- c = csp .count (csp .timer (timedelta (seconds = 0.1 )))
85
+ c = csp .count (csp .timer (timedelta (seconds = 0.5 )))
87
86
t = csp .sample (c , csp .const ("foo" ))
88
87
89
88
pubStruct = MetaPubData .collectts (
@@ -104,22 +103,23 @@ def graph(count: int):
104
103
)
105
104
106
105
csp .add_graph_output ("sub_data" , sub_data )
107
- # csp.print('sub', sub_data)
106
+ csp .print ('sub' , sub_data )
108
107
# Wait for at least count ticks and until we get a live tick
109
- done_flag = csp .count (sub_data ) >= count
110
- done_flag = csp .and_ (done_flag , sub_data .mapped_live is True )
108
+ done_flag = csp .and_ (csp .count (sub_data ) >= count , sub_data .mapped_live == True ) # noqa: E712
111
109
stop = csp .filter (done_flag , done_flag )
112
110
csp .stop_engine (stop )
113
111
114
- count = 5
115
- results = csp .run (graph , count , starttime = datetime .utcnow (), endtime = timedelta (seconds = 30 ), realtime = True )
112
+ results = csp .run (graph , 5 , starttime = datetime .utcnow (), endtime = timedelta (seconds = 20 ), realtime = True )
116
113
assert len (results ["sub_data" ]) >= 5
117
114
print (results )
118
115
for result in results ["sub_data" ]:
119
116
assert result [1 ].mapped_partition >= 0
120
117
assert result [1 ].mapped_offset >= 0
121
118
assert result [1 ].mapped_live is not None
122
119
assert result [1 ].mapped_timestamp < datetime .utcnow ()
120
+ # first record should be non live
121
+ assert results ["sub_data" ][0 ][1 ].mapped_live is False
122
+ # last record should be live
123
123
assert results ["sub_data" ][- 1 ][1 ].mapped_live
124
124
125
125
@pytest .mark .skipif (not os .environ .get ("CSP_TEST_KAFKA" ), reason = "Skipping kafka adapter tests" )
@@ -145,8 +145,7 @@ def graph(symbols: list, count: int):
145
145
struct_field_map = {"b" : "b2" , "i" : "i2" , "d" : "d2" , "s" : "s2" , "dt" : "dt2" }
146
146
147
147
done_flags = []
148
- topic = f"mktdata.{ os .getpid ()} "
149
- _precreate_topic (topic )
148
+
150
149
for symbol in symbols :
151
150
kafkaadapter .publish (msg_mapper , topic , symbol , b , field_map = "b" )
152
151
kafkaadapter .publish (msg_mapper , topic , symbol , i , field_map = "i" )
@@ -183,10 +182,12 @@ def graph(symbols: list, count: int):
183
182
stop = csp .filter (stop , stop )
184
183
csp .stop_engine (stop )
185
184
185
+ topic = f"mktdata.{ os .getpid ()} "
186
+ _precreate_topic (topic )
186
187
symbols = ["AAPL" , "MSFT" ]
187
188
count = 100
188
189
results = csp .run (
189
- graph , symbols , count , starttime = datetime .utcnow (), endtime = timedelta (seconds = 30 ), realtime = True
190
+ graph , symbols , count , starttime = datetime .utcnow (), endtime = timedelta (seconds = 10 ), realtime = True
190
191
)
191
192
for symbol in symbols :
192
193
pub = results [f"pall_{ symbol } " ]
@@ -212,7 +213,7 @@ def pub_graph():
212
213
csp .stop_engine (stop )
213
214
# csp.print('pub', struct)
214
215
215
- csp .run (pub_graph , starttime = datetime .utcnow (), endtime = timedelta (seconds = 30 ), realtime = True )
216
+ csp .run (pub_graph , starttime = datetime .utcnow (), endtime = timedelta (seconds = 10 ), realtime = True )
216
217
217
218
# grab start/end times
218
219
def get_times_graph ():
@@ -232,7 +233,7 @@ def get_times_graph():
232
233
# csp.print('sub', data)
233
234
# csp.print('status', kafkaadapter.status())
234
235
235
- all_data = csp .run (get_times_graph , starttime = datetime .utcnow (), endtime = timedelta (seconds = 30 ), realtime = True )[
236
+ all_data = csp .run (get_times_graph , starttime = datetime .utcnow (), endtime = timedelta (seconds = 10 ), realtime = True )[
236
237
"data"
237
238
]
238
239
min_time = all_data [0 ][1 ].dt
@@ -258,7 +259,7 @@ def get_data(start_offset, expected_count):
258
259
KafkaStartOffset .EARLIEST ,
259
260
10 ,
260
261
starttime = datetime .utcnow (),
261
- endtime = timedelta (seconds = 30 ),
262
+ endtime = timedelta (seconds = 10 ),
262
263
realtime = True ,
263
264
)["data" ]
264
265
# print(res)
@@ -276,7 +277,7 @@ def get_data(start_offset, expected_count):
276
277
assert len (res ) == 0
277
278
278
279
res = csp .run (
279
- get_data , KafkaStartOffset .START_TIME , 10 , starttime = min_time , endtime = timedelta (seconds = 30 ), realtime = True
280
+ get_data , KafkaStartOffset .START_TIME , 10 , starttime = min_time , endtime = timedelta (seconds = 10 ), realtime = True
280
281
)["data" ]
281
282
assert len (res ) == 10
282
283
@@ -287,12 +288,12 @@ def get_data(start_offset, expected_count):
287
288
stime = all_data [2 ][1 ].dt + timedelta (milliseconds = 1 )
288
289
expected = [x for x in all_data if x [1 ].dt >= stime ]
289
290
res = csp .run (
290
- get_data , stime , len (expected ), starttime = datetime .utcnow (), endtime = timedelta (seconds = 30 ), realtime = True
291
+ get_data , stime , len (expected ), starttime = datetime .utcnow (), endtime = timedelta (seconds = 10 ), realtime = True
291
292
)["data" ]
292
293
assert len (res ) == len (expected )
293
294
294
295
res = csp .run (
295
- get_data , timedelta (seconds = 0 ), len (expected ), starttime = stime , endtime = timedelta (seconds = 30 ), realtime = True
296
+ get_data , timedelta (seconds = 0 ), len (expected ), starttime = stime , endtime = timedelta (seconds = 10 ), realtime = True
296
297
)["data" ]
297
298
assert len (res ) == len (expected )
298
299
@@ -314,8 +315,6 @@ def graph(symbols: list, count: int):
314
315
msg_mapper = RawBytesMessageMapper ()
315
316
316
317
done_flags = []
317
- topic = f"test_str.{ os .getpid ()} "
318
- _precreate_topic (topic )
319
318
for symbol in symbols :
320
319
topic = f"test_str.{ os .getpid ()} "
321
320
kafkaadapter .publish (msg_mapper , topic , symbol , d )
@@ -356,10 +355,13 @@ def graph(symbols: list, count: int):
356
355
stop = csp .filter (stop , stop )
357
356
csp .stop_engine (stop )
358
357
358
+ topic = f"test_str.{ os .getpid ()} "
359
+ _precreate_topic (topic )
360
+
359
361
symbols = ["AAPL" , "MSFT" ]
360
362
count = 10
361
363
results = csp .run (
362
- graph , symbols , count , starttime = datetime .utcnow (), endtime = timedelta (seconds = 30 ), realtime = True
364
+ graph , symbols , count , starttime = datetime .utcnow (), endtime = timedelta (seconds = 10 ), realtime = True
363
365
)
364
366
# print(results)
365
367
for symbol in symbols :
0 commit comments