]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6701 - Drop the db table SEMAPHORES
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 8 Jul 2015 11:54:39 +0000 (13:54 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 8 Jul 2015 14:00:52 +0000 (16:00 +0200)
27 files changed:
server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationStepModule.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDates.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/MigrationStepModuleTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest/before.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest/schema.sql [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/785_feed_semaphores_long_dates.rb [deleted file]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/924_drop_semaphores.rb [new file with mode: 0644]
sonar-db/src/main/java/org/sonar/db/DaoUtils.java
sonar-db/src/main/java/org/sonar/db/DbClient.java
sonar-db/src/main/java/org/sonar/db/MyBatis.java
sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDao.java [deleted file]
sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDto.java [deleted file]
sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreMapper.java [deleted file]
sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreUpdater.java [deleted file]
sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoresImpl.java
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/main/resources/org/sonar/db/semaphore/SemaphoreMapper.xml [deleted file]
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
sonar-db/src/test/java/org/sonar/db/semaphore/SemaphoreDaoTest.java [deleted file]
sonar-db/src/test/java/org/sonar/db/semaphore/SemaphoreUpdaterTest.java [deleted file]
sonar-db/src/test/java/org/sonar/db/semaphore/SemaphoresImplTest.java
sonar-db/src/test/resources/org/sonar/db/semaphore/SemaphoreDaoTest/old_semaphore.xml [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/utils/Semaphores.java

index 52cb95becf53b4641a7f04ad4a2d1d5fa08b3b26..398053e5d443a1dd3a98a69d0866b7ae547c39bc 100644 (file)
@@ -58,7 +58,6 @@ import org.sonar.server.db.migrations.v51.FeedIssueComponentUuids;
 import org.sonar.server.db.migrations.v51.FeedIssueTags;
 import org.sonar.server.db.migrations.v51.FeedIssuesLongDates;
 import org.sonar.server.db.migrations.v51.FeedManualMeasuresLongDates;
-import org.sonar.server.db.migrations.v51.FeedSemaphoresLongDates;
 import org.sonar.server.db.migrations.v51.FeedSnapshotsLongDates;
 import org.sonar.server.db.migrations.v51.FeedUsersLongDates;
 import org.sonar.server.db.migrations.v51.RemovePermissionsOnModulesMigrationStep;
@@ -129,7 +128,6 @@ public class MigrationStepModule extends Module {
       FeedSnapshotsLongDates.class,
       FeedIssuesLongDates.class,
       FeedFileSourcesBinaryData.class,
-      FeedSemaphoresLongDates.class,
       FeedManualMeasuresLongDates.class,
       FeedEventsLongDates.class,
       AddNewCharacteristics.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDates.java
deleted file mode 100644 (file)
index 3a3e5af..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.db.migrations.v51;
-
-import java.sql.SQLException;
-import java.util.Date;
-
-import org.sonar.api.utils.System2;
-import org.sonar.db.Database;
-import org.sonar.server.db.migrations.BaseDataChange;
-import org.sonar.server.db.migrations.MassUpdate;
-import org.sonar.server.db.migrations.Select;
-import org.sonar.server.db.migrations.SqlStatement;
-
-public class FeedSemaphoresLongDates extends BaseDataChange {
-
-  private final System2 system2;
-
-  public FeedSemaphoresLongDates(Database db, System2 system2) {
-    super(db);
-    this.system2 = system2;
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    final long now = system2.now();
-    MassUpdate massUpdate = context.prepareMassUpdate();
-    massUpdate
-      .select("SELECT s.created_at, s.updated_at, s.locked_at, s.id FROM semaphores s WHERE created_at_ms IS NULL");
-    massUpdate
-      .update("UPDATE semaphores SET created_at_ms=?, updated_at_ms=?, locked_at_ms=? WHERE id=?");
-    massUpdate.rowPluralName("semaphores");
-    massUpdate.execute(new MassUpdate.Handler() {
-      @Override
-      public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
-        for (int i = 1; i <= 3; i++) {
-          Date date = row.getNullableDate(i);
-          update.setLong(i, date == null ? null : Math.min(now, date.getTime()));
-        }
-
-        Long id = row.getNullableLong(4);
-        update.setLong(4, id);
-
-        return true;
-      }
-    });
-  }
-
-}
index 4f7878ed0269e879377912598530c66ba75b5d73..14b17452dbb171e28ea52d0f1da66e75baad4063 100644 (file)
@@ -40,7 +40,7 @@ public class BackendCleanup {
   private static final String[] INSPECTION_TABLES = {
     "action_plans", "authors", "duplications_index", "events", "issues", "issue_changes", "manual_measures",
     "notifications", "project_links", "project_measures", "projects", "resource_index",
-    "semaphores", "snapshots", "file_sources"
+    "snapshots", "file_sources"
   };
   private static final String[] RESOURCE_RELATED_TABLES = {
     "group_roles", "user_roles", "properties"
index 4ed0965d145207a5955a9fdcf8e57411b960b02a..5e399f2170fa519d3745b26a7998f437c2e420fd 100644 (file)
@@ -30,7 +30,6 @@ import org.sonar.db.DatabaseChecker;
 import org.sonar.db.DefaultDatabase;
 import org.sonar.db.MyBatis;
 import org.sonar.db.purge.PurgeProfiler;
-import org.sonar.db.semaphore.SemaphoreUpdater;
 import org.sonar.db.semaphore.SemaphoresImpl;
 import org.sonar.db.version.DatabaseVersion;
 import org.sonar.server.component.db.ComponentDao;
@@ -89,7 +88,6 @@ public class PlatformLevel1 extends PlatformLevel {
       DatabaseVersion.class,
       PurgeProfiler.class,
       DefaultServerFileSystem.class,
-      SemaphoreUpdater.class,
       SemaphoresImpl.class,
       TempFolderCleaner.class,
       new TempFolderProvider(),
index 107509dc705c714074bdba48b41fd23c0d19fb30..c2afa75acd74b13801c30d38d90368b93ab66579 100644 (file)
@@ -29,6 +29,6 @@ public class MigrationStepModuleTest {
   public void verify_count_of_added_MigrationStep_types() {
     ComponentContainer container = new ComponentContainer();
     new MigrationStepModule().configure(container);
-    assertThat(container.size()).isEqualTo(55);
+    assertThat(container.size()).isEqualTo(54);
   }
 }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest.java
deleted file mode 100644 (file)
index d225a57..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.db.migrations.v51;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.server.db.migrations.MigrationStep;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.api.utils.DateUtils.parseDate;
-
-public class FeedSemaphoresLongDatesTest {
-  @Rule
-  public DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedSemaphoresLongDatesTest.class, "schema.sql");
-
-  @Before
-  public void before() {
-    db.prepareDbUnit(getClass(), "before.xml");
-  }
-
-  @Test
-  public void execute() throws Exception {
-    MigrationStep migration = newMigration(System2.INSTANCE);
-
-    migration.execute();
-
-    int count = db
-      .countSql("select count(*) from semaphores where " +
-        "created_at_ms is not null " +
-        "and updated_at_ms is not null " +
-        "and locked_at_ms is not null");
-    assertThat(count).isEqualTo(2);
-  }
-
-  @Test
-  public void take_now_if_date_in_the_future() throws Exception {
-    System2 system = mock(System2.class);
-    when(system.now()).thenReturn(1234L);
-
-    MigrationStep migration = newMigration(system);
-
-    migration.execute();
-
-    int count = db
-      .countSql("select count(*) from semaphores where " +
-        "created_at_ms = 1234");
-    assertThat(count).isEqualTo(1);
-  }
-
-  @Test
-  public void take_snapshot_date_if_in_the_past() throws Exception {
-    MigrationStep migration = newMigration(System2.INSTANCE);
-
-    migration.execute();
-
-    long snapshotTime = parseDate("2014-09-25").getTime();
-    int count = db
-      .countSql("select count(*) from semaphores where " +
-        "created_at_ms=" + snapshotTime);
-    assertThat(count).isEqualTo(1);
-  }
-
-  private FeedSemaphoresLongDates newMigration(System2 system) {
-    return new FeedSemaphoresLongDates(db.database(), system);
-  }
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest/before.xml
deleted file mode 100644 (file)
index 1dc6228..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<dataset>
-  <!-- new migration -->
-  <semaphores
-      id="1"
-      created_at="2014-09-25"
-      created_at_ms="[null]"
-      updated_at="2014-09-25"
-      updated_at_ms="[null]"
-      locked_at="2014-09-25"
-      locked_at_ms="[null]"
-      />
-
-  <!-- re-entrant migration - ignore the ones that are already fed with new dates -->
-  <semaphores
-      id="2"
-      created_at="2014-09-25"
-      created_at_ms="1500000000"
-      updated_at="2014-09-25"
-      updated_at_ms="1500000000"
-      locked_at="2014-09-25"
-      locked_at_ms="1500000000"
-      />
-
-  <!-- NULL dates -->
-  <semaphores
-      id="3"
-      created_at="[null]"
-      created_at_ms="[null]"
-      updated_at="[null]"
-      updated_at_ms="[null]"
-      locked_at="[null]"
-      locked_at_ms="[null]"
-      />
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSemaphoresLongDatesTest/schema.sql
deleted file mode 100644 (file)
index 6d652a8..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-CREATE TABLE "SEMAPHORES" (
-  "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "CREATED_AT" TIMESTAMP,
-  "CREATED_AT_MS" BIGINT,
-  "LOCKED_AT" TIMESTAMP,
-  "LOCKED_AT_MS" BIGINT,
-  "UPDATED_AT" TIMESTAMP,
-  "UPDATED_AT_MS" BIGINT,
-);
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/785_feed_semaphores_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/785_feed_semaphores_long_dates.rb
deleted file mode 100644 (file)
index 7936cbe..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 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.
-#
-
-#
-# SonarQube 5.1
-#
-class FeedSemaphoresLongDates < ActiveRecord::Migration
-  def self.up
-    execute_java_migration('org.sonar.server.db.migrations.v51.FeedSemaphoresLongDates')
-  end
-end
-
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/924_drop_semaphores.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/924_drop_semaphores.rb
new file mode 100644 (file)
index 0000000..2aa7e63
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 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.
+#
+
+#
+# SonarQube 5.2
+# SONAR-6701
+#
+class DropSemaphores < ActiveRecord::Migration
+
+  def self.up
+    remove_index :semaphores, :name => 'uniq_semaphore_checksums'
+    drop_table 'semaphores'
+  end
+
+end
index 409d3d6b34431ac3986e1a12dba2907064270ed0..86d53c57caa323fda6188ccfe937327ded84e64e 100644 (file)
@@ -53,7 +53,6 @@ import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
 import org.sonar.db.qualitygate.QualityGateConditionDao;
 import org.sonar.db.qualitygate.QualityGateDao;
 import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.semaphore.SemaphoreDao;
 import org.sonar.db.source.FileSourceDao;
 import org.sonar.db.user.AuthorDao;
 import org.sonar.db.user.AuthorizationDao;
@@ -104,7 +103,6 @@ public final class DaoUtils {
       ResourceDao.class,
       ResourceKeyUpdaterDao.class,
       RoleDao.class,
-      SemaphoreDao.class,
       SnapshotDao.class,
       UserDao.class,
       UserGroupDao.class,
index f71210c74ee6afbc6aa3e94c215f66f9c547116f..3017ac1a0a01b3aaf07b75d2b9ad3cb68032c2ac 100644 (file)
@@ -54,7 +54,6 @@ import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
 import org.sonar.db.qualitygate.QualityGateConditionDao;
 import org.sonar.db.qualitygate.QualityGateDao;
 import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.semaphore.SemaphoreDao;
 import org.sonar.db.source.FileSourceDao;
 import org.sonar.db.user.AuthorDao;
 import org.sonar.db.user.AuthorizationDao;
@@ -106,7 +105,6 @@ public class DbClient {
   private final ProjectQgateAssociationDao projectQgateAssociationDao;
   private final DuplicationDao duplicationDao;
   private final NotificationQueueDao notificationQueueDao;
-  private final SemaphoreDao semaphoreDao;
 
   public DbClient(Database database, MyBatis myBatis, Dao[] daos) {
     this.database = database;
@@ -155,7 +153,6 @@ public class DbClient {
     projectQgateAssociationDao = getDao(map, ProjectQgateAssociationDao.class);
     duplicationDao = getDao(map, DuplicationDao.class);
     notificationQueueDao = getDao(map, NotificationQueueDao.class);
-    semaphoreDao = getDao(map, SemaphoreDao.class);
     doOnLoad(map);
   }
 
@@ -332,10 +329,6 @@ public class DbClient {
     return notificationQueueDao;
   }
 
-  public SemaphoreDao semaphoreDao() {
-    return semaphoreDao;
-  }
-
   protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
     return (K) map.get(clazz);
   }
index e4e3bce008bd2b4186991b9eaf811a69863b2925..8bf39f3dedf07e87183e3fd203e8d2232e52ae33 100644 (file)
@@ -121,8 +121,6 @@ import org.sonar.db.qualityprofile.QualityProfileMapper;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleMapper;
 import org.sonar.db.rule.RuleParamDto;
-import org.sonar.db.semaphore.SemaphoreDto;
-import org.sonar.db.semaphore.SemaphoreMapper;
 import org.sonar.db.source.FileSourceMapper;
 import org.sonar.db.user.AuthorDto;
 import org.sonar.db.user.AuthorMapper;
@@ -206,7 +204,6 @@ public class MyBatis {
     loadAlias(conf, "Rule", RuleDto.class);
     loadAlias(conf, "RuleParam", RuleParamDto.class);
     loadAlias(conf, "Snapshot", SnapshotDto.class);
-    loadAlias(conf, "Semaphore", SemaphoreDto.class);
     loadAlias(conf, "SchemaMigration", SchemaMigrationDto.class);
     loadAlias(conf, "User", UserDto.class);
     loadAlias(conf, "UserRole", UserRoleDto.class);
@@ -250,7 +247,7 @@ public class MyBatis {
       IsAliveMapper.class,
       LoadedTemplateMapper.class, MeasureFilterMapper.class, Migration44Mapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
       ResourceKeyUpdaterMapper.class, ResourceIndexMapper.class, RoleMapper.class, RuleMapper.class,
-      SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, GroupMapper.class, UserGroupMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
+      SchemaMigrationMapper.class, UserMapper.class, GroupMapper.class, UserGroupMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
       FileSourceMapper.class, ActionPlanMapper.class,
       ActionPlanStatsMapper.class,
       NotificationQueueMapper.class, CharacteristicMapper.class,
diff --git a/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDao.java b/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDao.java
deleted file mode 100644 (file)
index 59c89c7..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.db.semaphore;
-
-import com.google.common.base.Strings;
-import javax.annotation.CheckForNull;
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.api.utils.Semaphores;
-import org.sonar.api.utils.System2;
-import org.sonar.db.Dao;
-import org.sonar.db.MyBatis;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static org.sonar.api.utils.DateUtils.longToDate;
-
-public class SemaphoreDao implements Dao {
-
-  private static final String SEMAPHORE_NAME_MUST_NOT_BE_EMPTY = "Semaphore name must not be empty";
-  private final MyBatis mybatis;
-  private final System2 system;
-
-  public SemaphoreDao(MyBatis mybatis, System2 system) {
-    this.mybatis = mybatis;
-    this.system = system;
-  }
-
-  public Semaphores.Semaphore acquire(String name, int maxAgeInSeconds) {
-    checkArgument(!Strings.isNullOrEmpty(name), SEMAPHORE_NAME_MUST_NOT_BE_EMPTY);
-    checkArgument(maxAgeInSeconds >= 0, "Semaphore max age must be positive: " + maxAgeInSeconds);
-
-    try (SqlSession session = mybatis.openSession(false)) {
-      SemaphoreDto semaphore = tryToInsert(name, system.now(), session);
-      boolean isAcquired;
-      if (semaphore == null) {
-        semaphore = selectSemaphore(name, session);
-        isAcquired = acquireIfOutdated(name, maxAgeInSeconds, session);
-      } else {
-        isAcquired = true;
-      }
-      return createLock(semaphore, isAcquired);
-    }
-  }
-
-  public Semaphores.Semaphore acquire(String name) {
-    checkArgument(!Strings.isNullOrEmpty(name), SEMAPHORE_NAME_MUST_NOT_BE_EMPTY);
-
-    try (SqlSession session = mybatis.openSession(false)) {
-      SemaphoreDto semaphore = tryToInsert(name, system.now(), session);
-      if (semaphore == null) {
-        semaphore = selectSemaphore(name, session);
-        return createLock(semaphore, false);
-      } else {
-        return createLock(semaphore, true);
-      }
-    }
-  }
-
-  public void update(Semaphores.Semaphore semaphore) {
-    checkArgument(semaphore != null, "Semaphore must not be null");
-
-    try (SqlSession session = mybatis.openSession(false)) {
-      mapper(session).update(semaphore.getName(), system.now());
-      session.commit();
-    }
-  }
-
-  public void release(String name) {
-    checkArgument(!Strings.isNullOrEmpty(name), SEMAPHORE_NAME_MUST_NOT_BE_EMPTY);
-    try (SqlSession session = mybatis.openSession(false)) {
-      mapper(session).release(name);
-      session.commit();
-    }
-  }
-
-  private boolean acquireIfOutdated(String name, int maxAgeInSeconds, SqlSession session) {
-    long now = system.now();
-    long updatedBefore = now - (long) maxAgeInSeconds * 1000;
-
-    boolean ok = mapper(session).acquire(name, updatedBefore, now) == 1;
-    session.commit();
-    return ok;
-  }
-
-  /**
-   * Insert the semaphore and commit. Rollback and return null if the semaphore already exists in db (whatever
-   * the lock date)
-   */
-  @CheckForNull
-  private SemaphoreDto tryToInsert(String name, long lockedNow, SqlSession session) {
-    try {
-      long now = system.now();
-      SemaphoreDto semaphore = new SemaphoreDto()
-        .setName(name)
-        .setCreatedAt(now)
-        .setUpdatedAt(now)
-        .setLockedAt(lockedNow);
-      mapper(session).initialize(semaphore);
-      session.commit();
-      return semaphore;
-    } catch (Exception e) {
-      // probably because the semaphore already exists in db
-      session.rollback();
-      return null;
-    }
-  }
-
-  private Semaphores.Semaphore createLock(SemaphoreDto dto, boolean acquired) {
-    Semaphores.Semaphore semaphore = new Semaphores.Semaphore()
-      .setName(dto.getName())
-      .setLocked(acquired)
-      .setLockedAt(longToDate(dto.getLockedAt()))
-      .setCreatedAt(longToDate(dto.getCreatedAt()))
-      .setUpdatedAt(longToDate(dto.getUpdatedAt()));
-    if (!acquired) {
-      semaphore.setDurationSinceLocked(lockedSince(dto));
-    }
-    return semaphore;
-  }
-
-  private long lockedSince(SemaphoreDto semaphore) {
-    return system.now() - semaphore.getLockedAt();
-  }
-
-  protected SemaphoreDto selectSemaphore(String name, SqlSession session) {
-    return mapper(session).selectSemaphore(name);
-  }
-
-  private SemaphoreMapper mapper(SqlSession session) {
-    return session.getMapper(SemaphoreMapper.class);
-  }
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDto.java b/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreDto.java
deleted file mode 100644 (file)
index a26e6a3..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.db.semaphore;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-
-/**
- * @since 3.4
- */
-public class SemaphoreDto {
-  private Long id;
-  private String name;
-  private String checksum;
-  private Long lockedAt;
-  private Long createdAt;
-  private Long updatedAt;
-
-  public String getName() {
-    return name;
-  }
-
-  public SemaphoreDto setName(String s) {
-    this.name = s;
-    this.checksum = DigestUtils.md5Hex(s);
-    return this;
-  }
-
-  public Long getLockedAt() {
-    return lockedAt;
-  }
-
-  public SemaphoreDto setLockedAt(Long d) {
-    this.lockedAt = d;
-    return this;
-  }
-
-  public Long getId() {
-    return id;
-  }
-
-  public SemaphoreDto setId(Long id) {
-    this.id = id;
-    return this;
-  }
-
-  public Long getCreatedAt() {
-    return createdAt;
-  }
-
-  public SemaphoreDto setCreatedAt(Long createdAt) {
-    this.createdAt = createdAt;
-    return this;
-  }
-
-  public Long getUpdatedAt() {
-    return updatedAt;
-  }
-
-  public SemaphoreDto setUpdatedAt(Long updatedAt) {
-    this.updatedAt = updatedAt;
-    return this;
-  }
-
-  @Override
-  public String toString() {
-    return ReflectionToStringBuilder.toString(this);
-  }
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreMapper.java b/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreMapper.java
deleted file mode 100644 (file)
index fc517e9..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.db.semaphore;
-
-import org.apache.ibatis.annotations.Param;
-
-public interface SemaphoreMapper {
-
-  int initialize(SemaphoreDto semaphore);
-
-  int acquire(@Param("name") String name, @Param("updatedBefore") Long updatedBefore, @Param("now") Long now);
-
-  void release(String name);
-
-  SemaphoreDto selectSemaphore(@Param("name") String name);
-
-  void update(@Param("name") String name, @Param("now") Long now);
-}
diff --git a/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreUpdater.java b/sonar-db/src/main/java/org/sonar/db/semaphore/SemaphoreUpdater.java
deleted file mode 100644 (file)
index 767539d..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.db.semaphore;
-
-import com.google.common.collect.Maps;
-import java.util.Map;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.Semaphores;
-
-/**
- * @since 3.5
- */
-@ServerSide
-public class SemaphoreUpdater {
-
-  private static final Logger LOG = LoggerFactory.getLogger(SemaphoreUpdater.class);
-
-  private SemaphoreDao dao;
-
-  private Map<String, ScheduledExecutorService> handlers = Maps.newHashMap();
-
-  public SemaphoreUpdater(SemaphoreDao dao) {
-    this.dao = dao;
-  }
-
-  public void scheduleForUpdate(final Semaphores.Semaphore semaphore, int updatePeriodInSeconds) {
-    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
-    Runnable updater = new Runnable() {
-      @Override
-      public void run() {
-        try {
-          LOG.debug("Updating semaphore " + semaphore.getName());
-          dao.update(semaphore);
-        } catch (Exception e) {
-          LOG.error("Unable to update semaphore", e);
-        }
-
-      }
-    };
-    scheduler.scheduleWithFixedDelay(updater, updatePeriodInSeconds, updatePeriodInSeconds, TimeUnit.SECONDS);
-    handlers.put(semaphore.getName(), scheduler);
-  }
-
-  public void stopUpdate(final String name) {
-    if (handlers.containsKey(name)) {
-      handlers.get(name).shutdown();
-      try {
-        if (!handlers.get(name).awaitTermination(1, TimeUnit.SECONDS)) {
-          LOG.error("Unable to cancel semaphore updater in 1 second");
-        }
-      } catch (InterruptedException e) {
-        LOG.error("Unable to cancel semaphore updater", e);
-      } finally {
-        handlers.remove(name);
-      }
-    }
-  }
-}
index 63958124965d2ad68ed16ad9d33b81f659a31fd3..c586836fc06bd4349f347ddf94c9014c85891476 100644 (file)
@@ -21,34 +21,24 @@ package org.sonar.db.semaphore;
 
 import org.sonar.api.utils.Semaphores;
 
-/**
- * @since 3.4
- */
 public class SemaphoresImpl implements Semaphores {
 
-  private SemaphoreDao dao;
-  private SemaphoreUpdater updater;
-
-  public SemaphoresImpl(SemaphoreDao dao, SemaphoreUpdater updater) {
-    this.dao = dao;
-    this.updater = updater;
-  }
-
   @Override
   public Semaphore acquire(String name, int maxAgeInSeconds, int updatePeriodInSeconds) {
-    Semaphore semaphore = dao.acquire(name, maxAgeInSeconds);
-    updater.scheduleForUpdate(semaphore, updatePeriodInSeconds);
-    return semaphore;
+    throw fail();
   }
 
   @Override
   public Semaphore acquire(String name) {
-    return dao.acquire(name);
+    throw fail();
   }
 
   @Override
   public void release(String name) {
-    updater.stopUpdate(name);
-    dao.release(name);
+    throw fail();
+  }
+
+  private static RuntimeException fail() {
+    throw new UnsupportedOperationException("Semaphores are not supported since 5.2 and the drop of database connection from analyzer");
   }
 }
index e8435f2b05b8b08cf36b6e730c18601e004f0ae6..7313d12d2f880a1c78816251d6a3b1fa9ec37f26 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.db.MyBatis;
 
 public class DatabaseVersion {
 
-  public static final int LAST_VERSION = 923;
+  public static final int LAST_VERSION = 924;
 
   /**
    * List of all the tables.
@@ -75,7 +75,6 @@ public class DatabaseVersion {
     "rules",
     "rules_parameters",
     "rules_profiles",
-    "semaphores",
     "schema_migrations",
     "snapshots",
     "users",
diff --git a/sonar-db/src/main/resources/org/sonar/db/semaphore/SemaphoreMapper.xml b/sonar-db/src/main/resources/org/sonar/db/semaphore/SemaphoreMapper.xml
deleted file mode 100644 (file)
index 5d1c102..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.db.semaphore.SemaphoreMapper">
-
-  <insert id="initialize" parameterType="map" useGeneratedKeys="false">
-    INSERT INTO semaphores (name, checksum, created_at, updated_at, locked_at)
-    VALUES (#{name}, #{checksum}, #{createdAt}, #{updatedAt}, #{lockedAt})
-  </insert>
-
-  <update id="acquire" parameterType="map">
-    update semaphores
-    set updated_at = #{now}, locked_at = #{now}
-    where name=#{name}
-    <if test="updatedBefore != null">
-      AND updated_at &lt; #{updatedBefore}
-    </if>
-  </update>
-
-  <delete id="release" parameterType="String">
-    delete from semaphores where name=#{id}
-  </delete>
-
-  <select id="selectSemaphore" parameterType="String" resultType="Semaphore">
-    select s.id, s.name as name, s.locked_at as lockedAt, s.created_at as createdAt, s.updated_at as updatedAt
-    from semaphores s where s.name=#{name}
-  </select>
-
-  <update id="update" parameterType="map">
-    update semaphores
-    set updated_at = #{now}
-    where name=#{name}
-  </update>
-
-</mapper>
-
index 706947ab524bb25de25712f736f76781a6c34f14..dd4afdca5659b001b76c6a21d3e493047c4d896a 100644 (file)
@@ -311,7 +311,6 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('781');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('782');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('783');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('784');
-INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('785');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('786');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('787');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('788');
@@ -343,6 +342,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('920');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('921');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('922');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('923');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('924');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index d0ad523678717b0a9c0b722209c6d5230b547e61..9aa98272ef505dd766f6e60220485133d2bd2edf 100644 (file)
@@ -391,15 +391,6 @@ CREATE TABLE "AUTHORS" (
   "UPDATED_AT" TIMESTAMP
 );
 
-CREATE TABLE "SEMAPHORES" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "NAME" VARCHAR(4000),
-  "CHECKSUM" VARCHAR(200),
-  "CREATED_AT" BIGINT,
-  "UPDATED_AT" BIGINT,
-  "LOCKED_AT" BIGINT
-);
-
 CREATE TABLE "MEASURE_FILTERS" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "NAME" VARCHAR(100) NOT NULL,
@@ -617,10 +608,6 @@ CREATE INDEX "RESOURCE_INDEX_RID" ON "RESOURCE_INDEX" ("RESOURCE_ID");
 
 CREATE INDEX "INDEX_ACTION_PLANS_ON_PROJET_ID" ON "ACTION_PLANS" ("PROJECT_ID");
 
-CREATE UNIQUE INDEX "UNIQ_SEMAPHORE_CHECKSUMS" ON "SEMAPHORES" ("CHECKSUM");
-
-CREATE INDEX "SEMAPHORE_NAMES" ON "SEMAPHORES" ("NAME");
-
 CREATE UNIQUE INDEX "UNIQ_AUTHOR_LOGINS" ON "AUTHORS" ("LOGIN");
 
 CREATE INDEX "MEASURE_FILTERS_NAME" ON "MEASURE_FILTERS" ("NAME");
diff --git a/sonar-db/src/test/java/org/sonar/db/semaphore/SemaphoreDaoTest.java b/sonar-db/src/test/java/org/sonar/db/semaphore/SemaphoreDaoTest.java
deleted file mode 100644 (file)
index 8652aac..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.db.semaphore;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.Semaphores;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class SemaphoreDaoTest {
-
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
-  System2 system = System2.INSTANCE;
-
-  @Rule
-  public DbTester dbTester = DbTester.create(system);
-
-  SemaphoreDao dao = dbTester.getDbClient().semaphoreDao();
-
-  @Before
-  public void setUp() throws Exception {
-    dbTester.truncateTables();
-  }
-
-  @Test
-  public void should_fail_to_acquire_if_null_semaphore_name() {
-    thrown.expect(IllegalArgumentException.class);
-    thrown.expectMessage("Semaphore name must not be empty");
-
-    dao.acquire(null, 5000);
-  }
-
-  @Test
-  public void should_fail_to_acquire_if_blank_semaphore_name() {
-    thrown.expect(IllegalArgumentException.class);
-    thrown.expectMessage("Semaphore name must not be empty");
-
-    dao.acquire("", 5000);
-  }
-
-  @Test
-  public void should_fail_to_acquire_if_negative_timeout() {
-    thrown.expect(IllegalArgumentException.class);
-    thrown.expectMessage("Semaphore max age must be positive: -5000");
-
-    dao.acquire("foo", -5000);
-  }
-
-  @Test
-  public void should_fail_to_release_if_blank_semaphore_name() {
-    thrown.expect(IllegalArgumentException.class);
-    thrown.expectMessage("Semaphore name must not be empty");
-
-    dao.release(null);
-  }
-
-  @Test
-  public void create_and_acquire_semaphore() {
-    Semaphores.Semaphore lock = dao.acquire("foo", 60);
-    assertThat(lock.isLocked()).isTrue();
-    assertThat(lock.getDurationSinceLocked()).isNull();
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore).isNotNull();
-    assertThat(semaphore.getName()).isEqualTo("foo");
-    assertThat(isRecent(semaphore.getCreatedAt())).isTrue();
-    assertThat(isRecent(semaphore.getUpdatedAt())).isTrue();
-    assertThat(isRecent(semaphore.getLockedAt())).isTrue();
-
-    dao.release("foo");
-    assertThat(selectSemaphore("foo")).isNull();
-  }
-
-  @Test
-  public void create_and_acquire_and_update_semaphore() throws Exception {
-    Semaphores.Semaphore lock = dao.acquire("foo", 60);
-    assertThat(lock.isLocked()).isTrue();
-    assertThat(lock.getDurationSinceLocked()).isNull();
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore.getCreatedAt()).isEqualTo(semaphore.getUpdatedAt());
-
-    Thread.sleep(1000);
-
-    dao.update(lock);
-
-    semaphore = selectSemaphore("foo");
-    assertThat(semaphore.getCreatedAt()).isLessThan(semaphore.getUpdatedAt());
-
-    dao.release("foo");
-    assertThat(selectSemaphore("foo")).isNull();
-  }
-
-  @Test
-  public void fail_to_update_null_semaphore() {
-    thrown.expect(IllegalArgumentException.class);
-    thrown.expectMessage("Semaphore must not be null");
-
-    dao.update(null);
-  }
-
-  @Test
-  public void create_and_acquire_semaphore_when_maxage_is_zeo() {
-    Semaphores.Semaphore lock = dao.acquire("foo", 0);
-    assertThat(lock.isLocked()).isTrue();
-    assertThat(lock.getDurationSinceLocked()).isNull();
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore).isNotNull();
-    assertThat(semaphore.getName()).isEqualTo("foo");
-    assertThat(isRecent(semaphore.getCreatedAt())).isTrue();
-    assertThat(isRecent(semaphore.getUpdatedAt())).isTrue();
-    assertThat(isRecent(semaphore.getLockedAt())).isTrue();
-
-    dao.release("foo");
-    assertThat(selectSemaphore("foo")).isNull();
-  }
-
-  @Test
-  public void create_and_acquire_semaphore_when_no_timeout() {
-    Semaphores.Semaphore lock = dao.acquire("foo");
-    assertThat(lock.isLocked()).isTrue();
-    assertThat(lock.getDurationSinceLocked()).isNull();
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore).isNotNull();
-    assertThat(semaphore.getName()).isEqualTo("foo");
-    assertThat(isRecent(semaphore.getCreatedAt())).isTrue();
-    assertThat(isRecent(semaphore.getUpdatedAt())).isTrue();
-    assertThat(isRecent(semaphore.getLockedAt())).isTrue();
-
-    dao.release("foo");
-    assertThat(selectSemaphore("foo")).isNull();
-  }
-
-  @Test
-  public void fail_to_acquire_locked_semaphore() {
-    dbTester.prepareDbUnit(getClass(), "old_semaphore.xml");
-    Semaphores.Semaphore lock = dao.acquire("foo", Integer.MAX_VALUE);
-    assertThat(lock.isLocked()).isFalse();
-    assertThat(lock.getDurationSinceLocked()).isNotNull();
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore).isNotNull();
-    assertThat(semaphore.getName()).isEqualTo("foo");
-    assertThat(isRecent(semaphore.getCreatedAt())).isFalse();
-    assertThat(isRecent(semaphore.getUpdatedAt())).isFalse();
-    assertThat(isRecent(semaphore.getLockedAt())).isFalse();
-  }
-
-  @Test
-  public void acquire_long_locked_semaphore() {
-    dbTester.prepareDbUnit(getClass(), "old_semaphore.xml");
-    Semaphores.Semaphore lock = dao.acquire("foo", 60);
-    assertThat(lock.isLocked()).isTrue();
-    assertThat(lock.getDurationSinceLocked()).isNull();
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore).isNotNull();
-    assertThat(semaphore.getName()).isEqualTo("foo");
-    assertThat(isRecent(semaphore.getCreatedAt())).isFalse();
-    assertThat(isRecent(semaphore.getUpdatedAt())).isTrue();
-    assertThat(isRecent(semaphore.getLockedAt())).isTrue();
-  }
-
-  @Test
-  public void acquire_locked_semaphore_when_timeout_is_zero() {
-    dbTester.prepareDbUnit(getClass(), "old_semaphore.xml");
-    Semaphores.Semaphore lock = dao.acquire("foo", 0);
-    assertThat(lock.isLocked()).isTrue();
-    assertThat(lock.getDurationSinceLocked()).isNull();
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore).isNotNull();
-    assertThat(semaphore.getName()).isEqualTo("foo");
-    assertThat(isRecent(semaphore.getCreatedAt())).isFalse();
-    assertThat(isRecent(semaphore.getUpdatedAt())).isTrue();
-    assertThat(isRecent(semaphore.getLockedAt())).isTrue();
-
-    dao.release("foo");
-    assertThat(selectSemaphore("foo")).isNull();
-  }
-
-  @Test
-  public void fail_to_acquire_locked_semaphore_when_no_timeout() {
-    dbTester.prepareDbUnit(getClass(), "old_semaphore.xml");
-    Semaphores.Semaphore lock = dao.acquire("foo");
-    assertThat(lock.isLocked()).isFalse();
-    assertThat(lock.getDurationSinceLocked()).isNotNull();
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore).isNotNull();
-    assertThat(semaphore.getName()).isEqualTo("foo");
-    assertThat(isRecent(semaphore.getCreatedAt())).isFalse();
-    assertThat(isRecent(semaphore.getUpdatedAt())).isFalse();
-    assertThat(isRecent(semaphore.getLockedAt())).isFalse();
-  }
-
-  @Test
-  public void should_select_semaphore_return_current_semaphore_when_acquiring() {
-    dao.acquire("foo");
-
-    SemaphoreDto semaphore = selectSemaphore("foo");
-    assertThat(semaphore).isNotNull();
-    assertThat(semaphore.getName()).isEqualTo("foo");
-    assertThat(semaphore.getCreatedAt()).isNotNull();
-    assertThat(semaphore.getUpdatedAt()).isNotNull();
-    assertThat(semaphore.getLockedAt()).isNotNull();
-  }
-
-  @Test
-  public void test_concurrent_locks() throws Exception {
-    for (int tests = 0; tests < 5; tests++) {
-      dao.release("my-lock");
-      int size = 5;
-      CyclicBarrier barrier = new CyclicBarrier(size);
-      CountDownLatch latch = new CountDownLatch(size);
-
-      AtomicInteger locks = new AtomicInteger(0);
-      for (int i = 0; i < size; i++) {
-        new Runner(dao, locks, barrier, latch).start();
-      }
-      latch.await();
-
-      // semaphore was locked only 1 time
-      assertThat(locks.get()).isEqualTo(1);
-    }
-  }
-
-  private SemaphoreDto selectSemaphore(String name) {
-    dbTester.getSession().commit();
-    return dao.selectSemaphore(name, dbTester.getSession());
-  }
-
-  private boolean isRecent(Long date) {
-    int oneMinuteInMs = 60 * 1000;
-    long future = system.now() + oneMinuteInMs;
-    long past = system.now() - oneMinuteInMs;
-    return date > past && date < future;
-  }
-
-  private static class Runner extends Thread {
-    SemaphoreDao dao;
-    AtomicInteger locks;
-    CountDownLatch latch;
-    CyclicBarrier barrier;
-
-    Runner(SemaphoreDao dao, AtomicInteger atomicSeq, CyclicBarrier barrier, CountDownLatch latch) {
-      this.dao = dao;
-      this.locks = atomicSeq;
-      this.latch = latch;
-      this.barrier = barrier;
-    }
-
-    @Override
-    public void run() {
-      try {
-        barrier.await();
-        for (int i = 0; i < 100; i++) {
-          if (dao.acquire("my-lock", 60 * 60 * 24).isLocked()) {
-            locks.incrementAndGet();
-          }
-        }
-        latch.countDown();
-
-      } catch (Exception e) {
-        e.printStackTrace();
-      }
-    }
-  }
-}
diff --git a/sonar-db/src/test/java/org/sonar/db/semaphore/SemaphoreUpdaterTest.java b/sonar-db/src/test/java/org/sonar/db/semaphore/SemaphoreUpdaterTest.java
deleted file mode 100644 (file)
index 7400e14..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.db.semaphore;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.Semaphores;
-
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-
-public class SemaphoreUpdaterTest {
-
-  private SemaphoreUpdater updater;
-  private SemaphoreDao dao;
-
-  @Before
-  public void before() {
-    dao = mock(SemaphoreDao.class);
-    updater = new SemaphoreUpdater(dao);
-  }
-
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
-  @Test
-  public void testScheduleUpdate() throws Exception {
-    Semaphores.Semaphore semaphore = new Semaphores.Semaphore().setName("foo");
-    updater.scheduleForUpdate(semaphore, 1);
-
-    Thread.sleep(2000);
-
-    verify(dao, atLeastOnce()).update(semaphore);
-  }
-
-  @Test
-  public void testCancelUpdate() throws Exception {
-    Semaphores.Semaphore semaphore = new Semaphores.Semaphore().setName("foo");
-    updater.scheduleForUpdate(semaphore, 1);
-    updater.stopUpdate("foo");
-
-    Thread.sleep(2000);
-
-    verify(dao, never()).update(semaphore);
-  }
-
-  @Test
-  public void shouldNotFailWhenCancelNotExistingSemaphore() {
-    updater.stopUpdate("foo");
-  }
-
-}
index a8d13641fdd3c848f03b8e8f9e06cc537f534aa9..c9435d547fbc9887a23a653a3a4facdfff92f68b 100644 (file)
 package org.sonar.db.semaphore;
 
 import org.junit.Test;
-import org.sonar.api.utils.Semaphores;
-
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
 public class SemaphoresImplTest {
 
-  @Test
-  public void should_be_a_bridge_over_dao() {
-    SemaphoreDao dao = mock(SemaphoreDao.class);
-    SemaphoreUpdater updater = mock(SemaphoreUpdater.class);
-    Semaphores.Semaphore semaphore = new Semaphores.Semaphore();
-    when(dao.acquire(anyString(), anyInt())).thenReturn(semaphore);
-
-    SemaphoresImpl impl = new SemaphoresImpl(dao, updater);
-
-    impl.acquire("do-xxx", 50000, 10);
-    verify(dao).acquire("do-xxx", 50000);
+  @Test(expected = UnsupportedOperationException.class)
+  public void acquire_is_unsupported() {
+    new SemaphoresImpl().acquire("foo");
+  }
 
-    impl.acquire("do-xxx");
-    verify(dao).acquire("do-xxx");
+  @Test(expected = UnsupportedOperationException.class)
+  public void acquire_with_timeout_is_unsupported() {
+    new SemaphoresImpl().acquire("foo", 1, 2);
+  }
 
-    impl.release("do-xxx");
-    verify(dao).release("do-xxx");
+  @Test(expected = UnsupportedOperationException.class)
+  public void release_is_unsupported() {
+    new SemaphoresImpl().release("foo");
   }
 }
diff --git a/sonar-db/src/test/resources/org/sonar/db/semaphore/SemaphoreDaoTest/old_semaphore.xml b/sonar-db/src/test/resources/org/sonar/db/semaphore/SemaphoreDaoTest/old_semaphore.xml
deleted file mode 100644 (file)
index ac6cf63..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<dataset>
-  <semaphores id="1" name="foo" checksum="acbd18db4cc2f85cedef654fccc4a4d8" created_at="1264374000000"
-              updated_at="1264374000000" locked_at="1264374000000"/>
-</dataset>
index a5281c42cab479a88e3bb23c11f3bcc950320927..566e756e6554d96cc255e4f77bd528d264606755 100644 (file)
@@ -27,8 +27,10 @@ import org.sonar.api.server.ServerSide;
  * A semaphore shared among all the processes that can connect to the central database.
  *
  * @since 3.4
+ * @deprecated in 5.2 as batch analyzer does not connect to database anymore
  */
 @ServerSide
+@Deprecated
 public interface Semaphores {
 
   /**