use of org.apache.bookkeeper.common.testing.executors.MockExecutorController in project bookkeeper by apache.
the class AbstractZkLedgerManagerTest method setup.
@Before
public void setup() throws Exception {
PowerMockito.mockStatic(Executors.class);
super.setup();
this.scheduler = PowerMockito.mock(ScheduledExecutorService.class);
this.schedulerController = new MockExecutorController().controlSubmit(scheduler).controlSchedule(scheduler).controlExecute(scheduler).controlScheduleAtFixedRate(scheduler, 10);
PowerMockito.when(Executors.newSingleThreadScheduledExecutor(any())).thenReturn(scheduler);
this.conf = new ClientConfiguration();
this.ledgerManager = mock(AbstractZkLedgerManager.class, withSettings().useConstructor(conf, mockZk).defaultAnswer(CALLS_REAL_METHODS));
this.metadata = new LedgerMetadata(5, 3, 3, DigestType.CRC32, new byte[0], Collections.emptyMap(), false);
doAnswer(invocationOnMock -> {
long ledgerId = invocationOnMock.getArgument(0);
return String.valueOf(ledgerId);
}).when(ledgerManager).getLedgerPath(anyLong());
doAnswer(invocationOnMock -> {
String ledgerStr = invocationOnMock.getArgument(0);
return Long.parseLong(ledgerStr);
}).when(ledgerManager).getLedgerId(anyString());
// verify constructor
assertEquals(conf.getZkLedgersRootPath(), ledgerManager.ledgerRootPath);
assertSame(mockZk, ledgerManager.zk);
assertSame(conf, ledgerManager.conf);
assertSame(scheduler, ledgerManager.scheduler);
}
use of org.apache.bookkeeper.common.testing.executors.MockExecutorController in project bookkeeper by apache.
the class MockZooKeeperTestCase method setup.
protected void setup() throws Exception {
this.mockZk = mock(ZooKeeper.class);
PowerMockito.mockStatic(ZkUtils.class);
this.zkCallbackExecutor = mock(ScheduledExecutorService.class);
this.zkCallbackController = new MockExecutorController().controlExecute(zkCallbackExecutor).controlSubmit(zkCallbackExecutor).controlSchedule(zkCallbackExecutor).controlScheduleAtFixedRate(zkCallbackExecutor, 10);
}
use of org.apache.bookkeeper.common.testing.executors.MockExecutorController in project bookkeeper by apache.
the class TestLedgerDirsManager method setUp.
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Executors.class);
File tmpDir = createTempDir("bkTest", ".dir");
curDir = Bookie.getCurrentDirectory(tmpDir);
Bookie.checkDirectoryStructure(curDir);
conf = TestBKConfiguration.newServerConfiguration();
conf.setLedgerDirNames(new String[] { tmpDir.toString() });
conf.setDiskLowWaterMarkUsageThreshold(conf.getDiskUsageThreshold());
conf.setDiskCheckInterval(diskCheckInterval);
conf.setIsForceGCAllowWhenNoSpace(true);
executor = PowerMockito.mock(ScheduledExecutorService.class);
executorController = new MockExecutorController().controlScheduleAtFixedRate(executor, 10);
PowerMockito.when(Executors.newSingleThreadScheduledExecutor(any())).thenReturn(executor);
mockDiskChecker = new MockDiskChecker(threshold, warnThreshold);
statsProvider = new TestStatsProvider();
statsLogger = statsProvider.getStatsLogger("test");
dirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()), statsLogger);
ledgerMonitor = new LedgerDirsMonitor(conf, mockDiskChecker, dirsManager);
ledgerMonitor.init();
}
use of org.apache.bookkeeper.common.testing.executors.MockExecutorController in project bookkeeper by apache.
the class LedgerStorageCheckpointTest method setUp.
@Before
public void setUp() throws Exception {
LOG.info("Setting up test {}", getClass());
PowerMockito.mockStatic(Executors.class);
try {
// start zookeeper service
startZKCluster();
} catch (Exception e) {
LOG.error("Error setting up", e);
throw e;
}
ScheduledExecutorService scheduledExecutorService = PowerMockito.mock(ScheduledExecutorService.class);
executorController = new MockExecutorController().controlSubmit(scheduledExecutorService).controlScheduleAtFixedRate(scheduledExecutorService, 10);
PowerMockito.when(scheduledExecutorService.awaitTermination(anyLong(), any(TimeUnit.class))).thenReturn(true);
PowerMockito.when(Executors.newSingleThreadScheduledExecutor(any())).thenReturn(scheduledExecutorService);
}
use of org.apache.bookkeeper.common.testing.executors.MockExecutorController in project bookkeeper by apache.
the class TestZkRegistrationClient method setup.
@Before
public void setup() throws Exception {
super.setup();
this.ledgersPath = "/" + runtime.getMethodName();
this.regPath = ledgersPath + "/" + AVAILABLE_NODE;
this.regReadonlyPath = regPath + "/" + READONLY;
this.mockExecutor = mock(ScheduledExecutorService.class);
this.controller = new MockExecutorController().controlExecute(mockExecutor).controlSubmit(mockExecutor).controlSchedule(mockExecutor).controlScheduleAtFixedRate(mockExecutor, 10);
this.zkRegistrationClient = new ZKRegistrationClient(mockZk, ledgersPath, mockExecutor);
}
Aggregations