You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2023/01/03 05:31:15 UTC

[GitHub] [solr] dsmiley commented on a diff in pull request #1218: SOLR-16573:SolrClientTestRule for EmbeddedSolrServer

dsmiley commented on code in PR #1218:
URL: https://github.com/apache/solr/pull/1218#discussion_r1060284411


##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.util;
+
+import static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.

Review Comment:
   A good first start.  I recommend that you review the [Javadoc style guide](https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html#styleguide), especially around the importance of the first sentence and brevity generally.  I think the first sentence should be the one you specified 2nd, so I suggest the following (along with some other changes).
   ```
   Provides access to a {@link SolrClient} instance and a running Solr in tests.
   Implementations could run Solr in different ways (e.g. strictly embedded, adding HTTP/Jetty, adding SolrCloud, or an external process).
   It's a JUnit {@link ExternalResource} (a {@code TestRule}), and thus closes the client and Solr itself when the test completes.
   This test utility is encouraged to be used by external projects that wish to test communicating with Solr, especially for plugin providers.
   ```
   
   



##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.util;
+
+import static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

Review Comment:
   can be removed



##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.util;
+
+import static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  protected SolrClientTestRule() {}
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }

Review Comment:
   can be removed



##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.util;
+
+import static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  protected SolrClientTestRule() {}
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  public abstract SolrClient getSolrClient();
+
+  public void clearIndex() throws SolrServerException, IOException {
+    new UpdateRequest().deleteByQuery("*:*").commit(solrClientTestRule.getSolrClient(), null);
+  }
+
+  public abstract Path getSolrHome();

Review Comment:
   needs docs.
   BTW I recall there is some doubt as to wether we actually need this.  I suspect we don't?  If we can eliminate it -- even better.



##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.util;
+
+import static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  protected SolrClientTestRule() {}
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  public abstract SolrClient getSolrClient();

Review Comment:
   needs docs



##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.util;
+
+import static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  protected SolrClientTestRule() {}
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  public abstract SolrClient getSolrClient();
+
+  public void clearIndex() throws SolrServerException, IOException {

Review Comment:
   needs docs



##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.util;
+
+import static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  protected SolrClientTestRule() {}

Review Comment:
   can be removed



##########
solr/test-framework/src/java/org/apache/solr/util/SolrClientTestRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.util;
+
+import static org.apache.solr.EmbeddedSolrServerTestBase.solrClientTestRule;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.junit.rules.ExternalResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SolrClientTestRule is an abstract class that extends JUnit's {@link ExternalResource} class,
+ * which is a TestRule that allows for specifying methods to be run before and after a test.
+ * SolrClientTestRule provides access to a {@link SolrClient} instance. SolrClientTestRule should be
+ * used in tests that need to interact with a Solr server and provides a convenient way to manage
+ * the lifecycle of the SolrClient instance.
+ */
+public abstract class SolrClientTestRule extends ExternalResource {
+
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  protected SolrClientTestRule() {}
+
+  @Override
+  protected void before() throws Throwable {
+    super.before();
+  }
+
+  public abstract SolrClient getSolrClient();
+
+  public void clearIndex() throws SolrServerException, IOException {
+    new UpdateRequest().deleteByQuery("*:*").commit(solrClientTestRule.getSolrClient(), null);

Review Comment:
   woah, this is suspicious -- the `solrClientTestRule.` part.  What's going on here?



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org