Beispiel #1
0
 def test_load_WhenCalledWithLogIndexAndBufferReader_WriteLogsAreCorrectlyAssigned(self):
     logbuffer_reader = mock.Mock(read_entry = lambda pos: {0: ("log1", 1), 10: ("log2", 5)}[pos])
     logindex = mock.Mock(tocommit = [ LogIndexEntry(LogIndexEntry.WRITE, 0),
                                       LogIndexEntry(LogIndexEntry.WRITE, 10)])
     
     logbuff = LogBuffer.load(logindex, logbuffer_reader)
     
     self.assertEquals(logbuff.writelogs, 
                       {(0, 1) : "log1", (10, 15): "log2"})
    def test_load_WhenCalledWithLogIndexAndBufferReader_WriteLogsAreCorrectlyAssigned(
            self):
        logbuffer_reader = mock.Mock(read_entry=lambda pos: {
            0: ("log1", 1),
            10: ("log2", 5)
        }[pos])
        logindex = mock.Mock(tocommit=[
            LogIndexEntry(LogIndexEntry.WRITE, 0),
            LogIndexEntry(LogIndexEntry.WRITE, 10)
        ])

        logbuff = LogBuffer.load(logindex, logbuffer_reader)

        self.assertEquals(logbuff.writelogs, {
            (0, 1): "log1",
            (10, 15): "log2"
        })
Beispiel #3
0
    def load(cls, io):
        chunkfile = ChunkFile.open(io)
        _, logindexheader, logindexio = ChunkIO.from_name(chunkfile, LOG_INDEX_NAME)
        _, logbufferheader, logbufferio = ChunkIO.from_name(chunkfile, LOG_BUFFER_NAME)
       
        logindex_reader = LogIndexReader(logindexio, logindexheader.length/LogIndexEntrySerializer.SERIALIZED_LENGTH)
        logindex = SerializedLogIndex.load(logindex_reader)

        logbuffer_reader = LogBufferReader(logbufferio, logbufferheader.length)
        logbuffer = LogBuffer.load(logindex, logbuffer_reader)
        
        txlog = TransactionLog(chunkfile, logindex, logbuffer)
        
        outpointchunk, outpointchunkheader = chunkfile.get_chunk(OUTPOINTS_NAME) 
        outpoint_io = TransactionalIO(txlog, outpointchunk)
        outpoint_reader = OutpointIndexReader(outpoint_io, outpointchunkheader.length)
        outpoints = SerializedItemSet.load(outpoint_reader)
        return cls(txlog, outpoints)
Beispiel #4
0
    def load(cls, io):
        chunkfile = ChunkFile.open(io)
        _, logindexheader, logindexio = ChunkIO.from_name(
            chunkfile, LOG_INDEX_NAME)
        _, logbufferheader, logbufferio = ChunkIO.from_name(
            chunkfile, LOG_BUFFER_NAME)

        logindex_reader = LogIndexReader(
            logindexio,
            logindexheader.length / LogIndexEntrySerializer.SERIALIZED_LENGTH)
        logindex = SerializedLogIndex.load(logindex_reader)

        logbuffer_reader = LogBufferReader(logbufferio, logbufferheader.length)
        logbuffer = LogBuffer.load(logindex, logbuffer_reader)

        txlog = TransactionLog(chunkfile, logindex, logbuffer)

        outpointchunk, outpointchunkheader = chunkfile.get_chunk(
            OUTPOINTS_NAME)
        outpoint_io = TransactionalIO(txlog, outpointchunk)
        outpoint_reader = OutpointIndexReader(outpoint_io,
                                              outpointchunkheader.length)
        outpoints = SerializedItemSet.load(outpoint_reader)
        return cls(txlog, outpoints)