Example #1
0
    def test_truncate_adds(self):
        u = uuid.uuid1()
        d = reporting.DataBuffer(self.TEST_DIR)

        for i in xrange(0, 20):
            d.add('/test', {
                'uuid': u,
                'Readings': [{
                    'ReadingTime': i,
                    'Reading': i
                }]
            })

        rv = d.read()
        self.assertEqual(len(rv['/test']['Readings']), 10)
        self.assertEqual(rv['/test']['Readings'][0]['Reading'], 0)

        for i in xrange(20, 30):
            d.add('/test', {
                'uuid': u,
                'Readings': [{
                    'ReadingTime': i,
                    'Reading': i
                }]
            })

        rv = d.read()  # should be the next 10 since we overwrite
        self.assertEqual(len(rv['/test']['Readings']), 10)
        self.assertEqual(rv['/test']['Readings'][0]['Reading'], 10)

        d.truncate(
            tspec
        )  # this doesn't do anything b/c we overwrote it in the circular buffer
        rv, tspec = d.read()  # should be the next 10
        self.assertEqual(len(rv['/test']['Readings']), 10)
        self.assertEqual(rv['/test']['Readings'][0]['Reading'], 10)

        d.truncate(tspec)
        rv, tspec = d.read()  # read past the end
        self.assertEqual(len(rv['/test']['Readings']), 10)
        self.assertEqual(rv['/test']['Readings'][0]['Reading'], 20)

        d.truncate(tspec)
        rv, tspec = d.read()  # read past the end
        self.assertEqual(len(rv), 0)
        del d
Example #2
0
 def test_truncate(self):
     u = uuid.uuid1()
     d = reporting.DataBuffer(self.TEST_DIR)
     for i in xrange(0, 20):
         d.add('/test', {
             'uuid': u,
             'Readings': [{
                 'ReadingTime': i,
                 'Reading': i
             }]
         })
     rv = d.read()
     print len(d)
     self.assertEqual(len(rv['/test']['Readings']), 20)
     d.truncate(tspec)
     self.assertEqual(len(d), 19)
     del d
Example #3
0
 def test_maxsize(self):
     u = uuid.uuid1()
     d = reporting.DataBuffer(10)
     for i in xrange(0, 20):
         d.add('/test', {
             'uuid': u,
             'Readings': [{
                 'ReadingTime': i,
                 'Reading': i
             }]
         })
     rv = d.read()
     self.assertEqual(len(rv['/test']['Readings']), 10)
     rv = d.read()
     self.assertEqual(len(rv['/test']['Readings']), 10)
     for i in xrange(10, 20):
         self.assertEqual(rv['/test']['Readings'][i - 10]['ReadingTime'], i)
         self.assertEqual(rv['/test']['Readings'][i - 10]['Reading'], i)
     del d
Example #4
0
    def test_partialread(self):
        u = uuid.uuid1()
        d = reporting.DataBuffer(self.TEST_DIR)

        for i in xrange(0, 20):
            d.add('/test', {
                'uuid': u,
                'Readings': [{
                    'ReadingTime': i,
                    'Reading': i
                }]
            })

        # make sure we don't mutate the object while doing this...
        rv = d.read()
        self.assertEqual(len(rv['/test']['Readings']), 20)
        rv = d.read()
        self.assertEqual(len(rv['/test']['Readings']), 20)
        del d
Example #5
0
 def test_metadata_split(self):
     u = uuid.uuid1()
     d = reporting.DataBuffer(self.TEST_DIR)
     for i in xrange(0, 20):
         d.add('/test', {
             'uuid': u,
             'Readings': [{
                 'ReadingTime': i,
                 'Reading': i
             }]
         })
     d.add('/test', {'uuid': u, 'Metadata': {'Extra': {'foo': 'bar'}}})
     rv = d.read()
     d.truncate()
     for i in xrange(0, 20):
         d.add('/test', {
             'uuid': u,
             'Readings': [{
                 'ReadingTime': i,
                 'Reading': i
             }]
         })
     rv = d.read()
Example #6
0
    def test_onestream(self):
        u = uuid.uuid1()
        d = reporting.DataBuffer(self.TEST_DIR)

        for i in xrange(0, 20):
            d.add('/test', {
                'uuid': u,
                'Readings': [{
                    'ReadingTime': i,
                    'Reading': i
                }]
            })
        rv = d.read()
        self.assertEqual(len(rv), 1)
        self.assertTrue('/test' in rv)
        val = rv['/test']
        self.assertTrue('uuid' in val)
        self.assertTrue('Readings' in val)
        self.assertTrue(val['uuid'] == u)
        self.assertEqual(len(val['Readings']), 20)
        for i in xrange(0, 20):
            self.assertEqual(val['Readings'][i]['ReadingTime'], i)
            self.assertEqual(val['Readings'][i]['Reading'], i)
        del d