use of alluxio.master.metastore.rocks.RocksBlockStore in project alluxio by Alluxio.
the class BackupManagerTest method rocksBlockStoreIteratorClosed.
@Test
public void rocksBlockStoreIteratorClosed() throws Exception {
// Prepare some data for the iterator
List<BlockStore.Block> blocks = new ArrayList<>();
blocks.add(createNewBlock(1L));
blocks.add(createNewBlock(2L));
blocks.add(createNewBlock(3L));
// When RocksBlockStore.iterator(), return mock iterator
AtomicBoolean blockIteratorClosed = new AtomicBoolean(false);
CloseableIterator<BlockStore.Block> testBlockIter = CloseableIterator.create(blocks.iterator(), (whatever) -> blockIteratorClosed.set(true));
RocksBlockStore mockBlockStore = mock(RocksBlockStore.class);
when(mockBlockStore.iterator()).thenReturn(testBlockIter);
// Prepare the BlockMaster for the backup operation
CoreMasterContext masterContext = MasterTestUtils.testMasterContext(new NoopJournalSystem(), null, () -> mockBlockStore, x -> new HeapInodeStore());
mMetricsMaster = new MetricsMasterFactory().create(mRegistry, masterContext);
mBlockMaster = new DefaultBlockMaster(mMetricsMaster, masterContext, mClock, ExecutorServiceFactories.constantExecutorServiceFactory(mExecutorService));
mRegistry.add(BlockMaster.class, mBlockMaster);
mRegistry.start(true);
// Perform the backup operation
BackupManager manager = new BackupManager(mRegistry);
File backupDir = AlluxioTestDirectory.createTemporaryDirectory("backup-dir");
File backupFile = new File(backupDir, "1.backup");
AtomicLong counter = new AtomicLong(0L);
manager.backup(new FileOutputStream(backupFile), counter);
// verify iterators all closed properly
assertTrue(blockIteratorClosed.get());
}
Aggregations