use of org.apache.heron.spi.packing.Resource in project heron by twitter.
the class NomadSchedulerTest method testGetTaskGroup.
@Test
public void testGetTaskGroup() {
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
Resource resource = new Resource(CPU_RESOURCE, MEMORY_RESOURCE, DISK_RESOURCE);
PackingPlan.ContainerPlan containerPlan = new PackingPlan.ContainerPlan(CONTAINER_INDEX, new HashSet<>(), Mockito.mock(Resource.class));
scheduler.initialize(this.mockConfig, this.mockRuntime);
Mockito.doReturn(new Task()).when(scheduler).getTask(Mockito.anyString(), Mockito.anyInt(), Mockito.any());
TaskGroup taskGroup = scheduler.getTaskGroup(GROUP_NAME, CONTAINER_INDEX, resource);
LOG.info("taskGroup: " + taskGroup);
Assert.assertEquals(GROUP_NAME, taskGroup.getName());
Assert.assertNotNull(taskGroup.getCount());
Assert.assertNotNull(taskGroup.getTasks());
}
use of org.apache.heron.spi.packing.Resource in project heron by twitter.
the class NomadSchedulerTest method testServiceCheck.
@SuppressWarnings("unchecked")
@Test
public void testServiceCheck() {
this.mockConfig = this.mockConfig.newBuilder().putAll(this.mockConfig).put(NomadContext.HERON_NOMAD_METRICS_SERVICE_ADDITIONAL_TAGS, "foo,bar").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_CHECK_TIMEOUT_SEC, "2").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_CHECK_INTERVAL_SEC, "10").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_REGISTER, true).build();
this.mockRuntime = this.mockRuntime.newBuilder().putAll(this.mockConfig).put(NomadContext.HERON_NOMAD_METRICS_SERVICE_ADDITIONAL_TAGS, "foo,bar").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_CHECK_TIMEOUT_SEC, "2").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_CHECK_INTERVAL_SEC, "10").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_REGISTER, true).build();
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
PowerMockito.mockStatic(SchedulerUtils.class);
Resource resource = new Resource(CPU_RESOURCE, MEMORY_RESOURCE, DISK_RESOURCE);
PowerMockito.when(SchedulerUtils.executorCommandArgs(Mockito.any(), Mockito.any(), Mockito.anyMap(), Mockito.anyString())).thenReturn(EXECUTOR_CMD_ARGS);
PowerMockito.mockStatic(NomadScheduler.class);
PowerMockito.when(NomadScheduler.getFetchCommand(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(TOPOLOGY_DOWNLOAD_CMD);
PowerMockito.when(NomadScheduler.getHeronNomadScript(this.mockConfig)).thenReturn(HERON_NOMAD_SCRIPT);
PowerMockito.when(NomadScheduler.longToInt(MEMORY_RESOURCE.asMegabytes())).thenReturn((int) MEMORY_RESOURCE.asMegabytes());
PowerMockito.when(NomadScheduler.longToInt(DISK_RESOURCE.asMegabytes())).thenReturn((int) DISK_RESOURCE.asMegabytes());
PowerMockito.when(NomadScheduler.getPrometheusMetricsFile(Mockito.any())).thenReturn(PORT_FILE);
PowerMockito.when(NomadScheduler.getMetricsServiceName(Mockito.any(), Mockito.anyInt())).thenReturn(String.format("metrics-heron-%s-%s", TOPOLOGY_NAME, CONTAINER_INDEX));
scheduler.initialize(this.mockConfig, this.mockRuntime);
Task task = scheduler.getTask(TASK_NAME, CONTAINER_INDEX, resource);
LOG.info("task: " + task);
Assert.assertEquals(task.getServices().size(), 1);
Assert.assertEquals(task.getServices().get(0).getName(), String.format("metrics-heron-%s-%s", TOPOLOGY_NAME, CONTAINER_INDEX));
String[] tags = { String.format("%s-%s", TOPOLOGY_NAME, CONTAINER_INDEX), "foo", "bar" };
Assert.assertEquals(task.getServices().get(0).getTags(), Arrays.asList(tags));
Assert.assertEquals(task.getServices().get(0).getPortLabel(), NomadConstants.METRICS_PORT);
Assert.assertEquals(task.getServices().get(0).getChecks().size(), 1);
Assert.assertEquals(task.getServices().get(0).getChecks().get(0).getPortLabel(), NomadConstants.METRICS_PORT);
Assert.assertEquals(task.getServices().get(0).getChecks().get(0).getType(), NomadConstants.NOMAD_SERVICE_CHECK_TYPE);
TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
Assert.assertEquals(task.getServices().get(0).getChecks().get(0).getInterval(), TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS));
Assert.assertEquals(task.getServices().get(0).getChecks().get(0).getTimeout(), TimeUnit.NANOSECONDS.convert(2, TimeUnit.SECONDS));
// if service registration is turned off
this.mockConfig = this.mockConfig.newBuilder().putAll(this.mockConfig).put(NomadContext.HERON_NOMAD_METRICS_SERVICE_REGISTER, false).build();
this.mockRuntime = this.mockRuntime.newBuilder().putAll(this.mockConfig).put(NomadContext.HERON_NOMAD_METRICS_SERVICE_REGISTER, false).build();
scheduler.initialize(this.mockConfig, this.mockRuntime);
task = scheduler.getTask(TASK_NAME, CONTAINER_INDEX, resource);
LOG.info("task: " + task);
Assert.assertTrue(task.getServices() == null);
}
Aggregations