expPassedEvents.add(event);
else
expFailedEvents.add(event);
}
DbusKeyCompositeFilter filter = new DbusKeyCompositeFilter(partConfigMap);
filter.dedupe();
List<DbusEvent> passedEvents = new ArrayList<DbusEvent>();
List<DbusEvent> failedEvents = new ArrayList<DbusEvent>();
for (DbusEvent event : dbusEvents)
{
if ( filter.allow(event))
{
passedEvents.add(event);
} else {
failedEvents.add(event);
}
}
System.out.println("Passed Event Size :" + passedEvents.size());
System.out.println("Failed Event Size :" + failedEvents.size());
assertEquals("Passed Size", expPassedEvents.size(), passedEvents.size());
assertEquals("Failed Size", expFailedEvents.size(), failedEvents.size());
for ( int i = 0; i < passedEvents.size(); i++ )
{
assertEquals("Passed Element " + i, expPassedEvents.get(i), passedEvents.get(i));
}
for ( int i = 0; i < passedEvents.size(); i++ )
{
assertEquals("Failed Element " + i, expFailedEvents.get(i), failedEvents.get(i));
}
ObjectMapper objMapper = new ObjectMapper();
String objStr = objMapper.writeValueAsString(filter.getFilterMap());
System.out.println("CompositeKeyFilter :" + objStr);
Map<Long, DbusKeyFilter> map2 = KeyFilterConfigJSONFactory.parseSrcIdFilterConfigMap(objStr);
String objStr2 = objMapper.writeValueAsString(filter.getFilterMap());
System.out.println("CompositeKeyFilter2 :" + objStr2);
assertEquals("CompositeKeys: JSON Serialization Test", objStr, objStr2);
//String objStr3 = "{\"filterMap\":{\"40\":{\"partitionType\":\"RANGE\",\"filters\":[{\"keyRange\":{\"start\":100,\"end\":200}},{\"keyRange\":{\"start\":300,\"end\":500}},{\"keyRange\":{\"start\":100,\"end\":200}},{\"keyRange\":{\"start\":300,\"end\":500}}]}}}";
//DbusKeyCompositeFilter f = KeyFilterJSONFactory.parseKeyCompositeFilter(objStr3);
//System.out.println("Deserialized Filter is :" + f);
String objStr4 = "{\"40\":{\"partitionType\":\"RANGE\",\"filters\":[{\"keyRange\":{\"start\":100,\"end\":200}},{\"keyRange\":{\"start\":300,\"end\":500}},{\"keyRange\":{\"start\":100,\"end\":200}},{\"keyRange\":{\"start\":300,\"end\":500}}]}}}";
Map<Long, DbusKeyFilter> map3 = KeyFilterConfigJSONFactory.parseSrcIdFilterConfigMap(objStr4);
DbusKeyCompositeFilter f2 = new DbusKeyCompositeFilter();
f2.setFilterMap(map3);
System.out.println("Deserialized Filter is (before dedupe): " + f2);
f2.dedupe();
System.out.println("Deserialized Filter is (after dedupe): " + f2);
}