private Map<String, String> buildAlertContext(AlertStreamEvent event) { Map<String, String> alertContext = new HashMap<>(); alertContext.put(PublishConstants.ALERT_EMAIL_MESSAGE, event.toString()); alertContext.put(PublishConstants.ALERT_EMAIL_POLICY, event.getPolicyId()); alertContext.put( PublishConstants.ALERT_EMAIL_TIMESTAMP, DateTimeUtil.millisecondsToHumanDateWithSeconds(event.getCreatedTime())); alertContext.put(PublishConstants.ALERT_EMAIL_STREAM, event.getStreamId()); alertContext.put(PublishConstants.ALERT_EMAIL_CREATOR, event.getCreatedBy()); return alertContext; }
@Test public void testPersistUpdatedEventUniq() throws Exception { StreamDefinition stream = createStream(); PolicyDefinition policy = createPolicy(stream.getStreamId(), "testPolicy"); AlertStreamEvent event = createEvent( stream, policy, new Object[] { System.currentTimeMillis(), "host1", "testPolicy-host1-01", "OPEN", 0, 0 }); HashMap<String, String> dedupFieldValues = new HashMap<String, String>(); dedupFieldValues.put( "alertKey", (String) event.getData()[event.getSchema().getColumnIndex("alertKey")]); EventUniq eventUniq = new EventUniq( event.getStreamId(), event.getPolicyId(), event.getCreatedTime(), dedupFieldValues); System.setProperty("config.resource", "/application-mongo-statestore.conf"); Config config = ConfigFactory.load(); DedupCache cache = new DedupCache(config, "testPublishment"); cache.addOrUpdate( eventUniq, (String) event.getData()[event.getSchema().getColumnIndex("state")]); DedupEventsStore accessor = DedupEventsStoreFactory.getStore(DedupEventsStoreType.Mongo, config, "testPublishment"); Map<EventUniq, ConcurrentLinkedDeque<DedupValue>> events = accessor.getEvents(); for (EventUniq one : events.keySet()) { if (one.equals(eventUniq)) { Assert.assertEquals(false, one.removable); } } for (Entry<EventUniq, ConcurrentLinkedDeque<DedupValue>> entry : events.entrySet()) { System.out.println(entry.getKey() + " >>> " + Joiner.on("\n\t").join(entry.getValue())); } eventUniq.removable = true; cache.persistUpdatedEventUniq(eventUniq); events = accessor.getEvents(); for (EventUniq one : events.keySet()) { if (one.equals(eventUniq)) { Assert.assertEquals(true, one.removable); } } for (Entry<EventUniq, ConcurrentLinkedDeque<DedupValue>> entry : events.entrySet()) { System.out.println(entry.getKey() + " >>> " + Joiner.on("\n\t").join(entry.getValue())); } }
private AlertStreamEvent createEvent( StreamDefinition stream, PolicyDefinition policy, Object[] data) { AlertStreamEvent event = new AlertStreamEvent(); event.setPolicyId(policy.getName()); event.setSchema(stream); event.setStreamId(stream.getStreamId()); event.setTimestamp(System.currentTimeMillis()); event.setCreatedTime(System.currentTimeMillis()); event.setData(data); return event; }