use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class RuntimeManagerMainTest method testManageTopologyDryRun.
@PrepareForTest({ ReflectionUtils.class, Runtime.class })
@Test(expected = UpdateDryRunResponse.class)
public void testManageTopologyDryRun() throws Exception {
config = mock(Config.class);
// prepare packing class
ResourceCompliantRRPacking repacking = new ResourceCompliantRRPacking();
when(config.getStringValue(Key.REPACKING_CLASS)).thenReturn(IRepacking.class.getName());
when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
when(config.getStringValue(RuntimeManagerRunner.RUNTIME_MANAGER_COMPONENT_PARALLELISM_KEY)).thenReturn("testSpout:4,testBolt:5");
// mock dry-run mode
when(config.getBooleanValue(Key.DRY_RUN)).thenReturn(true);
when(config.getDoubleValue(Key.INSTANCE_CPU)).thenReturn(1.0);
when(config.getByteAmountValue(Key.INSTANCE_RAM)).thenReturn(ByteAmount.fromGigabytes(1));
when(config.getByteAmountValue(Key.INSTANCE_DISK)).thenReturn(ByteAmount.fromGigabytes(1));
RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, Command.UPDATE));
// Mock validate runtime
PowerMockito.mockStatic(ReflectionUtils.class);
PowerMockito.doReturn(mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", eq(IStateManager.class.getName()));
PowerMockito.doReturn(repacking).when(ReflectionUtils.class, "newInstance", eq(IRepacking.class.getName()));
doReturn(true).when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
// Successfully get ISchedulerClient
ISchedulerClient client = mock(ISchedulerClient.class);
doReturn(client).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
// Mock updateTopologyHandler of runner
PowerMockito.mockStatic(Runtime.class);
SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
PowerMockito.when(Runtime.schedulerStateManagerAdaptor(any(Config.class))).thenReturn(manager);
RoundRobinPacking packing = new RoundRobinPacking();
PackingPlans.PackingPlan currentPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
// the actual topology does not matter
doReturn(TopologyAPI.Topology.getDefaultInstance()).when(manager).getTopology(eq(TOPOLOGY_NAME));
doReturn(currentPlan).when(manager).getPackingPlan(eq(TOPOLOGY_NAME));
try {
runtimeManagerMain.manageTopology();
} finally {
// verify scheduler client is never used
verifyZeroInteractions(client);
}
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class UpdateTopologyManagerTest method mockStateManager.
private static SchedulerStateManagerAdaptor mockStateManager(TopologyAPI.Topology topology, PackingPlans.PackingPlan packingPlan, Lock lock) {
SchedulerStateManagerAdaptor stateManager = mock(SchedulerStateManagerAdaptor.class);
when(stateManager.getPhysicalPlan(TOPOLOGY_NAME)).thenReturn(PhysicalPlans.PhysicalPlan.getDefaultInstance());
when(stateManager.getTopology(TOPOLOGY_NAME)).thenReturn(topology);
when(stateManager.getPackingPlan(eq(TOPOLOGY_NAME))).thenReturn(packingPlan);
when(stateManager.getLock(eq(TOPOLOGY_NAME), eq(IStateManager.LockName.UPDATE_TOPOLOGY))).thenReturn(lock);
return stateManager;
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class SchedulerUtilsTest method persistUpdatedPackingPlanWillUpdatesStateManager.
@Test
public void persistUpdatedPackingPlanWillUpdatesStateManager() {
SchedulerStateManagerAdaptor adaptor = Mockito.mock(SchedulerStateManagerAdaptor.class);
Mockito.when(adaptor.updatePackingPlan(Mockito.any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME))).thenReturn(true);
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(PackingTestUtils.testContainerPlan(1, 0, 1, 2));
PackingPlan packing = new PackingPlan("id", containers);
SchedulerUtils.persistUpdatedPackingPlan(TOPOLOGY_NAME, packing, adaptor);
Mockito.verify(adaptor).updatePackingPlan(Mockito.any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class SchedulerClientFactory method getSchedulerClient.
/**
* Implementation of getSchedulerClient - Used to create objects
* Currently it creates either HttpServiceSchedulerClient or LibrarySchedulerClient
*
* @return getSchedulerClient created. return null if failed to create ISchedulerClient instance
*/
public ISchedulerClient getSchedulerClient() throws SchedulerException {
LOG.fine("Creating scheduler client");
ISchedulerClient schedulerClient;
if (Context.schedulerService(config)) {
// get the instance of the state manager
SchedulerStateManagerAdaptor statemgr = Runtime.schedulerStateManagerAdaptor(runtime);
Scheduler.SchedulerLocation schedulerLocation = statemgr.getSchedulerLocation(Runtime.topologyName(runtime));
if (schedulerLocation == null) {
throw new SchedulerException("Failed to get scheduler location from state manager");
}
LOG.log(Level.FINE, "Scheduler is listening on location: {0} ", schedulerLocation.toString());
schedulerClient = new HttpServiceSchedulerClient(config, runtime, schedulerLocation.getHttpEndpoint());
} else {
// create an instance of scheduler
final IScheduler scheduler = LauncherUtils.getInstance().getSchedulerInstance(config, runtime);
LOG.fine("Invoke scheduler as a library");
schedulerClient = new LibrarySchedulerClient(config, runtime, scheduler);
}
return schedulerClient;
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class SubmitterMainTest method testValidateSubmit.
@Test
public void testValidateSubmit() throws Exception {
SubmitterMain submitterMain = new SubmitterMain(config, topology);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
// Topology is not running
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(null);
submitterMain.validateSubmit(adaptor, TOPOLOGY_NAME);
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(false);
submitterMain.validateSubmit(adaptor, TOPOLOGY_NAME);
}
Aggregations