Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review org.apache.solr.client.solrj.io.stream and responding to some warnings. #2530

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -253,7 +253,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 @@ -270,7 +270,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 @@ -489,7 +489,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 @@ -511,7 +511,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 @@ -936,7 +936,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 @@ -952,8 +952,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 @@ -94,7 +93,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 @@ -279,7 +278,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 @@ -323,7 +322,7 @@ public void testJDBCSolrMerge() throws Exception {
"name_s",
"Algeria",
"Canada",
"Great Britian",
"Great Britain",
"Netherlands",
"Norway",
"Nepal",
Expand Down Expand Up @@ -773,7 +772,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 @@ -784,30 +783,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 @@ -817,29 +813,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 @@ -862,9 +835,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 @@ -145,72 +142,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 @@ -235,12 +184,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 @@ -5152,12 +5152,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 @@ -5167,29 +5166,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
Loading