FullUpdateModifier { private static void dropDatabase(Map<String, Collection<String>> image, NotificationEvent event, MessageDeserializer deserializer) { SentryJSONDropDatabaseMessage message = (SentryJSONDropDatabaseMessage) deserializer.getDropDatabaseMessage(event.getMessage()); String dbName = message.getDB(); if ((dbName == null) || dbName.isEmpty()) { LOGGER.error("Drop database event is missing database name"); return; } dbName = dbName.toLowerCase(); String location = message.getLocation(); if ((location == null) || location.isEmpty()) { LOGGER.error("Drop database event is missing database location"); return; } String path = FullUpdateInitializer.pathFromURI(location); if (path == null) { return; } Set<String> locations = (Set<String>)image.get(dbName); if (locations == null) { LOGGER.debug("database {} is already deleted", dbName); return; } if (!locations.contains(path)) { LOGGER.warn("Database {} location does not match {}", dbName, path); return; } LOGGER.debug("drop database {} with location {}", dbName, location); image.remove(dbName); String dbPrefix = dbName + "."; for (Iterator<Map.Entry<String, Collection<String>>> it = image.entrySet().iterator(); it.hasNext(); ) { Map.Entry<String, Collection<String>> entry = it.next(); String key = entry.getKey(); if (key.startsWith(dbPrefix)) { LOGGER.debug("Removing {}", key); it.remove(); } } } private  FullUpdateModifier();   }
@Test public void testDropDatabase() throws Exception { Map<String, Collection<String>> update = new HashMap<>(); update.put(DB.toLowerCase(), Collections.singleton(PATH)); NotificationEvent event = new NotificationEvent(0, 0, DROP_DATABASE.toString(), ""); MessageDeserializer deserializer = Mockito.mock(SentryJSONMessageDeserializer.class); SentryJSONDropDatabaseMessage message = new SentryJSONDropDatabaseMessage(SERVER, PRINCIPAL, DB, 0L, LOCATION); Mockito.when(deserializer.getDropDatabaseMessage("")).thenReturn(message); FullUpdateModifier.applyEvent(update, event, deserializer); assertTrue(update.isEmpty()); }