Ejemplo n.º 1
0
	def test_simple(self):
		i = Incoming()
		_ = i.give([[1, 'string1'], [2, 'string2'], [3, 'string3']])
		self.assertEqual(totalSizeOf('string1') * 3, i.getMaxConsumption())

		_ = i.give([[4, 'string4'], [5, 'string5'], [6, 'string6']])
		self.assertEqual(totalSizeOf('string1') * 6, i.getMaxConsumption())
Ejemplo n.º 2
0
	def test_repr(self):
		q = Queue()
		self.assertEqual('<Queue at 0x%x with 0 item(s), counter=#-1, '
			'size=0>' % (id(q),), repr(q))

		q.extend(['a', 'b'])
		self.assertEqual('<Queue at 0x%x with 2 item(s), counter=#1, '
			'size=%d>' % (id(q), totalSizeOf('a') * 2), repr(q))

		q.handleSACK(SACK(0, ()))
		self.assertEqual('<Queue at 0x%x with 1 item(s), counter=#1, '
			'size=%d>' % (id(q), totalSizeOf('a')), repr(q))
Ejemplo n.º 3
0
	def test_StringFragmentConvertToStr(self):
		"""
		L{StringFragment}s are converted to C{window._wasSF}s if they are
		undeliverable inside L{Incoming}.
		"""
		i = Incoming()
		s = _wasSF("helloworld" * 100)
		sf = StringFragment(s, 0, len(s))
		i.give([[1, sf]])
		self.assertEqual(totalSizeOf(s), i.getMaxConsumption())
Ejemplo n.º 4
0
	def test_getMaxConsumption(self):
		"""
		The size of the Queue increases when we extend it or append to it,
		and decreases when we give it an ackNumber or sackNum that
		causes it to remove items.
		"""
		q = Queue()
		self.assertEqual(0, q.getMaxConsumption())
		q.extend(['a', 'b'])
		self.assertEqual(totalSizeOf('a') * 2, q.getMaxConsumption())
		q.handleSACK(SACK(0, ()))
		self.assertEqual(totalSizeOf('a'), q.getMaxConsumption())
		# strange-looking SACK, but it does exercise the code we want to exercise
		q.handleSACK(SACK(0, (1,)))
		self.assertEqual(0, q.getMaxConsumption())
		q.handleSACK(SACK(1, ()))
		self.assertEqual(0, q.getMaxConsumption())
		q.append('cc')
		self.assertEqual(totalSizeOf('cc'), q.getMaxConsumption())
Ejemplo n.º 5
0
	def test_sizeLimit(self):
		stringSize = totalSizeOf('string1')
		i = Incoming()
		self.assertEqual(([], False), i.give([[1, 'string1']], sizeLimit=stringSize * 3))
		self.assertEqual(([], False), i.give([[2, 'string2']], sizeLimit=stringSize * 3))
		self.assertEqual(([], False), i.give([[3, 'string3']], sizeLimit=stringSize * 3))
		self.assertEqual(([], True), i.give([[4, 'string4']], sizeLimit=stringSize * 3))
		self.assertEqual(([], True), i.give([[5, 'string5']], sizeLimit=stringSize * 3))

		# The items we kept giving it past the limit are dropped to the floor
		deliverable, hitLimit = i.give([[0, 'string0']], sizeLimit=stringSize * 3)
		self.assertEqual(['string0', 'string1', 'string2', 'string3'], deliverable)
		self.assertEqual(False, hitLimit)

		self.assertEqual(0, i.getUndeliverableCount())
		self.assertEqual(0, i.getMaxConsumption())