From 5b68b0c6abd98fc99acd57a2c5c691468e7dcb97 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 26 May 2010 19:31:52 +0000 Subject: Oooh, another minor myriad fix, it's getting solid now. :) --- src/cachestoremyriad.h | 2 +- src/myriad.cpp | 3 ++- src/unit/myriad.unit | 60 +++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 58 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/cachestoremyriad.h b/src/cachestoremyriad.h index 400e3f7..928eb46 100644 --- a/src/cachestoremyriad.h +++ b/src/cachestoremyriad.h @@ -49,7 +49,7 @@ namespace Bu { public: CacheStoreMyriad( Bu::Stream &sArch, - int iBlockSize=1024, int iPreAllocate=1 ) : + int iBlockSize=512, int iPreAllocate=8 ) : mStore( sArch, iBlockSize, iPreAllocate ) { try diff --git a/src/myriad.cpp b/src/myriad.cpp index 9d7a849..748350c 100644 --- a/src/myriad.cpp +++ b/src/myriad.cpp @@ -555,6 +555,7 @@ int Bu::Myriad::streamAddBlock( Stream *pStream ) int iBlock = findEmptyBlock(); pStream->aBlocks.append( iBlock ); bsBlockUsed.setBit( iBlock ); + bHeaderChanged = true; iUsed++; return iBlock; } @@ -569,7 +570,7 @@ void Bu::Myriad::setStreamSize( Stream *pStream, long iSize ) { // Shrink for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize; - iNewSize-64 > iSize; iNewSize -= iBlockSize ) + iNewSize-iBlockSize > iSize; iNewSize -= iBlockSize ) { if( bsBlockUsed.getBit( pStream->aBlocks.last() ) ) iUsed--; diff --git a/src/unit/myriad.unit b/src/unit/myriad.unit index d27c0dc..a88650f 100644 --- a/src/unit/myriad.unit +++ b/src/unit/myriad.unit @@ -25,8 +25,7 @@ suite Myriad FString sFileName("myriad-XXXXXXX"); File fMyriad = tempFile( sFileName ); - Myriad m( fMyriad ); - m.initialize( 64 ); + Myriad m( fMyriad, 32 ); MyriadStream ms = m.openStream( m.createStream() ); ms.setSize( 150 ); @@ -54,7 +53,21 @@ suite Myriad { buf[j] = (j+iSize)%256; } - s.write( buf, iSize-8 ); + if( random()%2 == 0 ) + { + s.write( buf, iSize-8 ); + } + else + { + for( int j = 0; j < iSize-8; ) + { + int iAmnt = (random()%8)+1; + if( iAmnt+j > iSize-8 ) + iAmnt = iSize-8-j; + iAmnt = s.write( buf+j, iAmnt ); + j += iAmnt; + } + } delete[] buf; iSize = ~iSize; s.write( &iSize, 4 ); @@ -79,7 +92,8 @@ suite Myriad { char b = buf[j]; delete[] buf; - throw ExceptionBase("Block failed computed data verify (%02X==%02X).", b, (char)((j+iSize)%256) ); + throw ExceptionBase("Block failed computed data verify " + "(%02X==%02X).", b, (char)((j+iSize)%256) ); } } delete[] buf; @@ -164,7 +178,7 @@ suite Myriad File fMyriad = tempFile( sFileName ); Myriad m( fMyriad ); - m.initialize( 64 ); + m.initialize( 128 ); Array aStream; @@ -190,5 +204,41 @@ suite Myriad } } } + + test stressTruncate2 + { + FString sFileName("myriad-XXXXXXX"); + + Array aStream; + + { + File fMyriad = tempFile( sFileName ); + Myriad m( fMyriad, 64 ); + + for( int j = 0; j < 5; j++ ) + { + aStream.append( m.createStream() ); + } + } + + srandom( 1024 ); + + char b; + for( int iter = 0; iter < 2500; iter++ ) + { + File fMyriad( sFileName, File::ReadWrite ); + Myriad m( fMyriad ); + for( Array::iterator i = aStream.begin(); i; i++ ) + { + MyriadStream ms = m.openStream( *i ); + addBlock( ms, false ); + ms.setSize( ms.tell() ); + unitTest( ms.read( &b, 1 ) == 0 ); + ms.setPos( 0 ); + verifyBlock( ms ); + unitTest( ms.read( &b, 1 ) == 0 ); + } + } + } } -- cgit v1.2.3