epugh commented on code in PR #4177: URL: https://github.com/apache/solr/pull/4177#discussion_r4108654654
########## solr/core/src/test/org/apache/solr/handler/admin/api/UpdateAPITest.java: ########## @@ -0,0 +1,371 @@ +/* + * 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. + */ + +package org.apache.solr.handler.admin.api; + +import static org.apache.solr.core.CoreContainer.ALLOW_PATHS_SYSPROP; + +import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import org.apache.solr.SolrTestCase; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; +import org.apache.solr.client.solrj.request.GenericV2SolrRequest; +import org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec; +import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.RequestWriter; +import org.apache.solr.client.solrj.request.UpdateRequest; +import org.apache.solr.client.solrj.response.JavaBinResponseParser; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.client.solrj.response.XMLResponseParser; +import org.apache.solr.client.solrj.response.json.JsonMapResponseParser; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.util.EnvUtils; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.util.ExternalPaths; +import org.apache.solr.util.SolrJettyTestRule; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; + +/** + * Integration tests for the v2 update API endpoints implemented via JAX-RS in {@link + * org.apache.solr.handler.admin.api.UpdateAPI}. + */ +public class UpdateAPITest extends SolrTestCase { + + @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule(); + + private static final String CORE_NAME = "update-api-test"; + private static final String CUSTOM_JSON_CORE_NAME = "custom-json-update-api-test"; + + @BeforeClass + public static void beforeClass() throws Exception { + EnvUtils.setProperty( + ALLOW_PATHS_SYSPROP, ExternalPaths.SERVER_HOME.toAbsolutePath().toString()); + solrTestRule.startSolr(createTempDir()); + solrTestRule + .newCollection(CORE_NAME) + .withConfigSet(ExternalPaths.TECHPRODUCTS_CONFIGSET) + .create(); + // can't use techproducts config because it enables srcField, which is incompatible with nested + // split=/exams requests + solrTestRule + .newCollection(CUSTOM_JSON_CORE_NAME) + .withConfigSet(ExternalPaths.DEFAULT_CONFIGSET) + .create(); + } + + @Test + public void testV1AndV2GenericUpdateParityAcrossFormats() throws Exception { + final SolrClient client = solrTestRule.getSolrClient(CORE_NAME); + + for (UpdateFormat format : UpdateFormat.values()) { + final String v1Id = "parity-v1-" + format.name().toLowerCase(Locale.ROOT); + final String v2Id = "parity-v2-" + format.name().toLowerCase(Locale.ROOT); + + final NamedList<Object> v1Response = sendV1Update(client, format, v1Id); + final NamedList<Object> v2Response = sendV2Update(client, format, v2Id); + + assertLegacySuccessfulAdd(format, v1Id, v1Response); + assertTypedSuccessfulAdd(format, v2Id, v2Response); + assertIndexed(client, v1Id); + assertIndexed(client, v2Id); + } + } + + @Test + public void testV1AndV2CustomJsonTransformParity() throws Exception { + final SolrClient client = solrTestRule.getSolrClient(CUSTOM_JSON_CORE_NAME); + final String payload = "{\"exams\":[{\"id\":\"custom-json-v1\",\"name\":\"V1 document\"}]}"; + + final ModifiableSolrParams params = new ModifiableSolrParams(); + params.set("split", "/exams"); + params.add("f", "id:/exams/id"); + params.add("f", "name_s:/exams/name"); + params.set("commit", true); + + final GenericSolrRequest v1Request = + new GenericSolrRequest(SolrRequest.METHOD.POST, "/update/json/docs", params); + v1Request.setRequiresCollection(true); + v1Request.setContentWriter( + new RequestWriter.StringPayloadContentWriter(payload, "application/json")); + client.request(v1Request, CUSTOM_JSON_CORE_NAME); + + final String v2Payload = payload.replace("custom-json-v1", "custom-json-v2"); + final GenericV2SolrRequest v2Request = + new GenericV2SolrRequest( + SolrRequest.METHOD.POST, "/cores/" + CUSTOM_JSON_CORE_NAME + "/update/json", params); + v2Request.setContentWriter( + new RequestWriter.StringPayloadContentWriter(v2Payload, "application/json")); + client.request(v2Request); + + assertIndexedField(client, CUSTOM_JSON_CORE_NAME, "custom-json-v1", "name_s", "V1 document"); + assertIndexedField(client, CUSTOM_JSON_CORE_NAME, "custom-json-v2", "name_s", "V1 document"); + } + + @Test + public void testUpdateJsonViaV2Api() throws Exception { + final SolrClient client = solrTestRule.getSolrClient(CORE_NAME); + + // POST via the V2 /update/json endpoint (also rewrites to /update/json/docs) + final GenericV2SolrRequest addReq = + new GenericV2SolrRequest(SolrRequest.METHOD.POST, "/cores/" + CORE_NAME + "/update/json"); + addReq.setContentWriter( + new RequestWriter.StringPayloadContentWriter( + "[{\"id\":\"v2updatejson1\",\"title\":\"V2 update/json test\"}]", "application/json")); + client.request(addReq); + + // Commit via standard SolrJ commit (v2 /update is docs-only and does not support commands) Review Comment: i reworked the comment. Having said that, I think once we are closer to merging, we need to review ALL the comments from the perspecgtive of "if this pr is merged, do these comments help me".. I like the verbosity as we "work the problem", but hate it afterwords beause it's so much to read! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
