2525ts0 = datetime .datetime (2015 , 1 , 1 , 12 , 0 , 0 )
2626ts1 = ts0 + fiveMins
2727
28+ now = datetime .datetime .utcfromtimestamp (144379690 )
29+ fiveMinsAgo = now - fiveMins
30+ tenMinsAgo = fiveMinsAgo - fiveMins
31+ fifteenMinsAgo = tenMinsAgo - fiveMins
32+ twentyMinsAgo = fifteenMinsAgo - fiveMins
33+ twentyFiveMinsAgo = twentyMinsAgo - fiveMins
34+
35+ codec = RiakPbcCodec ()
36+ nowMsec = codec ._unix_time_millis (now )
37+ tenMinsAgoMsec = codec ._unix_time_millis (tenMinsAgo )
38+ twentyMinsAgoMsec = codec ._unix_time_millis (twentyMinsAgo )
39+
40+ rows = [
41+ ['hash1' , 'user2' , twentyFiveMinsAgo , 'typhoon' , 90.3 ],
42+ ['hash1' , 'user2' , twentyMinsAgo , 'hurricane' , 82.3 ],
43+ ['hash1' , 'user2' , fifteenMinsAgo , 'rain' , 79.0 ],
44+ ['hash1' , 'user2' , fiveMinsAgo , 'wind' , None ],
45+ ['hash1' , 'user2' , now , 'snow' , 20.1 ]
46+ ]
47+
2848
2949@unittest .skipUnless (RUN_TIMESERIES , 'RUN_TIMESERIES is 0' )
3050class TimeseriesUnitTests (unittest .TestCase ):
@@ -169,46 +189,23 @@ class TimeseriesTests(IntegrationTestBase, unittest.TestCase):
169189 @classmethod
170190 def setUpClass (cls ):
171191 super (TimeseriesTests , cls ).setUpClass ()
172- cls .now = datetime .datetime .utcfromtimestamp (144379690 )
173- fiveMinsAgo = cls .now - fiveMins
174- tenMinsAgo = fiveMinsAgo - fiveMins
175- fifteenMinsAgo = tenMinsAgo - fiveMins
176- twentyMinsAgo = fifteenMinsAgo - fiveMins
177- twentyFiveMinsAgo = twentyMinsAgo - fiveMins
178192
179193 client = cls .create_client ()
180194 table = client .table (table_name )
181- rows = [
182- ['hash1' , 'user2' , twentyFiveMinsAgo , 'typhoon' , 90.3 ],
183- ['hash1' , 'user2' , twentyMinsAgo , 'hurricane' , 82.3 ],
184- ['hash1' , 'user2' , fifteenMinsAgo , 'rain' , 79.0 ],
185- ['hash1' , 'user2' , fiveMinsAgo , 'wind' , None ],
186- ['hash1' , 'user2' , cls .now , 'snow' , 20.1 ]
187- ]
188195 ts_obj = table .new (rows )
189196 result = ts_obj .store ()
190197 if not result :
191198 raise AssertionError ("expected success" )
192199 client .close ()
193200
194- codec = RiakPbcCodec ()
195- cls .nowMsec = codec ._unix_time_millis (cls .now )
196- cls .fiveMinsAgo = fiveMinsAgo
197- cls .twentyMinsAgo = twentyMinsAgo
198- cls .twentyFiveMinsAgo = twentyFiveMinsAgo
199- cls .tenMinsAgoMsec = codec ._unix_time_millis (tenMinsAgo )
200- cls .twentyMinsAgoMsec = codec ._unix_time_millis (twentyMinsAgo )
201- cls .numCols = len (rows [0 ])
202- cls .rows = rows
203-
204201 def validate_data (self , ts_obj ):
205202 if ts_obj .columns is not None :
206- self .assertEqual (len (ts_obj .columns ), self . numCols )
203+ self .assertEqual (len (ts_obj .columns ), 5 )
207204 self .assertEqual (len (ts_obj .rows ), 1 )
208205 row = ts_obj .rows [0 ]
209206 self .assertEqual (row [0 ], 'hash1' )
210207 self .assertEqual (row [1 ], 'user2' )
211- self .assertEqual (row [2 ], self . fiveMinsAgo )
208+ self .assertEqual (row [2 ], fiveMinsAgo )
212209 self .assertEqual (row [3 ], 'wind' )
213210 self .assertIsNone (row [4 ])
214211
@@ -233,8 +230,8 @@ def test_query_that_matches_some_data(self):
233230 """
234231 query = fmt .format (
235232 table = table_name ,
236- t1 = self . tenMinsAgoMsec ,
237- t2 = self . nowMsec )
233+ t1 = tenMinsAgoMsec ,
234+ t2 = nowMsec )
238235 ts_obj = self .client .ts_query ('GeoCheckin' , query )
239236 self .validate_data (ts_obj )
240237
@@ -247,12 +244,12 @@ def test_query_that_matches_more_data(self):
247244 """
248245 query = fmt .format (
249246 table = table_name ,
250- t1 = self . twentyMinsAgoMsec ,
251- t2 = self . nowMsec )
247+ t1 = twentyMinsAgoMsec ,
248+ t2 = nowMsec )
252249 ts_obj = self .client .ts_query ('GeoCheckin' , query )
253250 j = 0
254- for i , want in enumerate (self . rows ):
255- if want [2 ] == self . twentyFiveMinsAgo :
251+ for i , want in enumerate (rows ):
252+ if want [2 ] == twentyFiveMinsAgo :
256253 continue
257254 got = ts_obj .rows [j ]
258255 j += 1
@@ -264,13 +261,13 @@ def test_get_with_invalid_key(self):
264261 self .client .ts_get ('GeoCheckin' , key )
265262
266263 def test_get_single_value (self ):
267- key = ['hash1' , 'user2' , self . fiveMinsAgo ]
264+ key = ['hash1' , 'user2' , fiveMinsAgo ]
268265 ts_obj = self .client .ts_get ('GeoCheckin' , key )
269266 self .assertIsNotNone (ts_obj )
270267 self .validate_data (ts_obj )
271268
272269 def test_get_single_value_via_table (self ):
273- key = ['hash1' , 'user2' , self . fiveMinsAgo ]
270+ key = ['hash1' , 'user2' , fiveMinsAgo ]
274271 table = Table (self .client , 'GeoCheckin' )
275272 ts_obj = table .get (key )
276273 self .assertIsNotNone (ts_obj )
@@ -289,10 +286,11 @@ def test_stream_keys(self):
289286 self .assertEqual ('user2' , key [1 ])
290287 # TODO RTS-367 ENABLE
291288 # self.assertIsInstance(key[2], datetime.datetime)
292- self .assertEqual (len (streamed_keys ), 5 )
289+ keylen = len (streamed_keys )
290+ self .assertTrue (keylen == 5 or keylen == 4 )
293291
294292 def test_delete_single_value (self ):
295- key = ['hash1' , 'user2' , self . twentyFiveMinsAgo ]
293+ key = ['hash1' , 'user2' , twentyFiveMinsAgo ]
296294 rslt = self .client .ts_delete ('GeoCheckin' , key )
297295 self .assertTrue (rslt )
298296 ts_obj = self .client .ts_get ('GeoCheckin' , key )
0 commit comments