Search in sources :

Example 41 with RestClient

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());
}
Also used : RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 42 with RestClient

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();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) InputStream(java.io.InputStream) RestClient(org.infinispan.client.rest.RestClient) File(java.io.File)

Example 43 with RestClient

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());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.junit.Test)

Example 44 with RestClient

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"));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.junit.Test)

Example 45 with RestClient

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"));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Aggregations

RestClient (org.infinispan.client.rest.RestClient)65 Test (org.junit.Test)41 RestResponse (org.infinispan.client.rest.RestResponse)37 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)26 Json (org.infinispan.commons.dataconversion.internal.Json)15 RestCacheClient (org.infinispan.client.rest.RestCacheClient)11 Test (org.testng.annotations.Test)10 IOException (java.io.IOException)6 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)6 ArrayList (java.util.ArrayList)4 RestServerHelper (org.infinispan.rest.helper.RestServerHelper)4 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)4 InetSocketAddress (java.net.InetSocketAddress)3 List (java.util.List)3 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)3 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 TestUser (org.infinispan.server.test.api.TestUser)3 File (java.io.File)2 UncheckedIOException (java.io.UncheckedIOException)2