FullUpdateModifier { private static void addPartition(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { SentryJSONAddPartitionMessage message = (SentryJSONAddPartitionMessage) deserializer.getAddPartitionMessage(event.getMessage()); String dbName = message.getDB(); if ((dbName == null) || dbName.isEmpty()) { LOGGER.error("Add partition event is missing database name"); return; } String tableName = message.getTable(); if ((tableName == null) || tableName.isEmpty()) { LOGGER.error("Add partition event for {} is missing table name", dbName); return; } String authName = dbName.toLowerCase() + "." + tableName.toLowerCase(); List<String> locations = message.getLocations(); if (locations == null || locations.isEmpty()) { LOGGER.error("Add partition event for {} is missing partition locations", authName); return; } Set<String> oldLocations = (Set<String>) image.get(authName); if (oldLocations == null) { LOGGER.warn("Add partition for {}: missing table locations",authName); return; } for (String location: locations) { String path = FullUpdateInitializer.pathFromURI(location); if (path != null) { LOGGER.debug("Adding partition {}:{}", authName, path); oldLocations.add(path); } } } private  FullUpdateModifier();   }
@Test public void testAddPartition() throws Exception { Map<String, Collection<String>> update = new HashMap<>(); Set<String> locations = new HashSet<>(); locations.add(PATH); update.put(AUTH, locations); NotificationEvent event = new NotificationEvent(0, 0, ADD_PARTITION.toString(), ""); MessageDeserializer deserializer = Mockito.mock(SentryJSONMessageDeserializer.class); String partPath = "hello/world"; String partLocation = uri(partPath); SentryJSONAddPartitionMessage message = new SentryJSONAddPartitionMessage(SERVER, PRINCIPAL, TABLE_OBJ, Collections.emptyIterator(), Collections.emptyIterator(), 0L, Collections.singletonList(partLocation)); Mockito.when(deserializer.getAddPartitionMessage("")).thenReturn(message); FullUpdateModifier.applyEvent(update, event, deserializer); Set<String> expected = new HashSet<>(2); expected.add(PATH); expected.add(partPath); assertEquals(expected, update.get(AUTH)); }