cpoerschke commented on a change in pull request #346: URL: https://github.com/apache/solr/pull/346#discussion_r728252641
########## File path: solr/core/src/test/org/apache/solr/handler/component/ShardRequestTest.java ########## @@ -0,0 +1,47 @@ +/* + * 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.component; + +import org.apache.solr.SolrTestCase; +import org.junit.Test; + +public class ShardRequestTest extends SolrTestCase { + + @Test + public void testDefaultPurposeIsZero() throws Exception { + final ShardRequest sr = new ShardRequest(); + assertEquals(0, sr.purpose); + } + + @Test + public void testPurposePrivateIsOne() throws Exception { Review comment: That's a fair question. Yes, it's testing that the constant is and stays constant and the goal would be for the test to break if anyone ever tried to change the constant (without updating the test). The constant changing is admittedly quite unlikely. Or maybe another way of describing the goal of the test would be something like _"hey, so you're changing this constant which is used in various places, directly via `ShardRequest.PURPOSE_PRIVATE` or indirectly via direct `1` magic number hard-coding. are you sure you wanna change it? please make sure all the places that might be impacted by the change are accounted for."_ -- though yes, that's perhaps a bit obscure and/or implied via the constancy of the constant anyhow. I don't have a strong view on this (hence only the test for the `PURPOSE_PRIVATE` and not the rest) and would be happy to drop this if it's more confusing than useful. ########## File path: solr/core/src/java/org/apache/solr/update/PeerSync.java ########## @@ -78,6 +78,11 @@ private ShardHandler shardHandler; private List<SyncShardRequest> requests = new ArrayList<>(); + @VisibleForTesting + static final int SHARD_REQUEST_PURPOSE_GET_UPDATES = 0; // unspecified i.e. default purpose + @VisibleForTesting + static final int SHARD_REQUEST_PURPOSE_GET_VERSIONS = 1; // ShardRequest.PURPOSE_PRIVATE Review comment: Hmm, yes, good question. Would plain ``` static final int SHARD_REQUEST_PURPOSE_GET_UPDATES = 0; static final int SHARD_REQUEST_PURPOSE_GET_VERSIONS = 1; ``` be clearer maybe? As far as I can tell `PeerSync`'s use of the purpose field is mostly for its own purposes (pun intended!) i.e. the `RealTimeGetComponent` isn't going return anything different as a result of the purpose choice (though there are metrics side effects via `RequestHandlerBase` use of the purpose). -- 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]
