#NEWLINE# def testItemsCanBeAddedToCollectionInWriteOnlyMode( self ) : #NEWLINE# #INDENT# with aff4 . FACTORY . Create ( self . collection_urn , 'PackedVersionedCollection' , mode = 'w' , token = self . token ) as fd : #NEWLINE# #INDENT# for i in range ( 5 ) : #NEWLINE# #INDENT# fd . Add ( rdf_flows . GrrMessage ( request_id = i ) ) #NEWLINE# #UNINDENT# #UNINDENT# with aff4 . FACTORY . OpenWithLock ( self . collection_urn , 'PackedVersionedCollection' , token = self . token ) as fd : #NEWLINE# #INDENT# num_compacted = fd . Compact ( ) #NEWLINE# self . assertEqual ( num_compacted , 5 ) #NEWLINE# #UNINDENT# with aff4 . FACTORY . Open ( self . collection_urn , 'PackedVersionedCollection' , mode = 'w' , token = self . token ) as fd : #NEWLINE# #INDENT# for i in range ( 5 , 10 ) : #NEWLINE# #INDENT# fd . Add ( rdf_flows . GrrMessage ( request_id = i ) ) #NEWLINE# #UNINDENT# #UNINDENT# fd = aff4 . FACTORY . Open ( self . collection_urn , token = self . token ) #NEWLINE# self . assertEqual ( fd . CalculateLength ( ) , 10 ) #NEWLINE# results = list ( fd ) #NEWLINE# self . assertEqual ( len ( results ) , 10 ) #NEWLINE# for i in range ( 10 ) : #NEWLINE# #INDENT# self . assertEqual ( i , results [ i ] . request_id ) #NEWLINE# #UNINDENT# with aff4 . FACTORY . OpenWithLock ( self . collection_urn , 'PackedVersionedCollection' , token = self . token ) as fd : #NEWLINE# #INDENT# num_compacted = fd . Compact ( ) #NEWLINE# self . assertEqual ( num_compacted , 5 ) #NEWLINE# #UNINDENT# fd = aff4 . FACTORY . Open ( self . collection_urn , token = self . token ) #NEWLINE# self . assertEqual ( fd . CalculateLength ( ) , 10 ) #NEWLINE# results = list ( fd ) #NEWLINE# self . assertEqual ( len ( results ) , 10 ) #NEWLINE# for i in range ( 10 ) : #NEWLINE# #INDENT# self . assertEqual ( i , results [ i ] . request_id )