Example #1
0
    def test_record_increments_the_number_of_samples_taken_with_the_appropriate_frequency(self):
        guesstimator = Guesstimator(redis_host='localhost', random=MockRandom(), environment='test')
        guesstimator.create_sample_set(
            name='100-percent-sample',
            recording_frequency=1.0
        )
        
        guesstimator.record('100-percent-sample')
        guesstimator.record('100-percent-sample')
        self.assertEqual( '2', self.redis.hget( guesstimator._get_hash_key('100-percent-sample'), 'samples_taken' ) )

        guesstimator.create_sample_set(
            name='50-percent-sample',
            recording_frequency=0.5
        )        
        guesstimator.record('50-percent-sample')
        guesstimator.record('50-percent-sample')
        guesstimator.record('50-percent-sample')
        guesstimator.record('50-percent-sample')
        self.assertEqual( '3', self.redis.hget( guesstimator._get_hash_key('50-percent-sample'), 'samples_taken' ) )

        guesstimator.create_sample_set(
            name='25-percent-sample',
            recording_frequency=0.25
        )        
        guesstimator.record('25-percent-sample')
        guesstimator.record('25-percent-sample')
        guesstimator.record('25-percent-sample')
        guesstimator.record('25-percent-sample')
        guesstimator.record('25-percent-sample')
        guesstimator.record('25-percent-sample')
        guesstimator.record('25-percent-sample')
        self.assertEqual( '2', self.redis.hget( guesstimator._get_hash_key('25-percent-sample'), 'samples_taken' ) )
Example #2
0
 def test_create_sample_set_populates_hash_with_parameters_provided(self):
     mock_time = MockTime()
     guesstimator = Guesstimator(redis_host='localhost', time=mock_time, environment='test')
     guesstimator.create_sample_set(
         name='foobar-sample',
         recording_frequency=0.05
     )
     self.assertEqual( '0.05', self.redis.hget( guesstimator._get_hash_key('foobar-sample'), 'recording_frequency' ) )
     self.assertEqual( '0', self.redis.hget( guesstimator._get_hash_key('foobar-sample'), 'samples_taken' ) )
     self.assertEqual( '%s' % mock_time.time, self.redis.hget( guesstimator._get_hash_key('foobar-sample'), 'sample_start_time' ) )
Example #3
0
 def test_reset_resets_timestamp_and_samples_taken(self):
     mock_time = MockTime()
     new_time = 1345576088.71
     guesstimator = Guesstimator(redis_host='localhost', random=MockRandom(), time=mock_time, environment='test')
     
     guesstimator.create_sample_set(
         name='100-percent-sample',
         recording_frequency=1.0
     )
     guesstimator.record('100-percent-sample')
     guesstimator.record('100-percent-sample')
     
     timestamp, samples_taken = guesstimator.read('100-percent-sample')
     self.assertEqual( '2', self.redis.hget( guesstimator._get_hash_key('100-percent-sample'), 'samples_taken' ) )
     self.assertFalse( timestamp == new_time )
     
     mock_time.time = new_time
     guesstimator.reset('100-percent-sample')
     timestamp, samples_taken = guesstimator.read('100-percent-sample')
     
     self.assertEqual( '0', self.redis.hget( guesstimator._get_hash_key('100-percent-sample'), 'samples_taken' ) )
     self.assertEqual( new_time, timestamp )
Example #4
0
 def _delete_guesstimator_data(self):
     guesstimator = Guesstimator(redis_host='localhost', environment='test')
     self.redis.delete( guesstimator._sample_set_list_key )
     for sample_set_name in guesstimator.list_sample_sets():
         self.redis.delete(guesstimator._get_hash_key(sample_set_name))