NotificationProcessor { boolean processNotificationEvent(NotificationEvent event) throws Exception { LOGGER .debug("Processing event with id:{} and Type:{}", event.getEventId(), event.getEventType()); EventType eventType = EventType.valueOf(event.getEventType()); Timer timer = SentryMetrics .getInstance() .getTimer(MetricRegistry.name(HMSFollower.class, eventType.toString().toLowerCase())); try (Context ignored = timer.time()) { switch (eventType) { case CREATE_DATABASE: return processCreateDatabase(event); case DROP_DATABASE: return processDropDatabase(event); case CREATE_TABLE: return processCreateTable(event); case DROP_TABLE: return processDropTable(event); case ALTER_TABLE: return processAlterTable(event); case ADD_PARTITION: return processAddPartition(event); case DROP_PARTITION: return processDropPartition(event); case ALTER_PARTITION: return processAlterPartition(event); default: LOGGER.error("Notification with ID:{} has invalid event type: {}", event.getEventId(), event.getEventType()); return false; } } } NotificationProcessor(SentryStoreInterface sentryStore, String authServerName,
      Configuration conf);   }
@Test public void testAlterTableWithInvalidEvent() throws Exception { String dbName = "db1"; String tableName1 = "table1"; String tableName2 = "table2"; long inputEventId = 1; NotificationEvent notificationEvent; List<FieldSchema> partCols; StorageDescriptor sd; Mockito.doNothing().when(sentryStore).persistLastProcessedNotificationID(Mockito.anyLong()); Mockito.doNothing().when(sentryStore).addAuthzPathsMapping(Mockito.anyString(), Mockito.anyCollection(), Mockito.any(UniquePathsUpdate.class)); Configuration authConf = new Configuration(); authConf.set(ServiceConstants.ServerConfig.PROCESSOR_FACTORIES, "org.apache.sentry.hdfs.SentryHDFSServiceProcessorFactory"); authConf.set(ServiceConstants.ServerConfig.SENTRY_POLICY_STORE_PLUGINS, "org.apache.sentry.hdfs.SentryPlugin"); notificationProcessor = new NotificationProcessor(sentryStore, hiveInstance, authConf); sd = new StorageDescriptor(); sd.setLocation("hdfs: partCols = new ArrayList<>(); partCols.add(new FieldSchema("ds", "string", "")); Table table = new Table(tableName1, dbName, null, 0, 0, 0, sd, partCols, null, null, null, null); notificationEvent = new NotificationEvent(inputEventId, 0, EventMessage.EventType.CREATE_TABLE.toString(), messageFactory.buildCreateTableMessage(table, Collections.emptyIterator()).toString()); notificationEvent.setDbName(dbName); notificationEvent.setTableName(tableName1); inputEventId += 1; notificationProcessor.processNotificationEvent(notificationEvent); verify(sentryStore, times(1)).addAuthzPathsMapping(Mockito.anyString(), Mockito.anyCollection(), Mockito.any(UniquePathsUpdate.class)); reset(sentryStore); notificationEvent = new NotificationEvent(1, 0, EventMessage.EventType.ALTER_TABLE.toString(), messageFactory.buildAlterTableMessage( new Table(tableName1, dbName, null, 0, 0, 0, sd, null, null, null, null, null), new Table(tableName1, dbName, null, 0, 0, 0, sd, null, null, null, null, null)).toString()); notificationEvent.setDbName(dbName); notificationEvent.setTableName(tableName1); inputEventId += 1; notificationProcessor.processNotificationEvent(notificationEvent); verify(sentryStore, times(0)).renameAuthzObj(Mockito.anyString(), Mockito.anyString(), Mockito.any(UniquePathsUpdate.class)); verify(sentryStore, times(0)).deleteAuthzPathsMapping(Mockito.anyString(), Mockito.anyCollection(), Mockito.any(UniquePathsUpdate.class)); reset(sentryStore); sd = new StorageDescriptor(); sd.setLocation("hdfs: partCols = new ArrayList<>(); partCols.add(new FieldSchema("ds", "string", "")); Table table1 = new Table(tableName2, dbName, null, 0, 0, 0, sd, partCols, null, null, null, null); notificationEvent = new NotificationEvent(inputEventId, 0, EventMessage.EventType.CREATE_TABLE.toString(), messageFactory.buildCreateTableMessage(table1, Collections.emptyIterator()).toString()); notificationEvent.setDbName(dbName); notificationEvent.setTableName(tableName2); notificationProcessor.processNotificationEvent(notificationEvent); verify(sentryStore, times(1)).addAuthzPathsMapping(Mockito.anyString(), Mockito.anyCollection(), Mockito.any(UniquePathsUpdate.class)); }