@Test public void testAlterTableChangeTableName() throws Exception { Map<String, Collection<String>> update = new HashMap<>(); update.put(DB.toLowerCase(), Collections.singleton(PATH)); Set<String> locations = new HashSet<>(1); locations.add(PATH); update.put(AUTH, locations); String newTableName = "Table2"; String newAuth = DB.toLowerCase() + "." + newTableName.toLowerCase(); NotificationEvent event = new NotificationEvent(0, 0, ALTER_TABLE.toString(), ""); event.setDbName(DB); event.setTableName(newTableName); MessageDeserializer deserializer = Mockito.mock(SentryJSONMessageDeserializer.class); SentryJSONAlterTableMessage message = new SentryJSONAlterTableMessage(SERVER, PRINCIPAL, TABLE_OBJ, TABLE_OBJ, 0L); Mockito.when(deserializer.getAlterTableMessage("")).thenReturn(message); FullUpdateModifier.applyEvent(update, event, deserializer); Map<String, Set<String>> expected = new HashMap<>(2); expected.put(DB.toLowerCase(), Collections.singleton(PATH)); expected.put(newAuth, Collections.singleton(PATH)); assertEquals(expected, update); }
static void applyEvent(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { EventMessage.EventType eventType = EventMessage.EventType.valueOf(event.getEventType()); switch (eventType) { case CREATE_DATABASE: createDatabase(image, event, deserializer); break; case DROP_DATABASE: dropDatabase(image, event, deserializer); break; case CREATE_TABLE: createTable(image, event, deserializer); break; case DROP_TABLE: dropTable(image, event, deserializer); break; case ALTER_TABLE: alterTable(image, event, deserializer); break; case ADD_PARTITION: addPartition(image, event, deserializer); break; case DROP_PARTITION: dropPartition(image, event, deserializer); break; case ALTER_PARTITION: alterPartition(image, event, deserializer); break; default: LOGGER.error("Notification with ID:{} has invalid event type: {}", event.getEventId(), event.getEventType()); break; } }
FullUpdateModifier { static void applyEvent(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { EventMessage.EventType eventType = EventMessage.EventType.valueOf(event.getEventType()); switch (eventType) { case CREATE_DATABASE: createDatabase(image, event, deserializer); break; case DROP_DATABASE: dropDatabase(image, event, deserializer); break; case CREATE_TABLE: createTable(image, event, deserializer); break; case DROP_TABLE: dropTable(image, event, deserializer); break; case ALTER_TABLE: alterTable(image, event, deserializer); break; case ADD_PARTITION: addPartition(image, event, deserializer); break; case DROP_PARTITION: dropPartition(image, event, deserializer); break; case ALTER_PARTITION: alterPartition(image, event, deserializer); break; default: LOGGER.error("Notification with ID:{} has invalid event type: {}", event.getEventId(), event.getEventType()); break; } } }
FullUpdateModifier { static void applyEvent(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { EventMessage.EventType eventType = EventMessage.EventType.valueOf(event.getEventType()); switch (eventType) { case CREATE_DATABASE: createDatabase(image, event, deserializer); break; case DROP_DATABASE: dropDatabase(image, event, deserializer); break; case CREATE_TABLE: createTable(image, event, deserializer); break; case DROP_TABLE: dropTable(image, event, deserializer); break; case ALTER_TABLE: alterTable(image, event, deserializer); break; case ADD_PARTITION: addPartition(image, event, deserializer); break; case DROP_PARTITION: dropPartition(image, event, deserializer); break; case ALTER_PARTITION: alterPartition(image, event, deserializer); break; default: LOGGER.error("Notification with ID:{} has invalid event type: {}", event.getEventId(), event.getEventType()); break; } } private  FullUpdateModifier(); }
FullUpdateModifier { static void applyEvent(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { EventMessage.EventType eventType = EventMessage.EventType.valueOf(event.getEventType()); switch (eventType) { case CREATE_DATABASE: createDatabase(image, event, deserializer); break; case DROP_DATABASE: dropDatabase(image, event, deserializer); break; case CREATE_TABLE: createTable(image, event, deserializer); break; case DROP_TABLE: dropTable(image, event, deserializer); break; case ALTER_TABLE: alterTable(image, event, deserializer); break; case ADD_PARTITION: addPartition(image, event, deserializer); break; case DROP_PARTITION: dropPartition(image, event, deserializer); break; case ALTER_PARTITION: alterPartition(image, event, deserializer); break; default: LOGGER.error("Notification with ID:{} has invalid event type: {}", event.getEventId(), event.getEventType()); break; } } private  FullUpdateModifier();  }
FullUpdateModifier { static void applyEvent(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { EventMessage.EventType eventType = EventMessage.EventType.valueOf(event.getEventType()); switch (eventType) { case CREATE_DATABASE: createDatabase(image, event, deserializer); break; case DROP_DATABASE: dropDatabase(image, event, deserializer); break; case CREATE_TABLE: createTable(image, event, deserializer); break; case DROP_TABLE: dropTable(image, event, deserializer); break; case ALTER_TABLE: alterTable(image, event, deserializer); break; case ADD_PARTITION: addPartition(image, event, deserializer); break; case DROP_PARTITION: dropPartition(image, event, deserializer); break; case ALTER_PARTITION: alterPartition(image, event, deserializer); break; default: LOGGER.error("Notification with ID:{} has invalid event type: {}", event.getEventId(), event.getEventType()); break; } } private  FullUpdateModifier();   }