]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5237 - moved DB part of stack to sonar-core
authorStephane Gamard <stephane.gamard@searchbox.com>
Mon, 28 Apr 2014 11:02:29 +0000 (13:02 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Mon, 28 Apr 2014 11:02:29 +0000 (13:02 +0200)
29 files changed:
sonar-core/src/main/java/org/sonar/core/cluster/LocalNonBlockingWorkQueue.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/db/BaseDao.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/db/Dao.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/db/Dto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/rule/RuleConstants.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
sonar-core/src/test/java/org/sonar/core/cluster/LocalNonBlockingWorkQueueTest.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java [deleted file]
sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java [deleted file]
sonar-server/src/main/java/org/sonar/server/db/BaseDao.java [deleted file]
sonar-server/src/main/java/org/sonar/server/db/Dao.java [deleted file]
sonar-server/src/main/java/org/sonar/server/db/Dto.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule2/RuleConstants.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule2/RuleDto.java [deleted file]
sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java
sonar-server/src/main/java/org/sonar/server/rule2/RuleIndex.java
sonar-server/src/main/java/org/sonar/server/rule2/RuleQuery.java
sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java
sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java
sonar-server/src/test/java/org/sonar/server/cluster/LocalNonBlockingWorkQueueTest.java [deleted file]
sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
sonar-server/src/test/java/org/sonar/server/rule2/RuleIndexTest.java
sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java

diff --git a/sonar-core/src/main/java/org/sonar/core/cluster/LocalNonBlockingWorkQueue.java b/sonar-core/src/main/java/org/sonar/core/cluster/LocalNonBlockingWorkQueue.java
new file mode 100644 (file)
index 0000000..25b10c3
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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.core.cluster;
+
+import org.sonar.core.cluster.WorkQueue;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+public class LocalNonBlockingWorkQueue implements WorkQueue{
+
+  private final static int WORKQUEUE_INITIAL_CAPACITY = 20;
+
+  private ConcurrentHashMap<String, Queue<Serializable>> index;
+  private ConcurrentHashMap<String, Queue<Serializable>> update;
+  private ConcurrentHashMap<String, Queue<Serializable>> delete;
+
+  public LocalNonBlockingWorkQueue(){
+    this.index = new ConcurrentHashMap<String, Queue<Serializable>>(WORKQUEUE_INITIAL_CAPACITY);
+    this.update = new ConcurrentHashMap<String, Queue<Serializable>>(WORKQUEUE_INITIAL_CAPACITY);
+    this.delete = new ConcurrentHashMap<String, Queue<Serializable>>(WORKQUEUE_INITIAL_CAPACITY);
+  }
+
+  private Integer enqueue(Map<String, Queue<Serializable>> map, String indexName, Serializable key){
+    if(!map.containsKey(indexName)){
+      map.put(indexName, new ConcurrentLinkedQueue<Serializable>());
+    }
+    map.get(indexName).offer(key);
+    return 0;
+  }
+
+  private Object dequeue(Map<String, Queue<Serializable>> map, String indexName){
+    return (map.containsKey(indexName))?
+      map.get(indexName).poll():
+        null;
+  }
+
+  @Override
+  public Integer enqueInsert(String indexName, Serializable key) {
+    return this.enqueue(index, indexName, key);
+  }
+
+  @Override
+  public Integer enqueUpdate(String indexName, Serializable key) {
+    return this.enqueue(update, indexName, key);
+  }
+
+  @Override
+  public Integer enqueDelete(String indexName, Serializable key) {
+    return this.enqueue(delete, indexName, key);
+  }
+
+  @Override
+  public Object dequeInsert(String indexName) {
+    return this.dequeue(index, indexName);
+  }
+
+  @Override
+  public Object dequeUpdate(String indexName) {
+    return this.dequeue(update, indexName);
+  }
+
+  @Override
+  public Object dequeDelete(String indexName) {
+    return this.dequeue(delete, indexName);
+  }
+
+  @Override
+  public Status getStatus(Integer workId) {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java b/sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java
new file mode 100644 (file)
index 0000000..e3790f6
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.core.cluster;
+
+import java.io.Serializable;
+
+public interface WorkQueue {
+
+  Integer enqueInsert(String indexName, Serializable key);
+
+  Integer enqueUpdate(String indexName, Serializable key);
+
+  Integer enqueDelete(String indexName, Serializable key);
+
+  Object dequeInsert(String indexName);
+
+  Object dequeUpdate(String indexName);
+
+  Object dequeDelete(String indexName);
+
+  Status getStatus(Integer workId);
+
+  interface Status {
+
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/db/BaseDao.java b/sonar-core/src/main/java/org/sonar/core/db/BaseDao.java
new file mode 100644 (file)
index 0000000..e10bbf6
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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.core.db;
+
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.core.cluster.WorkQueue;
+import org.sonar.core.persistence.MyBatis;
+
+import java.io.Serializable;
+
+public abstract class BaseDao<E extends Dto<K>, K extends Serializable, M extends Dao<E,K>>
+  implements Dao<E, K> {
+
+  protected MyBatis mybatis;
+  private WorkQueue queue;
+
+  protected BaseDao(WorkQueue workQueue, MyBatis myBatis) {
+    this.mybatis = myBatis;
+    this.queue = workQueue;
+  }
+
+  protected abstract String getIndexName();
+
+  protected abstract Class<M> getMapperClass();
+
+  private M getMapper(SqlSession session) {
+    return session.getMapper(getMapperClass());
+  }
+
+  protected void enqueInsert(K key) {
+    this.queue.enqueInsert(this.getIndexName(), key);
+  }
+
+  protected void enqueUpdate(K key) {
+    this.queue.enqueUpdate(this.getIndexName(), key);
+  }
+
+  protected void enqueDelete(K key) {
+    this.queue.enqueDelete(this.getIndexName(), key);
+  }
+
+  protected MyBatis getMyBatis(){
+    return this.mybatis;
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public E getByKey(K key) {
+    E item = null;
+    SqlSession session = getMyBatis().openSession();
+    item = getMapper(session).getByKey(key);
+    MyBatis.closeQuietly(session);
+    return item;
+  }
+
+  @Override
+  public void update(E item) {
+    SqlSession session = getMyBatis().openSession();
+    try {
+      getMapper(session).update(item);
+      session.commit();
+      this.enqueUpdate(item.getKey());
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  @Override
+  public void insert(E item) {
+    SqlSession session = getMyBatis().openSession();
+    try {
+      getMapper(session).insert(item);
+      session.commit();
+      this.enqueInsert(item.getKey());
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  @Override
+  public void delete(E item) {
+    this.deleteByKey(item.getKey());
+  }
+
+  @Override
+  public void deleteByKey(K key) {
+    SqlSession session = getMyBatis().openSession();
+    try {
+      getMapper(session).deleteByKey(key);
+      session.commit();
+    } finally {
+      MyBatis.closeQuietly(session);
+      this.enqueDelete(key);
+    }
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/db/Dao.java b/sonar-core/src/main/java/org/sonar/core/db/Dao.java
new file mode 100644 (file)
index 0000000..458d2b7
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.core.db;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+public interface Dao<E extends Dto<K>, K extends Serializable> {
+
+  public E getByKey(K key);
+
+  public void update(E item);
+
+  public void insert(E item);
+
+  public void delete(E item);
+
+  public void deleteByKey(K key);
+
+  public Collection<K> insertsSince(Long timestamp);
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/db/Dto.java b/sonar-core/src/main/java/org/sonar/core/db/Dto.java
new file mode 100644 (file)
index 0000000..2ac53d7
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.core.db;
+
+import java.io.Serializable;
+
+public interface Dto<K extends Serializable> {
+
+  K getKey();
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleConstants.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleConstants.java
new file mode 100644 (file)
index 0000000..636a6dc
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.core.rule;
+
+public interface RuleConstants {
+
+  public static final String INDEX_NAME = "rules";
+  public static final String ES_TYPE = "rule";
+}
index 3b5677fc9b90179452f1491a177be71f12e44f05..1c87168d8b57b29caa98b54c24ae2d8e3cd7da09 100644 (file)
@@ -24,6 +24,8 @@ import org.apache.ibatis.session.SqlSession;
 import org.sonar.api.BatchComponent;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.core.cluster.WorkQueue;
+import org.sonar.core.db.BaseDao;
 import org.sonar.core.persistence.MyBatis;
 
 import javax.annotation.CheckForNull;
@@ -33,12 +35,22 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 
-public class RuleDao implements BatchComponent, ServerComponent {
+public class RuleDao extends BaseDao<RuleDto, RuleKey, RuleMapper>
+  implements BatchComponent, ServerComponent {
 
-  private MyBatis mybatis;
 
-  public RuleDao(MyBatis mybatis) {
-    this.mybatis = mybatis;
+  public RuleDao(MyBatis mybatis, WorkQueue queue) {
+    super(queue, mybatis);
+  }
+
+  @Override
+  protected String getIndexName() {
+    return RuleConstants.INDEX_NAME;
+  }
+
+  @Override
+  protected Class<RuleMapper> getMapperClass() {
+    return RuleMapper.class;
   }
 
   public List<RuleDto> selectAll() {
@@ -131,29 +143,18 @@ public class RuleDao implements BatchComponent, ServerComponent {
     getMapper(session).update(rule);
   }
 
-  public void update(RuleDto rule) {
-    SqlSession session = mybatis.openSession();
-    try {
-      update(rule, session);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
+//  public RuleDto update(RuleDto rule) {
+//   return super.update(rule);
+//  }
+//
+//  public RuleDto insert(RuleDto ruleToInsert) {
+//    return super.insert(ruleToInsert);
+//  }
 
   public void insert(RuleDto ruleToInsert, SqlSession session) {
     getMapper(session).insert(ruleToInsert);
   }
 
-  public void insert(RuleDto ruleToInsert) {
-    SqlSession session = mybatis.openSession();
-    try {
-      insert(ruleToInsert, session);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
 
   public void insert(Collection<RuleDto> rules) {
     SqlSession session = mybatis.openBatchSession();
@@ -307,4 +308,10 @@ public class RuleDao implements BatchComponent, ServerComponent {
     }
     return dtos;
   }
+
+  @Override
+  public Collection<RuleKey> insertsSince(Long timestamp) {
+    // TODO Auto-generated method stub
+    return null;
+  }
 }
index 8bb8f4e38b51e76643340785d18a046228a8936c..78dd41c99a54d715c7d9a15c82198ed740e2dd8d 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonar.core.rule;
 
+import org.sonar.api.rule.RuleKey;
+
+import org.sonar.core.db.Dto;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
@@ -30,7 +33,7 @@ import javax.annotation.Nullable;
 
 import java.util.Date;
 
-public final class RuleDto {
+public final class RuleDto implements Dto<RuleKey>{
 
   public static final Integer DISABLED_CHARACTERISTIC_ID = -1;
 
@@ -61,6 +64,12 @@ public final class RuleDto {
   private Date createdAt;
   private Date updatedAt;
 
+  @Override
+  public RuleKey getKey() {
+    return RuleKey.of(this.getRepositoryKey(), this.getRuleKey());
+  }
+
+  @Deprecated
   public Integer getId() {
     return id;
   }
index e31b14e04aa8fee3634abe3b66e31a4844501feb..536071017ebccf6b3a69e44397f1cb49bf617943 100644 (file)
@@ -21,10 +21,12 @@ package org.sonar.core.rule;
 
 import org.apache.ibatis.annotations.Param;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.core.db.Dao;
 
 import java.util.List;
 
-public interface RuleMapper {
+public interface RuleMapper extends Dao<RuleDto, RuleKey>{
+
   List<RuleDto> selectAll();
 
   List<RuleDto> selectEnablesAndNonManual();
diff --git a/sonar-core/src/test/java/org/sonar/core/cluster/LocalNonBlockingWorkQueueTest.java b/sonar-core/src/test/java/org/sonar/core/cluster/LocalNonBlockingWorkQueueTest.java
new file mode 100644 (file)
index 0000000..c352f14
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * 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.core.cluster;
+
+import org.sonar.core.cluster.LocalNonBlockingWorkQueue;
+
+import org.junit.Test;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+
+public class LocalNonBlockingWorkQueueTest {
+
+  private static final String WORKING_INDEX = "working_index";
+  private static final String NON_WORKING_INDEX = "non_working_index";
+
+  @Test
+  public void test_insert_queue(){
+    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
+
+    assertThat(queue.dequeInsert(WORKING_INDEX)).isNull();
+    assertThat(queue.dequeInsert(NON_WORKING_INDEX)).isNull();
+
+    queue.enqueInsert(WORKING_INDEX, new Integer(0));
+    assertThat(queue.dequeInsert(NON_WORKING_INDEX)).isNull();
+
+    Object dequeued = queue.dequeInsert(WORKING_INDEX);
+    assertThat(queue.dequeInsert(NON_WORKING_INDEX)).isNull();
+    assertThat(queue.dequeInsert(WORKING_INDEX)).isNull();
+
+    assertThat(dequeued).isEqualTo(new Integer(0));
+  }
+
+  @Test
+  public void test_update_queue(){
+    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
+
+    assertThat(queue.dequeUpdate(WORKING_INDEX)).isNull();
+    assertThat(queue.dequeUpdate(NON_WORKING_INDEX)).isNull();
+
+    queue.enqueUpdate(WORKING_INDEX, new Integer(0));
+    assertThat(queue.dequeUpdate(NON_WORKING_INDEX)).isNull();
+
+    Object dequeued = queue.dequeUpdate(WORKING_INDEX);
+    assertThat(queue.dequeUpdate(NON_WORKING_INDEX)).isNull();
+    assertThat(queue.dequeUpdate(WORKING_INDEX)).isNull();
+
+    assertThat(dequeued).isEqualTo(new Integer(0));
+  }
+
+  @Test
+  public void test_delete_queue(){
+    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
+
+    assertThat(queue.dequeDelete(WORKING_INDEX)).isNull();
+    assertThat(queue.dequeDelete(NON_WORKING_INDEX)).isNull();
+
+    queue.enqueDelete(WORKING_INDEX, new Integer(0));
+    assertThat(queue.dequeDelete(NON_WORKING_INDEX)).isNull();
+
+    Object dequeued = queue.dequeDelete(WORKING_INDEX);
+    assertThat(queue.dequeDelete(NON_WORKING_INDEX)).isNull();
+    assertThat(queue.dequeDelete(WORKING_INDEX)).isNull();
+
+    assertThat(dequeued).isEqualTo(new Integer(0));
+  }
+
+  @Test
+  public void test_enque_seralizable_object(){
+
+    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
+
+    class NonSerializable implements Serializable{
+      private Object var1;
+      private Map<String, Object> objs;
+    }
+
+    NonSerializable nonSer = new NonSerializable();
+    assertThat(queue.enqueInsert(WORKING_INDEX, nonSer)).isNotNull();
+
+    Object dequeued = queue.dequeInsert(WORKING_INDEX);
+    assertThat(queue.dequeInsert(NON_WORKING_INDEX)).isNull();
+
+    assertThat(dequeued).isNotNull();
+    assertThat(dequeued.getClass()).isEqualTo(NonSerializable.class);
+  }
+
+  @Test
+  public void test_under_queue_capacity(){
+    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
+
+    for(int i = 0; i < 10; i++){
+      assertThat(queue.enqueDelete(WORKING_INDEX, i)).isNotNull();
+    }
+
+    for(int i = 0; i < 10; i++){
+      assertThat(queue.dequeDelete(WORKING_INDEX)).isNotNull();
+    }
+    assertThat(queue.dequeDelete(WORKING_INDEX)).isNull();
+
+  }
+
+  @Test
+  public void test_over_queue_capacity(){
+    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
+
+    for(int i = 0; i < 100; i++){
+      assertThat(queue.enqueDelete(WORKING_INDEX, i)).isNotNull();
+    }
+
+    for(int i = 0; i < 100; i++){
+      assertThat(queue.dequeDelete(WORKING_INDEX)).isNotNull();
+    }
+    assertThat(queue.dequeDelete(WORKING_INDEX)).isNull();
+
+  }
+
+}
index 6386962c054ab7ce98a067f8e6d3c0ceca4b45ad..8b6aaf45095197f94cf7f4e3e0071a4a574f662e 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.core.rule;
 
+import org.sonar.core.cluster.WorkQueue;
+
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -34,6 +36,8 @@ import org.sonar.core.persistence.AbstractDaoTestCase;
 
 import java.util.List;
 
+import static org.mockito.Mockito.mock;
+
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -43,7 +47,8 @@ public class RuleDaoTest extends AbstractDaoTestCase {
 
   @Before
   public void createDao() throws Exception {
-    dao = new RuleDao(getMyBatis());
+    WorkQueue queue = mock(WorkQueue.class);
+    dao = new RuleDao(getMyBatis(), queue);
   }
 
   @Test
diff --git a/sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java b/sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java
deleted file mode 100644 (file)
index c3c5360..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.sonar.server.cluster;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-public class LocalNonBlockingWorkQueue implements WorkQueue{
-
-  private final static int WORKQUEUE_INITIAL_CAPACITY = 20;
-
-  private ConcurrentHashMap<String, Queue<Serializable>> index;
-  private ConcurrentHashMap<String, Queue<Serializable>> update;
-  private ConcurrentHashMap<String, Queue<Serializable>> delete;
-
-  public LocalNonBlockingWorkQueue(){
-    this.index = new ConcurrentHashMap<String, Queue<Serializable>>(WORKQUEUE_INITIAL_CAPACITY);
-    this.update = new ConcurrentHashMap<String, Queue<Serializable>>(WORKQUEUE_INITIAL_CAPACITY);
-    this.delete = new ConcurrentHashMap<String, Queue<Serializable>>(WORKQUEUE_INITIAL_CAPACITY);
-  }
-
-  private Integer enqueue(Map<String, Queue<Serializable>> map, String indexName, Serializable key){
-    if(!map.containsKey(indexName)){
-      map.put(indexName, new ConcurrentLinkedQueue<Serializable>());
-    }
-    map.get(indexName).offer(key);
-    return 0;
-  }
-
-  private Object dequeue(Map<String, Queue<Serializable>> map, String indexName){
-    return (map.containsKey(indexName))?
-      map.get(indexName).poll():
-        null;
-  }
-
-  @Override
-  public Integer enqueInsert(String indexName, Serializable key) {
-    return this.enqueue(index, indexName, key);
-  }
-
-  @Override
-  public Integer enqueUpdate(String indexName, Serializable key) {
-    return this.enqueue(update, indexName, key);
-  }
-
-  @Override
-  public Integer enqueDelete(String indexName, Serializable key) {
-    return this.enqueue(delete, indexName, key);
-  }
-
-  @Override
-  public Object dequeInsert(String indexName) {
-    return this.dequeue(index, indexName);
-  }
-
-  @Override
-  public Object dequeUpdate(String indexName) {
-    return this.dequeue(update, indexName);
-  }
-
-  @Override
-  public Object dequeDelete(String indexName) {
-    return this.dequeue(delete, indexName);
-  }
-
-  @Override
-  public Status getStatus(Integer workId) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java b/sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java
deleted file mode 100644 (file)
index 79c3b52..0000000
+++ /dev/null
@@ -1,43 +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.cluster;
-
-import java.io.Serializable;
-
-public interface WorkQueue {
-
-  Integer enqueInsert(String indexName, Serializable key);
-
-  Integer enqueUpdate(String indexName, Serializable key);
-
-  Integer enqueDelete(String indexName, Serializable key);
-
-  Object dequeInsert(String indexName);
-
-  Object dequeUpdate(String indexName);
-
-  Object dequeDelete(String indexName);
-
-  Status getStatus(Integer workId);
-
-  interface Status {
-
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java
deleted file mode 100644 (file)
index 21a2270..0000000
+++ /dev/null
@@ -1,110 +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;
-
-import org.apache.ibatis.session.SqlSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.server.cluster.WorkQueue;
-
-import java.io.Serializable;
-
-public abstract class BaseDao<E extends Dto<K>, K extends Serializable> implements Dao<E, K> {
-
-  private MyBatis myBatis;
-  private WorkQueue workQueue;
-
-  protected BaseDao(WorkQueue workQueue, MyBatis myBatis) {
-    this.myBatis = myBatis;
-    this.workQueue = workQueue;
-  }
-
-  protected abstract String getIndexName();
-
-  protected void enqueInsert(K key) {
-    this.workQueue.enqueInsert(this.getIndexName(), key);
-  }
-
-  protected void enqueUpdate(K key) {
-    this.workQueue.enqueUpdate(this.getIndexName(), key);
-  }
-
-  protected void enqueDelete(K key) {
-    this.workQueue.enqueDelete(this.getIndexName(), key);
-  }
-
-  protected MyBatis getMyBatis(){
-    return this.myBatis;
-  }
-
-  @Override
-  @SuppressWarnings("unchecked")
-  public E getByKey(K key) {
-    E item = null;
-    SqlSession session = getMyBatis().openSession();
-    item = (E) session.getMapper(this.getClass()).getByKey(key);
-    MyBatis.closeQuietly(session);
-    return item;
-  }
-
-  @Override
-  public E update(E item) {
-    SqlSession session = getMyBatis().openSession();
-    E result = null;
-    try {
-      result = (E) session.getMapper(this.getClass()).update(item);
-      session.commit();
-    } finally {
-      this.enqueUpdate(item.getKey());
-      MyBatis.closeQuietly(session);
-      return result;
-    }
-  }
-
-  @Override
-  public E insert(E item) {
-    SqlSession session = getMyBatis().openSession();
-    E result = null;
-    try {
-      result = (E) session.getMapper(this.getClass()).insert(item);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-      this.enqueInsert(item.getKey());
-      return result;
-    }
-  }
-
-  @Override
-  public void delete(E item) {
-    this.deleteByKey(item.getKey());
-  }
-
-  @Override
-  public void deleteByKey(K key) {
-    SqlSession session = getMyBatis().openSession();
-    try {
-      session.getMapper(this.getClass()).deleteByKey(key);
-      session.commit();
-    } finally {
-      MyBatis.closeQuietly(session);
-      this.enqueDelete(key);
-    }
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/db/Dao.java b/sonar-server/src/main/java/org/sonar/server/db/Dao.java
deleted file mode 100644 (file)
index e3fad2e..0000000
+++ /dev/null
@@ -1,39 +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;
-
-import java.io.Serializable;
-import java.util.Collection;
-
-public interface Dao<E extends Dto<K>, K extends Serializable> {
-
-  public E getByKey(K key);
-
-  public E update(E item);
-
-  public E insert(E item);
-
-  public void delete(E item);
-
-  public void deleteByKey(K key);
-
-  public Collection<K> insertsSince(Long timestamp);
-
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/db/Dto.java b/sonar-server/src/main/java/org/sonar/server/db/Dto.java
deleted file mode 100644 (file)
index 483a276..0000000
+++ /dev/null
@@ -1,28 +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;
-
-import java.io.Serializable;
-
-public interface Dto<K extends Serializable> {
-
-  K getKey();
-
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleConstants.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleConstants.java
deleted file mode 100644 (file)
index 98abd6f..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.sonar.server.rule2;
-
-public interface RuleConstants {
-
-  public static final String INDEX_NAME = "rules";
-  public static final String ES_TYPE = "rule";
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java
deleted file mode 100644 (file)
index 3bc9875..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.sonar.server.rule2;
-
-import java.util.Collection;
-
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.server.cluster.WorkQueue;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.server.db.BaseDao;
-
-public class RuleDao extends BaseDao<RuleDto, RuleKey> {
-
-  protected RuleDao(WorkQueue workQueue, MyBatis myBatis) {
-    super(workQueue, myBatis);
-  }
-
-  @Override
-  protected String getIndexName() {
-    return RuleConstants.INDEX_NAME;
-  }
-
-  @Override
-  public Collection<RuleKey> insertsSince(Long timestamp) {
-    // TODO Auto-generated method stub
-    return null;
-  }
-}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleDto.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleDto.java
deleted file mode 100644 (file)
index 621de3a..0000000
+++ /dev/null
@@ -1,344 +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.rule2;
-
-import org.sonar.api.rule.RuleKey;
-
-import org.sonar.core.rule.SeverityUtil;
-import org.sonar.server.db.Dto;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.check.Cardinality;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Date;
-
-public final class RuleDto implements Dto<RuleKey> {
-
-  public static final Integer DISABLED_CHARACTERISTIC_ID = -1;
-
-  private String repositoryKey;
-  private String ruleKey;
-  private String description;
-  private String status;
-  private String name;
-  private String configKey;
-  private Integer severity;
-  private Cardinality cardinality;
-  private String language;
-  private Integer parentId;
-  private String noteData;
-  private String noteUserLogin;
-  private Date noteCreatedAt;
-  private Date noteUpdatedAt;
-  private Integer subCharacteristicId;
-  private Integer defaultSubCharacteristicId;
-  private String remediationFunction;
-  private String defaultRemediationFunction;
-  private String remediationCoefficient;
-  private String defaultRemediationCoefficient;
-  private String remediationOffset;
-  private String defaultRemediationOffset;
-  private String effortToFixDescription;
-  private Date createdAt;
-  private Date updatedAt;
-
-  @Override
-  public RuleKey getKey() {
-    return RuleKey.of(this.getRepositoryKey(), this.getRuleKey());
-  }
-
-  public String getRepositoryKey() {
-    return repositoryKey;
-  }
-
-  public RuleDto setRepositoryKey(String repositoryKey) {
-    this.repositoryKey = repositoryKey;
-    return this;
-  }
-
-  public String getRuleKey() {
-    return ruleKey;
-  }
-
-  public RuleDto setRuleKey(String ruleKey) {
-    this.ruleKey = ruleKey;
-    return this;
-  }
-
-  public String getDescription() {
-    return description;
-  }
-
-  public RuleDto setDescription(String description) {
-    this.description = description;
-    return this;
-  }
-
-  public String getStatus() {
-    return status;
-  }
-
-  public RuleDto setStatus(String status) {
-    this.status = status;
-    return this;
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public RuleDto setName(String name) {
-    this.name = name;
-    return this;
-  }
-
-  public String getConfigKey() {
-    return configKey;
-  }
-
-  public RuleDto setConfigKey(String configKey) {
-    this.configKey = configKey;
-    return this;
-  }
-
-  public Integer getSeverity() {
-    return severity;
-  }
-
-  public String getSeverityString() {
-    return SeverityUtil.getSeverityFromOrdinal(severity);
-  }
-
-  public RuleDto setSeverity(String severity) {
-    this.severity = SeverityUtil.getOrdinalFromSeverity(severity);
-    return this;
-  }
-
-  public RuleDto setSeverity(Integer severity) {
-    this.severity = severity;
-    return this;
-  }
-
-
-  public Cardinality getCardinality() {
-    return cardinality;
-  }
-
-  public RuleDto setCardinality(Cardinality cardinality) {
-    this.cardinality = cardinality;
-    return this;
-  }
-
-  public String getLanguage() {
-    return language;
-  }
-
-  public RuleDto setLanguage(String language) {
-    this.language = language;
-    return this;
-  }
-
-  @CheckForNull
-  public Integer getParentId() {
-    return parentId;
-  }
-
-  public RuleDto setParentId(@Nullable Integer parentId) {
-    this.parentId = parentId;
-    return this;
-  }
-
-  public String getNoteData() {
-    return noteData;
-  }
-
-  public RuleDto setNoteData(String noteData) {
-    this.noteData = noteData;
-    return this;
-  }
-
-  public String getNoteUserLogin() {
-    return noteUserLogin;
-  }
-
-  public RuleDto setNoteUserLogin(String noteUserLogin) {
-    this.noteUserLogin = noteUserLogin;
-    return this;
-  }
-
-  public Date getNoteCreatedAt() {
-    return noteCreatedAt;
-  }
-
-  public RuleDto setNoteCreatedAt(Date noteCreatedAt) {
-    this.noteCreatedAt = noteCreatedAt;
-    return this;
-  }
-
-  public Date getNoteUpdatedAt() {
-    return noteUpdatedAt;
-  }
-
-  public RuleDto setNoteUpdatedAt(Date noteUpdatedAt) {
-    this.noteUpdatedAt = noteUpdatedAt;
-    return this;
-  }
-
-  @CheckForNull
-  public Integer getSubCharacteristicId() {
-    return subCharacteristicId;
-  }
-
-  public RuleDto setSubCharacteristicId(@Nullable Integer subCharacteristicId) {
-    this.subCharacteristicId = subCharacteristicId;
-    return this;
-  }
-
-  @CheckForNull
-  public Integer getDefaultSubCharacteristicId() {
-    return defaultSubCharacteristicId;
-  }
-
-  public RuleDto setDefaultSubCharacteristicId(@Nullable Integer defaultSubCharacteristicId) {
-    this.defaultSubCharacteristicId = defaultSubCharacteristicId;
-    return this;
-  }
-
-  @CheckForNull
-  public String getRemediationFunction() {
-    return remediationFunction;
-  }
-
-  public RuleDto setRemediationFunction(@Nullable String remediationFunction) {
-    this.remediationFunction = remediationFunction;
-    return this;
-  }
-
-  @CheckForNull
-  public String getDefaultRemediationFunction() {
-    return defaultRemediationFunction;
-  }
-
-  public RuleDto setDefaultRemediationFunction(@Nullable String defaultRemediationFunction) {
-    this.defaultRemediationFunction = defaultRemediationFunction;
-    return this;
-  }
-
-  @CheckForNull
-  public String getRemediationCoefficient() {
-    return remediationCoefficient;
-  }
-
-  public RuleDto setRemediationCoefficient(@Nullable String remediationCoefficient) {
-    this.remediationCoefficient = remediationCoefficient;
-    return this;
-  }
-
-  @CheckForNull
-  public String getDefaultRemediationCoefficient() {
-    return defaultRemediationCoefficient;
-  }
-
-  public RuleDto setDefaultRemediationCoefficient(@Nullable String defaultRemediationCoefficient) {
-    this.defaultRemediationCoefficient = defaultRemediationCoefficient;
-    return this;
-  }
-
-  @CheckForNull
-  public String getRemediationOffset() {
-    return remediationOffset;
-  }
-
-  public RuleDto setRemediationOffset(@Nullable String remediationOffset) {
-    this.remediationOffset = remediationOffset;
-    return this;
-  }
-
-  @CheckForNull
-  public String getDefaultRemediationOffset() {
-    return defaultRemediationOffset;
-  }
-
-  public RuleDto setDefaultRemediationOffset(@Nullable String defaultRemediationOffset) {
-    this.defaultRemediationOffset = defaultRemediationOffset;
-    return this;
-  }
-
-  @CheckForNull
-  public String getEffortToFixDescription() {
-    return effortToFixDescription;
-  }
-
-  public RuleDto setEffortToFixDescription(@Nullable String effortToFixDescription) {
-    this.effortToFixDescription = effortToFixDescription;
-    return this;
-  }
-
-  public Date getCreatedAt() {
-    return createdAt;
-  }
-
-  public RuleDto setCreatedAt(Date createdAt) {
-    this.createdAt = createdAt;
-    return this;
-  }
-
-  public Date getUpdatedAt() {
-    return updatedAt;
-  }
-
-  public RuleDto setUpdatedAt(Date updatedAt) {
-    this.updatedAt = updatedAt;
-    return this;
-  }
-
-  @Override
-  public boolean equals(Object obj) {
-    if (!(obj instanceof RuleDto)) {
-      return false;
-    }
-    if (this == obj) {
-      return true;
-    }
-    RuleDto other = (RuleDto) obj;
-    return new EqualsBuilder()
-      .append(repositoryKey, other.getRepositoryKey())
-      .append(ruleKey, other.getRuleKey())
-      .isEquals();
-  }
-
-  @Override
-  public int hashCode() {
-    return new HashCodeBuilder(17, 37)
-      .append(repositoryKey)
-      .append(ruleKey)
-      .toHashCode();
-  }
-
-  @Override
-  public String toString() {
-    return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
-  }
-}
index 89ccff40a508c08e24a1c0aeac2c27f7bcf81b62..865ba63d1bd650c0a82677480f405462bf10a381 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * 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.rule2;
 
 import org.sonar.api.rule.Severity;
index d7bda890e89b5e186e0f8f7665564243f55cc817..e30f7e29ec18918008cdb067bc4ca3c157406614 100644 (file)
@@ -1,17 +1,37 @@
+/*
+ * 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.rule2;
 
 import org.elasticsearch.common.settings.ImmutableSettings;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.sonar.api.rule.RuleKey;
-import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.profiling.Profiling;
-import org.sonar.server.cluster.WorkQueue;
+import org.sonar.core.rule.RuleConstants;
+import org.sonar.core.rule.RuleDao;
+import org.sonar.core.db.Dao;
 import org.sonar.server.search.BaseIndex;
 
 import java.io.IOException;
@@ -25,8 +45,8 @@ public class RuleIndex extends BaseIndex<RuleKey> {
 
   private static final Logger LOG = LoggerFactory.getLogger(RuleIndex.class);
 
-  public RuleIndex(WorkQueue workQueue, RuleDao dao, Profiling profiling) {
-    super(workQueue, dao, profiling);
+  public RuleIndex(WorkQueue queue, RuleDao dao, Profiling profiling) {
+    super(queue, dao, profiling);
   }
 
   @Override
index 2a7cc349988dd408641aa6f4dadef0f55e08b43f..d526c2839ddb6a4565bf6e27c1ec280f00d36902 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * 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.rule2;
 
 public class RuleQuery {
index a9087216fd83c688d06281b190295d574f78c636..dfd0835e3cf34d4f0c3bc4d00cd8ebeb83680f48 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.server.rule2;
 
 import org.sonar.api.rule.RuleKey;
+import org.sonar.core.rule.RuleDao;
+import org.sonar.core.rule.RuleDto;
 import org.sonar.server.search.Hit;
 
 import javax.annotation.CheckForNull;
index 9eaf598196ec81d427e6382065914333246c3d1b..1d6529238e039318e43a1a7003a006e93687080f 100644 (file)
@@ -33,12 +33,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.core.persistence.MyBatis;
+import org.sonar.core.cluster.WorkQueue;
+import org.sonar.core.db.Dao;
 import org.sonar.core.profiling.Profiling;
 import org.sonar.core.profiling.Profiling.Level;
 import org.sonar.core.profiling.StopWatch;
-import org.sonar.server.cluster.WorkQueue;
-import org.sonar.server.db.Dao;
 
 import java.io.Serializable;
 import java.util.Collection;
index 0547675b535c37205797c72542dcdec7f2d135ab..de2d4bc0d9f0311e207fe4d8c86318edb0324bb8 100644 (file)
  */
 package org.sonar.server.search;
 
+import org.sonar.core.cluster.WorkQueue;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.server.cluster.WorkQueue;
 
 import java.io.Serializable;
 
diff --git a/sonar-server/src/test/java/org/sonar/server/cluster/LocalNonBlockingWorkQueueTest.java b/sonar-server/src/test/java/org/sonar/server/cluster/LocalNonBlockingWorkQueueTest.java
deleted file mode 100644 (file)
index 117db38..0000000
+++ /dev/null
@@ -1,136 +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.cluster;
-
-import org.junit.Test;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-
-public class LocalNonBlockingWorkQueueTest {
-
-  private static final String WORKING_INDEX = "working_index";
-  private static final String NON_WORKING_INDEX = "non_working_index";
-
-  @Test
-  public void test_insert_queue(){
-    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
-
-    assertThat(queue.dequeInsert(WORKING_INDEX)).isNull();
-    assertThat(queue.dequeInsert(NON_WORKING_INDEX)).isNull();
-
-    queue.enqueInsert(WORKING_INDEX, new Integer(0));
-    assertThat(queue.dequeInsert(NON_WORKING_INDEX)).isNull();
-
-    Object dequeued = queue.dequeInsert(WORKING_INDEX);
-    assertThat(queue.dequeInsert(NON_WORKING_INDEX)).isNull();
-    assertThat(queue.dequeInsert(WORKING_INDEX)).isNull();
-
-    assertThat(dequeued).isEqualTo(new Integer(0));
-  }
-
-  @Test
-  public void test_update_queue(){
-    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
-
-    assertThat(queue.dequeUpdate(WORKING_INDEX)).isNull();
-    assertThat(queue.dequeUpdate(NON_WORKING_INDEX)).isNull();
-
-    queue.enqueUpdate(WORKING_INDEX, new Integer(0));
-    assertThat(queue.dequeUpdate(NON_WORKING_INDEX)).isNull();
-
-    Object dequeued = queue.dequeUpdate(WORKING_INDEX);
-    assertThat(queue.dequeUpdate(NON_WORKING_INDEX)).isNull();
-    assertThat(queue.dequeUpdate(WORKING_INDEX)).isNull();
-
-    assertThat(dequeued).isEqualTo(new Integer(0));
-  }
-
-  @Test
-  public void test_delete_queue(){
-    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
-
-    assertThat(queue.dequeDelete(WORKING_INDEX)).isNull();
-    assertThat(queue.dequeDelete(NON_WORKING_INDEX)).isNull();
-
-    queue.enqueDelete(WORKING_INDEX, new Integer(0));
-    assertThat(queue.dequeDelete(NON_WORKING_INDEX)).isNull();
-
-    Object dequeued = queue.dequeDelete(WORKING_INDEX);
-    assertThat(queue.dequeDelete(NON_WORKING_INDEX)).isNull();
-    assertThat(queue.dequeDelete(WORKING_INDEX)).isNull();
-
-    assertThat(dequeued).isEqualTo(new Integer(0));
-  }
-
-  @Test
-  public void test_enque_seralizable_object(){
-
-    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
-
-    class NonSerializable implements Serializable{
-      private Object var1;
-      private Map<String, Object> objs;
-    }
-
-    NonSerializable nonSer = new NonSerializable();
-    assertThat(queue.enqueInsert(WORKING_INDEX, nonSer)).isNotNull();
-
-    Object dequeued = queue.dequeInsert(WORKING_INDEX);
-    assertThat(queue.dequeInsert(NON_WORKING_INDEX)).isNull();
-
-    assertThat(dequeued).isNotNull();
-    assertThat(dequeued.getClass()).isEqualTo(NonSerializable.class);
-  }
-
-  @Test
-  public void test_under_queue_capacity(){
-    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
-
-    for(int i = 0; i < 10; i++){
-      assertThat(queue.enqueDelete(WORKING_INDEX, i)).isNotNull();
-    }
-
-    for(int i = 0; i < 10; i++){
-      assertThat(queue.dequeDelete(WORKING_INDEX)).isNotNull();
-    }
-    assertThat(queue.dequeDelete(WORKING_INDEX)).isNull();
-
-  }
-
-  @Test
-  public void test_over_queue_capacity(){
-    LocalNonBlockingWorkQueue queue = new LocalNonBlockingWorkQueue();
-
-    for(int i = 0; i < 100; i++){
-      assertThat(queue.enqueDelete(WORKING_INDEX, i)).isNotNull();
-    }
-
-    for(int i = 0; i < 100; i++){
-      assertThat(queue.dequeDelete(WORKING_INDEX)).isNotNull();
-    }
-    assertThat(queue.dequeDelete(WORKING_INDEX)).isNull();
-
-  }
-
-}
index 01c35e4d405c4599bde84394ba1887c9125c4cf8..6707ea1385211ffc503bc46810db0e1dfe1e712b 100644 (file)
@@ -34,6 +34,8 @@ import org.sonar.api.server.rule.RulesDefinition;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.System2;
+import org.sonar.core.cluster.LocalNonBlockingWorkQueue;
+import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.qualityprofile.db.ActiveRuleDao;
@@ -50,7 +52,11 @@ import java.util.Date;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.fest.assertions.Fail.fail;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
 public class RegisterRulesTest extends AbstractDaoTestCase {
@@ -85,14 +91,16 @@ public class RegisterRulesTest extends AbstractDaoTestCase {
   ActiveRuleDao activeRuleDao;
   CharacteristicDao characteristicDao;
   System2 system;
+  WorkQueue queue;
   Date date = DateUtils.parseDateTime("2014-03-17T19:10:03+0100");
 
   @Before
   public void before() {
     system = mock(System2.class);
+    queue = mock(WorkQueue.class);
     when(system.now()).thenReturn(date.getTime());
     myBatis = getMyBatis();
-    ruleDao = new RuleDao(myBatis);
+    ruleDao = new RuleDao(myBatis, queue);
     ruleTagDao = new RuleTagDao(myBatis);
     activeRuleDao = new ActiveRuleDao(myBatis);
     ruleTagOperations = new RuleTagOperations(ruleTagDao, esRuleTags);
index a1e21f995b8652ff0defa9a44f854372d13bd799..f356961ddef7de3e2fe2679c9da37febedf36f88 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.rule2;
 
-import org.sonar.server.cluster.LocalNonBlockingWorkQueue;
+import org.sonar.core.cluster.LocalNonBlockingWorkQueue;
 
 import com.github.tlrx.elasticsearch.test.annotations.ElasticsearchNode;
 import com.github.tlrx.elasticsearch.test.support.junit.runners.ElasticsearchRunner;
index 0f75176d5e15cc7fc6cf5013047a37f3630d7863..46232717b59950f8f079c353f59bc0869b5981b3 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.server.search;
 
-import org.sonar.server.cluster.LocalNonBlockingWorkQueue;
-
 import com.github.tlrx.elasticsearch.test.annotations.ElasticsearchNode;
 import com.github.tlrx.elasticsearch.test.support.junit.runners.ElasticsearchRunner;
 import org.elasticsearch.client.transport.NoNodeAvailableException;
@@ -32,6 +30,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.sonar.api.config.Settings;
+import org.sonar.core.cluster.LocalNonBlockingWorkQueue;
 import org.sonar.core.profiling.Profiling;
 
 import java.io.Serializable;