use of io.hops.hopsworks.alert.dao.AlertManagerConfigFacade in project hopsworks by logicalclocks.
the class TestAlertManagerConfigTimer method testRestoreBackup.
@Test
public void testRestoreBackup() throws AlertManagerUnreachableException, AlertManagerConfigCtrlCreateException, AlertManagerConfigUpdateException, IOException, AlertManagerConfigReadException, AlertManagerClientCreateException {
Mockito.doAnswer((Answer<Void>) invocation -> {
Object[] args = invocation.getArguments();
if (args != null && args.length > 0 && args[0] != null) {
AlertManagerConfigEntity alertManagerConfigEntity = (AlertManagerConfigEntity) args[0];
AlertManagerConfig alertManagerConfig = fromJson(alertManagerConfigEntity.getContent());
LOGGER.log(Level.INFO, "Update database routes={0}, receivers={1}.", new Object[] { alertManagerConfig.getRoute().getRoutes().size(), alertManagerConfig.getReceivers().size() });
assert alertManagerConfig.getRoute().getRoutes().size() == 15;
assert alertManagerConfig.getReceivers().size() == 9;
}
return null;
}).when(alertManagerConfigFacade).update(Mockito.any());
alertManagerConfiguration.restoreFromBackup();
AlertManagerConfig alertManagerConfig = alertManagerConfigController.read();
assert alertManagerConfig.getRoute().getRoutes().size() == 15;
assert alertManagerConfig.getReceivers().size() == 9;
}
use of io.hops.hopsworks.alert.dao.AlertManagerConfigFacade in project hopsworks by logicalclocks.
the class TestAlertManagerConfigTimer method setUp.
@Before
public void setUp() throws ServiceDiscoveryException, AlertManagerConfigFileNotFoundException, AlertManagerConfigReadException, JsonProcessingException {
String alertmanagerConfigPath = TestAlertManagerConfigTimer.class.getResource("/alertmanager.yml").getPath();
alertManagerConfigDBPath = TestAlertManagerConfigTimer.class.getResource("/alertmanagerDB.yml").getPath();
client = Mockito.mock(AlertManagerClient.class);
alertManagerConfigController = new AlertManagerConfigController.Builder().withConfigPath(alertmanagerConfigPath).withClient(client).build();
alertManagerConfigFacade = Mockito.mock(AlertManagerConfigFacade.class);
Mockito.doAnswer((Answer<Void>) invocation -> {
Object[] args = invocation.getArguments();
LOGGER.log(Level.INFO, "Save to database: {0}.", args);
return null;
}).when(alertManagerConfigFacade).save(Mockito.any());
Mockito.doAnswer((Answer<Void>) invocation -> {
Object[] args = invocation.getArguments();
LOGGER.log(Level.INFO, "Update database: {0}.", args);
return null;
}).when(alertManagerConfigFacade).update(Mockito.any());
AlertManagerConfig alertManagerConfig = read(new File(alertManagerConfigDBPath));
AlertManagerConfigEntity alertManagerConfigEntity = new AlertManagerConfigEntity();
alertManagerConfigEntity.setId(1);
alertManagerConfigEntity.setCreated(new Date());
alertManagerConfigEntity.setContent(toJson(alertManagerConfig));
Mockito.when(alertManagerConfigFacade.getLatest()).thenReturn(Optional.of(alertManagerConfigEntity));
alertReceiverFacade = Mockito.mock(AlertReceiverFacade.class);
List<AlertReceiver> receivers = createReceivers();
Mockito.when(alertReceiverFacade.findAll()).thenReturn(receivers);
Mockito.doAnswer((Answer<Optional<AlertReceiver>>) invocation -> {
Object[] args = invocation.getArguments();
Optional<AlertReceiver> alertReceiver = receivers.stream().filter(receiver -> receiver.getName().equals(args[0])).findFirst();
return alertReceiver;
}).when(alertReceiverFacade).findByName(Mockito.any());
alertManagerConfiguration = new AlertManagerConfiguration(client, alertManagerConfigController, alertManagerConfigFacade, alertReceiverFacade);
alertManagerConfigBackup = alertManagerConfigController.read();
alertManagerConfigBackupDB = read(new File(alertManagerConfigDBPath));
}
Aggregations