def test_get_entries_raises_on_invalid_response(self): json_entries = test_util.entries_to_json(test_util.make_entries(4, 4)) json_entries["entries"][0].pop("leaf_input") client = self.one_shot_client(json_entries) entries = client.get_entries(4, 4) self.assertRaises(log_client.InvalidResponseError, entries.next)
def test_get_entries_raises_on_too_large_response(self): large_response = test_util.entries_to_json(test_util.make_entries( 4, 5)) client = self.one_shot_client(large_response) entries = client.get_entries(4, 4) self.assertRaises(log_client.InvalidResponseError, entries.next)
def test_get_entries_raises_immediately_on_invalid_base64(self): json_entries = test_util.entries_to_json(test_util.make_entries(3, 4)) json_entries["entries"][1]["leaf_input"] = "garbagebase64^^^" client = self.one_shot_client(json_entries) entries = client.get_entries(3, 4) # We shouldn't see anything, even if the first entry appeared valid. self.assertRaises(log_client.InvalidResponseError, entries.next)
def test_get_entries_raises_on_too_large_response(self): large_response = test_util.entries_to_json( test_util.make_entries(4, 5)) client = self.one_shot_client(large_response) entries = client.get_entries(4, 4) self.assertRaises(log_client.InvalidResponseError, entries.next)
def test_get_entries_raises_on_too_large_response(self): large_response = test_util.entries_to_json( test_util.make_entries(4, 5)) client = self.one_shot_client(large_response) consumer = self.get_entries(client, 4, 4) self.assertTrue(consumer.result.check(log_client.InvalidResponseError))
def test_get_entries_raises_on_too_large_response(self): large_response = test_util.entries_to_json(test_util.make_entries( 4, 5)) client = self.one_shot_client(large_response) consumer = self.get_entries(client, 4, 4) self.assertTrue(consumer.result.check(log_client.InvalidResponseError))
def test_get_entries_raises_on_invalid_response(self): json_entries = test_util.entries_to_json(test_util.make_entries(0, 9)) json_entries["entries"][5]["leaf_input"] = "garbagebase64^^^" client = self.one_shot_client(json_entries) consumer = self.get_entries(client, 0, 9) self.assertTrue(consumer.result.check(log_client.InvalidResponseError)) # The entire response should be discarded upon error. self.assertFalse(consumer.received)
def test_get_entries_succedes_after_retry(self): json_entries = test_util.entries_to_json(test_util.make_entries(0, 9)) json_entries["entries"][5]["leaf_input"] = "garbagebase64^^^" client = self.one_shot_client(json_entries) producer = client.get_entries(0, 9) # remove exponential back-off producer._calculate_retry_delay = lambda _: 1 consumer = self.EntryConsumer() d = producer.startProducing(consumer) d.addBoth(consumer.done) # pump retries halfway through (there are actually two delays before # firing requests, so this loop will go only through half of retries) self.pump_get_entries(1, FLAGS.get_entries_max_retries) self.assertFalse(hasattr(consumer, 'result')) json_entries = test_util.entries_to_json(test_util.make_entries(0, 9)) response = self.FakeHandler.make_response(200, "OK", json_content=json_entries) client._handler._agent._responder.get_response.return_value = response self.pump_get_entries(1) self.assertTrue(test_util.verify_entries(consumer.received, 0, 9))
def test_get_entries_use_stored_entries(self): fake_db = self.FakeDB() # if client tries to fetch entries instead of taking them from db, then # he will get 0 - 9 entries. If he uses db then he will get 10 - 19 fake_db.scan_entries = mock.Mock( return_value=test_util.make_entries(10, 19)) client = self.default_client(entries_db=fake_db) consumer = self.get_entries(client, 0, 9) self.assertEqual(len(consumer.received), 10) for i in range(0, 9): self.assertEqual(test_util.make_entry(i + 10), consumer.received[i])
def test_get_entries_use_stored_entries(self): fake_db = self.FakeDB() # if client tries to fetch entries instead of taking them from db, then # he will get 0 - 9 entries. If he uses db then he will get 10 - 19 fake_db.scan_entries = mock.Mock( return_value=test_util.make_entries(10, 19)) client = self.default_client(entries_db=fake_db, reactor_=reactor) consumer = self.get_entries(client, 0, 9) consumer.consumed.addCallback(lambda _: self.assertEqual(len(consumer.received), 10)) consumer.consumed.addCallback(lambda _: [self.assertEqual(test_util.make_entry(i + 10), consumer.received[i]) for i in range(0, 9)])
def test_get_entries_raises_on_too_large_response(self): large_response = test_util.entries_to_json( test_util.make_entries(4, 5)) client = self.one_shot_client(large_response) producer = client.get_entries(4, 4) # remove exponential back-off producer._calculate_retry_delay = lambda _: 1 consumer = self.EntryConsumer() d = producer.startProducing(consumer) d.addBoth(consumer.done) # pump through retries (with retries there are 2 delays per request and # initial delay) self.pump_get_entries(1, FLAGS.get_entries_max_retries * 2 + 1) self.assertTrue(consumer.result.check(log_client.InvalidResponseError))
def test_get_entries_raises_on_invalid_response(self): json_entries = test_util.entries_to_json(test_util.make_entries(0, 9)) json_entries["entries"][5]["leaf_input"] = "garbagebase64^^^" client = self.one_shot_client(json_entries) producer = client.get_entries(0, 9) # remove exponential back-off producer._calculate_retry_delay = lambda _: 1 consumer = self.EntryConsumer() d = producer.startProducing(consumer) d.addBoth(consumer.done) # pump through retries (with retries there are 2 delays per request and # and initial delay) self.pump_get_entries(1, FLAGS.get_entries_max_retries * 2 + 1) self.assertTrue(consumer.result.check(log_client.InvalidResponseError)) # The entire response should be discarded upon error. self.assertFalse(consumer.received)