예제 #1
0
 @Test
 public void doTest() throws SchedulerException, MeasurementException {
   PollJob job = new PollJob();
   JobExecutionContext context = mock(JobExecutionContext.class);
   Map params = new HashMap();
   JobDataMap jobMap = new JobDataMap(params);
   MeasurementDefinition def = MocksFactory.createMockMeasurementDefinition();
   MeasurementListener listener = mock(MeasurementListener.class);
   Scheduler scheduler = mock(Scheduler.class);
   CoreMeasurementService service = mock(CoreMeasurementService.class);
   SchedulerContext schedulerContext =
       new SchedulerContext(
           Collections.singletonMap(PollJob.MEASUREMENT_SERVICE_ATTR_NAME, service));
   jobMap.put(PollJob.LISTENER_ATTR_NAME, listener);
   jobMap.put(PollJob.MEASUREMENT_DEF_ATTR_NAME, def);
   jobMap.put(PollJob.MEASUREMENT_SERVICE_ATTR_NAME, service);
   when(context.getMergedJobDataMap()).thenReturn(jobMap);
   when(context.getScheduler()).thenReturn(scheduler);
   when(scheduler.getContext()).thenReturn(schedulerContext);
   CapabilityValue capValue = new CapabilityValue(RandomUtils.nextLong());
   when(service.getCapabilityValue(Matchers.<String>any(), Matchers.<String>any()))
       .thenReturn(capValue);
   job.execute(context);
   verify(context).getMergedJobDataMap();
   verify(service).getCapabilityValue(def.getResourceUri(), def.getCapabilityUri());
   verify(listener).newCapabilityValue(capValue);
   assertEquals(capValue.getMetricsId(), def.getId());
 }
 @Override
 public void addMeasurement(Measurement measurement) {
   log.debug("Adding measurement");
   final TimeSeries timeSeries = new TimeSeries(measurement.getLabel());
   timeSeries.setKey(measurement.getLabel());
   for (CapabilityValue value : measurement.getValues()) {
     timeSeries.addOrUpdate(new Second(value.getGatherTimestamp()), value.getNumericValue());
   }
   data.addSeries(timeSeries);
   measurements.put(measurement.getId(), measurement);
 }
 @Override
 public void newCapabilityValues(java.util.List<CapabilityValue> values) {
   log.debug("Got new capabilities to update visualization");
   for (CapabilityValue value : values) {
     Measurement measurement = measurements.get(value.getMetricsId());
     if (data.getSeries(measurement.getLabel()) == null) {
       data.addSeries(new TimeSeries(measurement.getLabel()));
     }
     data.getSeries(measurement.getLabel())
         .addOrUpdate(new Second(value.getGatherTimestamp()), value.getNumericValue());
     log.debug("Amount of series: {}", data.getSeries().size());
   }
 }