<s> import os <EOL> import time <EOL> import unittest <EOL> import eventlet <EOL> import mock <EOL> import six <EOL> from swift . common import exceptions , utils <EOL> from swift . common . storage_policy import POLICIES <EOL> from swift . common . utils import Timestamp <EOL> from swift . obj import ssync_sender , diskfile , ssync_receiver <EOL> from test . unit import patch_policies , make_timestamp_iter <EOL> from test . unit . obj . common import FakeReplicator , BaseTest <EOL> class NullBufferedHTTPConnection ( object ) : <EOL> def __init__ ( * args , ** kwargs ) : <EOL> pass <EOL> def putrequest ( * args , ** kwargs ) : <EOL> pass <EOL> def putheader ( * args , ** kwargs ) : <EOL> pass <EOL> def endheaders ( * args , ** kwargs ) : <EOL> pass <EOL> def getresponse ( * args , ** kwargs ) : <EOL> pass <EOL> def close ( * args , ** kwargs ) : <EOL> pass <EOL> class FakeResponse ( object ) : <EOL> def __init__ ( self , chunk_body = '<STR_LIT>' ) : <EOL> self . status = <NUM_LIT:200> <EOL> self . close_called = False <EOL> if chunk_body : <EOL> self . fp = six . StringIO ( <EOL> '<STR_LIT>' % ( len ( chunk_body ) , chunk_body ) ) <EOL> def read ( self , * args , ** kwargs ) : <EOL> return '<STR_LIT>' <EOL> def close ( self ) : <EOL> self . close_called = True <EOL> class FakeConnection ( object ) : <EOL> def __init__ ( self ) : <EOL> self . sent = [ ] <EOL> self . closed = False <EOL> def send ( self , data ) : <EOL> self . sent . append ( data ) <EOL> def close ( self ) : <EOL> self . closed = True <EOL> @ patch_policies ( ) <EOL> class TestSender ( BaseTest ) : <EOL> def setUp ( self ) : <EOL> super ( TestSender , self ) . setUp ( ) <EOL> self . testdir = os . path . join ( self . tmpdir , '<STR_LIT>' ) <EOL> utils . mkdirs ( os . path . join ( self . testdir , '<STR_LIT>' ) ) <EOL> self . daemon = FakeReplicator ( self . testdir ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , None , None , None ) <EOL> def test_call_catches_MessageTimeout ( self ) : <EOL> def connect ( self ) : <EOL> exc = exceptions . MessageTimeout ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> exc . cancel ( ) <EOL> raise exc <EOL> with mock . patch . object ( ssync_sender . Sender , '<STR_LIT>' , connect ) : <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES . legacy ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> success , candidates = self . sender ( ) <EOL> self . assertFalse ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> error_lines = self . daemon . logger . get_lines_for_level ( '<STR_LIT:error>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( error_lines ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> error_lines [ <NUM_LIT:0> ] ) <EOL> def test_call_catches_ReplicationException ( self ) : <EOL> def connect ( self ) : <EOL> raise exceptions . ReplicationException ( '<STR_LIT>' ) <EOL> with mock . patch . object ( ssync_sender . Sender , '<STR_LIT>' , connect ) : <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES . legacy ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> success , candidates = self . sender ( ) <EOL> self . assertFalse ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> error_lines = self . daemon . logger . get_lines_for_level ( '<STR_LIT:error>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( error_lines ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> error_lines [ <NUM_LIT:0> ] ) <EOL> def test_call_catches_other_exceptions ( self ) : <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES . legacy ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . connect = '<STR_LIT>' <EOL> success , candidates = self . sender ( ) <EOL> self . assertFalse ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> error_lines = self . daemon . logger . get_lines_for_level ( '<STR_LIT:error>' ) <EOL> for line in error_lines : <EOL> self . assertTrue ( line . startswith ( <EOL> '<STR_LIT>' ) ) <EOL> def test_call_catches_exception_handling_exception ( self ) : <EOL> job = node = None <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . connect = '<STR_LIT>' <EOL> success , candidates = self . sender ( ) <EOL> self . assertFalse ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> error_lines = self . daemon . logger . get_lines_for_level ( '<STR_LIT:error>' ) <EOL> for line in error_lines : <EOL> self . assertTrue ( line . startswith ( <EOL> '<STR_LIT>' ) ) <EOL> def test_call_calls_others ( self ) : <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . connect = mock . MagicMock ( ) <EOL> self . sender . missing_check = mock . MagicMock ( ) <EOL> self . sender . updates = mock . MagicMock ( ) <EOL> self . sender . disconnect = mock . MagicMock ( ) <EOL> success , candidates = self . sender ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> self . sender . connect . assert_called_once_with ( ) <EOL> self . sender . missing_check . assert_called_once_with ( ) <EOL> self . sender . updates . assert_called_once_with ( ) <EOL> self . sender . disconnect . assert_called_once_with ( ) <EOL> def test_call_calls_others_returns_failure ( self ) : <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . connect = mock . MagicMock ( ) <EOL> self . sender . missing_check = mock . MagicMock ( ) <EOL> self . sender . updates = mock . MagicMock ( ) <EOL> self . sender . disconnect = mock . MagicMock ( ) <EOL> self . sender . failures = <NUM_LIT:1> <EOL> success , candidates = self . sender ( ) <EOL> self . assertFalse ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> self . sender . connect . assert_called_once_with ( ) <EOL> self . sender . missing_check . assert_called_once_with ( ) <EOL> self . sender . updates . assert_called_once_with ( ) <EOL> self . sender . disconnect . assert_called_once_with ( ) <EOL> def test_connect ( self ) : <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' , index = <NUM_LIT:0> ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES [ <NUM_LIT:1> ] ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> with mock . patch ( <EOL> '<STR_LIT>' <EOL> ) as mock_conn_class : <EOL> mock_conn = mock_conn_class . return_value <EOL> mock_resp = mock . MagicMock ( ) <EOL> mock_resp . status = <NUM_LIT:200> <EOL> mock_conn . getresponse . return_value = mock_resp <EOL> self . sender . connect ( ) <EOL> mock_conn_class . assert_called_once_with ( '<STR_LIT>' ) <EOL> expectations = { <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> mock . call ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> mock . call ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ] , <EOL> '<STR_LIT>' : [ mock . call ( ) ] , <EOL> } <EOL> for method_name , expected_calls in expectations . items ( ) : <EOL> mock_method = getattr ( mock_conn , method_name ) <EOL> self . assertEqual ( expected_calls , mock_method . mock_calls , <EOL> '<STR_LIT>' % ( <EOL> method_name , mock_method . mock_calls , <EOL> expected_calls ) ) <EOL> def test_connect_handoff ( self ) : <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES [ <NUM_LIT:1> ] , frag_index = <NUM_LIT:9> ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> with mock . patch ( <EOL> '<STR_LIT>' <EOL> ) as mock_conn_class : <EOL> mock_conn = mock_conn_class . return_value <EOL> mock_resp = mock . MagicMock ( ) <EOL> mock_resp . status = <NUM_LIT:200> <EOL> mock_conn . getresponse . return_value = mock_resp <EOL> self . sender . connect ( ) <EOL> mock_conn_class . assert_called_once_with ( '<STR_LIT>' ) <EOL> expectations = { <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> mock . call ( '<STR_LIT>' , <NUM_LIT:9> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ mock . call ( ) ] , <EOL> } <EOL> for method_name , expected_calls in expectations . items ( ) : <EOL> mock_method = getattr ( mock_conn , method_name ) <EOL> self . assertEqual ( expected_calls , mock_method . mock_calls , <EOL> '<STR_LIT>' % ( <EOL> method_name , mock_method . mock_calls , <EOL> expected_calls ) ) <EOL> def test_connect_handoff_no_frag ( self ) : <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES [ <NUM_LIT:0> ] ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> with mock . patch ( <EOL> '<STR_LIT>' <EOL> ) as mock_conn_class : <EOL> mock_conn = mock_conn_class . return_value <EOL> mock_resp = mock . MagicMock ( ) <EOL> mock_resp . status = <NUM_LIT:200> <EOL> mock_conn . getresponse . return_value = mock_resp <EOL> self . sender . connect ( ) <EOL> mock_conn_class . assert_called_once_with ( '<STR_LIT>' ) <EOL> expectations = { <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ mock . call ( ) ] , <EOL> } <EOL> for method_name , expected_calls in expectations . items ( ) : <EOL> mock_method = getattr ( mock_conn , method_name ) <EOL> self . assertEqual ( expected_calls , mock_method . mock_calls , <EOL> '<STR_LIT>' % ( <EOL> method_name , mock_method . mock_calls , <EOL> expected_calls ) ) <EOL> def test_connect_handoff_none_frag ( self ) : <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES [ <NUM_LIT:1> ] , frag_index = None ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> with mock . patch ( <EOL> '<STR_LIT>' <EOL> ) as mock_conn_class : <EOL> mock_conn = mock_conn_class . return_value <EOL> mock_resp = mock . MagicMock ( ) <EOL> mock_resp . status = <NUM_LIT:200> <EOL> mock_conn . getresponse . return_value = mock_resp <EOL> self . sender . connect ( ) <EOL> mock_conn_class . assert_called_once_with ( '<STR_LIT>' ) <EOL> expectations = { <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ mock . call ( ) ] , <EOL> } <EOL> for method_name , expected_calls in expectations . items ( ) : <EOL> mock_method = getattr ( mock_conn , method_name ) <EOL> self . assertEqual ( expected_calls , mock_method . mock_calls , <EOL> '<STR_LIT>' % ( <EOL> method_name , mock_method . mock_calls , <EOL> expected_calls ) ) <EOL> def test_connect_handoff_replicated ( self ) : <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES [ <NUM_LIT:1> ] ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> with mock . patch ( <EOL> '<STR_LIT>' <EOL> ) as mock_conn_class : <EOL> mock_conn = mock_conn_class . return_value <EOL> mock_resp = mock . MagicMock ( ) <EOL> mock_resp . status = <NUM_LIT:200> <EOL> mock_conn . getresponse . return_value = mock_resp <EOL> self . sender . connect ( ) <EOL> mock_conn_class . assert_called_once_with ( '<STR_LIT>' ) <EOL> expectations = { <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' : [ mock . call ( ) ] , <EOL> } <EOL> for method_name , expected_calls in expectations . items ( ) : <EOL> mock_method = getattr ( mock_conn , method_name ) <EOL> self . assertEqual ( expected_calls , mock_method . mock_calls , <EOL> '<STR_LIT>' % ( <EOL> method_name , mock_method . mock_calls , <EOL> expected_calls ) ) <EOL> def test_call ( self ) : <EOL> def patch_sender ( sender ) : <EOL> sender . connect = mock . MagicMock ( ) <EOL> sender . missing_check = mock . MagicMock ( ) <EOL> sender . updates = mock . MagicMock ( ) <EOL> sender . disconnect = mock . MagicMock ( ) <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> available_map = dict ( [ ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ] ) <EOL> sender = ssync_sender . Sender ( <EOL> self . daemon , node , job , [ ] , remote_check_objs = None ) <EOL> patch_sender ( sender ) <EOL> sender . available_map = available_map <EOL> success , candidates = sender ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertEqual ( { } , candidates ) <EOL> sender = ssync_sender . Sender ( <EOL> self . daemon , node , job , [ '<STR_LIT>' ] , remote_check_objs = None ) <EOL> patch_sender ( sender ) <EOL> sender . available_map = available_map <EOL> success , candidates = sender ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertEqual ( available_map , candidates ) <EOL> wanted = '<STR_LIT>' <EOL> sender = ssync_sender . Sender ( <EOL> self . daemon , node , job , [ '<STR_LIT>' ] , <EOL> remote_check_objs = None ) <EOL> patch_sender ( sender ) <EOL> sender . send_map = { wanted : [ ] } <EOL> sender . available_map = available_map <EOL> success , candidates = sender ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertEqual ( available_map , candidates ) <EOL> wanted = '<STR_LIT>' <EOL> remote_check_objs = set ( available_map . keys ( ) ) <EOL> sender = ssync_sender . Sender ( <EOL> self . daemon , node , job , [ '<STR_LIT>' ] , <EOL> remote_check_objs = remote_check_objs ) <EOL> patch_sender ( sender ) <EOL> sender . send_map = { wanted : [ ] } <EOL> sender . available_map = available_map <EOL> success , candidates = sender ( ) <EOL> self . assertTrue ( success ) <EOL> expected_map = dict ( [ ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( expected_map , candidates ) <EOL> def test_call_and_missing_check_metadata_legacy_response ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if device == '<STR_LIT>' and partition == '<STR_LIT>' and suffixes == [ '<STR_LIT:abc>' ] and policy == POLICIES . legacy : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) , <EOL> '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . node = { } <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) ) <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . connect = mock . MagicMock ( ) <EOL> self . sender . df_mgr . get_diskfile_from_hash = mock . MagicMock ( ) <EOL> self . sender . disconnect = mock . MagicMock ( ) <EOL> success , candidates = self . sender ( ) <EOL> self . assertTrue ( success ) <EOL> found_post = found_put = False <EOL> for chunk in self . sender . connection . sent : <EOL> if '<STR_LIT:POST>' in chunk : <EOL> found_post = True <EOL> if '<STR_LIT>' in chunk : <EOL> found_put = True <EOL> self . assertFalse ( found_post ) <EOL> self . assertTrue ( found_put ) <EOL> self . assertEqual ( self . sender . failures , <NUM_LIT:0> ) <EOL> def test_call_and_missing_check ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if device == '<STR_LIT>' and partition == '<STR_LIT>' and suffixes == [ '<STR_LIT:abc>' ] and policy == POLICIES . legacy : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . node = { } <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . connect = mock . MagicMock ( ) <EOL> self . sender . updates = mock . MagicMock ( ) <EOL> self . sender . disconnect = mock . MagicMock ( ) <EOL> success , candidates = self . sender ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertEqual ( candidates , <EOL> dict ( [ ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) ] ) ) <EOL> self . assertEqual ( self . sender . failures , <NUM_LIT:0> ) <EOL> def test_call_and_missing_check_with_obj_list ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if device == '<STR_LIT>' and partition == '<STR_LIT>' and suffixes == [ '<STR_LIT:abc>' ] and policy == POLICIES . legacy : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , suffixes ) ) <EOL> job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender = ssync_sender . Sender ( self . daemon , None , job , [ '<STR_LIT:abc>' ] , <EOL> [ '<STR_LIT>' ] ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . connect = mock . MagicMock ( ) <EOL> self . sender . updates = mock . MagicMock ( ) <EOL> self . sender . disconnect = mock . MagicMock ( ) <EOL> success , candidates = self . sender ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertEqual ( candidates , <EOL> dict ( [ ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) ] ) ) <EOL> self . assertEqual ( self . sender . failures , <NUM_LIT:0> ) <EOL> def test_call_and_missing_check_with_obj_list_but_required ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if device == '<STR_LIT>' and partition == '<STR_LIT>' and suffixes == [ '<STR_LIT:abc>' ] and policy == POLICIES . legacy : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , suffixes ) ) <EOL> job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender = ssync_sender . Sender ( self . daemon , { } , job , [ '<STR_LIT:abc>' ] , <EOL> [ '<STR_LIT>' ] ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . connect = mock . MagicMock ( ) <EOL> self . sender . updates = mock . MagicMock ( ) <EOL> self . sender . disconnect = mock . MagicMock ( ) <EOL> success , candidates = self . sender ( ) <EOL> self . assertTrue ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> def test_connect_send_timeout ( self ) : <EOL> self . daemon . node_timeout = <NUM_LIT> <EOL> self . daemon . conn_timeout = <NUM_LIT> <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES . legacy ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> def putrequest ( * args , ** kwargs ) : <EOL> eventlet . sleep ( <NUM_LIT:0.1> ) <EOL> with mock . patch . object ( <EOL> ssync_sender . bufferedhttp . BufferedHTTPConnection , <EOL> '<STR_LIT>' , putrequest ) : <EOL> success , candidates = self . sender ( ) <EOL> self . assertFalse ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> error_lines = self . daemon . logger . get_lines_for_level ( '<STR_LIT:error>' ) <EOL> for line in error_lines : <EOL> self . assertTrue ( line . startswith ( <EOL> '<STR_LIT>' ) ) <EOL> def test_connect_receive_timeout ( self ) : <EOL> self . daemon . node_timeout = <NUM_LIT> <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' , index = <NUM_LIT:0> ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES . legacy ) <EOL> self . sender = ssync_sender . Sender ( self . daemon , node , job , None ) <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> class FakeBufferedHTTPConnection ( NullBufferedHTTPConnection ) : <EOL> def getresponse ( * args , ** kwargs ) : <EOL> eventlet . sleep ( <NUM_LIT:0.1> ) <EOL> with mock . patch . object ( <EOL> ssync_sender . bufferedhttp , '<STR_LIT>' , <EOL> FakeBufferedHTTPConnection ) : <EOL> success , candidates = self . sender ( ) <EOL> self . assertFalse ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> error_lines = self . daemon . logger . get_lines_for_level ( '<STR_LIT:error>' ) <EOL> for line in error_lines : <EOL> self . assertTrue ( line . startswith ( <EOL> '<STR_LIT>' ) ) <EOL> def test_connect_bad_status ( self ) : <EOL> self . daemon . node_timeout = <NUM_LIT> <EOL> node = dict ( replication_ip = '<STR_LIT>' , replication_port = <NUM_LIT> , <EOL> device = '<STR_LIT>' , index = <NUM_LIT:0> ) <EOL> job = dict ( partition = '<STR_LIT>' , policy = POLICIES . legacy ) <EOL> class FakeBufferedHTTPConnection ( NullBufferedHTTPConnection ) : <EOL> def getresponse ( * args , ** kwargs ) : <EOL> response = FakeResponse ( ) <EOL> response . status = <NUM_LIT> <EOL> response . read = lambda : '<STR_LIT>' <EOL> return response <EOL> missing_check_fn = '<STR_LIT>' <EOL> with mock . patch ( missing_check_fn ) as mock_missing_check : <EOL> with mock . patch . object ( <EOL> ssync_sender . bufferedhttp , '<STR_LIT>' , <EOL> FakeBufferedHTTPConnection ) : <EOL> self . sender = ssync_sender . Sender ( <EOL> self . daemon , node , job , [ '<STR_LIT:abc>' ] ) <EOL> success , candidates = self . sender ( ) <EOL> self . assertFalse ( success ) <EOL> self . assertEqual ( candidates , { } ) <EOL> error_lines = self . daemon . logger . get_lines_for_level ( '<STR_LIT:error>' ) <EOL> for line in error_lines : <EOL> self . assertTrue ( line . startswith ( <EOL> '<STR_LIT>' ) ) <EOL> self . assertIn ( '<STR_LIT>' , line ) <EOL> self . assertFalse ( mock_missing_check . called ) <EOL> def test_readline_newline_in_buffer ( self ) : <EOL> self . sender . response_buffer = '<STR_LIT>' <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . response_buffer , '<STR_LIT>' ) <EOL> def test_readline_buffer_exceeds_network_chunk_size_somehow ( self ) : <EOL> self . daemon . network_chunk_size = <NUM_LIT:2> <EOL> self . sender . response_buffer = '<STR_LIT>' <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . response_buffer , '<STR_LIT>' ) <EOL> def test_readline_at_start_of_chunk ( self ) : <EOL> self . sender . response = FakeResponse ( ) <EOL> self . sender . response . fp = six . StringIO ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> def test_readline_chunk_with_extension ( self ) : <EOL> self . sender . response = FakeResponse ( ) <EOL> self . sender . response . fp = six . StringIO ( <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> def test_readline_broken_chunk ( self ) : <EOL> self . sender . response = FakeResponse ( ) <EOL> self . sender . response . fp = six . StringIO ( '<STR_LIT>' ) <EOL> self . assertRaises ( <EOL> exceptions . ReplicationException , self . sender . readline ) <EOL> self . assertTrue ( self . sender . response . close_called ) <EOL> def test_readline_terminated_chunk ( self ) : <EOL> self . sender . response = FakeResponse ( ) <EOL> self . sender . response . fp = six . StringIO ( '<STR_LIT>' ) <EOL> self . assertRaises ( <EOL> exceptions . ReplicationException , self . sender . readline ) <EOL> self . assertTrue ( self . sender . response . close_called ) <EOL> def test_readline_all ( self ) : <EOL> self . sender . response = FakeResponse ( ) <EOL> self . sender . response . fp = six . StringIO ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> def test_readline_all_trailing_not_newline_termed ( self ) : <EOL> self . sender . response = FakeResponse ( ) <EOL> self . sender . response . fp = six . StringIO ( <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . readline ( ) , '<STR_LIT>' ) <EOL> def test_missing_check_timeout ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . connection . send = lambda d : eventlet . sleep ( <NUM_LIT:1> ) <EOL> self . sender . daemon . node_timeout = <NUM_LIT> <EOL> self . assertRaises ( exceptions . MessageTimeout , self . sender . missing_check ) <EOL> def test_missing_check_has_empty_suffixes ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if ( device != '<STR_LIT>' or partition != '<STR_LIT>' or <EOL> policy != POLICIES . legacy or <EOL> suffixes != [ '<STR_LIT:abc>' , '<STR_LIT>' ] ) : <EOL> yield <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , <EOL> policy , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' , '<STR_LIT>' ] <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . missing_check ( ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . send_map , { } ) <EOL> self . assertEqual ( self . sender . available_map , { } ) <EOL> def test_missing_check_has_suffixes ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if ( device == '<STR_LIT>' and partition == '<STR_LIT>' and <EOL> policy == POLICIES . legacy and <EOL> suffixes == [ '<STR_LIT:abc>' , '<STR_LIT>' ] ) : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) , <EOL> '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) , <EOL> '<STR_LIT>' : Timestamp ( <NUM_LIT> ) , <EOL> '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , <EOL> policy , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' , '<STR_LIT>' ] <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . missing_check ( ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . send_map , { } ) <EOL> candidates = [ ( '<STR_LIT>' , <EOL> dict ( ts_data = Timestamp ( <NUM_LIT> ) ) ) , <EOL> ( '<STR_LIT>' , <EOL> dict ( ts_data = Timestamp ( <NUM_LIT> ) , <EOL> ts_meta = Timestamp ( <NUM_LIT> ) ) ) , <EOL> ( '<STR_LIT>' , <EOL> dict ( ts_data = Timestamp ( <NUM_LIT> ) , <EOL> ts_meta = Timestamp ( <NUM_LIT> ) , <EOL> ts_ctype = Timestamp ( <NUM_LIT> ) ) ) ] <EOL> self . assertEqual ( self . sender . available_map , dict ( candidates ) ) <EOL> def test_missing_check_far_end_disconnect ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if ( device == '<STR_LIT>' and partition == '<STR_LIT>' and <EOL> policy == POLICIES . legacy and <EOL> suffixes == [ '<STR_LIT:abc>' ] ) : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , <EOL> policy , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . response = FakeResponse ( chunk_body = '<STR_LIT:\r\n>' ) <EOL> exc = None <EOL> try : <EOL> self . sender . missing_check ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . available_map , <EOL> dict ( [ ( '<STR_LIT>' , <EOL> dict ( ts_data = Timestamp ( <NUM_LIT> ) ) ) ] ) ) <EOL> def test_missing_check_far_end_disconnect2 ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if ( device == '<STR_LIT>' and partition == '<STR_LIT>' and <EOL> policy == POLICIES . legacy and <EOL> suffixes == [ '<STR_LIT:abc>' ] ) : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , <EOL> policy , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = '<STR_LIT>' ) <EOL> exc = None <EOL> try : <EOL> self . sender . missing_check ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . available_map , <EOL> dict ( [ ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) ] ) ) <EOL> def test_missing_check_far_end_unexpected ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if ( device == '<STR_LIT>' and partition == '<STR_LIT>' and <EOL> policy == POLICIES . legacy and <EOL> suffixes == [ '<STR_LIT:abc>' ] ) : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , <EOL> policy , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . response = FakeResponse ( chunk_body = '<STR_LIT>' ) <EOL> exc = None <EOL> try : <EOL> self . sender . missing_check ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( self . sender . available_map , <EOL> dict ( [ ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) ] ) ) <EOL> def test_missing_check_send_map ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if ( device == '<STR_LIT>' and partition == '<STR_LIT>' and <EOL> policy == POLICIES . legacy and <EOL> suffixes == [ '<STR_LIT:abc>' ] ) : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , <EOL> policy , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . missing_check ( ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> self . sender . send_map , { '<STR_LIT>' : { '<STR_LIT:data>' : True , '<STR_LIT>' : True } } ) <EOL> self . assertEqual ( self . sender . available_map , <EOL> dict ( [ ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) ] ) ) <EOL> def test_missing_check_extra_line_parts ( self ) : <EOL> def yield_hashes ( device , partition , policy , suffixes = None , ** kwargs ) : <EOL> if ( device == '<STR_LIT>' and partition == '<STR_LIT>' and <EOL> policy == POLICIES . legacy and <EOL> suffixes == [ '<STR_LIT:abc>' ] ) : <EOL> yield ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) <EOL> else : <EOL> raise Exception ( <EOL> '<STR_LIT>' % ( device , partition , <EOL> policy , suffixes ) ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> } <EOL> self . sender . suffixes = [ '<STR_LIT:abc>' ] <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . daemon . _diskfile_mgr . yield_hashes = yield_hashes <EOL> self . sender . missing_check ( ) <EOL> self . assertEqual ( self . sender . send_map , <EOL> { '<STR_LIT>' : { '<STR_LIT:data>' : True } } ) <EOL> self . assertEqual ( self . sender . available_map , <EOL> dict ( [ ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : Timestamp ( <NUM_LIT> ) } ) ] ) ) <EOL> def test_updates_timeout ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . connection . send = lambda d : eventlet . sleep ( <NUM_LIT:1> ) <EOL> self . sender . daemon . node_timeout = <NUM_LIT> <EOL> self . assertRaises ( exceptions . MessageTimeout , self . sender . updates ) <EOL> def test_updates_empty_send_map ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . updates ( ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_unexpected_response_lines1 ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> exc = None <EOL> try : <EOL> self . sender . updates ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_unexpected_response_lines2 ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> exc = None <EOL> try : <EOL> self . sender . updates ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_is_deleted ( self ) : <EOL> device = '<STR_LIT>' <EOL> part = '<STR_LIT>' <EOL> object_parts = ( '<STR_LIT:a>' , '<STR_LIT:c>' , '<STR_LIT:o>' ) <EOL> df = self . _make_open_diskfile ( device , part , * object_parts ) <EOL> object_hash = utils . hash_path ( * object_parts ) <EOL> delete_timestamp = utils . normalize_timestamp ( time . time ( ) ) <EOL> df . delete ( delete_timestamp ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : device , <EOL> '<STR_LIT>' : part , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender . node = { } <EOL> self . sender . send_map = { object_hash : { '<STR_LIT:data>' : True } } <EOL> self . sender . send_delete = mock . MagicMock ( ) <EOL> self . sender . send_put = mock . MagicMock ( ) <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . updates ( ) <EOL> self . sender . send_delete . assert_called_once_with ( <EOL> '<STR_LIT>' , delete_timestamp ) <EOL> self . assertEqual ( self . sender . send_put . mock_calls , [ ] ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_update_send_delete ( self ) : <EOL> device = '<STR_LIT>' <EOL> part = '<STR_LIT>' <EOL> object_parts = ( '<STR_LIT:a>' , '<STR_LIT:c>' , '<STR_LIT:o>' ) <EOL> df = self . _make_open_diskfile ( device , part , * object_parts ) <EOL> object_hash = utils . hash_path ( * object_parts ) <EOL> delete_timestamp = utils . normalize_timestamp ( time . time ( ) ) <EOL> df . delete ( delete_timestamp ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : device , <EOL> '<STR_LIT>' : part , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender . node = { } <EOL> self . sender . send_map = { object_hash : { '<STR_LIT:data>' : True } } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . updates ( ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % delete_timestamp <EOL> ) <EOL> def test_updates_put ( self ) : <EOL> ts_iter = make_timestamp_iter ( ) <EOL> device = '<STR_LIT>' <EOL> part = '<STR_LIT>' <EOL> object_parts = ( '<STR_LIT:a>' , '<STR_LIT:c>' , '<STR_LIT:o>' ) <EOL> t1 = next ( ts_iter ) <EOL> df = self . _make_open_diskfile ( <EOL> device , part , * object_parts , timestamp = t1 ) <EOL> t2 = next ( ts_iter ) <EOL> metadata = { '<STR_LIT>' : t2 . internal , '<STR_LIT>' : '<STR_LIT>' } <EOL> df . write_metadata ( metadata ) <EOL> object_hash = utils . hash_path ( * object_parts ) <EOL> df . open ( ) <EOL> expected = df . get_metadata ( ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : device , <EOL> '<STR_LIT>' : part , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender . node = { } <EOL> self . sender . send_map = { object_hash : { '<STR_LIT:data>' : True } } <EOL> self . sender . send_delete = mock . MagicMock ( ) <EOL> self . sender . send_put = mock . MagicMock ( ) <EOL> self . sender . send_post = mock . MagicMock ( ) <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . updates ( ) <EOL> self . assertEqual ( self . sender . send_delete . mock_calls , [ ] ) <EOL> self . assertEqual ( self . sender . send_post . mock_calls , [ ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . sender . send_put . mock_calls ) ) <EOL> args , _kwargs = self . sender . send_put . call_args <EOL> path , df = args <EOL> self . assertEqual ( path , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( df , diskfile . DiskFile ) ) <EOL> self . assertEqual ( expected , df . get_metadata ( ) ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_post ( self ) : <EOL> ts_iter = make_timestamp_iter ( ) <EOL> device = '<STR_LIT>' <EOL> part = '<STR_LIT>' <EOL> object_parts = ( '<STR_LIT:a>' , '<STR_LIT:c>' , '<STR_LIT:o>' ) <EOL> t1 = next ( ts_iter ) <EOL> df = self . _make_open_diskfile ( <EOL> device , part , * object_parts , timestamp = t1 ) <EOL> t2 = next ( ts_iter ) <EOL> metadata = { '<STR_LIT>' : t2 . internal , '<STR_LIT>' : '<STR_LIT>' } <EOL> df . write_metadata ( metadata ) <EOL> object_hash = utils . hash_path ( * object_parts ) <EOL> df . open ( ) <EOL> expected = df . get_metadata ( ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : device , <EOL> '<STR_LIT>' : part , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender . node = { } <EOL> self . sender . send_map = { object_hash : { '<STR_LIT>' : True } } <EOL> self . sender . send_delete = mock . MagicMock ( ) <EOL> self . sender . send_put = mock . MagicMock ( ) <EOL> self . sender . send_post = mock . MagicMock ( ) <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . updates ( ) <EOL> self . assertEqual ( self . sender . send_delete . mock_calls , [ ] ) <EOL> self . assertEqual ( self . sender . send_put . mock_calls , [ ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . sender . send_post . mock_calls ) ) <EOL> args , _kwargs = self . sender . send_post . call_args <EOL> path , df = args <EOL> self . assertEqual ( path , '<STR_LIT>' ) <EOL> self . assertIsInstance ( df , diskfile . DiskFile ) <EOL> self . assertEqual ( expected , df . get_metadata ( ) ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_put_and_post ( self ) : <EOL> ts_iter = make_timestamp_iter ( ) <EOL> device = '<STR_LIT>' <EOL> part = '<STR_LIT>' <EOL> object_parts = ( '<STR_LIT:a>' , '<STR_LIT:c>' , '<STR_LIT:o>' ) <EOL> t1 = next ( ts_iter ) <EOL> df = self . _make_open_diskfile ( <EOL> device , part , * object_parts , timestamp = t1 ) <EOL> t2 = next ( ts_iter ) <EOL> metadata = { '<STR_LIT>' : t2 . internal , '<STR_LIT>' : '<STR_LIT>' } <EOL> df . write_metadata ( metadata ) <EOL> object_hash = utils . hash_path ( * object_parts ) <EOL> df . open ( ) <EOL> expected = df . get_metadata ( ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : device , <EOL> '<STR_LIT>' : part , <EOL> '<STR_LIT>' : POLICIES . legacy , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> self . sender . node = { } <EOL> self . sender . send_map = { object_hash : { '<STR_LIT>' : True , '<STR_LIT:data>' : True } } <EOL> self . sender . send_delete = mock . MagicMock ( ) <EOL> self . sender . send_put = mock . MagicMock ( ) <EOL> self . sender . send_post = mock . MagicMock ( ) <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . updates ( ) <EOL> self . assertEqual ( self . sender . send_delete . mock_calls , [ ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . sender . send_put . mock_calls ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . sender . send_post . mock_calls ) ) <EOL> args , _kwargs = self . sender . send_put . call_args <EOL> path , df = args <EOL> self . assertEqual ( path , '<STR_LIT>' ) <EOL> self . assertIsInstance ( df , diskfile . DiskFile ) <EOL> self . assertEqual ( expected , df . get_metadata ( ) ) <EOL> args , _kwargs = self . sender . send_post . call_args <EOL> path , df = args <EOL> self . assertEqual ( path , '<STR_LIT>' ) <EOL> self . assertIsInstance ( df , diskfile . DiskFile ) <EOL> self . assertEqual ( expected , df . get_metadata ( ) ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_storage_policy_index ( self ) : <EOL> device = '<STR_LIT>' <EOL> part = '<STR_LIT>' <EOL> object_parts = ( '<STR_LIT:a>' , '<STR_LIT:c>' , '<STR_LIT:o>' ) <EOL> df = self . _make_open_diskfile ( device , part , * object_parts , <EOL> policy = POLICIES [ <NUM_LIT:0> ] ) <EOL> object_hash = utils . hash_path ( * object_parts ) <EOL> expected = df . get_metadata ( ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . job = { <EOL> '<STR_LIT>' : device , <EOL> '<STR_LIT>' : part , <EOL> '<STR_LIT>' : POLICIES [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : <NUM_LIT:0> } <EOL> self . sender . node = { } <EOL> self . sender . send_map = { object_hash : { '<STR_LIT:data>' : True } } <EOL> self . sender . send_delete = mock . MagicMock ( ) <EOL> self . sender . send_put = mock . MagicMock ( ) <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> self . sender . updates ( ) <EOL> args , _kwargs = self . sender . send_put . call_args <EOL> path , df = args <EOL> self . assertEqual ( path , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( df , diskfile . DiskFile ) ) <EOL> self . assertEqual ( expected , df . get_metadata ( ) ) <EOL> self . assertEqual ( os . path . join ( self . testdir , '<STR_LIT>' , <EOL> object_hash [ - <NUM_LIT:3> : ] , object_hash ) , <EOL> df . _datadir ) <EOL> def test_updates_read_response_timeout_start ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> orig_readline = self . sender . readline <EOL> def delayed_readline ( ) : <EOL> eventlet . sleep ( <NUM_LIT:1> ) <EOL> return orig_readline ( ) <EOL> self . sender . readline = delayed_readline <EOL> self . sender . daemon . http_timeout = <NUM_LIT> <EOL> self . assertRaises ( exceptions . MessageTimeout , self . sender . updates ) <EOL> def test_updates_read_response_disconnect_start ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( chunk_body = '<STR_LIT:\r\n>' ) <EOL> exc = None <EOL> try : <EOL> self . sender . updates ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_read_response_unexp_start ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> exc = None <EOL> try : <EOL> self . sender . updates ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_read_response_timeout_end ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> orig_readline = self . sender . readline <EOL> def delayed_readline ( ) : <EOL> rv = orig_readline ( ) <EOL> if rv == '<STR_LIT>' : <EOL> eventlet . sleep ( <NUM_LIT:1> ) <EOL> return rv <EOL> self . sender . readline = delayed_readline <EOL> self . sender . daemon . http_timeout = <NUM_LIT> <EOL> self . assertRaises ( exceptions . MessageTimeout , self . sender . updates ) <EOL> def test_updates_read_response_disconnect_end ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\r\n>' ) ) <EOL> exc = None <EOL> try : <EOL> self . sender . updates ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_updates_read_response_unexp_end ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_map = { } <EOL> self . sender . response = FakeResponse ( <EOL> chunk_body = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> exc = None <EOL> try : <EOL> self . sender . updates ( ) <EOL> except exceptions . ReplicationException as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_send_delete_timeout ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . connection . send = lambda d : eventlet . sleep ( <NUM_LIT:1> ) <EOL> self . sender . daemon . node_timeout = <NUM_LIT> <EOL> exc = None <EOL> try : <EOL> self . sender . send_delete ( '<STR_LIT>' , <EOL> utils . Timestamp ( '<STR_LIT>' ) ) <EOL> except exceptions . MessageTimeout as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , '<STR_LIT>' ) <EOL> def test_send_delete ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_delete ( '<STR_LIT>' , <EOL> utils . Timestamp ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def test_send_put_initial_timeout ( self ) : <EOL> df = self . _make_open_diskfile ( ) <EOL> df . _disk_chunk_size = <NUM_LIT:2> <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . connection . send = lambda d : eventlet . sleep ( <NUM_LIT:1> ) <EOL> self . sender . daemon . node_timeout = <NUM_LIT> <EOL> exc = None <EOL> try : <EOL> self . sender . send_put ( '<STR_LIT>' , df ) <EOL> except exceptions . MessageTimeout as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , '<STR_LIT>' ) <EOL> def test_send_put_chunk_timeout ( self ) : <EOL> df = self . _make_open_diskfile ( ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . daemon . node_timeout = <NUM_LIT> <EOL> one_shot = [ None ] <EOL> def mock_send ( data ) : <EOL> try : <EOL> one_shot . pop ( ) <EOL> except IndexError : <EOL> eventlet . sleep ( <NUM_LIT:1> ) <EOL> self . sender . connection . send = mock_send <EOL> exc = None <EOL> try : <EOL> self . sender . send_put ( '<STR_LIT>' , df ) <EOL> except exceptions . MessageTimeout as err : <EOL> exc = err <EOL> self . assertEqual ( str ( exc ) , '<STR_LIT>' ) <EOL> def test_send_put ( self ) : <EOL> ts_iter = make_timestamp_iter ( ) <EOL> t1 = next ( ts_iter ) <EOL> body = '<STR_LIT:test>' <EOL> extra_metadata = { '<STR_LIT>' : '<STR_LIT:value>' } <EOL> df = self . _make_open_diskfile ( body = body , timestamp = t1 , <EOL> extra_metadata = extra_metadata ) <EOL> expected = dict ( df . get_metadata ( ) ) <EOL> expected [ '<STR_LIT:body>' ] = body <EOL> expected [ '<STR_LIT>' ] = len ( body ) <EOL> t2 = next ( ts_iter ) <EOL> metadata = { '<STR_LIT>' : t2 . internal , '<STR_LIT>' : '<STR_LIT>' } <EOL> df . write_metadata ( metadata ) <EOL> df . open ( ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . send_put ( '<STR_LIT>' , df ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\r\n>' <EOL> '<STR_LIT:\r\n>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % expected ) <EOL> def test_send_post ( self ) : <EOL> ts_iter = make_timestamp_iter ( ) <EOL> extra_metadata = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> ts_0 = next ( ts_iter ) <EOL> df = self . _make_open_diskfile ( extra_metadata = extra_metadata , <EOL> timestamp = ts_0 ) <EOL> ts_1 = next ( ts_iter ) <EOL> newer_metadata = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ts_1 . internal } <EOL> df . write_metadata ( newer_metadata ) <EOL> self . sender . connection = FakeConnection ( ) <EOL> with df . open ( ) : <EOL> self . sender . send_post ( '<STR_LIT>' , df ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' . join ( self . sender . connection . sent ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:\r\n>' <EOL> '<STR_LIT:\r\n>' % ts_1 . internal ) <EOL> def test_disconnect_timeout ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . connection . send = lambda d : eventlet . sleep ( <NUM_LIT:1> ) <EOL> self . sender . daemon . node_timeout = <NUM_LIT> <EOL> self . sender . disconnect ( ) <EOL> self . assertEqual ( '<STR_LIT>' . join ( self . sender . connection . sent ) , '<STR_LIT>' ) <EOL> self . assertTrue ( self . sender . connection . closed ) <EOL> def test_disconnect ( self ) : <EOL> self . sender . connection = FakeConnection ( ) <EOL> self . sender . disconnect ( ) <EOL> self . assertEqual ( '<STR_LIT>' . join ( self . sender . connection . sent ) , '<STR_LIT>' ) <EOL> self . assertTrue ( self . sender . connection . closed ) <EOL> class TestModuleMethods ( unittest . TestCase ) : <EOL> def test_encode_missing ( self ) : <EOL> object_hash = '<STR_LIT>' <EOL> ts_iter = make_timestamp_iter ( ) <EOL> t_data = next ( ts_iter ) <EOL> t_type = next ( ts_iter ) <EOL> t_meta = next ( ts_iter ) <EOL> d_meta_data = t_meta . raw - t_data . raw <EOL> d_type_data = t_type . raw - t_data . raw <EOL> expected = '<STR_LIT>' % ( object_hash , t_data . internal ) <EOL> self . assertEqual ( <EOL> expected , <EOL> ssync_sender . encode_missing ( object_hash , t_data , ts_meta = t_data ) ) <EOL> expected = '<STR_LIT>' % ( object_hash , t_data . internal , d_meta_data ) <EOL> self . assertEqual ( <EOL> expected , <EOL> ssync_sender . encode_missing ( object_hash , t_data , ts_meta = t_meta ) ) <EOL> expected = '<STR_LIT>' % ( object_hash , t_data . internal , d_meta_data ) <EOL> self . assertEqual ( <EOL> expected , <EOL> ssync_sender . encode_missing ( object_hash , t_data , t_meta , t_data ) ) <EOL> expected = ( '<STR_LIT>' <EOL> % ( object_hash , t_data . internal , d_meta_data , d_type_data ) ) <EOL> self . assertEqual ( <EOL> expected , <EOL> ssync_sender . encode_missing ( object_hash , t_data , t_meta , t_type ) ) <EOL> expected = ( '<STR_LIT>' <EOL> % ( object_hash , t_data . internal , d_meta_data , d_type_data ) ) <EOL> self . assertEqual ( <EOL> expected , <EOL> ssync_sender . encode_missing ( object_hash , t_data , t_meta , t_type ) ) <EOL> expected = { '<STR_LIT>' : object_hash , '<STR_LIT>' : t_meta , <EOL> '<STR_LIT>' : t_data , '<STR_LIT>' : t_type } <EOL> msg = ssync_sender . encode_missing ( ** expected ) <EOL> actual = ssync_receiver . decode_missing ( msg ) <EOL> self . assertEqual ( expected , actual ) <EOL> expected = { '<STR_LIT>' : object_hash , '<STR_LIT>' : t_meta , <EOL> '<STR_LIT>' : t_meta , '<STR_LIT>' : t_meta } <EOL> msg = ssync_sender . encode_missing ( ** expected ) <EOL> actual = ssync_receiver . decode_missing ( msg ) <EOL> self . assertEqual ( expected , actual ) <EOL> def test_decode_wanted ( self ) : <EOL> parts = [ '<STR_LIT:d>' ] <EOL> expected = { '<STR_LIT:data>' : True } <EOL> self . assertEqual ( ssync_sender . decode_wanted ( parts ) , expected ) <EOL> parts = [ '<STR_LIT:m>' ] <EOL> expected = { '<STR_LIT>' : True } <EOL> self . assertEqual ( ssync_sender . decode_wanted ( parts ) , expected ) <EOL> parts = [ '<STR_LIT>' ] <EOL> expected = { '<STR_LIT:data>' : True , '<STR_LIT>' : True } <EOL> self . assertEqual ( ssync_sender . decode_wanted ( parts ) , expected ) <EOL> parts = [ '<STR_LIT>' ] <EOL> expected = { '<STR_LIT:data>' : True , '<STR_LIT>' : True } <EOL> self . assertEqual ( ssync_sender . decode_wanted ( parts ) , expected ) <EOL> parts = [ '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : True } ] <EOL> expected = { '<STR_LIT:data>' : True } <EOL> self . assertEqual ( ssync_sender . decode_wanted ( parts ) , expected ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
