def test_init_sharedPersistentConnections(self): persistent = True maxConn = 5 timeout = 3600 retry = False factory = ProxyFactory(sharedPool=True, persistent=persistent, maxPersistentPerHost=maxConn, cachedConnectionTimeout=timeout, retryAutomatically=retry) proxy1 = factory.getProxy('') proxy2 = factory.getProxy('') self.assertEqual(id(proxy1.agent._pool), id(proxy2.agent._pool)) self.assertEqual(proxy1.agent._pool.persistent, persistent) self.assertEqual(proxy1.agent._pool.maxPersistentPerHost, maxConn) self.assertEqual(proxy1.agent._pool.cachedConnectionTimeout, timeout) self.assertEqual(proxy1.agent._pool.retryAutomatically, retry) self.assertEqual(proxy2.agent._pool.persistent, persistent) self.assertEqual(proxy2.agent._pool.maxPersistentPerHost, maxConn) self.assertEqual(proxy2.agent._pool.cachedConnectionTimeout, timeout) self.assertEqual(proxy2.agent._pool.retryAutomatically, retry)
def test_getProxy(self): url1 = 'http://fakeurl1' url2 = 'http://fakeurl2' version = jsonrpc.VERSION_2 connectTimeout = 30 cred = UsernamePassword('username', 'password') contextFactory = WebClientContextFactory() factory = ProxyFactory(version=version, connectTimeout=connectTimeout, credentials=cred, contextFactory=contextFactory) proxy1 = factory.getProxy(url1) proxy2 = factory.getProxy(url2) self.assertNotEqual(id(proxy1), id(proxy2)) self.assertNotEqual(id(proxy1.agent._pool), id(proxy2.agent._pool)) self.assertEqual(proxy1.url, url1) self.assertEqual(proxy2.url, url2) self.assertEqual(proxy1.version, version) self.assertEqual(proxy2.version, version) self.assertEqual(proxy1.credentials, cred) self.assertEqual(proxy2.credentials, cred) self.assertEqual(proxy1.agent._connectTimeout, connectTimeout) self.assertEqual(proxy2.agent._connectTimeout, connectTimeout)
def test_init(self): factory = ProxyFactory() proxy = factory.getProxy('') self.assertEqual(proxy.version, jsonrpc.VERSION_1) self.assertTrue(isinstance(proxy.credentials, Anonymous)) self.assertTrue(proxy.agent._connectTimeout is None)
def test_init_HTTPCompression(self): factory = ProxyFactory(compressedHTTP=True) proxy = factory.getProxy('') self.assertTrue(isinstance(proxy.agent, ContentDecoderAgent)) self.assertTrue(isinstance(proxy.agent._agent, Agent)) self.assertTrue('gzip' in proxy.agent._decoders) self.assertEqual(proxy.agent._decoders['gzip'], GzipDecoder)
def test_sharedPool(self): factory = ProxyFactory(sharedPool=True) proxy1 = factory.getProxy('') proxy2 = factory.getProxy('') proxy3 = factory.getProxy('') self.assertNotEqual(id(proxy1), id(proxy2)) self.assertNotEqual(id(proxy2), id(proxy3)) self.assertNotEqual(id(proxy1), id(proxy3)) self.assertEqual(id(proxy1.agent._pool), id(factory._pool)) self.assertEqual(id(proxy2.agent._pool), id(factory._pool)) self.assertEqual(id(proxy3.agent._pool), id(factory._pool))
def printValue(value): print "Result: %s" % str(value) def printError(error): print 'error', error.value def shutDown(data): print "Shutting down reactor..." reactor.stop() address = 'http://localhost:8999' factory = ProxyFactory(compressedHTTP=True) proxy = factory.getProxy(address) ds = [] d = proxy.callRemote('echo', ['ajajaj', 'bjbjbj']) d.addCallbacks(printValue, printError) ds.append(d) d = proxy.callRemote('add', 14, 15) d.addCallbacks(printValue, printError) ds.append(d) d = proxy.callRemote('mysql_first_user') d.addCallbacks(printValue, printError) ds.append(d)
def printError(error): print 'error', error.value def shutDown(data): print "Shutting down reactor..." reactor.stop() address = 'http://localhost:8999' factory = ProxyFactory( persistent=True, # defaults maxPersistentPerHost=2, cachedConnectionTimeout=240, retryAutomatically=True) proxy = factory.getProxy(address) ds = [] d = proxy.callRemote('echo', ['ajajaj', 'bjbjbj']) d.addCallbacks(printValue, printError) ds.append(d) d = proxy.callRemote('add', 14, 15) d.addCallbacks(printValue, printError) ds.append(d) d = proxy.callRemote('mysql_first_user') d.addCallbacks(printValue, printError)
def printValue(value): print "Result: %s" % str(value) def printError(error): print 'error', error.value def shutDown(data): print "Shutting down reactor..." reactor.stop() address = 'http://localhost:8999' factory = ProxyFactory(sharedPool=True, persistent=True) proxy = factory.getProxy(address) ds = [] d = proxy.callRemote('echo', ['ajajaj', 'bjbjbj']) d.addCallbacks(printValue, printError) ds.append(d) d = proxy.callRemote('add', 14, 15) d.addCallbacks(printValue, printError) ds.append(d) d = proxy.callRemote('mysql_first_user') d.addCallbacks(printValue, printError) ds.append(d)