use of org.powermock.api.mockito.PowerMockito in project flink by apache.
the class RocksDBMemoryControllerUtilsTest method testCreateSharedResourcesWithExpectedCapacity.
@Test
public void testCreateSharedResourcesWithExpectedCapacity() {
PowerMockito.mockStatic(RocksDBMemoryControllerUtils.class);
final AtomicLong actualCacheCapacity = new AtomicLong(0L);
final AtomicLong actualWbmCapacity = new AtomicLong(0L);
when(RocksDBMemoryControllerUtils.allocateRocksDBSharedResources(anyLong(), anyDouble(), anyDouble(), anyBoolean())).thenCallRealMethod();
when(RocksDBMemoryControllerUtils.calculateActualCacheCapacity(anyLong(), anyDouble())).thenCallRealMethod();
when(RocksDBMemoryControllerUtils.calculateWriteBufferManagerCapacity(anyLong(), anyDouble())).thenCallRealMethod();
// because PowerMockito cannot mock on native static method easily,
// we introduce `createCache` and `createWriteBufferManager` wrappers here.
when(RocksDBMemoryControllerUtils.createCache(anyLong(), anyDouble())).thenAnswer((Answer<LRUCache>) invocation -> {
Object[] arguments = invocation.getArguments();
actualCacheCapacity.set((long) arguments[0]);
return (LRUCache) invocation.callRealMethod();
});
when(RocksDBMemoryControllerUtils.createWriteBufferManager(anyLong(), any(Cache.class))).thenAnswer((Answer<WriteBufferManager>) invocation -> {
Object[] arguments = invocation.getArguments();
actualWbmCapacity.set((long) arguments[0]);
return (WriteBufferManager) invocation.callRealMethod();
});
long totalMemorySize = 2048L;
double writeBufferRatio = 0.5;
double highPriPoolRatio = 0.1;
RocksDBSharedResources rocksDBSharedResources = RocksDBMemoryControllerUtils.allocateRocksDBSharedResources(totalMemorySize, writeBufferRatio, highPriPoolRatio, false);
long expectedCacheCapacity = RocksDBMemoryControllerUtils.calculateActualCacheCapacity(totalMemorySize, writeBufferRatio);
long expectedWbmCapacity = RocksDBMemoryControllerUtils.calculateWriteBufferManagerCapacity(totalMemorySize, writeBufferRatio);
assertThat(actualCacheCapacity.get(), is(expectedCacheCapacity));
assertThat(actualWbmCapacity.get(), is(expectedWbmCapacity));
assertThat(rocksDBSharedResources.getWriteBufferManagerCapacity(), is(expectedWbmCapacity));
}
Aggregations