From d3fad486224567cbef53cb97c40f857990220a67 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 4 Sep 2013 09:26:36 +0200 Subject: [PATCH] SONAR-4602 Revert eviction of dryRun cache on settings change as it is not needed --- .../persistence/DryRunDatabaseFactory.java | 11 ++- .../DryRunDatabaseFactoryTest.java | 3 - .../config/GlobalPropertyChangeHandler.java | 10 +-- .../api/config/SettingsChangeHandler.java | 85 ------------------- .../sonar/server/configuration/Backup.java | 2 +- .../configuration/PropertiesBackup.java | 7 +- .../server/platform/DryRunCacheListener.java | 45 ---------- .../org/sonar/server/platform/Platform.java | 1 - .../platform/SettingsChangeNotifier.java | 34 ++------ .../java/org/sonar/server/ui/JRubyFacade.java | 8 +- .../webapp/WEB-INF/app/models/property.rb | 2 +- .../server/configuration/BackupTest.java | 29 +++---- .../configuration/PropertiesBackupTest.java | 3 +- .../platform/SettingsChangeNotifierTest.java | 20 ++--- 14 files changed, 42 insertions(+), 218 deletions(-) delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/config/SettingsChangeHandler.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/platform/DryRunCacheListener.java diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java index 74a4946db93..979d956f482 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java @@ -124,12 +124,11 @@ public class DryRunDatabaseFactory implements ServerComponent { long startup = System.currentTimeMillis(); Long lastTimestampInCache = getLastTimestampInCache(projectId); - // TODO Temporary disable cache until cache eviction is ok - // if (lastTimestampInCache == null || !isValid(projectId, lastTimestampInCache)) { - lastTimestampInCache = System.nanoTime(); - cleanCache(projectId); - createNewDatabaseForDryRun(projectId, startup, lastTimestampInCache); - // } + if (lastTimestampInCache == null || !isValid(projectId, lastTimestampInCache)) { + lastTimestampInCache = System.nanoTime(); + cleanCache(projectId); + createNewDatabaseForDryRun(projectId, startup, lastTimestampInCache); + } return dbFileContent(projectId, lastTimestampInCache); } diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java index 5d26e439e86..bb5c335a4ca 100644 --- a/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java +++ b/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java @@ -25,7 +25,6 @@ import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -87,7 +86,6 @@ public class DryRunDatabaseFactoryTest extends AbstractDaoTestCase { } @Test - @Ignore public void should_reuse_database_without_project() throws IOException, SQLException { setupData("should_create_database"); @@ -138,7 +136,6 @@ public class DryRunDatabaseFactoryTest extends AbstractDaoTestCase { } @Test - @Ignore public void should_reuse_database_with_project() throws IOException, SQLException { setupData("should_create_database"); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/GlobalPropertyChangeHandler.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/GlobalPropertyChangeHandler.java index 07e8def006d..45f549e1086 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/GlobalPropertyChangeHandler.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/GlobalPropertyChangeHandler.java @@ -19,6 +19,8 @@ */ package org.sonar.api.config; +import org.sonar.api.ServerExtension; + import javax.annotation.Nullable; /** @@ -31,7 +33,7 @@ import javax.annotation.Nullable; * * @since 3.0 */ -public abstract class GlobalPropertyChangeHandler implements SettingsChangeHandler { +public abstract class GlobalPropertyChangeHandler implements ServerExtension { public static final class PropertyChange { private String key; @@ -65,10 +67,4 @@ public abstract class GlobalPropertyChangeHandler implements SettingsChangeHandl */ public abstract void onChange(PropertyChange change); - @Override - public void onChange(SettingsChange change) { - if (change.isGlobal()) { - onChange(PropertyChange.create(change.key(), change.newValue())); - } - } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/SettingsChangeHandler.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/SettingsChangeHandler.java deleted file mode 100644 index 09b800049a2..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/SettingsChangeHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.config; - -import org.sonar.api.ServerExtension; - -import javax.annotation.Nullable; - -/** - * Observe changes of properties done from web application. It does not support : - * - * - * @since 4.0 - */ -public interface SettingsChangeHandler extends ServerExtension { - - public static final class SettingsChange { - private String key; - private String newValue; - private String componentKey; - private String userLogin; - - private SettingsChange(String key, @Nullable String newValue, @Nullable String componentKey, @Nullable String userLogin) { - this.key = key; - this.newValue = newValue; - this.componentKey = componentKey; - this.userLogin = userLogin; - } - - public static SettingsChange create(String key, @Nullable String newValue, @Nullable String componentKey, @Nullable String userLogin) { - return new SettingsChange(key, newValue, componentKey, userLogin); - } - - public String key() { - return key; - } - - public String newValue() { - return newValue; - } - - public String componentKey() { - return componentKey; - } - - public String userLogin() { - return userLogin; - } - - public boolean isGlobal() { - return componentKey == null && userLogin == null; - } - - @Override - public String toString() { - return String.format("[key=%s, newValue=%s, componentKey=%s]", key, newValue, componentKey); - } - } - - /** - * This method gets called when a property is changed. - */ - public void onChange(SettingsChange change); - -} diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java b/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java index f4ecce316f1..8f52f8d9955 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java @@ -60,7 +60,7 @@ public class Backup { this.session = session; backupables.add(new MetricsBackup(session)); - backupables.add(new PropertiesBackup(persistentSettings, cleanDryRunCache)); + backupables.add(new PropertiesBackup(persistentSettings)); // Note that order is important, because profile can have reference to rule backupables.add(new RulesBackup(session)); backupables.add(new ProfilesBackup(session)); diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java index 33404e2e189..8dac49cfe9b 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/PropertiesBackup.java @@ -28,7 +28,6 @@ import org.sonar.api.database.configuration.Property; import org.sonar.core.persistence.DryRunDatabaseFactory; import org.sonar.core.properties.PropertyDto; import org.sonar.server.platform.PersistentSettings; -import org.sonar.server.startup.CleanDryRunCache; import java.util.List; import java.util.Map; @@ -39,11 +38,8 @@ public class PropertiesBackup implements Backupable { private final PersistentSettings persistentSettings; - private final CleanDryRunCache cleanDryRunCache; - - public PropertiesBackup(PersistentSettings persistentSettings, CleanDryRunCache cleanDryRunCache) { + public PropertiesBackup(PersistentSettings persistentSettings) { this.persistentSettings = persistentSettings; - this.cleanDryRunCache = cleanDryRunCache; } public void exportXml(SonarConfig sonarConfig) { @@ -76,7 +72,6 @@ public class PropertiesBackup implements Backupable { persistentSettings.deleteProperties(); persistentSettings.saveProperties(properties); - cleanDryRunCache.clean(); } public void configure(XStream xStream) { diff --git a/sonar-server/src/main/java/org/sonar/server/platform/DryRunCacheListener.java b/sonar-server/src/main/java/org/sonar/server/platform/DryRunCacheListener.java deleted file mode 100644 index e08df859805..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/platform/DryRunCacheListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.platform; - -import org.sonar.api.config.SettingsChangeHandler; -import org.sonar.core.resource.ResourceDao; - -public class DryRunCacheListener implements SettingsChangeHandler { - - private final PersistentSettings settings; - private final ResourceDao resourceDao; - - public DryRunCacheListener(PersistentSettings settings, ResourceDao resourceDao) { - this.settings = settings; - this.resourceDao = resourceDao; - } - - @Override - public void onChange(SettingsChange change) { - // TODO Temporary disable cache eviction - // if (change.isGlobal()) { - // settings.saveProperty(DryRunDatabaseFactory.SONAR_DRY_RUN_CACHE_LAST_UPDATE_KEY, String.valueOf(System.nanoTime())); - // } else if (change.componentKey() != null) { - // ResourceDto rootProject = resourceDao.getRootProjectByComponentKey(change.componentKey()); - // settings.saveProperty(DryRunDatabaseFactory.getCacheLastUpdateKey(rootProject.getId()), String.valueOf(System.nanoTime())); - // } - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 5e10b6cd0c3..65acf75027f 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -258,7 +258,6 @@ public final class Platform { coreContainer.addSingleton(ThreadLocalDatabaseSessionFactory.class); coreContainer.addPicoAdapter(new DatabaseSessionProvider()); coreContainer.addSingleton(ServerMetadataPersister.class); - coreContainer.addSingleton(DryRunCacheListener.class); coreContainer.addSingleton(CleanDryRunCache.class); coreContainer.startComponents(); } diff --git a/sonar-server/src/main/java/org/sonar/server/platform/SettingsChangeNotifier.java b/sonar-server/src/main/java/org/sonar/server/platform/SettingsChangeNotifier.java index 931a446ac76..0c6ef3f2a1d 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/SettingsChangeNotifier.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/SettingsChangeNotifier.java @@ -21,44 +21,26 @@ package org.sonar.server.platform; import com.google.common.annotations.VisibleForTesting; import org.sonar.api.ServerComponent; -import org.sonar.api.config.SettingsChangeHandler; -import org.sonar.core.resource.ResourceDao; -import org.sonar.core.resource.ResourceDto; -import org.sonar.core.user.UserDao; -import org.sonar.core.user.UserDto; +import org.sonar.api.config.GlobalPropertyChangeHandler; import javax.annotation.Nullable; public class SettingsChangeNotifier implements ServerComponent { @VisibleForTesting - SettingsChangeHandler[] changeHandlers; - private final ResourceDao resourceDao; - private final UserDao userDao; + GlobalPropertyChangeHandler[] changeHandlers; - public SettingsChangeNotifier(ResourceDao resourceDao, UserDao userDao, SettingsChangeHandler[] changeHandlers) { - this.resourceDao = resourceDao; - this.userDao = userDao; + public SettingsChangeNotifier(GlobalPropertyChangeHandler[] changeHandlers) { this.changeHandlers = changeHandlers; } - public SettingsChangeNotifier(ResourceDao resourceDao, UserDao userDao) { - this(resourceDao, userDao, new SettingsChangeHandler[0]); + public SettingsChangeNotifier() { + this(new GlobalPropertyChangeHandler[0]); } - public void onPropertyChange(String key, @Nullable String value, @Nullable Long componentId, @Nullable Long userId) { - String resourceKey = null; - if (componentId != null) { - ResourceDto resource = resourceDao.getResource(componentId); - resourceKey = resource != null ? resource.getKey() : null; - } - String userLogin = null; - if (userId != null) { - UserDto user = userDao.getUser(userId); - userLogin = user != null ? user.getLogin() : null; - } - SettingsChangeHandler.SettingsChange change = SettingsChangeHandler.SettingsChange.create(key, value, resourceKey, userLogin); - for (SettingsChangeHandler changeHandler : changeHandlers) { + public void onGlobalPropertyChange(String key, @Nullable String value) { + GlobalPropertyChangeHandler.PropertyChange change = GlobalPropertyChangeHandler.PropertyChange.create(key, value); + for (GlobalPropertyChangeHandler changeHandler : changeHandlers) { changeHandler.onChange(change); } } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 169a25e6975..acf58e4832a 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -342,11 +342,9 @@ public final class JRubyFacade { return get(ProfilesManager.class); } - public void updateProperty(String key, @Nullable String value, @Nullable Long componentId, @Nullable Long userId) { - if (componentId == null && userId == null) { - get(ServerSettings.class).setProperty(key, value); - } - get(SettingsChangeNotifier.class).onPropertyChange(key, value, componentId, userId); + public void setGlobalProperty(String key, @Nullable String value) { + get(ServerSettings.class).setProperty(key, value); + get(SettingsChangeNotifier.class).onGlobalPropertyChange(key, value); } public Settings getSettings() { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb index b6faefc36f4..b76da8946cd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb @@ -176,7 +176,7 @@ class Property < ActiveRecord::Base private def self.setGlobalProperty(key, value, resource_id, user_id) - Api::Utils.java_facade.updateProperty(key, value, resource_id && resource_id.to_i, user_id && user_id.to_i) + Api::Utils.java_facade.setGlobalProperty(key, value) unless (resource_id || user_id) end def self.all(key, resource_id=nil, user_id=nil) diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java index 6426692fc27..8380ab1e966 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java @@ -24,7 +24,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.CharEncoding; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; -import org.junit.Before; import org.junit.Test; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.configuration.Property; @@ -36,7 +35,6 @@ import org.sonar.api.rules.ActiveRuleParam; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleParam; import org.sonar.api.rules.RulePriority; -import org.sonar.server.startup.CleanDryRunCache; import java.io.IOException; import java.io.InputStream; @@ -56,13 +54,6 @@ import static org.mockito.Mockito.verify; public class BackupTest { - private CleanDryRunCache cleanDryRunCache; - - @Before - public void prepare() { - this.cleanDryRunCache = mock(CleanDryRunCache.class); - } - @Test public void shouldExportXml() throws Exception { SonarConfig sonarConfig = getSonarConfig(); @@ -76,7 +67,7 @@ public class BackupTest { @Test public void shouldReturnAValidXml() throws Exception { - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache), + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null), new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); SonarConfig sonarConfig = getSonarConfig(); sonarConfig.setMetrics(getMetrics()); @@ -92,7 +83,7 @@ public class BackupTest { public void shouldExportXmlInCdata() throws Exception { SonarConfig sonarConfig = getSonarConfig(); sonarConfig.setProperties(getPropertiesWithXmlIlliciteCharacters()); - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache))); + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null))); String xml = backup.getXmlFromSonarConfig(sonarConfig); assertXmlAreSimilar(xml, "backup-with-cdata.xml"); @@ -102,7 +93,7 @@ public class BackupTest { public void shouldExportXmlWithUtf8Characters() throws Exception { SonarConfig sonarConfig = getSonarConfig(); sonarConfig.setProperties(getPropertiesWithUtf8Characters()); - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache))); + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null))); String xml = backup.getXmlFromSonarConfig(sonarConfig); assertXmlAreSimilar(xml, "backup-with-utf8-char.xml"); @@ -110,7 +101,7 @@ public class BackupTest { @Test public void shouldImportXml() { - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache), + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null), new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); String xml = getFileFromClasspath("backup-restore-valid.xml"); @@ -193,7 +184,7 @@ public class BackupTest { @Test public void shouldImportXmlWithoutInheritanceInformation() { - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache), + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null), new RulesBackup((DatabaseSession) null), new ProfilesBackup((DatabaseSession) null))); String xml = getFileFromClasspath("backup-restore-without-inheritance.xml"); @@ -209,7 +200,7 @@ public class BackupTest { @Test public void shouldImportXmlWithXmlIlliciteCharacters() { - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache))); + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null))); String xml = getFileFromClasspath("backup-with-cdata.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); @@ -219,7 +210,7 @@ public class BackupTest { @Test public void shouldImportOneDotFiveFormat() { - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache))); + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null))); String xml = getFileFromClasspath("shouldImportOneDotFiveFormat.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); @@ -231,7 +222,7 @@ public class BackupTest { @Test public void shouldImportXmlWithUtf8Character() { - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache))); + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null))); String xml = getFileFromClasspath("backup-with-utf8-char.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); @@ -241,7 +232,7 @@ public class BackupTest { @Test public void shouldNotImportMetricIds() { - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache))); + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null))); String xml = getFileFromClasspath("backup-with-id-for-metrics.xml"); SonarConfig sonarConfig = backup.getSonarConfigFromXml(xml); @@ -255,7 +246,7 @@ public class BackupTest { SonarConfig sonarConfig = getSonarConfig(); sonarConfig.setProperties(getPropertiesWithCDATA()); - Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null, cleanDryRunCache))); + Backup backup = new Backup(Arrays.asList(new MetricsBackup(null), new PropertiesBackup(null))); String xml = backup.getXmlFromSonarConfig(sonarConfig); assertXmlAreSimilar(xml, "backup-with-splitted-cdata.xml"); diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java index 31a782ed464..51173e6262f 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/PropertiesBackupTest.java @@ -28,7 +28,6 @@ import org.sonar.api.CoreProperties; import org.sonar.api.database.configuration.Property; import org.sonar.core.properties.PropertyDto; import org.sonar.server.platform.PersistentSettings; -import org.sonar.server.startup.CleanDryRunCache; import java.util.Arrays; import java.util.Collection; @@ -49,7 +48,7 @@ public class PropertiesBackupTest { @Before public void setup() { persistentSettings = mock(PersistentSettings.class); - backup = new PropertiesBackup(persistentSettings, mock(CleanDryRunCache.class)); + backup = new PropertiesBackup(persistentSettings); } @Test diff --git a/sonar-server/src/test/java/org/sonar/server/platform/SettingsChangeNotifierTest.java b/sonar-server/src/test/java/org/sonar/server/platform/SettingsChangeNotifierTest.java index 2988c58462f..2b1bf1871ea 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/SettingsChangeNotifierTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/SettingsChangeNotifierTest.java @@ -21,9 +21,7 @@ package org.sonar.server.platform; import org.junit.Test; import org.mockito.ArgumentMatcher; -import org.sonar.api.config.SettingsChangeHandler; -import org.sonar.core.resource.ResourceDao; -import org.sonar.core.user.UserDao; +import org.sonar.api.config.GlobalPropertyChangeHandler; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.argThat; @@ -33,27 +31,27 @@ import static org.mockito.Mockito.verify; public class SettingsChangeNotifierTest { @Test public void onGlobalPropertyChange() { - SettingsChangeHandler handler = mock(SettingsChangeHandler.class); - SettingsChangeNotifier notifier = new SettingsChangeNotifier(mock(ResourceDao.class), mock(UserDao.class), new SettingsChangeHandler[] {handler}); + GlobalPropertyChangeHandler handler = mock(GlobalPropertyChangeHandler.class); + SettingsChangeNotifier notifier = new SettingsChangeNotifier(new GlobalPropertyChangeHandler[] {handler}); - notifier.onPropertyChange("foo", "bar", null, null); + notifier.onGlobalPropertyChange("foo", "bar"); - verify(handler).onChange(argThat(new ArgumentMatcher() { + verify(handler).onChange(argThat(new ArgumentMatcher() { @Override public boolean matches(Object o) { - SettingsChangeHandler.SettingsChange change = (SettingsChangeHandler.SettingsChange) o; - return change.key().equals("foo") && change.newValue().equals("bar") && change.componentKey() == null && change.userLogin() == null; + GlobalPropertyChangeHandler.PropertyChange change = (GlobalPropertyChangeHandler.PropertyChange) o; + return change.getKey().equals("foo") && change.getNewValue().equals("bar"); } })); } @Test public void no_handlers() { - SettingsChangeNotifier notifier = new SettingsChangeNotifier(mock(ResourceDao.class), mock(UserDao.class)); + SettingsChangeNotifier notifier = new SettingsChangeNotifier(); assertThat(notifier.changeHandlers).isEmpty(); // does not fail - notifier.onPropertyChange("foo", "bar", null, null); + notifier.onGlobalPropertyChange("foo", "bar"); } } -- 2.39.5