Esempio n. 1
0
    def test_buffering(self):
        """ Test data collection with buffering. """
        bdc = BufferingDataCollector(gen(), 1)
        reset_time()
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [[123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(False)
        advance_time()

        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [
            [123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]],
            [123456790.0, [[2, 3], [3, 4], [4, 5], [5, 6]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(True)
        advance_time()

        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [[123456791.0, [[3, 4], [4, 5], [5, 6], [6, 7]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(True)
Esempio n. 2
0
    def test_on_disk_limit(self):
        """ Test whether the on-disk file size limiting works. """
        reset_time()
        get_data = gen()

        bdc = BufferingDataCollector(get_data, 1)
        for i in range(0, 700000):
            bdc.collect('')
            bdc.data_sent_callback(False)
            advance_time()

        path = constants.get_buffer_file(get_data.__name__)

        self.assertTrue(os.stat(path).st_size < BufferingDataCollector.FILE_SIZE)
        
        f = open(path, 'r')
        line = f.readline()
        self.assertEquals('[123764780.0, [[307992, 307993], [307993, 307994], [307994, 307995], [307995, 307996]]]\n', line)
        f.close()
Esempio n. 3
0
    def test_get(self):
        """ Test direct data collection. """
        bdc = BufferingDataCollector(gen(), 1)
        reset_time()
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [[123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(True)
        advance_time()

        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [[123456790.0, [[2, 3], [3, 4], [4, 5], [5, 6]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(True)
Esempio n. 4
0
    def test_on_disk_limit(self):
        """ Test whether the on-disk file size limiting works. """
        reset_time()
        get_data = gen()

        bdc = BufferingDataCollector(get_data, 1)
        for i in range(0, 700000):
            bdc.collect('')
            bdc.data_sent_callback(False)
            advance_time()

        path = constants.get_buffer_file(get_data.__name__)

        self.assertTrue(os.stat(path).st_size < BufferingDataCollector.FILE_SIZE)
        
        f = open(path, 'r')
        line = f.readline()
        self.assertEquals('[123764780.0, [[307992, 307993], [307993, 307994], [307994, 307995], [307995, 307996]]]\n', line)
        f.close()
Esempio n. 5
0
    def test_on_disk_buffering(self):
        """ Test data collection with on-disk buffering. """
        get_data = gen()

        bdc = BufferingDataCollector(get_data, 1)
        reset_time()
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [[123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(False)
        advance_time()
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [
            [123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]],
            [123456790.0, [[2, 3], [3, 4], [4, 5], [5, 6]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(False)
        advance_time()
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [
            [123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]],
            [123456790.0, [[2, 3], [3, 4], [4, 5], [5, 6]]],
            [123456791.0, [[3, 4], [4, 5], [5, 6], [6, 7]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(False)
        advance_time()

        bdc2 = BufferingDataCollector(get_data, 1)
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [
            [123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]],
            [123456790.0, [[2, 3], [3, 4], [4, 5], [5, 6]]],
            [123456791.0, [[3, 4], [4, 5], [5, 6], [6, 7]]],
            [123456792.0, [[4, 5], [5, 6], [6, 7] ,[7, 8]]]]},
            bdc2.collect(''))
        bdc.data_sent_callback(True)
        advance_time()

        bdc3 = BufferingDataCollector(get_data, 1)
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [[123456793.0, [[5, 6], [6, 7] ,[7, 8], [8, 9]]]]},
            bdc3.collect(''))
        bdc.data_sent_callback(True)
Esempio n. 6
0
    def test_on_disk_buffering(self):
        """ Test data collection with on-disk buffering. """
        get_data = gen()

        bdc = BufferingDataCollector(get_data, 1)
        reset_time()
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [[123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(False)
        advance_time()
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [
            [123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]],
            [123456790.0, [[2, 3], [3, 4], [4, 5], [5, 6]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(False)
        advance_time()
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [
            [123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]],
            [123456790.0, [[2, 3], [3, 4], [4, 5], [5, 6]]],
            [123456791.0, [[3, 4], [4, 5], [5, 6], [6, 7]]]]},
            bdc.collect(''))
        bdc.data_sent_callback(False)
        advance_time()

        bdc2 = BufferingDataCollector(get_data, 1)
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [
            [123456789.0, [[1, 2], [2, 3], [3, 4], [4, 5]]],
            [123456790.0, [[2, 3], [3, 4], [4, 5], [5, 6]]],
            [123456791.0, [[3, 4], [4, 5], [5, 6], [6, 7]]],
            [123456792.0, [[4, 5], [5, 6], [6, 7] ,[7, 8]]]]},
            bdc2.collect(''))
        bdc.data_sent_callback(True)
        advance_time()

        bdc3 = BufferingDataCollector(get_data, 1)
        self.assertEquals(
            {'timestamp' : time.time(),
            'values' : [[123456793.0, [[5, 6], [6, 7] ,[7, 8], [8, 9]]]]},
            bdc3.collect(''))
        bdc.data_sent_callback(True)