<s> import tempfile <EOL> import unittest <EOL> import shutil <EOL> import os <EOL> import ufora . native . Storage as StorageNative <EOL> import ufora . distributed . SharedState . SharedState as SharedState <EOL> import ufora . native . Json as NativeJson <EOL> class LogFileDirectory ( unittest . TestCase ) : <EOL> def createLogFileDir ( self ) : <EOL> self . tempdir = tempfile . mkdtemp ( ) <EOL> self . keyspace = SharedState . Keyspace ( "<STR_LIT>" , NativeJson . Json ( "<STR_LIT>" ) , <NUM_LIT:1> ) <EOL> self . keyrange = SharedState . KeyRange ( self . keyspace , <NUM_LIT:0> , None , None , True , False ) <EOL> self . logFileDir = StorageNative . LogFileDirectory ( self . tempdir , self . keyspace , self . keyrange ) <EOL> self . baseDir = os . path . split ( self . logFileDir . getCurrentLogPath ( ) ) [ <NUM_LIT:0> ] <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . tempdir , True ) <EOL> def pathFor ( self , type , iter ) : <EOL> return os . path . join ( self . baseDir , '<STR_LIT>' % ( type , iter ) ) <EOL> def touchFile ( self , path ) : <EOL> with open ( path , '<STR_LIT:w>' ) : <EOL> pass <EOL> def perform_startup ( self , logFiles , stateFiles , targetLog , targetState ) : <EOL> self . createLogFileDir ( ) <EOL> for it in logFiles : <EOL> self . touchFile ( self . pathFor ( '<STR_LIT>' , it ) ) <EOL> for it in stateFiles : <EOL> self . touchFile ( self . pathFor ( '<STR_LIT>' , it ) ) <EOL> self . logFileDir = StorageNative . LogFileDirectory ( self . tempdir , self . keyspace , self . keyrange ) <EOL> self . assertEqual ( self . logFileDir . getCurrentLogPath ( ) , self . pathFor ( '<STR_LIT>' , targetLog ) ) <EOL> self . assertEqual ( self . logFileDir . getNextStatePath ( ) , self . pathFor ( '<STR_LIT>' , targetState ) ) <EOL> shutil . rmtree ( self . tempdir , True ) <EOL> def test_basic ( self ) : <EOL> self . createLogFileDir ( ) <EOL> targetSet = set ( { ix : self . pathFor ( '<STR_LIT>' , ix ) for ix in range ( <NUM_LIT:10> ) } . items ( ) ) <EOL> for ix in range ( <NUM_LIT:10> ) : <EOL> self . touchFile ( self . logFileDir . getCurrentLogPath ( ) ) <EOL> self . touchFile ( self . logFileDir . getNextStatePath ( ) ) <EOL> self . logFileDir . startNextLogFile ( ) <EOL> self . assertEqual ( set ( self . logFileDir . getAllLogFiles ( ) . items ( ) ) , targetSet ) <EOL> shutil . rmtree ( self . tempdir , True ) <EOL> def test_startup ( self ) : <EOL> self . perform_startup ( [ <NUM_LIT:0> ] , [ <NUM_LIT> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> self . perform_startup ( [ <NUM_LIT> ] , [ <NUM_LIT:0> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> self . perform_startup ( [ <NUM_LIT> ] , [ ] , <NUM_LIT> , <NUM_LIT> ) <EOL> self . perform_startup ( [ ] , [ <NUM_LIT> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> self . perform_startup ( [ ] , [ <NUM_LIT> ] , <NUM_LIT> , <NUM_LIT> ) <EOL> self . perform_startup ( [ ] , range ( <NUM_LIT> ) [ : : <NUM_LIT:10> ] , <NUM_LIT> , <NUM_LIT> ) </s>
