-
Notifications
You must be signed in to change notification settings - Fork 58
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
Refactor ExtensionsRunner test code out of production source tree #172
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.opensearch.sdk; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great! |
||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* An Extension Runner for testing using test settings. | ||
*/ | ||
public class ExtensionsRunnerForTest extends ExtensionsRunner { | ||
|
||
/** | ||
* Instantiates a new Extensions Runner using test settings. | ||
* | ||
* @throws IOException if the runner failed to read settings or API. | ||
*/ | ||
public ExtensionsRunnerForTest() throws IOException { | ||
super(new Extension() { | ||
@Override | ||
public ExtensionSettings getExtensionSettings() { | ||
return new ExtensionSettings("sample-extension", "127.0.0.1", "4532"); | ||
} | ||
|
||
@Override | ||
public List<ExtensionRestHandler> getExtensionRestHandlers() { | ||
return Collections.emptyList(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.Version; | ||
|
@@ -77,11 +78,14 @@ public class TestExtensionsRunner extends OpenSearchTestCase { | |
private ExtensionsRunner extensionsRunner; | ||
private TransportService transportService; | ||
|
||
private TransportService initialTransportService; | ||
owaiskazi19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
@BeforeEach | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
this.extensionsRunner = new ExtensionsRunner(); | ||
this.extensionsRunner = new ExtensionsRunnerForTest(); | ||
dbwiddis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.initialTransportService = extensionsRunner.extensionTransportService; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constructor of Tests further use IMO, we should pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point, let's "hack" as needed to get this merged. I agree with you and have questioned how we've tracked the transport service from some of the initial PRs. I'm not sure putting it in the constructor is the best solution but we do need something better than what we have. We do have a future requirement to gracefully handle disconnections/reconnections (hot plugin, etc.) and I think handling these will definitely need to be part of that functionality as well. |
||
this.transportService = spy( | ||
new TransportService( | ||
Settings.EMPTY, | ||
|
@@ -95,6 +99,17 @@ public void setUp() throws Exception { | |
); | ||
} | ||
|
||
@Override | ||
@AfterEach | ||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding the |
||
if (initialTransportService != null) { | ||
this.initialTransportService.stop(); | ||
this.initialTransportService.close(); | ||
Thread.sleep(1000); | ||
} | ||
} | ||
|
||
// test manager method invokes start on transport service | ||
@Test | ||
public void testTransportServiceStarted() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self/other reviewers: package private would be sufficient for tests if we only want to make ExtensionsRunner extendable for testing. However I think it's reasonable to think any user might wish to create a simple anonymous extension (possibly for their own testing!) so I like using
protected
here.