Search in sources :

Example 1 with Shutdown

use of org.apache.heron.scheduler.utils.Shutdown in project heron by twitter.

the class SchedulerMainTest method setUp.

/**
 * Basic setup before executing a test case
 */
@Before
public void setUp() throws Exception {
    Config config = mock(Config.class);
    when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(STATE_MANAGER_CLASS);
    when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(SCHEDULER_CLASS);
    int iSchedulerServerPort = 0;
    TopologyAPI.Topology topology = TopologyTests.createTopology(iTopologyName, new org.apache.heron.api.Config(), new HashMap<String, Integer>(), new HashMap<String, Integer>());
    // Mock objects to be verified
    stateManager = mock(IStateManager.class);
    scheduler = mock(IScheduler.class);
    final SettableFuture<PackingPlans.PackingPlan> future = getTestPacking();
    when(stateManager.getPackingPlan(null, iTopologyName)).thenReturn(future);
    // Mock ReflectionUtils stuff
    PowerMockito.spy(ReflectionUtils.class);
    PowerMockito.doReturn(stateManager).when(ReflectionUtils.class, "newInstance", STATE_MANAGER_CLASS);
    PowerMockito.doReturn(scheduler).when(ReflectionUtils.class, "newInstance", SCHEDULER_CLASS);
    // Mock objects to be verified
    schedulerMain = spy(new SchedulerMain(config, topology, iSchedulerServerPort, mock(Properties.class)));
    schedulerServer = mock(SchedulerServer.class);
    doReturn(schedulerServer).when(schedulerMain).getServer(any(Config.class), eq(scheduler), eq(iSchedulerServerPort));
    doReturn(true).when(scheduler).onSchedule(any(PackingPlan.class));
    // Mock SchedulerUtils stuff
    PowerMockito.spy(SchedulerUtils.class);
    PowerMockito.doReturn(true).when(SchedulerUtils.class, "setSchedulerLocation", any(Config.class), anyString(), eq(scheduler));
    // Avoid infinite waiting
    Shutdown shutdown = mock(Shutdown.class);
    doReturn(shutdown).when(schedulerMain).getShutdown();
}
Also used : IStateManager(org.apache.heron.spi.statemgr.IStateManager) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Mockito.anyString(org.mockito.Mockito.anyString) Properties(java.util.Properties) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) Shutdown(org.apache.heron.scheduler.utils.Shutdown) SchedulerServer(org.apache.heron.scheduler.server.SchedulerServer) IScheduler(org.apache.heron.spi.scheduler.IScheduler) Before(org.junit.Before)

Aggregations

Properties (java.util.Properties)1 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)1 SchedulerServer (org.apache.heron.scheduler.server.SchedulerServer)1 Shutdown (org.apache.heron.scheduler.utils.Shutdown)1 Config (org.apache.heron.spi.common.Config)1 PackingPlan (org.apache.heron.spi.packing.PackingPlan)1 IScheduler (org.apache.heron.spi.scheduler.IScheduler)1 IStateManager (org.apache.heron.spi.statemgr.IStateManager)1 Before (org.junit.Before)1 Mockito.anyString (org.mockito.Mockito.anyString)1