use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.
the class BackupManagerIT method testCreateDuplicateBackupResources.
@Test
public void testCreateDuplicateBackupResources() throws Exception {
String backupName = "testCreateDuplicateBackupResources";
// Start the source cluster
startSourceCluster();
RestClient client = source.getClient();
populateContainer(client);
RestCacheManagerClient cm = client.cacheManager("clustered");
RestResponse response = await(cm.createBackup(backupName));
assertEquals(202, response.getStatus());
response = await(cm.createBackup(backupName));
assertEquals(409, response.getStatus());
response = await(cm.deleteBackup(backupName));
// Expect a 202 response as the previous backup will be in progress, so the request is accepted for now
assertEquals(202, response.getStatus());
// Now wait until the backup has actually been deleted so that we successfully create another with the same name
Common.awaitStatus(() -> cm.deleteBackup(backupName), 202, 404);
response = await(cm.createBackup(backupName));
assertEquals(202, response.getStatus());
// Wait for the backup operation to finish
awaitOk(() -> cm.getBackup(backupName, false));
response = await(cm.deleteBackup(backupName));
assertEquals(204, response.getStatus());
}
use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.
the class BackupManagerIT method performTest.
private void performTest(Function<RestClient, RestResponse> backupAndDownload, Function<RestClient, RestResponse> delete, BiFunction<File, RestClient, RestResponse> restore, Consumer<RestClient> assertTargetContent, boolean syncToServer) throws Exception {
// Start the source cluster
startSourceCluster();
RestClient client = source.getClient();
// Populate the source container
populateContainer(client);
// Perform the backup and download
RestResponse getResponse = backupAndDownload.apply(client);
String fileName = getResponse.getHeader("Content-Disposition").split("=")[1];
// Delete the backup from the server
RestResponse deleteResponse = delete.apply(client);
assertEquals(204, deleteResponse.getStatus());
deleteResponse.close();
// Ensure that all of the backup files have been deleted from the source cluster
// We must wait for a short period time here to ensure that the returned entity has actually been removed from the filesystem
Thread.sleep(50);
assertNoServerBackupFilesExist(source);
// Shutdown the source cluster
stopSourceCluster();
// Start the target cluster
startTargetCluster();
client = target.getClient();
// Copy the returned zip bytes to the local working dir
File backupZip = new File(WORKING_DIR, fileName);
try (InputStream is = getResponse.getBodyAsStream()) {
Files.copy(is, backupZip.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
getResponse.close();
if (syncToServer) {
backupZip = new File(target.driver.syncFilesToServer(0, backupZip.getAbsolutePath()));
}
// Upload the backup to the target cluster
RestResponse restoreResponse = restore.apply(backupZip, client);
assertEquals(restoreResponse.getBody(), 201, restoreResponse.getStatus());
restoreResponse.close();
// Assert that all content has been restored as expected, connecting to the second node in the cluster to ensure
// that configurations and caches are restored cluster-wide
assertTargetContent.accept(target.getClient(1));
// Ensure that the backup files have been deleted from the target cluster
assertNoServerBackupFilesExist(target);
stopTargetCluster();
}
use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.
the class RestServerResource method testEnv.
@Test
public void testEnv() {
RestClient client = SERVER_TEST.rest().create();
RestResponse restResponse = sync(client.server().env());
assertEquals(200, restResponse.getStatus());
Json infoNode = Json.read(restResponse.getBody());
Json osVersion = infoNode.at("os.version");
assertEquals(System.getProperty("os.version"), osVersion.asString());
}
use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.
the class RestServerResource method testInfo.
@Test
public void testInfo() {
RestClient client = SERVER_TEST.rest().create();
RestResponse restResponse = sync(client.server().info());
String body = restResponse.getBody();
assertEquals(200, restResponse.getStatus());
Json infoNode = Json.read(body);
assertNotNull(infoNode.at("version"));
}
use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.
the class RestServerResource method testThreads.
@Test
public void testThreads() {
RestClient client = SERVER_TEST.rest().create();
RestResponse restResponse = sync(client.server().threads());
String dump = restResponse.getBody();
assertEquals(200, restResponse.getStatus());
assertEquals(MediaType.TEXT_PLAIN, restResponse.contentType());
assertTrue(dump.contains("state=RUNNABLE"));
}
Aggregations