Skip to content

Commit

Permalink
Demonstrate export/import round trip lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Jan 6, 2025
1 parent 63922fc commit 4bd184f
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions solr/packaging/test/test_roundtrip_export_import.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# These tests demonstrate that you can round trip data out of Solr and back.
# However you need to be careful about which fields you select, as if you include copyFields
# then on the import you run into issues.
# "json" format works with the bin/solr post tool.
# "jsonl" format works with curl and posting directory to /update/json
# There are no options for javabin or cbor.

load bats_helper

setup() {
Expand All @@ -28,19 +35,47 @@ teardown() {
solr stop --all >/dev/null 2>&1
}

@test "roundtrip export and import using post command" {
@test "roundtrip export and import using .json and post command" {
run solr start -e techproducts
run solr export --solr-url http://localhost:${SOLR_PORT} --name techproducts --query "*:* -id:test" --output "${BATS_TEST_TMPDIR}/output"
run solr export --fields id,name,manu,manu_id_s,cat,features,price,popularity,inStock,store,manufacturedate_dt,payloads --solr-url "http://localhost:${SOLR_PORT}" --name techproducts --query "*:* -id:test" --output "${BATS_TEST_TMPDIR}/output"

assert [ -e ${BATS_TEST_TMPDIR}/output.json ]

run solr create -c COLL_NAME -d sample_techproducts_configs

run solr post --solr-url http://localhost:${SOLR_PORT} -c COLL_NAME ${BATS_TEST_TMPDIR}/output.json
run solr post --format --solr-url "http://localhost:${SOLR_PORT}" -c COLL_NAME ${BATS_TEST_TMPDIR}/output.json

assert_output --partial '1 files indexed.'
refute_output --partial 'ERROR'
run curl "http://localhost:${SOLR_PORT}/solr/COLL_NAME/select?q=*:*&fl=id,name,manu,manu_id_s,cat,features,price,popularity,inStock,store,manufacturedate_dt,payloads"
assert_output --partial '"numFound":32'

# export once more the imported data, and compare that export to the original export from techproducts
run solr export --fields id,name,manu,manu_id_s,cat,features,price,popularity,inStock,store,manufacturedate_dt,payloads --solr-url http://localhost:${SOLR_PORT} --name COLL_NAME --query "*:* -id:test" --output "${BATS_TEST_TMPDIR}/COLL_NAME"

run diff <(jq -S . ${BATS_TEST_TMPDIR}/output.json) <(jq -S . ${BATS_TEST_TMPDIR}/COLL_NAME.json)
assert_success
assert_output ""
}

@test "roundtrip export and import using .jsonl and curl command" {
run solr start -e techproducts
run solr export --format jsonl --fields id,name,manu,manu_id_s,cat,features,price,popularity,inStock,store,manufacturedate_dt,payloads --solr-url http://localhost:${SOLR_PORT} --name techproducts --query "*:* -id:test" --output "${BATS_TEST_TMPDIR}/output"

assert [ -e ${BATS_TEST_TMPDIR}/output.jsonl ]

run solr create -c COLL_NAME -d sample_techproducts_configs

run curl "http://localhost:${SOLR_PORT}/api/collections/COLL_NAME/update/json" -H 'Content-type:application/json' -d "@${BATS_TEST_TMPDIR}/output.jsonl"

assert_output --partial '"status":0'
run curl "http://localhost:${SOLR_PORT}/solr/COLL_NAME/select?q=*:*"
assert_output --partial '"numFound":32'

run solr export --format jsonl --fields id,name,manu,manu_id_s,cat,features,price,popularity,inStock,store,manufacturedate_dt,payloads --solr-url http://localhost:${SOLR_PORT} --name COLL_NAME --query "*:* -id:test" --output "${BATS_TEST_TMPDIR}/COLL_NAME"

run diff <(jq -c . ${BATS_TEST_TMPDIR}/output.jsonl | sort) <(jq -c . ${BATS_TEST_TMPDIR}/COLL_NAME.jsonl | sort)
assert_success
assert_output ""

}

0 comments on commit 4bd184f

Please sign in to comment.