HoustonPutman commented on code in PR #4046:
URL: https://github.com/apache/solr/pull/4046#discussion_r2700008049
##########
solr/core/src/test/org/apache/solr/handler/admin/api/RestoreCollectionAPITest.java:
##########
@@ -110,45 +111,49 @@ public void
testReportsErrorIfProvidedCollectionNameIsInvalid() {
requestBody.collection = "invalid$collection@name";
final SolrException thrown =
expectThrows(
- SolrException.class,
- () -> {
- restoreCollectionAPI.restoreCollection("someBackupName",
requestBody);
- });
+ SolrException.class, () -> api.restoreCollection("someBackupName",
requestBody));
assertEquals(400, thrown.code());
assertThat(
thrown.getMessage(), containsString("Invalid collection:
[invalid$collection@name]"));
}
@Test
- public void testCreatesValidRemoteMessageForExistingCollectionRestore() {
+ public void testCreatesValidRemoteMessageForExistingCollectionRestore()
throws Exception {
final var requestBody = new RestoreCollectionRequestBody();
requestBody.collection = "someCollectionName";
- requestBody.location = "/some/location/path";
+ requestBody.location = "someLocation";
requestBody.backupId = 123;
- requestBody.repository = "someRepositoryName";
+ requestBody.repository = "someRepository";
requestBody.async = "someAsyncId";
- final var remoteMessage =
- restoreCollectionAPI.createRemoteMessage("someBackupName",
requestBody).getProperties();
+
when(mockClusterState.hasCollection(eq("someCollectionName"))).thenReturn(true);
+ api.restoreCollection("someBackupName", requestBody);
+ verify(mockCommandRunner)
+ .runCollectionCommand(contextCapturer.capture(),
messageCapturer.capture(), anyLong());
+
+ final ZkNodeProps createdMessage = messageCapturer.getValue();
+ final Map<String, Object> remoteMessage = createdMessage.getProperties();
- assertEquals(7, remoteMessage.size());
- assertEquals("restore", remoteMessage.get(QUEUE_OPERATION));
+ assertEquals(5, remoteMessage.size());
assertEquals("someCollectionName", remoteMessage.get(COLLECTION));
- assertEquals("/some/location/path", remoteMessage.get(BACKUP_LOCATION));
+ assertEquals("someLocation", remoteMessage.get(BACKUP_LOCATION));
assertEquals(Integer.valueOf(123), remoteMessage.get(BACKUP_ID));
- assertEquals("someRepositoryName", remoteMessage.get(BACKUP_REPOSITORY));
- assertEquals("someAsyncId", remoteMessage.get(ASYNC));
+ assertEquals("someRepository", remoteMessage.get(BACKUP_REPOSITORY));
assertEquals("someBackupName", remoteMessage.get(NAME));
+
+ AdminCmdContext context = contextCapturer.getValue();
Review Comment:
Ok, I created a common validation method `validateRunCommand` that makes
this really clean for all of the tests that do it. The method does everything
after calling the api.
```java
validateRunCommand(
CollectionParams.CollectionAction.DELETE,
message -> {
assertEquals(1, message.size());
assertThat(message, hasEntry(NAME, "someCollName"));
});
```
and
```java
validateRunCommand(
CollectionParams.CollectionAction.DELETE,
"someAsyncId",
message -> {
assertEquals(1, message.size());
assertThat(message, hasEntry(NAME, "someCollName"));
});
```
--
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]