Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ if [ $# -gt 0 ]; then
;;
-t|-data.home)
SOLR_DATA_HOME="$2"
PASS_TO_RUN_EXAMPLE+=("-t" "$SOLR_DATA_HOME")
shift 2
;;
-e|-example)
Expand Down
14 changes: 13 additions & 1 deletion solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public List<Option> getOptions() {
.desc("Path to the Solr server directory.")
.longOpt("serverDir")
.build(),
Option.builder("t")
.argName("DIR")
.hasArg()
.required(false)
.desc("Path to the Solr data home directory.")
.longOpt("dataHomeDir")
.build(),
Option.builder("force")
.argName("FORCE")
.desc("Force option in case Solr is run as root.")
Expand Down Expand Up @@ -591,6 +598,9 @@ protected Map<String, Object> startSolr(
String forceArg = cli.hasOption("force") ? " -force" : "";
String verboseArg = verbose ? "-V" : "";

String dataDirArg = cli.hasOption("dataHomeDir") ? "-t" : "";
String dataDirValue = cli.hasOption("dataHomeDir") ? cli.getOptionValue("dataHomeDir") : "";

String addlOpts = cli.getOptionValue('a');
String addlOptsArg = (addlOpts != null) ? " -a \"" + addlOpts + "\"" : "";

Expand All @@ -610,7 +620,7 @@ protected Map<String, Object> startSolr(
String startCmd =
String.format(
Locale.ROOT,
"\"%s\" start %s -p %d -s \"%s\" %s %s %s %s %s %s %s",
"\"%s\" start %s -p %d -s \"%s\" %s %s %s %s %s %s %s %s %s",
callScript,
cloudModeArg,
port,
Expand All @@ -620,6 +630,8 @@ protected Map<String, Object> startSolr(
memArg,
forceArg,
verboseArg,
dataDirArg,
dataDirValue,
extraArgs,
addlOptsArg);
startCmd = startCmd.replaceAll("\\s+", " ").trim(); // for pretty printing
Expand Down
16 changes: 11 additions & 5 deletions solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void tearDown() throws Exception {
}

@Test
@LuceneTestCase.Nightly
// @LuceneTestCase.Nightly
public void testTechproductsExample() throws Exception {
testExample("techproducts");
}
Expand Down Expand Up @@ -353,10 +353,16 @@ protected void testExample(String exampleName) throws Exception {

String[] toolArgs =
new String[] {
"-e", exampleName,
"-serverDir", solrServerDir.getAbsolutePath(),
"-exampleDir", solrExampleDir.getAbsolutePath(),
"-p", String.valueOf(bindPort)
"-e",
exampleName,
"-serverDir",
solrServerDir.getAbsolutePath(),
"-exampleDir",
solrExampleDir.getAbsolutePath(),
"-p",
String.valueOf(bindPort),
"-t",
"dude"
};

// capture tool output to stdout
Expand Down
125 changes: 125 additions & 0 deletions solr/packaging/test/test_replication.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env bats

# 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.

load bats_helper

setup() {
common_clean_setup
}

teardown() {
# save a snapshot of SOLR_HOME for failed tests
save_home_on_failure

solr stop -all >/dev/null 2>&1
}

@test "user managed index replication without zookeeper" {
skip

# This test is fragile. I think we are creating files etc in solr/packaging/build/solr-10.0.0-SNAPSHOT/example/techproducts
# which means you may need to run gradle clean between runs or we can't start up Solr.
# I think we can't run both bats test either, one after the other ;-(

mkdir -p test_data_dir_8983
mkdir -p test_data_dir_7574

solr start -e techproducts -p 8983 -t test_data_dir_8983 -V
solr start -e techproducts -p 7574 -t test_data_dir_7574 -V -Dsolr.disable.allowUrls=true
solr assert --started http://localhost:8983 --timeout 5000
solr assert --started http://localhost:7574 --timeout 5000

run curl 'http://localhost:8983/solr/techproducts/select?q=*:*'
assert_output --partial '"numFound":32'

# Not totally sure why this didn't load it's data, but it works for our needs!
run curl 'http://localhost:7574/solr/techproducts/select?q=*:*'
assert_output --partial '"numFound":0'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect this to return 32 as well. Could we perhaps issue a deleteByQuery request to empty the index before replicating?


run curl 'http://localhost:8983/solr/techproducts/replication?command=enablereplication'
assert_output --partial '"OK"'
run curl 'http://localhost:7574/solr/techproducts/replication?command=fetchindex&leaderUrl=http://localhost:8983/solr/techproducts'
assert_output --partial '"OK"'

# Wish we could block on fetchindex.. Does checking details help?
sleep 5
run curl 'http://localhost:7574/solr/techproducts/select?q=*:*'
assert_output --partial '"numFound":32'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do a while loop instead of sleep perhaps? And another way to assert replication is to compare index generation/version, but probably not necessary here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh, no examples of a while.... I wonder... DO we need the bin/solr assert to assert a doc count with a query? I like the timeout capability built into the assert..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still wishing we had a better bin/solr assert ;-). The curl's are all over the place. And the timeout would be nice...


run bash -c 'solr stop -all 2>&1'
refute_output --partial 'forcefully killing'
}

@test "user managed index replication WITH Zookeeper" {
# This test is fragile. I think we are creating files etc in solr/packaging/build/solr-10.0.0-SNAPSHOT/example/techproducts
# which means you may need to run gradle clean between runs or we can't start up Solr.
# I think we can't run both bats test either, one after the other ;-(

mkdir -p test_data_dir_8983

solr start -c -e techproducts -p 8983 -t test_data_dir_8983 -V
solr start -c -p 7574 -V -Dsolr.disable.allowUrls=true
solr assert --started http://localhost:8983 --timeout 5000
solr assert --started http://localhost:7574 --timeout 5000

run curl 'http://localhost:8983/solr/techproducts/select?q=*:*'
assert_output --partial '"numFound":32'
run curl 'http://localhost:8983/solr/techproducts_shard1_replica_n1/select?q=*:*'
assert_output --partial '"numFound":32'

# setup the follower
local source_configset_dir="${SOLR_TIP}/server/solr/configsets/sample_techproducts_configs"
test -d $source_configset_dir

run solr zk upconfig -d ${source_configset_dir} -n techproducts -z localhost:8574
assert_output --partial "Uploading"
run solr create -c techproducts -d sample_techproducts_configs -solrUrl http://localhost:7574
assert_output --partial "Created collection 'techproducts'"

run curl 'http://localhost:7574/solr/techproducts/select?q=*:*'
assert_output --partial '"numFound":0'

run curl -X POST -H 'Content-type:application/json' -d '{"add-requesthandler": {"name": "/replication","class": "solr.ReplicationHandler","follower": { "leaderUrl": "http://localhost:8983/solr/techproducts_shard1_replica_n1" ,"pollInterval": "00:00:20" }}}' http://localhost:7574/api/collections/techproducts/config
assert_output --partial '"status":0'

sleep 30


run curl 'http://localhost:8983/solr/techproducts_shard1_replica_n1/replication?command=details'
assert_output --partial '"replicationEnabled":"true"'
#run curl 'http://localhost:7574/solr/techproducts_shard1_replica_n1/replication?command=fetchindex&leaderUrl=http://localhost:8983/solr/techproducts_shard1_replica_n1'
#assert_output --partial '"OK"'

# Wish we could block on fetchindex.. Does checking details help?
sleep 5
run curl 'http://localhost:7574/solr/techproducts/select?q=*:*'
assert_output --partial '"numFound":32'

# Create a doc on the leader and check the follower
run solr post -url http://localhost:8983/solr/techproducts/update -mode args -out -commit "{'add': {doc:{'id': 'newproduct'}}}"
assert_output --partial '"status":0'

sleep 25

run curl 'http://localhost:7574/solr/techproducts/select?q=*:*&rows=0'
assert_output --partial '"numFound":33'



run bash -c 'solr stop -all 2>&1'
refute_output --partial 'forcefully killing'
}