Skip to content

Commit 1084db9

Browse files
bogdanstoikepugh
andauthored
SOLR-17367 - org.apache.solr.cli.PostTool is ignoring -params option (#2557)
--------- Co-authored-by: Eric Pugh <[email protected]>
1 parent fcf84ee commit 1084db9

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

solr/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ Bug Fixes
202202

203203
* SOLR-17333: Rate-limiting feature: fix live-update of config (Michael Gibney)
204204

205+
* SOLR-17367: Restore the use of -params option to PostTool. (Bostoi via Eric Pugh)
206+
205207
Dependency Upgrades
206208
---------------------
207209
(No changes)

solr/core/src/java/org/apache/solr/cli/PostTool.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class PostTool extends ToolBase {
108108
boolean dryRun; // Avoids actual network traffic to Solr
109109

110110
String[] args;
111+
String params;
111112

112113
boolean auto = true;
113114
private int currentDepth;
@@ -311,6 +312,8 @@ public void runImpl(CommandLine cli) throws Exception {
311312

312313
args = cli.getArgs();
313314

315+
params = cli.getOptionValue("params", "");
316+
314317
execute(mode);
315318
}
316319

@@ -911,6 +914,14 @@ public boolean postData(
911914
return true;
912915
}
913916

917+
if (params.length() > 0) {
918+
try {
919+
uri = new URI(appendParam(uri.toString(), params));
920+
} catch (URISyntaxException e) {
921+
warn("Malformed params");
922+
}
923+
}
924+
914925
boolean success = true;
915926
if (type == null) {
916927
type = DEFAULT_CONTENT_TYPE;

solr/core/src/test/org/apache/solr/cli/PostToolTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,52 @@ public void testRunWithCollectionParam() throws Exception {
147147
assertEquals("*:* found unexpected number of documents", expectedDocCount, numFound);
148148
}
149149

150+
@Test
151+
public void testRunCsvWithCustomSeparatorParam() throws Exception {
152+
final String collection = "testRunCsvWithCustomSeparatorParam";
153+
154+
// Provide the port for the PostTool to look up.
155+
EnvUtils.setProperty("jetty.port", cluster.getJettySolrRunner(0).getLocalPort() + "");
156+
157+
withBasicAuth(CollectionAdminRequest.createCollection(collection, "conf1", 1, 1, 0, 0))
158+
.processAndWait(cluster.getSolrClient(), 10);
159+
160+
File tsvDoc = File.createTempFile("temp", ".tsv");
161+
162+
FileWriter fw = new FileWriter(tsvDoc, StandardCharsets.UTF_8);
163+
fw.write("1\tmytitle\n");
164+
fw.close();
165+
166+
String[] args = {
167+
"post",
168+
"-c",
169+
collection,
170+
"-credentials",
171+
SecurityJson.USER_PASS,
172+
"--params",
173+
"\"separator=%09&header=false&fieldnames=id,title_s\"",
174+
"--type",
175+
"text/csv",
176+
tsvDoc.getAbsolutePath()
177+
};
178+
assertEquals(0, runTool(args));
179+
180+
int numFound = 0;
181+
int expectedDocCount = 1;
182+
183+
for (int idx = 0; idx < 100; ++idx) {
184+
QueryRequest req = withBasicAuth(new QueryRequest(params("q", "*:*")));
185+
QueryResponse rsp = req.process(cluster.getSolrClient(), collection);
186+
187+
numFound = (int) rsp.getResults().getNumFound();
188+
if (numFound == expectedDocCount) {
189+
break;
190+
}
191+
Thread.sleep(100);
192+
}
193+
assertEquals("*:* found unexpected number of documents", expectedDocCount, numFound);
194+
}
195+
150196
private int runTool(String[] args) throws Exception {
151197
Tool tool = findTool(args);
152198
assertTrue(tool instanceof PostTool);

0 commit comments

Comments
 (0)