use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.
the class SchedulerClientFactoryTest method testGetServiceSchedulerClientFail.
@Test(expected = SchedulerException.class)
public void testGetServiceSchedulerClientFail() throws Exception {
// Instantiate mock objects
Config config = Mockito.mock(Config.class);
Config runtime = Mockito.mock(Config.class);
SchedulerStateManagerAdaptor statemgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
// Get a ServiceSchedulerClient
Mockito.when(config.getBooleanValue(Key.SCHEDULER_IS_SERVICE)).thenReturn(true);
// Mock the runtime object
Mockito.when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(statemgr);
Mockito.when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
// Failed to getSchedulerLocation
Mockito.when(statemgr.getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME))).thenReturn(null);
try {
new SchedulerClientFactory(config, runtime).getSchedulerClient();
} finally {
Mockito.verify(statemgr).getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME));
}
}
use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.
the class SchedulerClientFactoryTest method testGetServiceSchedulerClientOk.
@Test
public void testGetServiceSchedulerClientOk() {
// Instantiate mock objects
Config config = Mockito.mock(Config.class);
Config runtime = Mockito.mock(Config.class);
SchedulerStateManagerAdaptor statemgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
// Get a ServiceSchedulerClient
Mockito.when(config.getBooleanValue(Key.SCHEDULER_IS_SERVICE)).thenReturn(true);
// Mock the runtime object
Mockito.when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(statemgr);
Mockito.when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
// Get a schedulerLocation successfully
Mockito.when(statemgr.getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME))).thenReturn(Scheduler.SchedulerLocation.getDefaultInstance());
Assert.assertNotNull(new SchedulerClientFactory(config, runtime).getSchedulerClient());
}
use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.
the class SchedulerClientFactoryTest method testGetLibrarySchedulerClientNotExist.
@Test(expected = SchedulerException.class)
@PrepareForTest(ReflectionUtils.class)
public void testGetLibrarySchedulerClientNotExist() throws Exception {
// Instantiate mock objects
Config config = Mockito.mock(Config.class);
Config runtime = Mockito.mock(Config.class);
// Return a MockScheduler
Mockito.when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(IScheduler.class.getName());
PowerMockito.mockStatic(ReflectionUtils.class);
PowerMockito.doReturn(Mockito.mock(IScheduler.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IScheduler.class.getName()));
// Return some scheduler class not exist
final String SCHEDULER_CLASS_NOT_EXIST = "class_not_exist";
Mockito.when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(SCHEDULER_CLASS_NOT_EXIST);
PowerMockito.doThrow(new ClassNotFoundException()).when(ReflectionUtils.class, "newInstance", Mockito.eq(SCHEDULER_CLASS_NOT_EXIST));
Assert.assertNull(new SchedulerClientFactory(config, runtime).getSchedulerClient());
}
use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.
the class KubernetesSchedulerTest method testGetJobLinks.
@Test
public void testGetJobLinks() throws Exception {
final String SCHEDULER_URI = "http://k8s.uri";
final String JOB_LINK = SCHEDULER_URI + KubernetesConstants.JOB_LINK;
Config c = Config.newBuilder().put(KubernetesContext.HERON_KUBERNETES_SCHEDULER_URI, SCHEDULER_URI).build();
scheduler.initialize(c, mockRuntime);
List<String> links = scheduler.getJobLinks();
Assert.assertEquals(1, links.size());
System.out.println(links.get(0));
System.out.println(JOB_LINK);
Assert.assertTrue(links.get(0).equals(JOB_LINK));
}
use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.
the class KubernetesSchedulerTest method testFetchCommand.
@Test
public void testFetchCommand() throws URISyntaxException {
final String expectedFetchCommand = "/opt/heron/heron-core/bin/heron-downloader https://heron/topology.tar.gz .";
Config mockConfig = Mockito.mock(Config.class);
Mockito.when(mockConfig.getStringValue(Key.DOWNLOADER_BINARY)).thenReturn("/opt/heron/heron-core/bin/heron-downloader");
Config mockRuntimeConfig = Mockito.mock(Config.class);
Mockito.when(mockRuntimeConfig.get(Key.TOPOLOGY_PACKAGE_URI)).thenReturn(new URI("https://heron/topology.tar.gz"));
Assert.assertEquals(expectedFetchCommand, KubernetesUtils.getFetchCommand(mockConfig, mockRuntimeConfig));
}
Aggregations