Skip to content

Commit

Permalink
Review org.apache.solr.client.solrj.io.stream and responding to some …
Browse files Browse the repository at this point in the history
…warnings. (#2530)

Review org.apache.solr.client.solrj.io.stream and responding to some intellij warnings.  Typos, methods not used, return values not used, that sort of thing..

---------

Co-authored-by: Christine Poerschke <[email protected]>
  • Loading branch information
epugh and cpoerschke committed Jul 16, 2024
1 parent cf74b16 commit d684934
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

/**
* tests various streaming expressions (via the SolrJ {@link SolrStream} API) against a SolrCloud
* cluster using both Authenticationand Role based Authorization
* cluster using both Authentication and Role based Authorization
*/
public class CloudAuthStreamTest extends SolrCloudTestCase {

Expand All @@ -67,8 +67,8 @@ public class CloudAuthStreamTest extends SolrCloudTestCase {
private static String solrUrl = null;

/**
* Helper that returns the original {@link SolrRequest} <em>with it's original type</em> so it can
* be chained. This menthod knows that for the purpose of this test, every user name is it's own
* Helper that returns the original {@link SolrRequest} <em>with its original type</em> so it can
* be chained. This method knows that for the purpose of this test, every username is its own
* password
*
* @see SolrRequest#setBasicAuthCredentials
Expand Down Expand Up @@ -254,7 +254,7 @@ public void testEchoStream() throws Exception {
assertEquals("hello world", tuples.get(0).get("echo"));
}

public void testEchoStreamNoCredentials() throws Exception {
public void testEchoStreamNoCredentials() {
final SolrStream solrStream =
new SolrStream(
solrUrl + "/" + COLLECTION_X,
Expand All @@ -271,7 +271,7 @@ public void testEchoStreamNoCredentials() throws Exception {
});
}

public void testEchoStreamInvalidCredentials() throws Exception {
public void testEchoStreamInvalidCredentials() {
final SolrStream solrStream =
new SolrStream(
solrUrl + "/" + COLLECTION_X,
Expand Down Expand Up @@ -490,7 +490,7 @@ public void testExecutorUpdateStreamInsufficientCredentials() throws Exception {
params("qt", "/stream", "_trace", "executor_via_" + trace, "expr", expr));
solrStream.setCredentials(user, user);

// NOTE: Becaue of the backgroun threads, no failures will to be returned to client...
// NOTE: Because of the background threads, no failures will to be returned to client...
final List<Tuple> tuples = getTuples(solrStream);
assertEquals(0, tuples.size());

Expand All @@ -512,7 +512,7 @@ public void testDaemonUpdateStream() throws Exception {

{
// NOTE: in spite of what is implied by 'terminate=true', this daemon will NEVER terminate on
// it's own as long as the updates are successful (apparently that requires usage of a topic()
// its own as long as the updates are successful (apparently that requires usage of a topic()
// stream to set a "sleepMillis"?!)
final String expr =
"daemon(id=daemonId,runInterval=1000,terminate=true,update("
Expand Down Expand Up @@ -937,7 +937,7 @@ protected static long countDocsInCollection(final String collection, final Strin

/** Slurps a stream into a List */
protected static List<Tuple> getTuples(final TupleStream tupleStream) throws IOException {
List<Tuple> tuples = new ArrayList<Tuple>();
List<Tuple> tuples = new ArrayList<>();
try {
log.trace("TupleStream: {}", tupleStream);
tupleStream.open();
Expand All @@ -953,8 +953,8 @@ protected static List<Tuple> getTuples(final TupleStream tupleStream) throws IOE
return tuples;
}

/** Sigh. DaemonStream requires polling the same core where the stream was exectured. */
protected static String getRandomCoreUrl(final String collection) throws Exception {
/** Sigh. DaemonStream requires polling the same core where the stream was executed. */
protected static String getRandomCoreUrl(final String collection) {
final List<String> replicaUrls =
cluster
.getZkStateReader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4.SuppressPointFields;
Expand Down Expand Up @@ -95,7 +94,7 @@ public static void setupCluster() throws Exception {
public static void setupDatabase() throws Exception {

// Initialize Database
// Ok, so.....hsqldb is doing something totally weird so I thought I'd take a moment to explain
// Ok, so.....hsqldb is doing something totally weird, so I thought I'd take a moment to explain
// it.
// According to http://www.hsqldb.org/doc/1.8/guide/guide.html#N101EF, section "Components of
// SQL Expressions", clause "name", "When an SQL statement is issued, any lowercase characters
Expand Down Expand Up @@ -280,7 +279,7 @@ public void testJDBCSolrMerge() throws Exception {

// Load Solr
new UpdateRequest()
.add(id, "0", "code_s", "GB", "name_s", "Great Britian")
.add(id, "0", "code_s", "GB", "name_s", "Great Britain")
.add(id, "1", "code_s", "CA", "name_s", "Canada")
.commit(cluster.getSolrClient(), COLLECTIONORALIAS);

Expand Down Expand Up @@ -324,7 +323,7 @@ public void testJDBCSolrMerge() throws Exception {
"name_s",
"Algeria",
"Canada",
"Great Britian",
"Great Britain",
"Netherlands",
"Norway",
"Nepal",
Expand Down Expand Up @@ -774,7 +773,7 @@ protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {
return tuples;
}

protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... values)
protected void assertOrderOf(List<Tuple> tuples, String fieldName, int... values)
throws Exception {
int i = 0;
for (int val : values) {
Expand All @@ -785,30 +784,27 @@ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... val
}
++i;
}
return true;
}

protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, double... values)
throws Exception {
protected void assertOrderOf(List<Tuple> tuples, String fieldName, double... values) {
int i = 0;
for (double val : values) {
Tuple t = tuples.get(i);
double tip = (double) t.get(fieldName);
assertEquals("Found value:" + tip + " expecting:" + val, val, tip, 0.00001);
++i;
}
return true;
}

protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, String... values)
protected void assertOrderOf(List<Tuple> tuples, String fieldName, String... values)
throws Exception {
int i = 0;
for (String val : values) {
Tuple t = tuples.get(i);

if (null == val) {
if (null != t.get(fieldName)) {
throw new Exception("Found value:" + (String) t.get(fieldName) + " expecting:null");
throw new Exception("Found value:" + t.get(fieldName) + " expecting:null");
}
} else {
String tip = (String) t.get(fieldName);
Expand All @@ -818,29 +814,6 @@ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, String...
}
++i;
}
return true;
}

protected boolean assertFields(List<Tuple> tuples, String... fields) throws Exception {
for (Tuple tuple : tuples) {
for (String field : fields) {
if (!tuple.getFields().containsKey(field)) {
throw new Exception(String.format(Locale.ROOT, "Expected field '%s' not found", field));
}
}
}
return true;
}

protected boolean assertNotFields(List<Tuple> tuples, String... fields) throws Exception {
for (Tuple tuple : tuples) {
for (String field : fields) {
if (tuple.getFields().containsKey(field)) {
throw new Exception(String.format(Locale.ROOT, "Unexpected field '%s' found", field));
}
}
}
return true;
}

public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {
Expand All @@ -863,9 +836,7 @@ public boolean assertDouble(Tuple tuple, String fieldName, double d) throws Exce
public boolean assertString(Tuple tuple, String fieldName, String expected) throws Exception {
String actual = (String) tuple.get(fieldName);

if ((null == expected && null != actual)
|| (null != expected && null == actual)
|| (null != expected && !expected.equals(actual))) {
if ((null == expected && null != actual) || (null != expected && !expected.equals(actual))) {
throw new Exception("Longs not equal:" + expected + " : " + actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static void setupCluster() throws Exception {
solrClientCache = new SolrClientCache();
}

/** setup the testbed with necessary collections, documents, and alias */
/** set up the testbed with necessary collections, documents, and alias */
public static void setupCollectionsAndAlias() throws Exception {

final NormalDistribution[] dists = new NormalDistribution[CARDINALITY];
Expand Down Expand Up @@ -299,7 +299,7 @@ public void testParallelStats() throws Exception {
assertNull(statsStream.parallelizedStream);
}

// execute the provided expression with tiered=true and compare to results of tiered=false
// execute the provided expression with tiered=true and compare to result of tiered=false
private void compareTieredStreamWithNonTiered(String facetExprTmpl, int dims) throws IOException {
String facetExpr = String.format(Locale.US, facetExprTmpl, ALIAS_NAME, "true");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.client.solrj.io.SolrClientCache;
import org.apache.solr.client.solrj.io.Tuple;
Expand All @@ -47,8 +46,6 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {
private static final int TIMEOUT = DEFAULT_TIMEOUT;
private static final String id = "id";

private static boolean useAlias;

@BeforeClass
public static void setupCluster() throws Exception {
configureCluster(4)
Expand All @@ -71,7 +68,7 @@ public static void setupCluster() throws Exception {
.configure();

String collection;
useAlias = random().nextBoolean();
boolean useAlias = random().nextBoolean();
if (useAlias) {
collection = COLLECTIONORALIAS + "_collection";
} else {
Expand Down Expand Up @@ -146,72 +143,24 @@ protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {
return tuples;
}

protected boolean assertOrder(List<Tuple> tuples, int... ids) throws Exception {
return assertOrderOf(tuples, "id", ids);
}

protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids)
throws Exception {
int i = 0;
for (int val : ids) {
Tuple t = tuples.get(i);
String tip = t.getString(fieldName);
if (!tip.equals(Integer.toString(val))) {
throw new Exception("Found value:" + tip + " expecting:" + val);
}
++i;
}
return true;
}

protected boolean assertMapOrder(List<Tuple> tuples, int... ids) throws Exception {
int i = 0;
for (int val : ids) {
Tuple t = tuples.get(i);
List<Map<?, ?>> tip = t.getMaps("group");
int id = (int) tip.get(0).get("id");
if (id != val) {
throw new Exception("Found value:" + id + " expecting:" + val);
}
++i;
}
return true;
}

protected boolean assertFields(List<Tuple> tuples, String... fields) throws Exception {
protected void assertFields(List<Tuple> tuples, String... fields) throws Exception {
for (Tuple tuple : tuples) {
for (String field : fields) {
if (!tuple.getFields().containsKey(field)) {
throw new Exception(String.format(Locale.ROOT, "Expected field '%s' not found", field));
}
}
}
return true;
}

protected boolean assertNotFields(List<Tuple> tuples, String... fields) throws Exception {
protected void assertNotFields(List<Tuple> tuples, String... fields) throws Exception {
for (Tuple tuple : tuples) {
for (String field : fields) {
if (tuple.getFields().containsKey(field)) {
throw new Exception(String.format(Locale.ROOT, "Unexpected field '%s' found", field));
}
}
}
return true;
}

protected boolean assertGroupOrder(Tuple tuple, int... ids) throws Exception {
List<?> group = (List<?>) tuple.get("tuples");
int i = 0;
for (int val : ids) {
Map<?, ?> t = (Map<?, ?>) group.get(i);
Long tip = (Long) t.get("id");
if (tip.intValue() != val) {
throw new Exception("Found value:" + tip.intValue() + " expecting:" + val);
}
++i;
}
return true;
}

public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {
Expand All @@ -236,12 +185,9 @@ public boolean assertDouble(Tuple tuple, String fieldName, double expectedValue)
public boolean assertString(Tuple tuple, String fieldName, String expected) throws Exception {
String actual = (String) tuple.get(fieldName);

if ((null == expected && null != actual)
|| (null != expected && null == actual)
|| (null != expected && !expected.equals(actual))) {
throw new Exception("Longs not equal:" + expected + " : " + actual);
if ((null != expected || null == actual) && (null == expected || expected.equals(actual))) {
return true;
}

return true;
throw new Exception("Longs not equal:" + expected + " : " + actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5169,12 +5169,11 @@ protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {
return tuples;
}

protected boolean assertOrder(List<Tuple> tuples, int... ids) throws Exception {
return assertOrderOf(tuples, "id", ids);
protected void assertOrder(List<Tuple> tuples, int... ids) throws Exception {
assertOrderOf(tuples, "id", ids);
}

protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids)
throws Exception {
protected void assertOrderOf(List<Tuple> tuples, String fieldName, int... ids) throws Exception {
int i = 0;
for (int val : ids) {
Tuple t = tuples.get(i);
Expand All @@ -5184,29 +5183,26 @@ protected boolean assertOrderOf(List<Tuple> tuples, String fieldName, int... ids
}
++i;
}
return true;
}

protected boolean assertFields(List<Tuple> tuples, String... fields) throws Exception {
protected void assertFields(List<Tuple> tuples, String... fields) throws Exception {
for (Tuple tuple : tuples) {
for (String field : fields) {
if (!tuple.getFields().containsKey(field)) {
throw new Exception(String.format(Locale.ROOT, "Expected field '%s' not found", field));
}
}
}
return true;
}

protected boolean assertNotFields(List<Tuple> tuples, String... fields) throws Exception {
protected void assertNotFields(List<Tuple> tuples, String... fields) throws Exception {
for (Tuple tuple : tuples) {
for (String field : fields) {
if (tuple.getFields().containsKey(field)) {
throw new Exception(String.format(Locale.ROOT, "Unexpected field '%s' found", field));
}
}
}
return true;
}

protected boolean assertGroupOrder(Tuple tuple, int... ids) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void submitAllTest() throws IOException {
List<Long> results = new ArrayList<>();
results.addAll(StreamExecutorHelper.submitAllAndAwaitAggregatingExceptions(tasks, "test"));
Collections.sort(results);
List<Long> expected = List.of(0l, 1l, 2l, 3l, 4l);
List<Long> expected = List.of(0L, 1L, 2L, 3L, 4L);
assertEquals(expected, results);
}

Expand Down
Loading

0 comments on commit d684934

Please sign in to comment.