You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2020/09/29 02:35:30 UTC
[netbeans] branch master updated: Quicksearch API allows to check
for cancel. (#2298)
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new e812655 Quicksearch API allows to check for cancel. (#2298)
e812655 is described below
commit e812655fa7ac17cc155c172754661922a51ebf26
Author: Svatopluk Dedic <sv...@oracle.com>
AuthorDate: Tue Sep 29 04:35:08 2020 +0200
Quicksearch API allows to check for cancel. (#2298)
* Quicksearch API allows to check for cancel.
* Added test for obsolete, fixed other tests.
---
platform/spi.quicksearch/apichanges.xml | 87 ++++++++++++++++++++++
.../spi.quicksearch/nbproject/project.properties | 1 +
platform/spi.quicksearch/nbproject/project.xml | 1 +
.../modules/quicksearch/CategoryResult.java | 4 +-
.../netbeans/spi/quicksearch/SearchProvider.java | 5 ++
.../netbeans/spi/quicksearch/SearchResponse.java | 14 ++++
.../modules/quicksearch/ObsoleteSupportTest.java | 2 +-
.../modules/quicksearch/ProviderModelTest.java | 2 +-
.../modules/quicksearch/SlowProviderTest.java | 41 +++++++++-
.../modules/quicksearch/UnitTestUtils.java | 4 +-
10 files changed, 152 insertions(+), 9 deletions(-)
diff --git a/platform/spi.quicksearch/apichanges.xml b/platform/spi.quicksearch/apichanges.xml
new file mode 100644
index 0000000..083e845
--- /dev/null
+++ b/platform/spi.quicksearch/apichanges.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<?xml-stylesheet type="text/xml" href="CHANGEME/nbbuild/javadoctools/apichanges.xsl"?>
+<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.0//EN" "../../nbbuild/javadoctools/apichanges.dtd">
+
+
+<apichanges>
+ <apidefs>
+ <apidef name="quicksearch_spi">Quicksearch SPI</apidef>
+ </apidefs>
+
+ <changes>
+ <change id="isObsolete">
+ <api name="quicksearch_spi"/>
+ <summary>
+ Allows to check for obsoleted resultset.
+ </summary>
+ <version major="1" minor="37"/>
+ <date day="7" month="8" year="2020"/>
+ <author login="sdedic"/>
+ <compatibility binary="compatible" source="compatible" addition="yes"/>
+ <description>
+ A <a href="@TOP@/org/netbeans/spi/quicksearch/SearchProvider.html">SearchProvider</a> that
+ is searching and cannot find a result can check whether the result is still valid, using
+ <a href="@TOP@/org/netbeans/spi/quicksearch/SearchResponse.html#isObsolete--"><code>SearchResponse.isObsolete()</code></a>.
+ It was only possible to check for terminated search when a new item was added.
+ </description>
+ <class package="org.netbeans.spi.quicksearch" name="SearchResponse"/>
+ </change>
+
+ </changes>
+
+ <!-- Now the surrounding HTML text and document structure: -->
+
+ <htmlcontents>
+<!--
+
+ NO NO NO NO NO!
+
+ ==============> DO NOT EDIT ME! <==============
+
+ AUTOMATICALLY GENERATED FROM APICHANGES.XML, DO NOT EDIT
+
+ SEE CHANGEME/apichanges.xml
+
+-->
+ <head>
+ <title>Change History for the Progress API</title>
+ <link rel="stylesheet" href="prose.css" type="text/css"/>
+ </head>
+ <body>
+
+<p class="overviewlink"><a href="overview-summary.html">Overview</a></p>
+
+<h1>Introduction</h1>
+
+<p>This document lists changes made to the Progress API/SPI.</p>
+
+<!-- The actual lists of changes, as summaries and details: -->
+
+ <hr/><standard-changelists module-code-name="org.netbeans.spi.quicksearch"/>
+
+ <hr/><p>@FOOTER@</p>
+
+ </body>
+ </htmlcontents>
+
+</apichanges>
diff --git a/platform/spi.quicksearch/nbproject/project.properties b/platform/spi.quicksearch/nbproject/project.properties
index 02b43d0..e86c855 100644
--- a/platform/spi.quicksearch/nbproject/project.properties
+++ b/platform/spi.quicksearch/nbproject/project.properties
@@ -18,5 +18,6 @@ is.autoload=true
javac.source=1.6
javac.compilerargs=-Xlint -Xlint:-serial
javadoc.arch=${basedir}/arch.xml
+javadoc.apichanges=${basedir}/apichanges.xml
test.config.stableBTD.includes=**/*Test.class
diff --git a/platform/spi.quicksearch/nbproject/project.xml b/platform/spi.quicksearch/nbproject/project.xml
index 2bfbc72..7ef05d5 100644
--- a/platform/spi.quicksearch/nbproject/project.xml
+++ b/platform/spi.quicksearch/nbproject/project.xml
@@ -117,6 +117,7 @@
</test-dependency>
<test-dependency>
<code-name-base>org.netbeans.core.startup</code-name-base>
+ <recursive/>
</test-dependency>
<test-dependency>
<code-name-base>org.netbeans.libs.junit4</code-name-base>
diff --git a/platform/spi.quicksearch/src/org/netbeans/modules/quicksearch/CategoryResult.java b/platform/spi.quicksearch/src/org/netbeans/modules/quicksearch/CategoryResult.java
index d5ff7ad..64deac3 100644
--- a/platform/spi.quicksearch/src/org/netbeans/modules/quicksearch/CategoryResult.java
+++ b/platform/spi.quicksearch/src/org/netbeans/modules/quicksearch/CategoryResult.java
@@ -121,7 +121,9 @@ public final class CategoryResult implements Runnable {
}
public boolean isObsolete() {
- return obsolete;
+ synchronized (LOCK) {
+ return obsolete;
+ }
}
/** Sends notification about category change, always runs in EQ thread */
diff --git a/platform/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchProvider.java b/platform/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchProvider.java
index 1a955ce..3cd1d0a 100644
--- a/platform/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchProvider.java
+++ b/platform/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchProvider.java
@@ -65,6 +65,11 @@ public interface SearchProvider {
* }
* </pre>
*
+ * It may happen that the Provider searches for some considerable time, or searches
+ * a considerable number of items without any results. It may check use
+ * {@link SearchResponse#isObsolete()} to determine if the search was cancelled
+ * or obsoleted without adding any items.
+ * <p>
* Threading: This method can be called outside EQ thread by infrastructure.
*
* @param request Search request object that contains information what to
diff --git a/platform/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchResponse.java b/platform/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchResponse.java
index e44c6b5..cb78959 100644
--- a/platform/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchResponse.java
+++ b/platform/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchResponse.java
@@ -99,5 +99,19 @@ public final class SearchResponse {
new ResultsModel.ItemResult(catResult, sRequest, action,
htmlDisplayName, shortcut, displayHint));
}
+
+ /**
+ * Determines if the response is already obsolete. The result is the same as the
+ * return value from {@link #addResult(java.lang.Runnable, java.lang.String)}: if
+ * false, the Provider should terminate the search immediately. Provider can query
+ * this status in case it does not find any results so it does not waste time
+ * searching further.
+ *
+ * @return true, if the result is obsolete.
+ * @since 12.2
+ */
+ public boolean isObsolete() {
+ return catResult.isObsolete();
+ }
}
diff --git a/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ObsoleteSupportTest.java b/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ObsoleteSupportTest.java
index 32f271a..8e70f80 100644
--- a/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ObsoleteSupportTest.java
+++ b/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ObsoleteSupportTest.java
@@ -35,7 +35,7 @@ public class ObsoleteSupportTest extends NbTestCase {
public void testObsoleteSupport () throws Exception {
System.out.println("Testing obsolete support...");
- UnitTestUtils.prepareTest(new String [] { "/org/netbeans/modules/quicksearch/resources/testGetProviders.xml" });
+ UnitTestUtils.prepareTest(new String [] { "org/netbeans/modules/quicksearch/resources/testGetProviders.xml" });
ResultsModel rm = ResultsModel.getInstance();
CommandEvaluator.evaluate("test obsolete 1", rm);
diff --git a/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ProviderModelTest.java b/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ProviderModelTest.java
index 5f41707..86c8728 100644
--- a/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ProviderModelTest.java
+++ b/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ProviderModelTest.java
@@ -41,7 +41,7 @@ public class ProviderModelTest extends NbTestCase {
/** Tests ProviderModel functionality */
public void testGetProviders () throws Exception {
- UnitTestUtils.prepareTest(new String [] { "/org/netbeans/modules/quicksearch/resources/testGetProviders.xml" });
+ UnitTestUtils.prepareTest(new String [] { "org/netbeans/modules/quicksearch/resources/testGetProviders.xml" });
ProviderModel model = ProviderModel.getInstance();
diff --git a/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/SlowProviderTest.java b/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/SlowProviderTest.java
index a171115..c80dfe7 100644
--- a/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/SlowProviderTest.java
+++ b/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/SlowProviderTest.java
@@ -19,6 +19,7 @@
package org.netbeans.modules.quicksearch;
+import java.util.concurrent.Semaphore;
import org.netbeans.junit.NbTestCase;
import org.netbeans.junit.RandomlyFails;
import org.netbeans.spi.quicksearch.SearchProvider;
@@ -41,7 +42,7 @@ public class SlowProviderTest extends NbTestCase {
@RandomlyFails
public void testResponsiveness () throws Exception {
- UnitTestUtils.prepareTest(new String [] { "/org/netbeans/modules/quicksearch/resources/testSlowProvider.xml" });
+ UnitTestUtils.prepareTest(new String [] { "org/netbeans/modules/quicksearch/resources/testSlowProvider.xml" });
System.out.println("Testing resposiveness against slow providers...");
@@ -61,7 +62,7 @@ public class SlowProviderTest extends NbTestCase {
// should be still running
assertFalse(t.isFinished());
-
+
// wait for all providers
t.waitFinished();
@@ -73,13 +74,47 @@ public class SlowProviderTest extends NbTestCase {
}
+
+ /**
+ * Checks that the slow search is given a flag to terminate even though
+ * it does not find anything
+ */
+ public void testSlowSearchObsoleted() throws Exception {
+ UnitTestUtils.prepareTest(new String [] { "org/netbeans/modules/quicksearch/resources/testSlowProvider.xml" });
+
+ ResultsModel mod = ResultsModel.getInstance();
+ org.openide.util.Task t =
+ CommandEvaluator.evaluate("sample text", mod);
+
+ RequestProcessor.getDefault().post(t);
+
+ // should be still running
+ assertFalse(t.isFinished());
+
+ assertFalse("Resultset must be valid initially", obsoleteAtStart);
+
+ sync.acquire();
+ // cancel as if ESC was pressed in popup
+ mod.setContent(null);
+
+ // wait for all providers
+ assertTrue("Must complete in approx 5secs", t.waitFinished(WAIT_TIME * 2));
+
+ assertTrue("The provider must saw obsoleted resultset", obsoleteAtEnd);
+ }
+ private static final Semaphore sync = new Semaphore(0);
+ private volatile static boolean obsoleteAtStart;
+ private volatile static boolean obsoleteAtEnd;
public static class SlowProvider implements SearchProvider {
-
+
public void evaluate(SearchRequest request, SearchResponse response) {
try {
+ obsoleteAtStart = response.isObsolete();
+ sync.release();
Thread.sleep(5000);
+ obsoleteAtEnd = response.isObsolete();
} catch (InterruptedException ex) {
System.err.println("SlowProvider interrupted...");
}
diff --git a/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/UnitTestUtils.java b/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/UnitTestUtils.java
index d5ae548..083b36b 100644
--- a/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/UnitTestUtils.java
+++ b/platform/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/UnitTestUtils.java
@@ -22,9 +22,7 @@ package org.netbeans.modules.quicksearch;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.net.URL;
-import javax.swing.text.Utilities;
import junit.framework.Assert;
-import org.netbeans.junit.NbTestCase;
import org.openide.filesystems.Repository;
import org.openide.filesystems.XMLFileSystem;
import org.openide.util.Lookup;
@@ -59,7 +57,7 @@ public class UnitTestUtils extends ProxyLookup {
URL[] layers = new URL[stringLayers.length];
for (int cntr = 0; cntr < layers.length; cntr++) {
- layers[cntr] = Utilities.class.getResource(stringLayers[cntr]);
+ layers[cntr] = UnitTestUtils.class.getClassLoader().getResource(stringLayers[cntr]);
}
XMLFileSystem system = new XMLFileSystem();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists