use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class TestDbNotificationListener method insertTable.
@Test
public void insertTable() throws Exception {
String defaultDbName = "default";
String tblName = "inserttbl";
String tblOwner = "me";
String serdeLocation = testTempDir;
String fileAdded = "/warehouse/mytable/b1";
String checksumAdded = "1234";
FieldSchema col1 = new FieldSchema("col1", "int", "no comment");
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(col1);
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
StorageDescriptor sd = new StorageDescriptor(cols, serdeLocation, "input", "output", false, 0, serde, null, null, emptyParameters);
Table table = new Table(tblName, defaultDbName, tblOwner, startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
FireEventRequestData data = new FireEventRequestData();
InsertEventRequestData insertData = new InsertEventRequestData();
data.setInsertData(insertData);
insertData.addToFilesAdded(fileAdded);
insertData.addToFilesAddedChecksum(checksumAdded);
insertData.setReplace(false);
FireEventRequest rqst = new FireEventRequest(true, data);
rqst.setDbName(defaultDbName);
rqst.setTableName(tblName);
// Event 2
FireEventResponse response = msClient.fireListenerEvent(rqst);
assertTrue("Event id must be set in the fireEvent response", response.isSetEventIds());
Assert.assertNotNull(response.getEventIds());
Assert.assertTrue(response.getEventIds().size() == 1);
Assert.assertEquals(firstEventId + 2, response.getEventIds().get(0).longValue());
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(2, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(1);
assertEquals(firstEventId + 2, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.INSERT.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
assertEquals(tblName, event.getTableName());
// Parse the message field
verifyInsert(event, defaultDbName, tblName);
// Parse the message field
InsertMessage insertMessage = md.getInsertMessage(event.getMessage());
assertEquals(defaultDbName, insertMessage.getDB());
assertEquals(tblName, insertMessage.getTable());
assertEquals(TableType.MANAGED_TABLE.toString(), insertMessage.getTableType());
assertFalse(insertMessage.isReplace());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.INSERT, firstEventId + 2);
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_TABLE, firstEventId + 1);
testEventCounts(defaultDbName, firstEventId, null, null, 2);
}
use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class TestDbNotificationListener method createFunction.
@Test
public void createFunction() throws Exception {
String defaultDbName = "default";
String funcName = "createfunction";
String funcName2 = "createfunction2";
String ownerName = "me";
String funcClass = "o.a.h.h.createfunc";
String funcClass2 = "o.a.h.h.createfunc2";
String funcResource = Paths.get(testTempDir, "somewhere").toString();
String funcResource2 = Paths.get(testTempDir, "somewhere2").toString();
Function func = new Function(funcName, defaultDbName, funcClass, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource)));
// Event 1
msClient.createFunction(func);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(0);
assertEquals(firstEventId + 1, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.CREATE_FUNCTION.toString(), event.getEventType());
assertEquals(defaultDbName, event.getDbName());
// Parse the message field
CreateFunctionMessage createFuncMsg = md.getCreateFunctionMessage(event.getMessage());
assertEquals(defaultDbName, createFuncMsg.getDB());
Function funcObj = createFuncMsg.getFunctionObj();
assertEquals(defaultDbName, funcObj.getDbName());
assertEquals(funcName, funcObj.getFunctionName());
assertEquals(funcClass, funcObj.getClassName());
assertEquals(ownerName, funcObj.getOwnerName());
assertEquals(FunctionType.JAVA, funcObj.getFunctionType());
assertEquals(1, funcObj.getResourceUrisSize());
assertEquals(ResourceType.JAR, funcObj.getResourceUris().get(0).getResourceType());
assertEquals(funcResource, funcObj.getResourceUris().get(0).getUri());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_FUNCTION, firstEventId + 1);
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
DummyRawStoreFailEvent.setEventSucceed(false);
func = new Function(funcName2, defaultDbName, funcClass2, ownerName, PrincipalType.USER, startTime, FunctionType.JAVA, Arrays.asList(new ResourceUri(ResourceType.JAR, funcResource2)));
try {
msClient.createFunction(func);
fail("Error: create function should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
testEventCounts(defaultDbName, firstEventId, null, null, 1);
}
use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class TestDbNotificationListener method dropDatabase.
@Test
public void dropDatabase() throws Exception {
String dbName = "dropdb";
String dbName2 = "dropdb2";
String dbLocationUri = testTempDir;
String dbDescription = "no description";
msClient.createDatabase(new Database(dbName, dbDescription, dbLocationUri, emptyParameters));
// Get the DB for comparison below since it may include additional parameters
Database db = msClient.getDatabase(dbName);
// Drop the database
msClient.dropDatabase(dbName);
// Read notification from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
// Two events: one for create db and other for drop db
assertEquals(2, rsp.getEventsSize());
testEventCounts(dbName, firstEventId, null, null, 2);
// Read event from notification
NotificationEvent event = rsp.getEvents().get(1);
assertEquals(firstEventId + 2, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.DROP_DATABASE.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
assertNull(event.getTableName());
// Parse the message field
DropDatabaseMessage dropDbMsg = md.getDropDatabaseMessage(event.getMessage());
assertEquals(dbName, dropDbMsg.getDB());
assertEquals(db, dropDbMsg.getDatabaseObject());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.DROP_DATABASE, firstEventId + 2);
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_DATABASE, firstEventId + 1);
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
msClient.createDatabase(new Database(dbName2, dbDescription, dbLocationUri, emptyParameters));
DummyRawStoreFailEvent.setEventSucceed(false);
try {
msClient.dropDatabase(dbName2);
fail("Error: drop database should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(3, rsp.getEventsSize());
testEventCounts(dbName2, firstEventId, null, null, 1);
}
use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class TestDbNotificationListener method createDatabase.
@Test
public void createDatabase() throws Exception {
String dbName = "createdb";
String dbName2 = "createdb2";
String dbLocationUri = testTempDir;
String dbDescription = "no description";
Database db = new Database(dbName, dbDescription, dbLocationUri, emptyParameters);
msClient.createDatabase(db);
// Read notification from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
// Read event from notification
NotificationEvent event = rsp.getEvents().get(0);
assertEquals(firstEventId + 1, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.CREATE_DATABASE.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
assertNull(event.getTableName());
// Parse the message field
CreateDatabaseMessage createDbMsg = md.getCreateDatabaseMessage(event.getMessage());
assertEquals(dbName, createDbMsg.getDB());
assertEquals(db, createDbMsg.getDatabaseObject());
// Verify the eventID was passed to the non-transactional listener
MockMetaStoreEventListener.popAndVerifyLastEventId(EventType.CREATE_DATABASE, firstEventId + 1);
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
DummyRawStoreFailEvent.setEventSucceed(false);
db = new Database(dbName2, dbDescription, dbLocationUri, emptyParameters);
try {
msClient.createDatabase(db);
fail("Error: create database should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(1, rsp.getEventsSize());
// There's only one event corresponding to CREATE DATABASE
testEventCounts(dbName, firstEventId, null, null, 1);
testEventCounts(dbName2, firstEventId, null, null, 0);
}
use of org.apache.hadoop.hive.metastore.api.NotificationEventResponse in project hive by apache.
the class TestDbNotificationListener method getOnlyMaxEvents.
@Test
public void getOnlyMaxEvents() throws Exception {
Database db = new Database("db1", "no description", testTempDir, emptyParameters);
msClient.createDatabase(db);
db = new Database("db2", "no description", testTempDir, emptyParameters);
msClient.createDatabase(db);
db = new Database("db3", "no description", testTempDir, emptyParameters);
msClient.createDatabase(db);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 2, null);
assertEquals(2, rsp.getEventsSize());
assertEquals(firstEventId + 1, rsp.getEvents().get(0).getEventId());
assertEquals(firstEventId + 2, rsp.getEvents().get(1).getEventId());
}
Aggregations