mirror of https://github.com/apache/lucene.git
SOLR-10614: remove static backdoor fields from SimplePostTool.
Enabling testTechproductsExample
This commit is contained in:
parent
df6da67204
commit
dbe6fc5d8f
|
@ -371,6 +371,9 @@ Other Changes
|
||||||
|
|
||||||
* SOLR-10601: StreamExpressionParser should handle white space around = in named parameters (Joel Bernstein)
|
* SOLR-10601: StreamExpressionParser should handle white space around = in named parameters (Joel Bernstein)
|
||||||
|
|
||||||
|
* SOLR-10614: Static fields have turned to instance's field in SimplePostTool.
|
||||||
|
Enabled TestSolrCLIRunExample.testTechproductsExample(). (Andrey Kudryavtsev, Mikhail Khludnev)
|
||||||
|
|
||||||
================== 6.5.1 ==================
|
================== 6.5.1 ==================
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
|
|
|
@ -125,8 +125,8 @@ public class SimplePostTool {
|
||||||
"Usage: java [SystemProperties] -jar post.jar [-h|-] [<file|folder|url|arg> [<file|folder|url|arg>...]]";
|
"Usage: java [SystemProperties] -jar post.jar [-h|-] [<file|folder|url|arg> [<file|folder|url|arg>...]]";
|
||||||
|
|
||||||
// Used in tests to avoid doing actual network traffic
|
// Used in tests to avoid doing actual network traffic
|
||||||
static boolean mockMode = false;
|
boolean mockMode = false;
|
||||||
static PageFetcher pageFetcher;
|
PageFetcher pageFetcher;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
DATA_MODES.add(DATA_MODE_FILES);
|
DATA_MODES.add(DATA_MODE_FILES);
|
||||||
|
@ -810,7 +810,7 @@ public class SimplePostTool {
|
||||||
} else {
|
} else {
|
||||||
if(type == null) type = DEFAULT_CONTENT_TYPE;
|
if(type == null) type = DEFAULT_CONTENT_TYPE;
|
||||||
}
|
}
|
||||||
info("POSTing file " + file.getName() + (auto?" ("+type+")":"") + " to [base]" + suffix);
|
info("POSTing file " + file.getName() + (auto?" ("+type+")":"") + " to [base]" + suffix + (mockMode ? " MOCK!":""));
|
||||||
is = new FileInputStream(file);
|
is = new FileInputStream(file);
|
||||||
postData(is, file.length(), output, type, url);
|
postData(is, file.length(), output, type, url);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -851,7 +851,7 @@ public class SimplePostTool {
|
||||||
/**
|
/**
|
||||||
* Performs a simple get on the given URL
|
* Performs a simple get on the given URL
|
||||||
*/
|
*/
|
||||||
public static void doGet(String url) {
|
public void doGet(String url) {
|
||||||
try {
|
try {
|
||||||
doGet(new URL(url));
|
doGet(new URL(url));
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
|
@ -862,7 +862,7 @@ public class SimplePostTool {
|
||||||
/**
|
/**
|
||||||
* Performs a simple get on the given URL
|
* Performs a simple get on the given URL
|
||||||
*/
|
*/
|
||||||
public static void doGet(URL url) {
|
public void doGet(URL url) {
|
||||||
try {
|
try {
|
||||||
if(mockMode) return;
|
if(mockMode) return;
|
||||||
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
|
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
|
||||||
|
|
|
@ -16,12 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.util;
|
package org.apache.solr.util;
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
|
||||||
import org.apache.solr.util.SimplePostTool.PageFetcher;
|
|
||||||
import org.apache.solr.util.SimplePostTool.PageFetcherResult;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -34,6 +28,12 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
import org.apache.solr.util.SimplePostTool.PageFetcher;
|
||||||
|
import org.apache.solr.util.SimplePostTool.PageFetcherResult;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NOTE: do *not* use real hostnames, not even "example.com", in this test.
|
* NOTE: do *not* use real hostnames, not even "example.com", in this test.
|
||||||
*
|
*
|
||||||
|
@ -42,6 +42,7 @@ import java.util.Set;
|
||||||
* the hostnames.
|
* the hostnames.
|
||||||
*/
|
*/
|
||||||
public class SimplePostToolTest extends SolrTestCaseJ4 {
|
public class SimplePostToolTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
SimplePostTool t_file, t_file_auto, t_file_rec, t_web, t_test;
|
SimplePostTool t_file, t_file_auto, t_file_rec, t_web, t_test;
|
||||||
PageFetcher pf;
|
PageFetcher pf;
|
||||||
|
|
||||||
|
@ -70,8 +71,10 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
|
||||||
t_test = SimplePostTool.parseArgsAndInit(args);
|
t_test = SimplePostTool.parseArgsAndInit(args);
|
||||||
|
|
||||||
pf = new MockPageFetcher();
|
pf = new MockPageFetcher();
|
||||||
SimplePostTool.pageFetcher = pf;
|
for (SimplePostTool mockable : new SimplePostTool[]{t_web, t_file_auto}) {
|
||||||
SimplePostTool.mockMode = true;
|
mockable.pageFetcher = pf;
|
||||||
|
mockable.mockMode = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -170,7 +173,7 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
|
||||||
assertEquals(3, num);
|
assertEquals(3, num);
|
||||||
|
|
||||||
// Without respecting robots.txt
|
// Without respecting robots.txt
|
||||||
SimplePostTool.pageFetcher.robotsCache.clear();
|
t_web.pageFetcher.robotsCache.clear();
|
||||||
t_web.recursive = 5;
|
t_web.recursive = 5;
|
||||||
num = t_web.postWebPages(new String[] {"http://[ff01::114]/#removeme"}, 0, null);
|
num = t_web.postWebPages(new String[] {"http://[ff01::114]/#removeme"}, 0, null);
|
||||||
assertEquals(6, num);
|
assertEquals(6, num);
|
||||||
|
@ -178,9 +181,9 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRobotsExclusion() throws MalformedURLException {
|
public void testRobotsExclusion() throws MalformedURLException {
|
||||||
assertFalse(SimplePostTool.pageFetcher.isDisallowedByRobots(new URL("http://[ff01::114]/")));
|
assertFalse(t_web.pageFetcher.isDisallowedByRobots(new URL("http://[ff01::114]/")));
|
||||||
assertTrue(SimplePostTool.pageFetcher.isDisallowedByRobots(new URL("http://[ff01::114]/disallowed")));
|
assertTrue(t_web.pageFetcher.isDisallowedByRobots(new URL("http://[ff01::114]/disallowed")));
|
||||||
assertTrue("There should be two entries parsed from robots.txt", SimplePostTool.pageFetcher.robotsCache.get("[ff01::114]").size() == 2);
|
assertTrue("There should be two entries parsed from robots.txt", t_web.pageFetcher.robotsCache.get("[ff01::114]").size() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class MockPageFetcher extends PageFetcher {
|
static class MockPageFetcher extends PageFetcher {
|
||||||
|
@ -219,7 +222,7 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
|
||||||
sb.append("Disallow: # This is void\n");
|
sb.append("Disallow: # This is void\n");
|
||||||
sb.append("Disallow: /disallow # Disallow this path\n");
|
sb.append("Disallow: /disallow # Disallow this path\n");
|
||||||
sb.append("Disallow: /nonexistingpath # Disallow this path\n");
|
sb.append("Disallow: /nonexistingpath # Disallow this path\n");
|
||||||
this.robotsCache.put("[ff01::114]", SimplePostTool.pageFetcher.
|
this.robotsCache.put("[ff01::114]", super.
|
||||||
parseRobotsTxt(new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8))));
|
parseRobotsTxt(new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -298,7 +297,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test @Ignore
|
@Test
|
||||||
public void testTechproductsExample() throws Exception {
|
public void testTechproductsExample() throws Exception {
|
||||||
testExample("techproducts");
|
testExample("techproducts");
|
||||||
}
|
}
|
||||||
|
@ -317,7 +316,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
|
||||||
File solrExampleDir = tmpDir.toFile();
|
File solrExampleDir = tmpDir.toFile();
|
||||||
File solrServerDir = solrHomeDir.getParentFile();
|
File solrServerDir = solrHomeDir.getParentFile();
|
||||||
|
|
||||||
for (int i =0; i<2; i++){
|
for (int pass = 0; pass<2; pass++){
|
||||||
// need a port to start the example server on
|
// need a port to start the example server on
|
||||||
int bindPort = -1;
|
int bindPort = -1;
|
||||||
try (ServerSocket socket = new ServerSocket(0)) {
|
try (ServerSocket socket = new ServerSocket(0)) {
|
||||||
|
@ -379,7 +378,6 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
|
||||||
assertTrue("expected 32 docs in the " + exampleName + " example but found " + numFound + ", output: " + toolOutput,
|
assertTrue("expected 32 docs in the " + exampleName + " example but found " + numFound + ", output: " + toolOutput,
|
||||||
numFound == 32);
|
numFound == 32);
|
||||||
}finally{
|
}finally{
|
||||||
|
|
||||||
solrClient.close();
|
solrClient.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue