Search in sources :

Example 56 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class MesosLauncherTest method testLaunch.

@Test
public void testLaunch() throws Exception {
    MesosLauncher launcher = Mockito.spy(MesosLauncher.class);
    PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
    Config config = Mockito.mock(Config.class);
    Mockito.doReturn("working-dir").when(config).getStringValue(MesosContext.SCHEDULER_WORKING_DIRECTORY);
    Config runtime = Mockito.mock(Config.class);
    launcher.initialize(config, runtime);
    // Failed to setup working dir
    Mockito.doReturn(false).when(launcher).setupWorkingDirectory();
    Assert.assertFalse(launcher.launch(packingPlan));
    Mockito.doReturn(true).when(launcher).setupWorkingDirectory();
    String[] mockCommand = new String[] { "mock", "scheduler", "command" };
    Mockito.doReturn(mockCommand).when(launcher).getSchedulerCommand();
    // Failed to spwan the process
    Mockito.doReturn(null).when(launcher).startScheduler(mockCommand);
    Assert.assertFalse(launcher.launch(packingPlan));
    // Happy path
    Process p = Mockito.mock(Process.class);
    Mockito.doReturn(p).when(launcher).startScheduler(mockCommand);
    Assert.assertTrue(launcher.launch(packingPlan));
}
Also used : Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Test(org.junit.Test)

Example 57 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class MesosSchedulerTest method before.

@Before
public void before() throws Exception {
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    Mockito.when(config.getStringValue(Key.ROLE)).thenReturn(ROLE);
    Mockito.when(config.getStringValue(Key.CORE_PACKAGE_URI)).thenReturn(CORE_PACKAGE_URI);
    Config runtime = Mockito.mock(Config.class);
    Mockito.when(runtime.getLongValue(Key.NUM_CONTAINERS)).thenReturn(NUM_CONTAINER);
    Properties properties = new Properties();
    properties.put(Key.TOPOLOGY_PACKAGE_URI.value(), TOPOLOGY_PACKAGE_URI);
    Mockito.when(runtime.get(Key.SCHEDULER_PROPERTIES)).thenReturn(properties);
    mesosFramework = Mockito.mock(MesosFramework.class);
    SchedulerDriver driver = Mockito.mock(SchedulerDriver.class);
    baseContainer = Mockito.mock(BaseContainer.class);
    scheduler = Mockito.spy(MesosScheduler.class);
    Mockito.doReturn(mesosFramework).when(scheduler).getMesosFramework();
    Mockito.doReturn(driver).when(scheduler).getSchedulerDriver(Mockito.anyString(), Mockito.eq(mesosFramework));
    Mockito.doNothing().when(scheduler).startSchedulerDriver();
    scheduler.initialize(config, runtime);
}
Also used : BaseContainer(org.apache.heron.scheduler.mesos.framework.BaseContainer) MesosFramework(org.apache.heron.scheduler.mesos.framework.MesosFramework) Config(org.apache.heron.spi.common.Config) Properties(java.util.Properties) SchedulerDriver(org.apache.mesos.SchedulerDriver) Before(org.junit.Before)

Example 58 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class SlurmSchedulerTest method testOnKill.

@Test
public void testOnKill() throws Exception {
    SlurmController controller = Mockito.mock(SlurmController.class);
    Mockito.doReturn(controller).when(scheduler).getController();
    Mockito.doReturn(SLURM_ID_FILE).when(scheduler).getJobIdFilePath();
    Config config = createRunnerConfig();
    Config runtime = Mockito.mock(Config.class);
    PowerMockito.spy(SlurmContext.class);
    PowerMockito.doReturn(WORKING_DIRECTORY).when(SlurmContext.class, "workingDirectory", config);
    scheduler.initialize(config, runtime);
    // Failed to kill job via controller
    Mockito.doReturn(false).when(controller).killJob(Mockito.anyString());
    Assert.assertFalse(scheduler.onKill(Scheduler.KillTopologyRequest.getDefaultInstance()));
    Mockito.verify(controller).killJob(Mockito.anyString());
    // Happy path
    Mockito.doReturn(true).when(controller).killJob(Mockito.anyString());
    Assert.assertTrue(scheduler.onKill(Scheduler.KillTopologyRequest.getDefaultInstance()));
    Mockito.verify(controller, Mockito.times(2)).killJob(Mockito.anyString());
}
Also used : Config(org.apache.heron.spi.common.Config) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 59 with Config

use of org.apache.heron.spi.common.Config in project heron by twitter.

the class AuroraContextTest method testUsesConfigString.

@Test
public void testUsesConfigString() {
    final String auroraTemplate = "/dir/test.aurora";
    Config config = Config.newBuilder().put(AuroraContext.JOB_TEMPLATE, auroraTemplate).put(Key.HERON_CONF, "/test").build();
    Assert.assertEquals("Expected to use value from JOB_TEMPLATE config", auroraTemplate, AuroraContext.getHeronAuroraPath(config));
}
Also used : Config(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Example 60 with Config

use of org.apache.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(org.apache.heron.spi.common.Config) Test(org.junit.Test)

Aggregations

Config (org.apache.heron.spi.common.Config)140 Test (org.junit.Test)75 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 PackingPlan (org.apache.heron.spi.packing.PackingPlan)22 HashMap (java.util.HashMap)18 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)18 Pair (org.apache.heron.common.basics.Pair)16 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)15 IOException (java.io.IOException)11 LauncherUtils (org.apache.heron.scheduler.utils.LauncherUtils)11 Map (java.util.Map)10 V1Volume (io.kubernetes.client.openapi.models.V1Volume)9 URI (java.net.URI)9 IScheduler (org.apache.heron.spi.scheduler.IScheduler)9 IStateManager (org.apache.heron.spi.statemgr.IStateManager)9 Before (org.junit.Before)9 File (java.io.File)7 LinkedList (java.util.LinkedList)7 Resource (org.apache.heron.spi.packing.Resource)7 CommandLine (org.apache.commons.cli.CommandLine)6