jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1351266 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/stats/ test/java/org/apache/jackrabbit/core/stats/
Date Mon, 18 Jun 2012 10:13:56 GMT
Author: alexparvulescu
Date: Mon Jun 18 10:13:56 2012
New Revision: 1351266

URL: http://svn.apache.org/viewvc?rev=1351266&view=rev
Log:
JCR-3346 JMX Popular Queries size issue

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatCoreTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java?rev=1351266&r1=1351265&r2=1351266&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatDtoImpl.java
Mon Jun 18 10:13:56 2012
@@ -97,8 +97,8 @@ public class QueryStatDtoImpl implements
     @Override
     public String toString() {
         return "QueryStat [creationTime=" + creationTime + ", duration="
-                + durationMs + ", language=" + language + ", statement="
-                + statement + "]";
+                + durationMs + ", position " + position + ", language="
+                + language + ", statement=" + statement + "]";
     }
 
     public int getOccurrenceCount() {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java?rev=1351266&r1=1351265&r2=1351266&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/stats/QueryStatImpl.java
Mon Jun 18 10:13:56 2012
@@ -73,9 +73,12 @@ public class QueryStatImpl implements Qu
         public synchronized void setMaxSize(int maxSize) {
             if (maxSize < this.maxSize) {
                 // shrink the queue
-                int delta = this.maxSize - maxSize;
+                int delta = super.size() - maxSize;
                 for (int i = 0; i < delta; i++) {
-                    poll();
+                    E t = poll();
+                    if (t == null) {
+                        break;
+                    }
                 }
             }
             this.maxSize = maxSize;
@@ -165,7 +168,7 @@ public class QueryStatImpl implements Qu
     }
 
     public int getPopularQueriesQueueSize() {
-        return popularQueries.getMaxSize();
+        return popularQueries.getMaxSize() / POPULAR_QUEUE_MULTIPLIER;
     }
 
     public void setPopularQueriesQueueSize(int size) {

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatCoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatCoreTest.java?rev=1351266&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatCoreTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatCoreTest.java
Mon Jun 18 10:13:56 2012
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.stats;
+
+import static javax.jcr.query.Query.JCR_SQL2;
+
+import javax.jcr.query.QueryManager;
+
+import org.apache.jackrabbit.core.JackrabbitRepositoryStub;
+import org.apache.jackrabbit.core.RepositoryContext;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * Query stats test cases.
+ */
+public class QueryStatCoreTest extends AbstractJCRTest {
+
+    private QueryStatCore queryStat;
+    private QueryManager qm;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        RepositoryContext context = JackrabbitRepositoryStub
+                .getRepositoryContext(superuser.getRepository());
+        queryStat = context.getStatManager().getQueryStat();
+        queryStat.setEnabled(true);
+
+        qm = superuser.getWorkspace().getQueryManager();
+    }
+
+    protected void tearDown() throws Exception {
+        qm = null;
+        super.tearDown();
+    }
+
+    private void runRandomQuery() throws Exception {
+        String sql = "SELECT * FROM [nt:unstructured] as t where CONTAINS(t, '"
+                + System.currentTimeMillis() + "') ";
+        qm.createQuery(sql, JCR_SQL2).execute();
+    }
+
+    public void testPopularQuery() throws Exception {
+
+        int size = 15;
+        queryStat.setPopularQueriesQueueSize(size);
+
+        // test clear
+        runRandomQuery();
+        queryStat.clearPopularQueriesQueue();
+        assertEquals(0, queryStat.getPopularQueries().length);
+
+        // test run one
+        queryStat.clearPopularQueriesQueue();
+        runRandomQuery();
+        assertEquals(1, queryStat.getPopularQueries().length);
+
+        // run more than max size
+        queryStat.clearPopularQueriesQueue();
+        for (int i = 0; i < size + 5; i++) {
+            runRandomQuery();
+        }
+        assertEquals(size, queryStat.getPopularQueries().length);
+
+        // test shrink
+        int newSize = 5;
+        queryStat.setPopularQueriesQueueSize(newSize);
+        assertEquals(newSize, queryStat.getPopularQueries().length);
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/QueryStatCoreTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java?rev=1351266&r1=1351265&r2=1351266&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/stats/TestAll.java
Mon Jun 18 10:13:56 2012
@@ -37,6 +37,7 @@ public class TestAll extends TestCase {
 
         suite.addTestSuite(RepositoryStatisticsImplTest.class);
         suite.addTestSuite(TimeSeriesRecorderTest.class);
+        suite.addTestSuite(QueryStatCoreTest.class);
 
         return suite;
     }



Mime
View raw message