TEST_F(NoChunkFixture, ChunkRollbackWorks) {
|
ChunkType chunk;
|
chunk.setMin( BSON("a" << 10) );
|
chunk.setMax( BSON("a" << 20) );
|
|
// Initial chunk added
|
string errMsg;
|
scoped_ptr<CollectionMetadata> cloned( getCollMetadata().clonePlus( chunk,
|
ChunkVersion( 1,
|
0,
|
OID() ),
|
&errMsg ) );
|
ASSERT( cloned.get() != NULL );
|
|
// Chunk added that we will later move off
|
chunk.setMin( BSON("a" << 30) );
|
chunk.setMax( BSON("a" << 40) );
|
cloned.reset( cloned->clonePlus( chunk, ChunkVersion( 2, 0, OID() ), &errMsg ) );
|
|
ASSERT( cloned.get() != NULL );
|
ASSERT_EQUALS( cloned->getShardVersion().majorVersion(), 2 );
|
ASSERT_EQUALS( cloned->getCollVersion().majorVersion(), 2 );
|
|
// Move off the chunk
|
cloned.reset( cloned->cloneMinus( chunk, ChunkVersion( 3, 0, OID() ), &errMsg ) );
|
|
ASSERT( cloned.get() != NULL );
|
ASSERT_EQUALS( cloned->getShardVersion().majorVersion(), 3 );
|
ASSERT_EQUALS( cloned->getCollVersion().majorVersion(), 3 );
|
|
// Undo the move
|
cloned.reset( cloned->clonePlus( chunk, ChunkVersion( 2, 0, OID() ), &errMsg ) );
|
|
ASSERT( cloned.get() != NULL );
|
ASSERT_EQUALS( cloned->getShardVersion().majorVersion(), 2 );
|
// Fails, the coll version is still 3
|
ASSERT_EQUALS( cloned->getCollVersion().majorVersion(), 2 );
|
}
|