<s> """<STR_LIT>""" <EOL> from mock import Mock <EOL> from nose . tools import eq_ , nottest , ok_ , raises <EOL> from threading import Lock , Thread <EOL> from time import sleep , time <EOL> import sys <EOL> try : <EOL> import requests_kerberos <EOL> except ImportError : <EOL> sys . modules [ '<STR_LIT>' ] = Mock ( ) <EOL> from hdfs . ext . kerberos import KerberosClient <EOL> class TestKerberosClient ( object ) : <EOL> def test_concurrency ( self ) : <EOL> lock = Lock ( ) <EOL> calls = set ( ) <EOL> items = [ ] <EOL> def add_item ( method , url , ** kwargs ) : <EOL> with lock : <EOL> ok_ ( not items ) <EOL> items . append ( kwargs [ '<STR_LIT>' ] ) <EOL> sleep ( <NUM_LIT> ) <EOL> with lock : <EOL> thread = items . pop ( ) <EOL> eq_ ( thread , kwargs [ '<STR_LIT>' ] ) <EOL> calls . add ( thread ) <EOL> return Mock ( ) <EOL> session = Mock ( ) <EOL> session . request = add_item <EOL> client = KerberosClient ( '<STR_LIT>' , max_concurrency = <NUM_LIT:1> , session = session ) <EOL> args = ( '<STR_LIT:POST>' , '<STR_LIT>' ) <EOL> t1 = Thread ( <EOL> target = client . _request , <EOL> args = args , <EOL> kwargs = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : True } <EOL> ) <EOL> t1 . start ( ) <EOL> t2 = Thread ( <EOL> target = client . _request , <EOL> args = args , <EOL> kwargs = { '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : True } <EOL> ) <EOL> t2 . start ( ) <EOL> t1 . join ( ) <EOL> t2 . join ( ) <EOL> eq_ ( calls , set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> def test_concurrency_no_auth ( self ) : <EOL> lock = Lock ( ) <EOL> calls = set ( ) <EOL> items = [ ] <EOL> def add_item ( method , url , ** kwargs ) : <EOL> thread = kwargs [ '<STR_LIT>' ] <EOL> with lock : <EOL> if items : <EOL> other = items . pop ( ) <EOL> ok_ ( other != thread ) <EOL> else : <EOL> items . append ( thread ) <EOL> sleep ( <NUM_LIT> ) <EOL> with lock : <EOL> ok_ ( not items ) <EOL> calls . add ( thread ) <EOL> return Mock ( ) <EOL> session = Mock ( ) <EOL> session . request = add_item <EOL> client = KerberosClient ( '<STR_LIT>' , max_concurrency = <NUM_LIT:1> , session = session ) <EOL> args = ( '<STR_LIT:POST>' , '<STR_LIT>' ) <EOL> t1 = Thread ( <EOL> target = client . _request , <EOL> args = args , <EOL> kwargs = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : True } <EOL> ) <EOL> t1 . start ( ) <EOL> t2 = Thread ( target = client . _request , args = args , kwargs = { '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> t2 . start ( ) <EOL> t1 . join ( ) <EOL> t2 . join ( ) <EOL> eq_ ( calls , set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) </s>
