--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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 {
+
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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);
+
+}
--- /dev/null
+/*
+ * 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();
+
+}
--- /dev/null
+/*
+ * 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";
+}
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;
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() {
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();
}
return dtos;
}
+
+ @Override
+ public Collection<RuleKey> insertsSince(Long timestamp) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
*/
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;
import java.util.Date;
-public final class RuleDto {
+public final class RuleDto implements Dto<RuleKey>{
public static final Integer DISABLED_CHARACTERISTIC_ID = -1;
private Date createdAt;
private Date updatedAt;
+ @Override
+ public RuleKey getKey() {
+ return RuleKey.of(this.getRepositoryKey(), this.getRuleKey());
+ }
+
+ @Deprecated
public Integer getId() {
return id;
}
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();
--- /dev/null
+/*
+ * 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();
+
+ }
+
+}
*/
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;
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;
@Before
public void createDao() throws Exception {
- dao = new RuleDao(getMyBatis());
+ WorkQueue queue = mock(WorkQueue.class);
+ dao = new RuleDao(getMyBatis(), queue);
}
@Test
+++ /dev/null
-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;
- }
-
-}
+++ /dev/null
-/*
- * 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 {
-
- }
-}
+++ /dev/null
-/*
- * 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);
- }
- }
-}
+++ /dev/null
-/*
- * 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);
-
-}
+++ /dev/null
-/*
- * 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();
-
-}
+++ /dev/null
-package org.sonar.server.rule2;
-
-public interface RuleConstants {
-
- public static final String INDEX_NAME = "rules";
- public static final String ES_TYPE = "rule";
-}
+++ /dev/null
-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;
- }
-}
+++ /dev/null
-/*
- * 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();
- }
-}
+/*
+ * 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;
+/*
+ * 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;
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
+/*
+ * 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 {
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;
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;
*/
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;
+++ /dev/null
-/*
- * 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();
-
- }
-
-}
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;
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 {
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);
*/
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;
*/
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;
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;