<s> from hazelcast . serialization . predicate import SqlPredicate <EOL> from tests . base import SingleMemberTestCase <EOL> from tests . util import random_string <EOL> class TransactionalMapTest ( SingleMemberTestCase ) : <EOL> def setUp ( self ) : <EOL> self . map = self . client . get_map ( random_string ( ) ) . blocking ( ) <EOL> def test_put ( self ) : <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertIsNone ( tx_map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT:value>" ) <EOL> def test_put_when_present ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertEqual ( tx_map . put ( "<STR_LIT:key>" , "<STR_LIT>" ) , "<STR_LIT:value>" ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT>" ) <EOL> def test_put_if_absent ( self ) : <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertIsNone ( tx_map . put_if_absent ( "<STR_LIT:key>" , "<STR_LIT:value>" ) ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT:value>" ) <EOL> def test_put_if_absent_when_present ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertEqual ( tx_map . put_if_absent ( "<STR_LIT:key>" , "<STR_LIT>" ) , "<STR_LIT:value>" ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT:value>" ) <EOL> def test_get ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertEqual ( tx_map . get ( "<STR_LIT:key>" ) , "<STR_LIT:value>" ) <EOL> def test_get_for_update ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertEqual ( tx_map . get_for_update ( "<STR_LIT:key>" ) , "<STR_LIT:value>" ) <EOL> self . assertTrue ( self . map . is_locked ( "<STR_LIT:key>" ) ) <EOL> self . assertFalse ( self . map . is_locked ( "<STR_LIT:key>" ) ) <EOL> def test_contains_key ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertTrue ( tx_map . contains_key ( "<STR_LIT:key>" ) ) <EOL> def test_contains_key_when_missing ( self ) : <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertFalse ( tx_map . contains_key ( "<STR_LIT:key>" ) ) <EOL> def test_size ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertTrue ( tx_map . size ( ) , <NUM_LIT:1> ) <EOL> def test_is_empty ( self ) : <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertTrue ( tx_map . is_empty ( ) ) <EOL> def test_is_empty_when_not_empty ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertFalse ( tx_map . is_empty ( ) ) <EOL> def test_set ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertIsNone ( tx_map . set ( "<STR_LIT:key>" , "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT>" ) <EOL> def test_replace ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertEqual ( "<STR_LIT:value>" , tx_map . replace ( "<STR_LIT:key>" , "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT>" ) <EOL> def test_replace_when_missing ( self ) : <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertIsNone ( tx_map . replace ( "<STR_LIT:key>" , "<STR_LIT>" ) ) <EOL> self . assertIsNone ( self . map . get ( "<STR_LIT:key>" ) ) <EOL> def test_replace_if_same_when_same ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertTrue ( tx_map . replace_if_same ( "<STR_LIT:key>" , "<STR_LIT:value>" , "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT>" ) <EOL> def test_replace_if_same_when_different ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertFalse ( tx_map . replace_if_same ( "<STR_LIT:key>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT:value>" ) <EOL> def test_remove ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertEqual ( "<STR_LIT:value>" , tx_map . remove ( "<STR_LIT:key>" ) ) <EOL> self . assertFalse ( self . map . contains_key ( "<STR_LIT:key>" ) ) <EOL> def test_remove_when_missing ( self ) : <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertIsNone ( tx_map . remove ( "<STR_LIT:key>" ) ) <EOL> def test_remove_if_same_when_same ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertTrue ( tx_map . remove_if_same ( "<STR_LIT:key>" , "<STR_LIT:value>" ) ) <EOL> self . assertFalse ( self . map . contains_key ( "<STR_LIT:key>" ) ) <EOL> def test_remove_if_same_when_different ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertFalse ( tx_map . remove_if_same ( "<STR_LIT:key>" , "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . map . get ( "<STR_LIT:key>" ) , "<STR_LIT:value>" ) <EOL> def test_delete ( self ) : <EOL> self . map . put ( "<STR_LIT:key>" , "<STR_LIT:value>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertIsNone ( tx_map . delete ( "<STR_LIT:key>" ) ) <EOL> self . assertFalse ( self . map . contains_key ( "<STR_LIT:key>" ) ) <EOL> def test_key_set ( self ) : <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertItemsEqual ( tx_map . key_set ( ) , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_key_set_with_predicate ( self ) : <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertItemsEqual ( tx_map . key_set ( predicate = SqlPredicate ( "<STR_LIT>" ) ) , [ "<STR_LIT>" ] ) <EOL> def test_values ( self ) : <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertItemsEqual ( tx_map . values ( ) , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_values_with_predicate ( self ) : <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . map . put ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertItemsEqual ( tx_map . values ( predicate = SqlPredicate ( "<STR_LIT>" ) ) , [ "<STR_LIT>" ] ) <EOL> def test_str ( self ) : <EOL> with self . client . new_transaction ( ) as tx : <EOL> tx_map = tx . get_map ( self . map . name ) <EOL> self . assertTrue ( str ( tx_map ) . startswith ( "<STR_LIT>" ) ) </s>
