示例#1
0
	def test_twoRangesMissingThenFill(self):
		i = Incoming()
		self.assertEqual(
			(['string0', 'string1'], False),
			i.give([[0, 'string0'], [1, 'string1'], [4, 'string4'], [6, 'string6']]))
		self.assertEqual(SACK(1, (4, 6)), i.getSACK())
		self.assertEqual(
			(['string2', 'string3', 'string4', 'string5', 'string6'], False),
			i.give([[2, 'string2'], [3, 'string3'], [5, 'string5']]))
		self.assertEqual(SACK(6, ()), i.getSACK())
示例#2
0
	def test_outOfOrder(self):
		i = Incoming()
		# string0 missing
		self.assertEqual(([], False), i.give([[1, 'string1'], [2, 'string2']]))
		self.assertEqual(SACK(-1, (1, 2)), i.getSACK())
		# finally deliver it
		self.assertEqual((['string0', 'string1', 'string2'], False), i.give([[0, 'string0']]))
		# make sure it still works
		self.assertEqual((['string3'], False), i.give([[3, 'string3']]))
		self.assertEqual(SACK(3, ()), i.getSACK())
示例#3
0
	def test_twoRangesMissingAbove9(self):
		"""
		Test that the sackList is sorted by the numeric value of the
		numbers.  This test was ported from Javascript and is not really
		necessary in Python.
		"""
		i = Incoming()
		self.assertEqual(
			(['string0', 'string1'], False),
			i.give([[0, 'string0'], [1, 'string1'], [4, 'string4'], [10, 'string6']]))
		self.assertEqual(SACK(1, (4, 10)), i.getSACK())
示例#4
0
	def test_outOfOrderJustOneCall(self):
		"""
		L{Incoming} handles all the strings even when they're given
		out-of-order in one L{Incoming.give} call.

		You should *not* pass .give unsorted sequences in production code,
		because you may hit the item/size limit.  It will also be slower because
		it must modify a dictionary more frequently.
		"""
		i = Incoming()
		self.assertEqual((['string0', 'string1'], False), i.give([[1, 'string1'], [0, 'string0']]))
		self.assertEqual(SACK(1, ()), i.getSACK())
示例#5
0
文件: mocks.py 项目: ludios/Minerva
class MockServerStream(object):
	streamId = "a stream id of unusual length"

	def __init__(self, clock=None, streamId=None, streamProtocolFactory=None):
		## if streamId is None: # make a random one?
		self._notifications = []
		self.streamId = streamId
		self.streamProtocolFactory = streamProtocolFactory
		self.log = ListLog()
		self._incoming = Incoming()
		self.queue = Queue()
		self._transports = set()
		self.allSeenTransports = []
		self.lastSackSeenByServer = SACK(-1, ())


	def getNew(self):
		return self.log.getNew()


	def sendString(self, string):
		self.log.append(['sendString', string])


	def reset(self, reasonString):
		self.log.append(['reset', reasonString])


	def resetFromPeer(self, reasonString, applicationLevel):
		self.log.append(['resetFromPeer', reasonString, applicationLevel])
		for t in self._transports.copy():
			t.closeGently()


	def stringsReceived(self, transport, strings):
		self.log.append(['stringsReceived', transport, strings])
		self._incoming.give(strings)


	def sackReceived(self, sack):
		"""
		Returns C{True} if SACK was bad, C{False} otherwise.
		"""
		self.log.append(['sackReceived', sack])
		self.lastSackSeenByServer = sack
		return self.queue.handleSACK(sack)


	def transportOnline(self, transport, wantsStrings, succeedsTransport):
		self.allSeenTransports.append(transport)
		self.log.append(['transportOnline', transport, wantsStrings, succeedsTransport])
		assert transport not in self._transports
		self._transports.add(transport)


	def transportOffline(self, transport):
		self.log.append(['transportOffline', transport])
		self._transports.remove(transport)


	def serverShuttingDown(self, transport):
		self.log.append(['serverShuttingDown', transport])


	def pauseProducing(self):
		self.log.append(['pauseProducing'])


	def resumeProducing(self):
		self.log.append(['resumeProducing'])


	def stopProducing(self):
		self.log.append(['stopProducing'])


	def getSACK(self):
		self.log.append(['getSACK'])
		return self._incoming.getSACK()


	def notifyFinish(self):
		"""
		Notify when finishing the request

		@return: A deferred.  The deferred will be triggered when the
		stream is finished -- always with a C{None} value.
		"""
		self.log.append(['notifyFinish'])
		self._notifications.append(defer.Deferred())
		return self._notifications[-1]


	def _pretendFinish(self):
		for d in self._notifications:
			d.callback(None)
		self._notifications = None
示例#6
0
	def test_twoRangesMissing(self):
		i = Incoming()
		self.assertEqual(
			(['string0', 'string1'], False),
			i.give([[0, 'string0'], [1, 'string1'], [4, 'string4'], [6, 'string6']]))
		self.assertEqual(SACK(1, (4, 6)), i.getSACK())
示例#7
0
	def test_itemMissing(self):
		i = Incoming()
		self.assertEqual(
			(['string0', 'string1'], False),
			i.give([[0, 'string0'], [1, 'string1'], [3, 'string3']]))
		self.assertEqual(SACK(1, (3,)), i.getSACK())
示例#8
0
	def test_threeItems(self):
		i = Incoming()
		self.assertEqual(
			(['string0', 'string1', 'string2'], False),
			i.give([[0, 'string0'], [1, 'string1'], [2, 'string2']]))
		self.assertEqual(SACK(2, ()), i.getSACK())
示例#9
0
	def test_SACKNoItems(self):
		i = Incoming()
		self.assertEqual(SACK(-1, ()), i.getSACK())