use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class SchedulerServerTest method testSchedulerServer.
@Test
public void testSchedulerServer() throws Exception {
int freePort = SysUtils.getFreePort();
IScheduler scheduler = Mockito.mock(IScheduler.class);
Config runtime = Mockito.mock(Config.class);
SchedulerServer schedulerServer = Mockito.spy(new SchedulerServer(runtime, scheduler, freePort));
Assert.assertEquals(NetworkUtils.getHostName(), schedulerServer.getHost());
Assert.assertEquals(freePort, schedulerServer.getPort());
}
use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class LauncherUtilsTest method constructsConfigWithTopologyInfo.
@Test
public void constructsConfigWithTopologyInfo() throws Exception {
TopologyAPI.Topology mockTopology = PowerMockito.mock(TopologyAPI.Topology.class);
PowerMockito.when(mockTopology.getId()).thenReturn("testTopologyId");
PowerMockito.when(mockTopology.getName()).thenReturn("testTopologyName");
SchedulerStateManagerAdaptor mockStMgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
PowerMockito.spy(TopologyUtils.class);
PowerMockito.doReturn(456).when(TopologyUtils.class, "getNumContainers", mockTopology);
Config runtime = Config.newBuilder().putAll(LauncherUtils.getInstance().createPrimaryRuntime(mockTopology)).putAll(LauncherUtils.getInstance().createAdaptorRuntime(mockStMgr)).build();
Assert.assertEquals("testTopologyId", Runtime.topologyId(runtime));
Assert.assertEquals("testTopologyName", Runtime.topologyName(runtime));
Assert.assertEquals(mockTopology, Runtime.topology(runtime));
Assert.assertEquals(mockStMgr, Runtime.schedulerStateManagerAdaptor(runtime));
Assert.assertEquals(456 + 1, Runtime.numContainers(runtime).longValue());
}
use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class LauncherUtilsTest method generatesPackingPlan.
@Test
public void generatesPackingPlan() throws Exception {
final String PACKING_CLASS = "nonExistingTestPackingClass";
final PackingPlan mockPackingPlan = Mockito.mock(PackingPlan.class);
IPacking mockPacking = Mockito.mock(IPacking.class);
Mockito.when(mockPacking.pack()).thenReturn(mockPackingPlan);
PowerMockito.spy(ReflectionUtils.class);
PowerMockito.doReturn(mockPacking).when(ReflectionUtils.class, "newInstance", PACKING_CLASS);
TopologyAPI.Topology mockTopology = PowerMockito.mock(TopologyAPI.Topology.class);
Config mockConfig = Mockito.mock(Config.class);
Mockito.when(mockConfig.getStringValue(Key.PACKING_CLASS)).thenReturn(PACKING_CLASS);
Mockito.when(mockConfig.get(Key.TOPOLOGY_DEFINITION)).thenReturn(mockTopology);
PackingPlan resultPacking = LauncherUtils.getInstance().createPackingPlan(mockConfig, mockConfig);
Assert.assertEquals(mockPackingPlan, resultPacking);
Mockito.verify(mockPacking).initialize(Mockito.any(Config.class), Mockito.eq(mockTopology));
Mockito.verify(mockPacking).pack();
Mockito.verify(mockPacking).close();
}
use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class AuroraContextTest method testFallback.
@Test
public void testFallback() {
Config config = Config.newBuilder().put(Key.HERON_CONF, "/test").build();
Assert.assertEquals("Expected to use heron_conf/heron.aurora", "/test/heron.aurora", AuroraContext.getHeronAuroraPath(config));
}
use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class AuroraSchedulerTest method testOnSchedule.
/**
* Tests that we can schedule
*/
@Test
public void testOnSchedule() throws Exception {
AuroraController controller = Mockito.mock(AuroraController.class);
doReturn(controller).when(scheduler).getController();
SchedulerStateManagerAdaptor stateManager = mock(SchedulerStateManagerAdaptor.class);
Config runtime = Mockito.mock(Config.class);
when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(stateManager);
when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
Config mConfig = Mockito.mock(Config.class);
PowerMockito.mockStatic(Config.class);
when(Config.toClusterMode(mConfig)).thenReturn(mConfig);
when(mConfig.getStringValue(eq(AuroraContext.JOB_TEMPLATE), anyString())).thenReturn(AURORA_PATH);
scheduler.initialize(mConfig, runtime);
// Fail to schedule due to null PackingPlan
Assert.assertFalse(scheduler.onSchedule(null));
PackingPlan plan = new PackingPlan(PACKING_PLAN_ID, new HashSet<PackingPlan.ContainerPlan>());
assertTrue(plan.getContainers().isEmpty());
// Fail to schedule due to PackingPlan is empty
Assert.assertFalse(scheduler.onSchedule(plan));
// Construct valid PackingPlan
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(PackingTestUtils.testContainerPlan(CONTAINER_ID));
PackingPlan validPlan = new PackingPlan(PACKING_PLAN_ID, containers);
// Failed to create job via controller
doReturn(false).when(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
doReturn(true).when(stateManager).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
Assert.assertFalse(scheduler.onSchedule(validPlan));
Mockito.verify(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
Mockito.verify(stateManager).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
// Happy path
doReturn(true).when(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
assertTrue(scheduler.onSchedule(validPlan));
Mockito.verify(controller, Mockito.times(2)).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
Mockito.verify(stateManager, Mockito.times(2)).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
}
Aggregations