cfs/test/fsproc/testBlockBuffer_utest2.cc
// split 2 out of 4 blocks
split 2 out of 4 blocks
split 2 out of 4 blocks
TEST(SplitBufferItem, T2) {
  uint32_t blockNum = 4;
  int blockSize = 32;
  char *memPtr = (char *)malloc(blockNum * blockSize);
  BlockBuffer buffer(blockNum, blockSize, memPtr);
  int index = 1;
  int lockGrabbed;
  bool hasDirty = true;
  BlockBufferItem *item;
  item = buffer.getBlock(1000, lockGrabbed, hasDirty, index);
  int outBlockIdx1 = item->getIdx();
  EXPECT_EQ(lockGrabbed, BLOCK_BUF_LOCK_GRAB_YES);
  buffer.releaseBlock(1000);
  item = buffer.getBlock(1001, lockGrabbed, hasDirty, index);
  int outBlockIdx2 = item->getIdx();
  EXPECT_EQ(lockGrabbed, BLOCK_BUF_LOCK_GRAB_YES);
  buffer.releaseBlock(1001);
  std::unordered_set<BlockBufferItem *> itemSet;
  buffer.splitBufferItemsByIndex(index, itemSet);
  EXPECT_EQ(itemSet.size(), 2);
  std::unordered_set<int> blockIdxSet;
  for (uint i = 0; i < 100; i++) {
    item = buffer.getBlock(1002 + i, lockGrabbed, hasDirty);
    EXPECT_NE(item, nullptr);
    EXPECT_EQ(lockGrabbed, BLOCK_BUF_LOCK_GRAB_YES);
    blockIdxSet.emplace(item->getIdx());
    EXPECT_LT(blockIdxSet.size(), blockNum);
    EXPECT_EQ(blockIdxSet.find(outBlockIdx1), blockIdxSet.end());
    EXPECT_EQ(blockIdxSet.find(outBlockIdx2), blockIdxSet.end());
    buffer.releaseBlock(item);
  }
  free(memPtr);
}
TEST ( SplitBufferItem , T2 ) { uint32_t blockNum = 4 ; int blockSize = 32 ; char * memPtr = ( char * ) malloc ( blockNum * blockSize ) ; BlockBuffer buffer ( blockNum , blockSize , memPtr ) ; int index = 1 ; int lockGrabbed ; bool hasDirty = true ; BlockBufferItem * item ; item = buffer . getBlock ( 1000 , lockGrabbed , hasDirty , index ) ; int outBlockIdx1 = item -> getIdx ( ) ; EXPECT_EQ ( lockGrabbed , BLOCK_BUF_LOCK_GRAB_YES ) ; buffer . releaseBlock ( 1000 ) ; item = buffer . getBlock ( 1001 , lockGrabbed , hasDirty , index ) ; int outBlockIdx2 = item -> getIdx ( ) ; EXPECT_EQ ( lockGrabbed , BLOCK_BUF_LOCK_GRAB_YES ) ; buffer . releaseBlock ( 1001 ) ; std :: unordered_set < BlockBufferItem * > itemSet ; buffer . splitBufferItemsByIndex ( index , itemSet ) ; EXPECT_EQ ( itemSet . size ( ) , 2 ) ; std :: unordered_set < int > blockIdxSet ; for ( uint i = 0 ; i < 100 ; i ++ ) { item = buffer . getBlock ( 1002 + i , lockGrabbed , hasDirty ) ; EXPECT_NE ( item , nullptr ) ; EXPECT_EQ ( lockGrabbed , BLOCK_BUF_LOCK_GRAB_YES ) ; blockIdxSet . emplace ( item -> getIdx ( ) ) ; EXPECT_LT ( blockIdxSet . size ( ) , blockNum ) ; EXPECT_EQ ( blockIdxSet . find ( outBlockIdx1 ) , blockIdxSet . end ( ) ) ; EXPECT_EQ ( blockIdxSet . find ( outBlockIdx2 ) , blockIdxSet . end ( ) ) ; buffer . releaseBlock ( item ) ; } free ( memPtr ) ; }
split 2 out of 4 blocks
split 2 out of 4 blocks
// buffer.updateBlockIndex(item, index); // buffer.updateBlockIndex(item, index);