示例#1
0
class TestPhantomReader(object):
    def setup_class(self):
        stop = Event()
        self.multireader = FileMultiReader('yandextank/plugins/Phantom/tests/phout.dat', stop)
        stop.set()

    def teardown_class(self):
        self.multireader.close()

    def test_read_all(self):
        reader = PhantomReader(
            self.multireader.get_file(), cache_size=1024)
        df = pd.DataFrame()
        for chunk in reader:
            df = df.append(chunk)
        assert (len(df) == 200)
        assert (df['interval_real'].mean() == 11000714.0)

    def test_reader_closed(self):
        reader = PhantomReader(self.multireader.get_file(), cache_size=64)
        frames = [i for i in reader]
        result = pd.concat(frames)
        assert len(result) == 200
        assert (result['interval_real'].mean() == 11000714.0)

    def test_reader_us(self):
        with open('yandextank/plugins/Phantom/tests/phout.dat') as f:
            chunk = f.read()
        result = string_to_df_microsec(chunk)
        expected = pd.read_pickle('yandextank/plugins/Phantom/tests/expected_df.dat')
        result['ts'] -= result['ts'][0]
        assert result.equals(expected)
示例#2
0
 def phout_multi_read(self):
     with open(self.filename) as f:
         exp = f.read()
     errors = []
     stop = Event()
     mr = FileMultiReader(self.filename, stop)
     threads = [Thread(target=self.mock_consumer,
                       args=(mr.get_file(i), exp, i, errors),
                       name='Thread-%d' % i) for i in [1000, 4000, 8000]]
     [th.start() for th in threads]
     stop.set()
     [th.join() for th in threads]
     mr.close()
     return errors
示例#3
0
 def phout_multi_readline(self):
     errors = []
     stop = Event()
     mr = FileMultiReader(self.filename, stop)
     threads = [Thread(target=self.mock_complex_consumer,
                       args=(mr.get_file(i), exp, 10, errors),
                       name='Thread-%d' % i) for i, exp in
                [(1000, '\n1543699431'),
                 (4000, '815\t0\t200\n1543699487'),
                 (8000, '10968\t3633\t16\t7283\t36\t7387\t1066\t328\t0\t405\n1543699534')]]
     [th.start() for th in threads]
     stop.set()
     [th.join() for th in threads]
     mr.close()
     return errors
示例#4
0
 def phout_multi_read(self):
     with open(self.filename) as f:
         exp = f.read()
     errors = []
     stop = Event()
     mr = FileMultiReader(self.filename, stop)
     threads = [
         Thread(target=self.mock_consumer,
                args=(mr.get_file(i), exp, i, errors),
                name='Thread-%d' % i) for i in [1000, 4000, 8000]
     ]
     [th.start() for th in threads]
     stop.set()
     [th.join() for th in threads]
     mr.close()
     return errors
示例#5
0
 def phout_multi_readline(self):
     errors = []
     stop = Event()
     mr = FileMultiReader(self.filename, stop)
     threads = [
         Thread(target=self.mock_complex_consumer,
                args=(mr.get_file(i), exp, 10, errors),
                name='Thread-%d' % i) for i, exp in
         [(1000, '\n1543699431'), (4000, '815\t0\t200\n1543699487'),
          (8000,
           '10968\t3633\t16\t7283\t36\t7387\t1066\t328\t0\t405\n1543699534'
           )]
     ]
     [th.start() for th in threads]
     stop.set()
     [th.join() for th in threads]
     mr.close()
     return errors