Commit 9dc96c46 by Apoorv Naik Committed by Madhan Neethiraj

ATLAS-1292: Integration test fixes caused by recent bootstrap changes

parent 774975c9
......@@ -80,8 +80,11 @@ public class EntityNotificationIT extends BaseResourceIT {
@Test
public void testCreateEntity() throws Exception {
Referenceable tableInstance = createHiveTableInstance(DATABASE_NAME, TABLE_NAME);
Referenceable hiveDBInstance = createHiveDBInstance(DATABASE_NAME);
Id dbID = createInstance(hiveDBInstance);
hiveDBInstance.replaceWithNewId(dbID);
Referenceable tableInstance = createHiveTableInstance(hiveDBInstance, TABLE_NAME);
tableId = createInstance(tableInstance);
final String guid = tableId._getId();
......@@ -107,7 +110,11 @@ public class EntityNotificationIT extends BaseResourceIT {
public void testDeleteEntity() throws Exception {
final String tableName = "table-" + randomString();
final String dbName = "db-" + randomString();
Referenceable tableInstance = createHiveTableInstance(dbName, tableName);
Referenceable hiveDBInstance = createHiveDBInstance(dbName);
Id dbID = createInstance(hiveDBInstance);
hiveDBInstance.replaceWithNewId(dbID);
Referenceable tableInstance = createHiveTableInstance(hiveDBInstance, tableName);
final Id tableId = createInstance(tableInstance);
final String guid = tableId._getId();
......
......@@ -65,8 +65,11 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
//send valid message
final Referenceable entity = new Referenceable(DATABASE_TYPE);
entity.set("name", "db" + randomString());
String dbName = "db" + randomString();
entity.set("name", dbName);
entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
sendHookMessage(new HookNotification.EntityCreateRequest(TEST_USER, entity));
waitFor(MAX_WAIT_TIME, new Predicate() {
......@@ -81,21 +84,24 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
@Test
public void testCreateEntity() throws Exception {
final Referenceable entity = new Referenceable(DATABASE_TYPE);
entity.set("name", "db" + randomString());
String dbName = "db" + randomString();
entity.set("name", dbName);
entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
sendHookMessage(new HookNotification.EntityCreateRequest(TEST_USER, entity));
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, entity.get("name")));
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, entity.get("qualifiedName")));
return results.length() == 1;
}
});
//Assert that user passed in hook message is used in audit
Referenceable instance = serviceClient.getEntity(DATABASE_TYPE, "name", (String) entity.get("name"));
Referenceable instance = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", (String) entity.get("qualifiedName"));
List<EntityAuditEvent> events =
serviceClient.getEntityAuditEvents(instance.getId()._getId(), (short) 1);
assertEquals(events.size(), 1);
......@@ -108,22 +114,25 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
final String dbName = "db" + randomString();
entity.set("name", dbName);
entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
serviceClient.createEntity(entity);
final Referenceable newEntity = new Referenceable(DATABASE_TYPE);
newEntity.set("owner", randomString());
sendHookMessage(
new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "name", dbName, newEntity));
new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "qualifiedName", dbName, newEntity));
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
Referenceable localEntity = serviceClient.getEntity(DATABASE_TYPE, "name", dbName);
Referenceable localEntity = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName);
return (localEntity.get("owner") != null && localEntity.get("owner").equals(newEntity.get("owner")));
}
});
//Its partial update and un-set fields are not updated
Referenceable actualEntity = serviceClient.getEntity(DATABASE_TYPE, "name", dbName);
Referenceable actualEntity = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName);
assertEquals(actualEntity.get("description"), entity.get("description"));
}
......@@ -133,24 +142,27 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
final String dbName = "db" + randomString();
entity.set("name", dbName);
entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
serviceClient.createEntity(entity);
final Referenceable newEntity = new Referenceable(DATABASE_TYPE);
final String newName = "db" + randomString();
newEntity.set("name", newName);
newEntity.set("qualifiedName", newName);
sendHookMessage(
new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "name", dbName, newEntity));
new HookNotification.EntityPartialUpdateRequest(TEST_USER, DATABASE_TYPE, "qualifiedName", dbName, newEntity));
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, newName));
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, newName));
return results.length() == 1;
}
});
//no entity with the old qualified name
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, dbName));
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, dbName));
assertEquals(results.length(), 0);
}
......@@ -161,10 +173,13 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
final String dbName = "db" + randomString();
entity.set("name", dbName);
entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
final String dbId = serviceClient.createEntity(entity).get(0);
sendHookMessage(
new HookNotification.EntityDeleteRequest(TEST_USER, DATABASE_TYPE, "name", dbName));
new HookNotification.EntityDeleteRequest(TEST_USER, DATABASE_TYPE, "qualifiedName", dbName));
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
......@@ -180,24 +195,29 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
final String dbName = "db" + randomString();
entity.set("name", dbName);
entity.set("description", randomString());
entity.set("qualifiedName", dbName);
entity.set("clusterName", randomString());
serviceClient.createEntity(entity);
final Referenceable newEntity = new Referenceable(DATABASE_TYPE);
newEntity.set("name", dbName);
newEntity.set("name", randomString());
newEntity.set("description", randomString());
newEntity.set("owner", randomString());
newEntity.set("qualifiedName", dbName);
newEntity.set("clusterName", randomString());
//updating unique attribute
sendHookMessage(new HookNotification.EntityUpdateRequest(TEST_USER, newEntity));
waitFor(MAX_WAIT_TIME, new Predicate() {
@Override
public boolean evaluate() throws Exception {
JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE, dbName));
JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE, newEntity.get("qualifiedName")));
return results.length() == 1;
}
});
Referenceable actualEntity = serviceClient.getEntity(DATABASE_TYPE, "name", dbName);
Referenceable actualEntity = serviceClient.getEntity(DATABASE_TYPE, "qualifiedName", dbName);
assertEquals(actualEntity.get("description"), newEntity.get("description"));
assertEquals(actualEntity.get("owner"), newEntity.get("owner"));
}
......
......@@ -90,14 +90,11 @@ public abstract class BaseResourceIT {
}
protected void createType(TypesDef typesDef) throws Exception {
HierarchicalTypeDefinition<ClassType> sampleType = typesDef.classTypesAsJavaList().get(0);
try {
serviceClient.getType(sampleType.typeName);
LOG.info("Types already exist. Skipping type creation");
} catch(AtlasServiceException ase) {
//Expected if type doesnt exist
String typesAsJSON = TypesSerialization.toJson(typesDef);
createType(typesAsJSON);
} catch(AtlasServiceException ase) {
LOG.info("Types failed. Tests might malfunction");
}
}
......@@ -186,6 +183,7 @@ public abstract class BaseResourceIT {
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDefinition),
ImmutableList.of(structTypeDefinition),
ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait),
// ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef));
createType(typesDef);
......@@ -210,11 +208,7 @@ public abstract class BaseResourceIT {
return RandomStringUtils.randomAlphanumeric(10);
}
protected Referenceable createHiveTableInstance(String dbName, String tableName) throws Exception {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
databaseInstance.set("name", dbName);
databaseInstance.set("description", "foo database");
protected Referenceable createHiveTableInstance(Referenceable databaseInstance, String tableName) throws Exception {
Referenceable tableInstance =
new Referenceable(HIVE_TABLE_TYPE, "classification", "pii", "phi", "pci", "sox", "sec", "finance");
tableInstance.set("name", tableName);
......@@ -246,6 +240,15 @@ public abstract class BaseResourceIT {
return tableInstance;
}
protected Referenceable createHiveDBInstance(String dbName) {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
databaseInstance.set("name", dbName);
databaseInstance.set("qualifiedName", dbName);
databaseInstance.set("clusterName", randomString());
databaseInstance.set("description", "foo database");
return databaseInstance;
}
public interface Predicate {
/**
......
......@@ -167,9 +167,10 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
for (int index = 0; index < rows.length(); index++) {
final JSONObject row = rows.getJSONObject(index);
LOG.info("JsonRow - {}", row);
Assert.assertNotNull(row.getString("name"));
Assert.assertNotNull(row.getString("comment"));
Assert.assertNotNull(row.getString("dataType"));
Assert.assertNotNull(row.getString("type"));
Assert.assertEquals(row.getString("$typeName$"), "hive_column");
}
}
......@@ -185,23 +186,15 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
for (int index = 0; index < rows.length(); index++) {
final JSONObject row = rows.getJSONObject(index);
LOG.info("JsonRow - {}", row);
Assert.assertNotNull(row.getString("name"));
Assert.assertNotNull(row.getString("comment"));
Assert.assertNotNull(row.getString("dataType"));
Assert.assertNotNull(row.getString("type"));
Assert.assertEquals(row.getString("$typeName$"), "hive_column");
}
}
@Test
public void testSchemaForEmptyTable() throws Exception {
WebResource resource = service.path(BASE_URI).path("").path("schema");
ClientResponse clientResponse = resource.accept(Servlets.JSON_MEDIA_TYPE).type(Servlets.JSON_MEDIA_TYPE)
.method(HttpMethod.GET, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
@Test
public void testSchemaForInvalidTable() throws Exception {
WebResource resource = service.path(BASE_URI).path("blah").path("schema");
......@@ -264,6 +257,8 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
throws Exception {
Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set("qualifiedName", name);
referenceable.set("clusterName", locationUri + name);
referenceable.set("description", description);
referenceable.set("owner", owner);
referenceable.set("locationUri", locationUri);
......@@ -272,10 +267,11 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
return createInstance(referenceable);
}
Referenceable column(String name, String dataType, String comment, String... traitNames) throws Exception {
Referenceable column(String name, String type, String comment, String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set("dataType", dataType);
referenceable.set("qualifiedName", name);
referenceable.set("type", type);
referenceable.set("comment", comment);
return referenceable;
......@@ -304,13 +300,14 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
Referenceable referenceable = new Referenceable(HIVE_PROCESS_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
referenceable.set("user", user);
referenceable.set("userName", user);
referenceable.set("startTime", System.currentTimeMillis());
referenceable.set("endTime", System.currentTimeMillis() + 10000);
referenceable.set("inputs", inputTables);
referenceable.set("outputs", outputTables);
referenceable.set("operationType", "testOperation");
referenceable.set("queryText", queryText);
referenceable.set("queryPlan", queryPlan);
referenceable.set("queryId", queryId);
......
......@@ -41,7 +41,7 @@ import java.util.Set;
/**
* Entity Lineage v2 Integration Tests.
*/
public class EntityLineageJerseyResourceIT extends BaseResourceIT {
public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceIT {
private static final String BASE_URI = "api/atlas/v2/lineage/";
private static final String INPUT_DIRECTION = "INPUT";
private static final String OUTPUT_DIRECTION = "OUTPUT";
......@@ -191,63 +191,4 @@ public class EntityLineageJerseyResourceIT extends BaseResourceIT {
loadProcess("loadSalesMonthly" + randomString(), "John ETL", ImmutableList.of(salesFactDaily),
ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph");
}
Id database(String name, String description, String owner, String locationUri, String... traitNames)
throws Exception {
Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set("description", description);
referenceable.set("owner", owner);
referenceable.set("locationUri", locationUri);
referenceable.set("createTime", System.currentTimeMillis());
return createInstance(referenceable);
}
Referenceable column(String name, String dataType, String comment, String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set("dataType", dataType);
referenceable.set("comment", comment);
return referenceable;
}
Id table(String name, String description, Id dbId, String owner, String tableType, List<Referenceable> columns,
String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(HIVE_TABLE_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
referenceable.set("description", description);
referenceable.set("owner", owner);
referenceable.set("tableType", tableType);
referenceable.set("createTime", System.currentTimeMillis());
referenceable.set("lastAccessTime", System.currentTimeMillis());
referenceable.set("retention", System.currentTimeMillis());
referenceable.set("db", dbId);
referenceable.set("columns", columns);
return createInstance(referenceable);
}
Id loadProcess(String name, String user, List<Id> inputTables, List<Id> outputTables, String queryText,
String queryPlan, String queryId, String queryGraph, String... traitNames) throws Exception {
Referenceable referenceable = new Referenceable(HIVE_PROCESS_TYPE, traitNames);
referenceable.set("name", name);
referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
referenceable.set("user", user);
referenceable.set("startTime", System.currentTimeMillis());
referenceable.set("endTime", System.currentTimeMillis() + 10000);
referenceable.set("inputs", inputTables);
referenceable.set("outputs", outputTables);
referenceable.set("queryText", queryText);
referenceable.set("queryPlan", queryPlan);
referenceable.set("queryId", queryId);
referenceable.set("queryGraph", queryGraph);
return createInstance(referenceable);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment