diff options
Diffstat (limited to '')
-rw-r--r-- | src/cachestoremyriad.h | 2 | ||||
-rw-r--r-- | src/myriad.cpp | 3 | ||||
-rw-r--r-- | src/unit/myriad.unit | 60 |
3 files changed, 58 insertions, 7 deletions
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 | |||
49 | { | 49 | { |
50 | public: | 50 | public: |
51 | CacheStoreMyriad( Bu::Stream &sArch, | 51 | CacheStoreMyriad( Bu::Stream &sArch, |
52 | int iBlockSize=1024, int iPreAllocate=1 ) : | 52 | int iBlockSize=512, int iPreAllocate=8 ) : |
53 | mStore( sArch, iBlockSize, iPreAllocate ) | 53 | mStore( sArch, iBlockSize, iPreAllocate ) |
54 | { | 54 | { |
55 | try | 55 | 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 ) | |||
555 | int iBlock = findEmptyBlock(); | 555 | int iBlock = findEmptyBlock(); |
556 | pStream->aBlocks.append( iBlock ); | 556 | pStream->aBlocks.append( iBlock ); |
557 | bsBlockUsed.setBit( iBlock ); | 557 | bsBlockUsed.setBit( iBlock ); |
558 | bHeaderChanged = true; | ||
558 | iUsed++; | 559 | iUsed++; |
559 | return iBlock; | 560 | return iBlock; |
560 | } | 561 | } |
@@ -569,7 +570,7 @@ void Bu::Myriad::setStreamSize( Stream *pStream, long iSize ) | |||
569 | { | 570 | { |
570 | // Shrink | 571 | // Shrink |
571 | for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize; | 572 | for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize; |
572 | iNewSize-64 > iSize; iNewSize -= iBlockSize ) | 573 | iNewSize-iBlockSize > iSize; iNewSize -= iBlockSize ) |
573 | { | 574 | { |
574 | if( bsBlockUsed.getBit( pStream->aBlocks.last() ) ) | 575 | if( bsBlockUsed.getBit( pStream->aBlocks.last() ) ) |
575 | iUsed--; | 576 | 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 | |||
25 | FString sFileName("myriad-XXXXXXX"); | 25 | FString sFileName("myriad-XXXXXXX"); |
26 | 26 | ||
27 | File fMyriad = tempFile( sFileName ); | 27 | File fMyriad = tempFile( sFileName ); |
28 | Myriad m( fMyriad ); | 28 | Myriad m( fMyriad, 32 ); |
29 | m.initialize( 64 ); | ||
30 | 29 | ||
31 | MyriadStream ms = m.openStream( m.createStream() ); | 30 | MyriadStream ms = m.openStream( m.createStream() ); |
32 | ms.setSize( 150 ); | 31 | ms.setSize( 150 ); |
@@ -54,7 +53,21 @@ suite Myriad | |||
54 | { | 53 | { |
55 | buf[j] = (j+iSize)%256; | 54 | buf[j] = (j+iSize)%256; |
56 | } | 55 | } |
57 | s.write( buf, iSize-8 ); | 56 | if( random()%2 == 0 ) |
57 | { | ||
58 | s.write( buf, iSize-8 ); | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | for( int j = 0; j < iSize-8; ) | ||
63 | { | ||
64 | int iAmnt = (random()%8)+1; | ||
65 | if( iAmnt+j > iSize-8 ) | ||
66 | iAmnt = iSize-8-j; | ||
67 | iAmnt = s.write( buf+j, iAmnt ); | ||
68 | j += iAmnt; | ||
69 | } | ||
70 | } | ||
58 | delete[] buf; | 71 | delete[] buf; |
59 | iSize = ~iSize; | 72 | iSize = ~iSize; |
60 | s.write( &iSize, 4 ); | 73 | s.write( &iSize, 4 ); |
@@ -79,7 +92,8 @@ suite Myriad | |||
79 | { | 92 | { |
80 | char b = buf[j]; | 93 | char b = buf[j]; |
81 | delete[] buf; | 94 | delete[] buf; |
82 | throw ExceptionBase("Block failed computed data verify (%02X==%02X).", b, (char)((j+iSize)%256) ); | 95 | throw ExceptionBase("Block failed computed data verify " |
96 | "(%02X==%02X).", b, (char)((j+iSize)%256) ); | ||
83 | } | 97 | } |
84 | } | 98 | } |
85 | delete[] buf; | 99 | delete[] buf; |
@@ -164,7 +178,7 @@ suite Myriad | |||
164 | 178 | ||
165 | File fMyriad = tempFile( sFileName ); | 179 | File fMyriad = tempFile( sFileName ); |
166 | Myriad m( fMyriad ); | 180 | Myriad m( fMyriad ); |
167 | m.initialize( 64 ); | 181 | m.initialize( 128 ); |
168 | 182 | ||
169 | Array<int> aStream; | 183 | Array<int> aStream; |
170 | 184 | ||
@@ -190,5 +204,41 @@ suite Myriad | |||
190 | } | 204 | } |
191 | } | 205 | } |
192 | } | 206 | } |
207 | |||
208 | test stressTruncate2 | ||
209 | { | ||
210 | FString sFileName("myriad-XXXXXXX"); | ||
211 | |||
212 | Array<int> aStream; | ||
213 | |||
214 | { | ||
215 | File fMyriad = tempFile( sFileName ); | ||
216 | Myriad m( fMyriad, 64 ); | ||
217 | |||
218 | for( int j = 0; j < 5; j++ ) | ||
219 | { | ||
220 | aStream.append( m.createStream() ); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | srandom( 1024 ); | ||
225 | |||
226 | char b; | ||
227 | for( int iter = 0; iter < 2500; iter++ ) | ||
228 | { | ||
229 | File fMyriad( sFileName, File::ReadWrite ); | ||
230 | Myriad m( fMyriad ); | ||
231 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) | ||
232 | { | ||
233 | MyriadStream ms = m.openStream( *i ); | ||
234 | addBlock( ms, false ); | ||
235 | ms.setSize( ms.tell() ); | ||
236 | unitTest( ms.read( &b, 1 ) == 0 ); | ||
237 | ms.setPos( 0 ); | ||
238 | verifyBlock( ms ); | ||
239 | unitTest( ms.read( &b, 1 ) == 0 ); | ||
240 | } | ||
241 | } | ||
242 | } | ||
193 | } | 243 | } |
194 | 244 | ||