Search in sources :

Example 16 with Config

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());
}
Also used : Config(com.twitter.heron.spi.common.Config) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Test(org.junit.Test)

Example 17 with Config

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());
}
Also used : Config(com.twitter.heron.spi.common.Config) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with Config

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();
}
Also used : IPacking(com.twitter.heron.spi.packing.IPacking) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with Config

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));
}
Also used : Config(com.twitter.heron.spi.common.Config) Test(org.junit.Test)

Example 20 with 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));
}
Also used : Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Matchers.anyString(org.mockito.Matchers.anyString) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Config (com.twitter.heron.spi.common.Config)87 Test (org.junit.Test)55 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)31 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)23 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)20 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)17 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)9 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)8 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)8 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)7 Before (org.junit.Before)7 HashSet (java.util.HashSet)5 ByteAmount (com.twitter.heron.common.basics.ByteAmount)4 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)4 PackingException (com.twitter.heron.spi.packing.PackingException)4 Resource (com.twitter.heron.spi.packing.Resource)4 URI (java.net.URI)4 Properties (java.util.Properties)4 CommandLine (org.apache.commons.cli.CommandLine)4 HeronTopology (com.twitter.heron.api.HeronTopology)3