Ejemplo n.º 1
0
    def test_scheduling_checkpoint_when_it_is_enabled(self):        
        # mocking
        q = get_queue()
        mywriter = Writer(q)
        mywriter.schedule_checkpoint_writing = MagicMock()

        conf = {'checkpoint_enabled' : True,
                'checkpoint_path' : self.checkpoint_path}
        mywriter.__init__(q, conf=conf)

        mywriter.schedule_checkpoint_writing.assert_called_with()
Ejemplo n.º 2
0
    def test_periodic_scheduling_calling_write_method(self):        
        q = get_queue()
        q.put(Message(content=1))
        conf = {'period' : 1}

        mywriter = Writer(q, conf=conf)
        mywriter.write = MagicMock(return_value=True)
        mywriter.start()

        # waits writer period
        time.sleep(1)

        mywriter.write.assert_called_with(1)
Ejemplo n.º 3
0
    def test_creating_file_if_checkpoint_does_not_exist(self):
        q = get_queue()
        conf = {'checkpoint_enabled' : True,
                'checkpoint_path' : self.checkpoint_path}

        mywriter = Writer(q, conf=conf)

        # after __init__, checkpoint file should be created
        self.assertTrue(os.path.exists(self.checkpoint_path))
Ejemplo n.º 4
0
    def test_default_values_in_initialization(self):
        q = get_queue()

        mywriter  = Writer(q)
        self.assertEqual(None, mywriter.period)
        self.assertEqual(True, mywriter.blockable)
        self.assertEqual(False, mywriter.checkpoint_enabled)
        self.assertEqual(None, mywriter.retry_timeout)
        self.assertEqual(1, mywriter.retry_period)
        self.assertEqual(300, mywriter.health_check_period)
        self.assertEqual(0, mywriter.processed)
        self.assertEqual(0, mywriter.discarded)

        if os.path.exists(self.checkpoint_path):
            os.remove(self.checkpoint_path)
            
        conf = {'checkpoint_enabled' : True,
                'checkpoint_path' : self.checkpoint_path}
        mywriter = Writer(q, conf=conf)
        self.assertEqual(60, mywriter.checkpoint_period)
        self.assertEqual('', mywriter.last_checkpoint)
Ejemplo n.º 5
0
    def test_initialization_calls(self):
        # mocking
        q = get_queue()
        mywriter = Writer(q)
        mywriter.set_conf = MagicMock()
        mywriter.setup = MagicMock()
        mywriter.schedule_tasks = MagicMock()

        conf = {'foo' : 'bar'}
        mywriter.__init__(q, conf=conf)

        # asserting that methods are called
        mywriter.set_conf.assert_called_with(conf)
        mywriter.setup.assert_called_with()
        mywriter.schedule_tasks.assert_called_with()