Search in sources :

Example 1 with AlertResponse

use of com.thinkbiganalytics.alerts.api.AlertResponse in project kylo by Teradata.

the class DefaultAlertManagerTest method testAlertResponding.

@Test(dependsOnGroups = "create", groups = "update1")
public void testAlertResponding() {
    Alert alert = this.manager.getAlertAsServiceAccount(id1).get();
    AlertResponse resp = this.manager.getResponse(alert);
    alert = resp.inProgress(LONG_DESCR);
    Assertions.assertThat(alert.getEvents()).hasSize(2).extracting("state", "description", "content").contains(Assertions.tuple(State.UNHANDLED, null, null), Assertions.tuple(State.IN_PROGRESS, TRUNK_DESCR, null));
    alert = resp.handle("Change handled", new Integer(42));
    Assertions.assertThat(alert.getEvents()).hasSize(3).extracting("state", "description", "content").contains(Assertions.tuple(State.UNHANDLED, null, null), Assertions.tuple(State.IN_PROGRESS, TRUNK_DESCR, null), Assertions.tuple(State.HANDLED, "Change handled", 42));
    Mockito.verify(this.alertReceiver, Mockito.times(2)).alertsAvailable(Matchers.anyInt());
}
Also used : AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) Alert(com.thinkbiganalytics.alerts.api.Alert) Test(org.testng.annotations.Test)

Example 2 with AlertResponse

use of com.thinkbiganalytics.alerts.api.AlertResponse in project kylo by Teradata.

the class AggregatingAlertProvider method accept.

/* (non-Javadoc)
     * @see reactor.fn.Consumer#accept(java.lang.Object)
     */
@Override
public void accept(Event<Alert> event) {
    final Alert alert = unwrapAlert(event.getData());
    final AlertManager mgr = (AlertManager) alert.getSource();
    final List<AlertResponder> responders = snapshotResponderts();
    responders.forEach(responder -> {
        AlertResponse resp = mgr.getResponse(alert);
        AlertResponseWrapper wrapper = new AlertResponseWrapper(resp);
        responder.alertChange(alert, wrapper);
    });
}
Also used : AlertManager(com.thinkbiganalytics.alerts.spi.AlertManager) AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) Alert(com.thinkbiganalytics.alerts.api.Alert) SourceAlert(com.thinkbiganalytics.alerts.api.SourceAlert) AlertResponder(com.thinkbiganalytics.alerts.api.AlertResponder)

Example 3 with AlertResponse

use of com.thinkbiganalytics.alerts.api.AlertResponse in project kylo by Teradata.

the class AggregatingAlertProviderTest method testRespondToChange.

@Test
public void testRespondToChange() throws InterruptedException {
    TestAlert initMgrAlert = new TestAlert(this.manager, true);
    CountDownLatch latch = new CountDownLatch(1);
    this.provider.addAlertManager(this.manager);
    when(this.manager.getAlert(any(Alert.ID.class))).thenReturn(Optional.of(initMgrAlert));
    when(this.manager.getAlertAsServiceAccount(any(Alert.ID.class))).thenReturn(Optional.of(initMgrAlert));
    when(this.manager.getResponse(any(Alert.class))).thenReturn(this.response);
    when(this.response.handle(any(String.class), any(Serializable.class))).thenReturn(initMgrAlert);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            latch.countDown();
            return null;
        }
    }).when(this.listener).alertChange(any(Alert.class));
    this.provider.respondTo(new SourceAlertID(initMgrAlert.getId(), this.manager), new AlertResponder() {

        @Override
        public void alertChange(Alert alert, AlertResponse response) {
            response.handle(null, "handled");
        }
    });
    latch.await(10, TimeUnit.SECONDS);
    verify(this.response).handle(eq(null), eq("handled"));
    verify(this.listener, atLeastOnce()).alertChange(any(Alert.class));
}
Also used : Serializable(java.io.Serializable) AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) CountDownLatch(java.util.concurrent.CountDownLatch) AlertResponder(com.thinkbiganalytics.alerts.api.AlertResponder) SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Alert(com.thinkbiganalytics.alerts.api.Alert) SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) Test(org.junit.Test)

Example 4 with AlertResponse

use of com.thinkbiganalytics.alerts.api.AlertResponse in project kylo by Teradata.

the class DefaultAlertManagerTest method testClear.

@Test(dependsOnGroups = "read2", groups = "update2")
public void testClear() {
    Alert alert = this.manager.getAlertAsServiceAccount(id1).get();
    AlertResponse resp = this.manager.getResponse(alert);
    resp.clear();
    alert = this.manager.getAlertAsServiceAccount(id1).get();
    Assertions.assertThat(alert).isNotNull();
    Assertions.assertThat(alert.isCleared()).isTrue();
    Mockito.verify(this.alertReceiver, Mockito.times(0)).alertsAvailable(Matchers.anyInt());
}
Also used : AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) Alert(com.thinkbiganalytics.alerts.api.Alert) Test(org.testng.annotations.Test)

Aggregations

Alert (com.thinkbiganalytics.alerts.api.Alert)4 AlertResponse (com.thinkbiganalytics.alerts.api.AlertResponse)4 AlertResponder (com.thinkbiganalytics.alerts.api.AlertResponder)2 Test (org.testng.annotations.Test)2 SourceAlert (com.thinkbiganalytics.alerts.api.SourceAlert)1 SourceAlertID (com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID)1 AlertManager (com.thinkbiganalytics.alerts.spi.AlertManager)1 Serializable (java.io.Serializable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1