Search in sources :

Example 1 with MockExecutorController

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);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Before(org.junit.Before)

Example 2 with MockExecutorController

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);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) ZooKeeper(org.apache.zookeeper.ZooKeeper)

Example 3 with MockExecutorController

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();
}
Also used : TestStatsProvider(org.apache.bookkeeper.test.TestStatsProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) DiskChecker(org.apache.bookkeeper.util.DiskChecker) File(java.io.File) Before(org.junit.Before)

Example 4 with MockExecutorController

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);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) TimeUnit(java.util.concurrent.TimeUnit) IOException(java.io.IOException) BKException(org.apache.bookkeeper.client.BKException) Before(org.junit.Before)

Example 5 with MockExecutorController

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);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MockExecutorController(org.apache.bookkeeper.common.testing.executors.MockExecutorController) Before(org.junit.Before)

Aggregations

ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 MockExecutorController (org.apache.bookkeeper.common.testing.executors.MockExecutorController)5 Before (org.junit.Before)4 File (java.io.File)1 IOException (java.io.IOException)1 TimeUnit (java.util.concurrent.TimeUnit)1 BKException (org.apache.bookkeeper.client.BKException)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)1 TestStatsProvider (org.apache.bookkeeper.test.TestStatsProvider)1 DiskChecker (org.apache.bookkeeper.util.DiskChecker)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1