FullUpdateModifier { private static void alterPartition(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { SentryJSONAlterPartitionMessage message = (SentryJSONAlterPartitionMessage) deserializer .getAlterPartitionMessage(event.getMessage()); String dbName = message.getDB(); if ((dbName == null) || dbName.isEmpty()) { LOGGER.error("Alter partition event is missing database name"); return; } String tableName = message.getTable(); if ((tableName == null) || tableName.isEmpty()) { LOGGER.error("Alter partition event for {} is missing table name", dbName); return; } String authName = dbName.toLowerCase() + "." + tableName.toLowerCase(); String prevLocation = message.getOldLocation(); if (prevLocation == null || prevLocation.isEmpty()) { LOGGER.error("Alter partition event for {} is missing old location", authName); } String prevPath = FullUpdateInitializer.pathFromURI(prevLocation); if (prevPath == null) { return; } String newLocation = message.getNewLocation(); if (newLocation == null || newLocation.isEmpty()) { LOGGER.error("Alter partition event for {} is missing new location", authName); } String newPath = FullUpdateInitializer.pathFromURI(newLocation); if (newPath == null) { return; } if (prevPath.equals(newPath)) { LOGGER.warn("Alter partition event for {} has the same old and new path {}", authName, prevPath); return; } Set<String> locations = (Set<String>) image.get(authName); if (locations == null) { LOGGER.warn("Missing partition locations for {}", authName); return; } if (locations.remove(prevPath)) { LOGGER.debug("Renaming {} to {}", prevPath, newPath); locations.add(newPath); } } private  FullUpdateModifier();   }
@Test public void testAlterPartition() throws Exception { String partPath = "hello/world"; String partLocation = uri(partPath); String newPath = "better/world"; String newLocation = uri(newPath); Map<String, Collection<String>> update = new HashMap<>(); Set<String> locations = new HashSet<>(); locations.add(PATH); locations.add(partPath); update.put(AUTH, locations); NotificationEvent event = new NotificationEvent(0, 0, ALTER_PARTITION.toString(), ""); MessageDeserializer deserializer = Mockito.mock(SentryJSONMessageDeserializer.class); Partition partitionObjBefore = new Partition(null, DB, TABLE, 0, 0, buildStorageDescriptor(partLocation), null); Partition partitionObjAfter = new Partition(null, DB, TABLE, 0, 0, buildStorageDescriptor(newLocation), null); SentryJSONAlterPartitionMessage message = new SentryJSONAlterPartitionMessage(SERVER, PRINCIPAL, TABLE_OBJ, partitionObjBefore, partitionObjAfter, 0L); Mockito.when(deserializer.getAlterPartitionMessage("")).thenReturn(message); FullUpdateModifier.applyEvent(update, event, deserializer); Set<String> expected = new HashSet<>(2); expected.add(PATH); expected.add(newPath); assertEquals(expected, update.get(AUTH)); }