コード例 #1
0
  @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()));
    }
  }
コード例 #2
0
 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;
 }
コード例 #3
0
  private StreamDefinition createStream() {
    StreamDefinition sd = new StreamDefinition();
    StreamColumn tsColumn = new StreamColumn();
    tsColumn.setName("timestamp");
    tsColumn.setType(StreamColumn.Type.LONG);

    StreamColumn hostColumn = new StreamColumn();
    hostColumn.setName("host");
    hostColumn.setType(StreamColumn.Type.STRING);

    StreamColumn alertKeyColumn = new StreamColumn();
    alertKeyColumn.setName("alertKey");
    alertKeyColumn.setType(StreamColumn.Type.STRING);

    StreamColumn stateColumn = new StreamColumn();
    stateColumn.setName("state");
    stateColumn.setType(StreamColumn.Type.STRING);

    // dedupCount, dedupFirstOccurrence

    StreamColumn dedupCountColumn = new StreamColumn();
    dedupCountColumn.setName("dedupCount");
    dedupCountColumn.setType(StreamColumn.Type.LONG);

    StreamColumn dedupFirstOccurrenceColumn = new StreamColumn();
    dedupFirstOccurrenceColumn.setName(DedupCache.DEDUP_FIRST_OCCURRENCE);
    dedupFirstOccurrenceColumn.setType(StreamColumn.Type.LONG);

    sd.setColumns(
        Arrays.asList(
            tsColumn,
            hostColumn,
            alertKeyColumn,
            stateColumn,
            dedupCountColumn,
            dedupFirstOccurrenceColumn));
    sd.setDataSource("testDatasource");
    sd.setStreamId("testStream");
    sd.setDescription("test stream");
    return sd;
  }