use of com.yahoo.athenz.common.server.notification.NotificationMetric in project athenz by yahoo.
the class CertFailedRefreshNotificationTaskTest method testGetNotificationAsMetric.
@Test
public void testGetNotificationAsMetric() {
Timestamp currentTimeStamp = Timestamp.fromCurrentTime();
Timestamp fiveDaysAgo = ZTSTestUtils.addDays(currentTimeStamp, -5);
Timestamp twentyFiveDaysFromNow = ZTSTestUtils.addDays(currentTimeStamp, 25);
Map<String, String> details = new HashMap<>();
details.put("domain", "dom1");
details.put(NOTIFICATION_DETAILS_UNREFRESHED_CERTS, "service0;provider0;instanceID0;" + fiveDaysAgo.toString() + ";" + twentyFiveDaysFromNow + ";hostName1|" + "service1;provider1;instanceID1;" + fiveDaysAgo.toString() + ";" + twentyFiveDaysFromNow + ";hostName2");
Notification notification = new Notification();
notification.setDetails(details);
CertFailedRefreshNotificationTask.CertFailedRefreshNotificationToMetricConverter converter = new CertFailedRefreshNotificationTask.CertFailedRefreshNotificationToMetricConverter();
NotificationMetric notificationAsMetrics = converter.getNotificationAsMetrics(notification, currentTimeStamp);
String[] expectedRecord1 = new String[] { METRIC_NOTIFICATION_TYPE_KEY, "cert_fail_refresh", METRIC_NOTIFICATION_DOMAIN_KEY, "dom1", METRIC_NOTIFICATION_SERVICE_KEY, "service0", METRIC_NOTIFICATION_PROVIDER_KEY, "provider0", METRIC_NOTIFICATION_INSTANCE_ID_KEY, "instanceID0", METRIC_NOTIFICATION_UPDATE_DAYS_KEY, "-5", METRIC_NOTIFICATION_EXPIRY_DAYS_KEY, "25" };
String[] expectedRecord2 = new String[] { METRIC_NOTIFICATION_TYPE_KEY, "cert_fail_refresh", METRIC_NOTIFICATION_DOMAIN_KEY, "dom1", METRIC_NOTIFICATION_SERVICE_KEY, "service1", METRIC_NOTIFICATION_PROVIDER_KEY, "provider1", METRIC_NOTIFICATION_INSTANCE_ID_KEY, "instanceID1", METRIC_NOTIFICATION_UPDATE_DAYS_KEY, "-5", METRIC_NOTIFICATION_EXPIRY_DAYS_KEY, "25" };
List<String[]> expectedAttributes = new ArrayList<>();
expectedAttributes.add(expectedRecord1);
expectedAttributes.add(expectedRecord2);
assertEquals(new NotificationMetric(expectedAttributes), notificationAsMetrics);
}
use of com.yahoo.athenz.common.server.notification.NotificationMetric in project athenz by yahoo.
the class MetricNotificationServiceTest method testNotify.
@Test
public void testNotify() {
Metric metric = Mockito.mock(Metric.class);
MetricNotificationService metricNotificationService = new MetricNotificationService(metric);
String[] attributesList1 = new String[] { "key1", "attribute11", "key2", "attribute12", "key3", "attribute13" };
String[] attributesList2 = new String[] { "key1", "attribute21", "key2", "attribute22", "key3", "attribute23" };
List<String[]> attributes = new ArrayList<>();
attributes.add(attributesList1);
attributes.add(attributesList2);
NotificationToMetricConverter notificationToMetricConverter = Mockito.mock(NotificationToMetricConverter.class);
Mockito.when(notificationToMetricConverter.getNotificationAsMetrics(Mockito.any(), Mockito.any())).thenReturn(new NotificationMetric(attributes));
Notification notification = new Notification();
notification.setNotificationToMetricConverter(notificationToMetricConverter);
boolean notify = metricNotificationService.notify(notification);
assertTrue(notify);
ArgumentCaptor<String> captorMetric = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String[]> captorAttributes = ArgumentCaptor.forClass(String[].class);
Mockito.verify(metric, Mockito.times(2)).increment(captorMetric.capture(), captorAttributes.capture());
assertEquals(2, captorMetric.getAllValues().size());
assertEquals("athenz_notification", captorMetric.getAllValues().get(0));
assertEquals("athenz_notification", captorMetric.getAllValues().get(1));
// Mockito captures all varargs arguments in a single array
assertEquals(12, captorAttributes.getAllValues().size());
List<String> expectedAttributes = new ArrayList<String>(Arrays.asList("key1", "attribute11", "key2", "attribute12", "key3", "attribute13", "key1", "attribute21", "key2", "attribute22", "key3", "attribute23"));
assertEquals(expectedAttributes, captorAttributes.getAllValues());
}
use of com.yahoo.athenz.common.server.notification.NotificationMetric in project athenz by yahoo.
the class AWSZTSHealthNotificationTaskTest method testGetNotificationAsMetric.
@Test
public void testGetNotificationAsMetric() {
Timestamp currentTimeStamp = Timestamp.fromCurrentTime();
Timestamp twentyFiveDaysFromNow = ZTSTestUtils.addDays(currentTimeStamp, 25);
Map<String, String> details = new HashMap<>();
details.put(NOTIFICATION_DETAILS_AFFECTED_ZTS, "affected zts");
details.put(NOTIFICATION_DETAILS_AWS_ZTS_HEALTH, "zts.url;domain0;role0;" + twentyFiveDaysFromNow + ";Error message");
Notification notification = new Notification();
notification.setDetails(details);
AWSZTSHealthNotificationTask.AWSZTSHealthNotificationToMetricConverter converter = new AWSZTSHealthNotificationTask.AWSZTSHealthNotificationToMetricConverter();
NotificationMetric notificationAsMetrics = converter.getNotificationAsMetrics(notification, currentTimeStamp);
String[] expectedRecord = new String[] { METRIC_NOTIFICATION_TYPE_KEY, "aws_zts_health", METRIC_NOTIFICATION_ZTS_KEY, "zts.url", METRIC_NOTIFICATION_DOMAIN_KEY, "domain0", METRIC_NOTIFICATION_ROLE_KEY, "role0", METRIC_NOTIFICATION_EXPIRY_DAYS_KEY, "25", METRIC_NOTIFICATION_ZTS_HEALTH_MSG_KEY, "Error message" };
List<String[]> expectedAttributes = new ArrayList<>();
expectedAttributes.add(expectedRecord);
assertEquals(new NotificationMetric(expectedAttributes), notificationAsMetrics);
}
Aggregations