joshgog commented on PR #1115:
URL: https://github.com/apache/solr/pull/1115#issuecomment-1292436699
Initially I had tried using JerseyTest but the test failed due to server
shutdown.
```
2> INFO: Started listener bound to [localhost:9998]
2> Oct 26, 2022 9:23:11 PM org.glassfish.grizzly.http.server.HttpServer
start
2> INFO: [HttpServer] Started.
2> Oct 26, 2022 9:23:12 PM
org.glassfish.grizzly.http.server.NetworkListener shutdownNow
2> INFO: Stopped listener bound to [localhost:9998]
```
The code is
```
public class ReplaceNodeAPITest extends JerseyTest {
private CoreContainer mockCoreContainer;
private static final String sourceNodeName = "demoSourceNode";
private static final String targetNodeName = "demoTargetNode";
private static final boolean waitForFinalState = false;
private SolrQueryRequest mockQueryRequest;
private SolrQueryResponse queryResponse;
@BeforeClass
public static void ensureWorkingMockito() {
assumeWorkingMockito();
}
protected Application configure() {
resetMocks();
final ResourceConfig config = new ResourceConfig();
config.register(ReplaceNodeAPI.class);
config.register(SolrJacksonMapper.class);
config.register(
new AbstractBinder() {
@Override
protected void configure() {
bindFactory(new
InjectionFactories.SingletonFactory<>(mockCoreContainer))
.to(CoreContainer.class)
.in(Singleton.class);
}
});
config.register(
new AbstractBinder() {
@Override
protected void configure() {
bindFactory(InjectionFactories.SolrQueryRequestFactory.class)
.to(SolrQueryRequest.class)
.in(RequestScoped.class);
}
});
config.register(
new AbstractBinder() {
@Override
protected void configure() {
bindFactory(InjectionFactories.SolrQueryResponseFactory.class)
.to(SolrQueryResponse.class)
.in(RequestScoped.class);
}
});
return config;
}
@Test
public void testSuccessfulReplaceNodeCommand() throws Exception {
final String expectedJson =
"{\"responseHeader\":{\"status\":0,\"QTime\":0}}";
final CollectionsHandler collectionsHandler =
mock(CollectionsHandler.class);
when(mockCoreContainer.getCollectionsHandler()).thenReturn(collectionsHandler);
ReplaceNodeAPI.ReplaceNodeRequestBody requestBody = new
ReplaceNodeAPI.ReplaceNodeRequestBody(targetNodeName, waitForFinalState);
Entity<ReplaceNodeRequestBody> entity = Entity.entity(requestBody,
MediaType.APPLICATION_JSON);
final Response response =
target("cluster/nodes/" + sourceNodeName +
"/commands/replace").request().post(entity);
final String jsonBody = response.readEntity(String.class);
assertEquals(200, response.getStatus());
assertEquals("application/json",
response.getHeaders().getFirst("Content-type"));
assertEquals(expectedJson,
"{\"responseHeader\":{\"status\":0,\"QTime\":0}}");
}
private void resetMocks() {
mockCoreContainer = mock(CoreContainer.class);
}
}
```
--
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]