|
@@ -21,16 +21,17 @@ import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.EnumSet;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
|
+import java.util.Set;
|
|
|
import java.util.SortedSet;
|
|
|
import java.util.TreeSet;
|
|
|
|
|
@@ -44,40 +45,48 @@ import org.apache.hadoop.yarn.server.applicationhistoryservice.apptimeline.Appli
|
|
|
|
|
|
public class ApplicationTimelineStoreTestUtils {
|
|
|
|
|
|
- private static final Map<String, Object> EMPTY_MAP = Collections.emptyMap();
|
|
|
- private static final Map<String, List<String>> EMPTY_REL_ENTITIES =
|
|
|
- new HashMap<String, List<String>>();
|
|
|
+ protected static final Map<String, Object> EMPTY_MAP =
|
|
|
+ Collections.emptyMap();
|
|
|
+ protected static final Map<String, Set<Object>> EMPTY_PRIMARY_FILTERS =
|
|
|
+ Collections.emptyMap();
|
|
|
+ protected static final Map<String, Set<String>> EMPTY_REL_ENTITIES =
|
|
|
+ Collections.emptyMap();
|
|
|
|
|
|
protected ApplicationTimelineStore store;
|
|
|
- private String entity1;
|
|
|
- private String entityType1;
|
|
|
- private String entity1b;
|
|
|
- private String entity2;
|
|
|
- private String entityType2;
|
|
|
- private Map<String, Object> primaryFilters;
|
|
|
- private Map<String, Object> secondaryFilters;
|
|
|
- private Map<String, Object> allFilters;
|
|
|
- private Map<String, Object> otherInfo;
|
|
|
- private Map<String, List<String>> relEntityMap;
|
|
|
- private NameValuePair userFilter;
|
|
|
- private Collection<NameValuePair> goodTestingFilters;
|
|
|
- private Collection<NameValuePair> badTestingFilters;
|
|
|
- private ATSEvent ev1;
|
|
|
- private ATSEvent ev2;
|
|
|
- private ATSEvent ev3;
|
|
|
- private ATSEvent ev4;
|
|
|
- private Map<String, Object> eventInfo;
|
|
|
- private List<ATSEvent> events1;
|
|
|
- private List<ATSEvent> events2;
|
|
|
+ protected String entity1;
|
|
|
+ protected String entityType1;
|
|
|
+ protected String entity1b;
|
|
|
+ protected String entity2;
|
|
|
+ protected String entityType2;
|
|
|
+ protected Map<String, Set<Object>> primaryFilters;
|
|
|
+ protected Map<String, Object> secondaryFilters;
|
|
|
+ protected Map<String, Object> allFilters;
|
|
|
+ protected Map<String, Object> otherInfo;
|
|
|
+ protected Map<String, Set<String>> relEntityMap;
|
|
|
+ protected NameValuePair userFilter;
|
|
|
+ protected Collection<NameValuePair> goodTestingFilters;
|
|
|
+ protected Collection<NameValuePair> badTestingFilters;
|
|
|
+ protected ATSEvent ev1;
|
|
|
+ protected ATSEvent ev2;
|
|
|
+ protected ATSEvent ev3;
|
|
|
+ protected ATSEvent ev4;
|
|
|
+ protected Map<String, Object> eventInfo;
|
|
|
+ protected List<ATSEvent> events1;
|
|
|
+ protected List<ATSEvent> events2;
|
|
|
|
|
|
/**
|
|
|
* Load test data into the given store
|
|
|
*/
|
|
|
protected void loadTestData() throws IOException {
|
|
|
ATSEntities atsEntities = new ATSEntities();
|
|
|
- Map<String, Object> primaryFilters = new HashMap<String, Object>();
|
|
|
- primaryFilters.put("user", "username");
|
|
|
- primaryFilters.put("appname", 12345l);
|
|
|
+ Map<String, Set<Object>> primaryFilters =
|
|
|
+ new HashMap<String, Set<Object>>();
|
|
|
+ Set<Object> l1 = new HashSet<Object>();
|
|
|
+ l1.add("username");
|
|
|
+ Set<Object> l2 = new HashSet<Object>();
|
|
|
+ l2.add(12345l);
|
|
|
+ primaryFilters.put("user", l1);
|
|
|
+ primaryFilters.put("appname", l2);
|
|
|
Map<String, Object> secondaryFilters = new HashMap<String, Object>();
|
|
|
secondaryFilters.put("startTime", 123456l);
|
|
|
secondaryFilters.put("status", "RUNNING");
|
|
@@ -91,9 +100,9 @@ public class ApplicationTimelineStoreTestUtils {
|
|
|
String entity2 = "id_2";
|
|
|
String entityType2 = "type_2";
|
|
|
|
|
|
- Map<String, List<String>> relatedEntities =
|
|
|
- new HashMap<String, List<String>>();
|
|
|
- relatedEntities.put(entityType2, Collections.singletonList(entity2));
|
|
|
+ Map<String, Set<String>> relatedEntities =
|
|
|
+ new HashMap<String, Set<String>>();
|
|
|
+ relatedEntities.put(entityType2, Collections.singleton(entity2));
|
|
|
|
|
|
ATSEvent ev3 = createEvent(789l, "launch_event", null);
|
|
|
ATSEvent ev4 = createEvent(-123l, "init_event", null);
|
|
@@ -156,15 +165,23 @@ public class ApplicationTimelineStoreTestUtils {
|
|
|
badTestingFilters.add(new NameValuePair("appname", 12345l));
|
|
|
badTestingFilters.add(new NameValuePair("status", "FINISHED"));
|
|
|
|
|
|
- primaryFilters = new HashMap<String, Object>();
|
|
|
- primaryFilters.put("user", "username");
|
|
|
- primaryFilters.put("appname", 12345l);
|
|
|
+ primaryFilters = new HashMap<String, Set<Object>>();
|
|
|
+ Set<Object> l1 = new HashSet<Object>();
|
|
|
+ l1.add("username");
|
|
|
+ Set<Object> l2 = new HashSet<Object>();
|
|
|
+ l2.add(12345l);
|
|
|
+ primaryFilters.put("user", l1);
|
|
|
+ primaryFilters.put("appname", l2);
|
|
|
secondaryFilters = new HashMap<String, Object>();
|
|
|
secondaryFilters.put("startTime", 123456l);
|
|
|
secondaryFilters.put("status", "RUNNING");
|
|
|
allFilters = new HashMap<String, Object>();
|
|
|
allFilters.putAll(secondaryFilters);
|
|
|
- allFilters.putAll(primaryFilters);
|
|
|
+ for (Entry<String, Set<Object>> pf : primaryFilters.entrySet()) {
|
|
|
+ for (Object o : pf.getValue()) {
|
|
|
+ allFilters.put(pf.getKey(), o);
|
|
|
+ }
|
|
|
+ }
|
|
|
otherInfo = new HashMap<String, Object>();
|
|
|
otherInfo.put("info1", "val1");
|
|
|
otherInfo.put("info2", "val2");
|
|
@@ -186,8 +203,8 @@ public class ApplicationTimelineStoreTestUtils {
|
|
|
events1.add(ev1);
|
|
|
|
|
|
relEntityMap =
|
|
|
- new HashMap<String, List<String>>();
|
|
|
- List<String> ids = new ArrayList<String>();
|
|
|
+ new HashMap<String, Set<String>>();
|
|
|
+ Set<String> ids = new HashSet<String>();
|
|
|
ids.add(entity1);
|
|
|
ids.add(entity1b);
|
|
|
relEntityMap.put(entityType1, ids);
|
|
@@ -212,8 +229,8 @@ public class ApplicationTimelineStoreTestUtils {
|
|
|
primaryFilters, otherInfo, store.getEntity(entity1b, entityType1,
|
|
|
EnumSet.allOf(Field.class)));
|
|
|
|
|
|
- verifyEntityInfo(entity2, entityType2, events2, relEntityMap, EMPTY_MAP,
|
|
|
- EMPTY_MAP, store.getEntity(entity2, entityType2,
|
|
|
+ verifyEntityInfo(entity2, entityType2, events2, relEntityMap,
|
|
|
+ EMPTY_PRIMARY_FILTERS, EMPTY_MAP, store.getEntity(entity2, entityType2,
|
|
|
EnumSet.allOf(Field.class)));
|
|
|
|
|
|
// test getting single fields
|
|
@@ -267,8 +284,8 @@ public class ApplicationTimelineStoreTestUtils {
|
|
|
entities = store.getEntities("type_2", null, null, null, null, null,
|
|
|
EnumSet.allOf(Field.class)).getEntities();
|
|
|
assertEquals(1, entities.size());
|
|
|
- verifyEntityInfo(entity2, entityType2, events2, relEntityMap, EMPTY_MAP,
|
|
|
- EMPTY_MAP, entities.get(0));
|
|
|
+ verifyEntityInfo(entity2, entityType2, events2, relEntityMap,
|
|
|
+ EMPTY_PRIMARY_FILTERS, EMPTY_MAP, entities.get(0));
|
|
|
|
|
|
entities = store.getEntities("type_1", 1l, null, null, null, null,
|
|
|
EnumSet.allOf(Field.class)).getEntities();
|
|
@@ -457,9 +474,9 @@ public class ApplicationTimelineStoreTestUtils {
|
|
|
/**
|
|
|
* Verify a single entity
|
|
|
*/
|
|
|
- private static void verifyEntityInfo(String entity, String entityType,
|
|
|
- List<ATSEvent> events, Map<String, List<String>> relatedEntities,
|
|
|
- Map<String, Object> primaryFilters, Map<String, Object> otherInfo,
|
|
|
+ protected static void verifyEntityInfo(String entity, String entityType,
|
|
|
+ List<ATSEvent> events, Map<String, Set<String>> relatedEntities,
|
|
|
+ Map<String, Set<Object>> primaryFilters, Map<String, Object> otherInfo,
|
|
|
ATSEntity retrievedEntityInfo) {
|
|
|
if (entity == null) {
|
|
|
assertNull(retrievedEntityInfo);
|
|
@@ -467,23 +484,27 @@ public class ApplicationTimelineStoreTestUtils {
|
|
|
}
|
|
|
assertEquals(entity, retrievedEntityInfo.getEntityId());
|
|
|
assertEquals(entityType, retrievedEntityInfo.getEntityType());
|
|
|
- if (events == null)
|
|
|
+ if (events == null) {
|
|
|
assertNull(retrievedEntityInfo.getEvents());
|
|
|
- else
|
|
|
+ } else {
|
|
|
assertEquals(events, retrievedEntityInfo.getEvents());
|
|
|
- if (relatedEntities == null)
|
|
|
+ }
|
|
|
+ if (relatedEntities == null) {
|
|
|
assertNull(retrievedEntityInfo.getRelatedEntities());
|
|
|
- else
|
|
|
+ } else {
|
|
|
assertEquals(relatedEntities, retrievedEntityInfo.getRelatedEntities());
|
|
|
- if (primaryFilters == null)
|
|
|
+ }
|
|
|
+ if (primaryFilters == null) {
|
|
|
assertNull(retrievedEntityInfo.getPrimaryFilters());
|
|
|
- else
|
|
|
+ } else {
|
|
|
assertTrue(primaryFilters.equals(
|
|
|
retrievedEntityInfo.getPrimaryFilters()));
|
|
|
- if (otherInfo == null)
|
|
|
+ }
|
|
|
+ if (otherInfo == null) {
|
|
|
assertNull(retrievedEntityInfo.getOtherInfo());
|
|
|
- else
|
|
|
+ } else {
|
|
|
assertTrue(otherInfo.equals(retrievedEntityInfo.getOtherInfo()));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -503,21 +524,25 @@ public class ApplicationTimelineStoreTestUtils {
|
|
|
/**
|
|
|
* Create a test entity
|
|
|
*/
|
|
|
- private static ATSEntity createEntity(String entity, String entityType,
|
|
|
+ protected static ATSEntity createEntity(String entity, String entityType,
|
|
|
Long startTime, List<ATSEvent> events,
|
|
|
- Map<String, List<String>> relatedEntities,
|
|
|
- Map<String, Object> primaryFilters, Map<String, Object> otherInfo) {
|
|
|
+ Map<String, Set<String>> relatedEntities,
|
|
|
+ Map<String, Set<Object>> primaryFilters,
|
|
|
+ Map<String, Object> otherInfo) {
|
|
|
ATSEntity atsEntity = new ATSEntity();
|
|
|
atsEntity.setEntityId(entity);
|
|
|
atsEntity.setEntityType(entityType);
|
|
|
atsEntity.setStartTime(startTime);
|
|
|
atsEntity.setEvents(events);
|
|
|
- if (relatedEntities != null)
|
|
|
- for (Entry<String, List<String>> e : relatedEntities.entrySet())
|
|
|
- for (String v : e.getValue())
|
|
|
+ if (relatedEntities != null) {
|
|
|
+ for (Entry<String, Set<String>> e : relatedEntities.entrySet()) {
|
|
|
+ for (String v : e.getValue()) {
|
|
|
atsEntity.addRelatedEntity(e.getKey(), v);
|
|
|
- else
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
atsEntity.setRelatedEntities(null);
|
|
|
+ }
|
|
|
atsEntity.setPrimaryFilters(primaryFilters);
|
|
|
atsEntity.setOtherInfo(otherInfo);
|
|
|
return atsEntity;
|