use of org.apache.hadoop.hive.metastore.messaging.DropIndexMessage in project hive by apache.
the class TestDbNotificationListener method dropIndex.
@Test
public void dropIndex() throws Exception {
String indexName = "dropIndex";
String dbName = "default";
String tableName = "dropIndexTable";
String indexTableName = tableName + "__" + indexName + "__";
int startTime = (int) (System.currentTimeMillis() / 1000);
List<FieldSchema> cols = new ArrayList<FieldSchema>();
cols.add(new FieldSchema("col1", "int", ""));
SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
Map<String, String> params = new HashMap<String, String>();
params.put("key", "value");
StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 17, serde, Arrays.asList("bucketcol"), Arrays.asList(new Order("sortcol", 1)), params);
Table table = new Table(tableName, dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 1
msClient.createTable(table);
Index index = new Index(indexName, null, "default", tableName, startTime, startTime, indexTableName, sd, emptyParameters, false);
Table indexTable = new Table(indexTableName, dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
// Event 2, 3 (index table and index)
msClient.createIndex(index, indexTable);
// Event 4 (drops index and indexTable)
msClient.dropIndex(dbName, tableName, indexName, true);
// Get notifications from metastore
NotificationEventResponse rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(4, rsp.getEventsSize());
NotificationEvent event = rsp.getEvents().get(3);
assertEquals(firstEventId + 4, event.getEventId());
assertTrue(event.getEventTime() >= startTime);
assertEquals(EventType.DROP_INDEX.toString(), event.getEventType());
assertEquals(dbName, event.getDbName());
// Parse the message field
DropIndexMessage dropIdxMsg = md.getDropIndexMessage(event.getMessage());
assertEquals(dbName, dropIdxMsg.getDB());
assertEquals(indexName.toLowerCase(), dropIdxMsg.getIndexName());
assertEquals(indexTableName.toLowerCase(), dropIdxMsg.getIndexTableName());
assertEquals(tableName.toLowerCase(), dropIdxMsg.getOrigTableName());
// When hive.metastore.transactional.event.listeners is set,
// a failed event should not create a new notification
index = new Index("dropIndexTable2", null, "default", tableName, startTime, startTime, "dropIndexTable__dropIndexTable2__", sd, emptyParameters, false);
Table indexTable2 = new Table("dropIndexTable__dropIndexTable2__", dbName, "me", startTime, startTime, 0, sd, null, emptyParameters, null, null, null);
msClient.createIndex(index, indexTable2);
DummyRawStoreFailEvent.setEventSucceed(false);
try {
// drops index and indexTable
msClient.dropIndex(dbName, tableName, "dropIndex2", true);
fail("Error: drop index should've failed");
} catch (Exception ex) {
// expected
}
rsp = msClient.getNextNotification(firstEventId, 0, null);
assertEquals(6, rsp.getEventsSize());
}
Aggregations