Search in sources :

Example 31 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class XSiteResourceTest method testBringAllCachesOnlineOffline.

@Test
public void testBringAllCachesOnlineOffline() {
    RestClient restClient = clientPerSite.get(LON);
    RestCacheManagerClient restCacheManagerClient = restClient.cacheManager(CACHE_MANAGER);
    assertSuccessful(restCacheManagerClient.takeOffline(SFO));
    Json json = jsonResponseBody(restCacheManagerClient.backupStatuses());
    assertEquals(json.at(SFO).at("status").asString(), "offline");
    assertSuccessful(restCacheManagerClient.bringBackupOnline(SFO));
    json = jsonResponseBody(restCacheManagerClient.backupStatuses());
    assertEquals(json.at(SFO).at("status").asString(), "online");
}
Also used : RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 32 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class XSiteResourceTest method testInvalidSite.

@Test
public void testInvalidSite() {
    RestClient client = clientPerSite.get(LON);
    RestCacheClient cache = client.cache(CACHE_1);
    assertStatus(404, cache.backupStatus("invalid-site"));
}
Also used : RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 33 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class XSiteResourceTest method testPushAllCaches.

@Test
public void testPushAllCaches() {
    RestClient restClientLon = clientPerSite.get(LON);
    RestClient restClientSfo = clientPerSite.get(SFO);
    RestCacheClient cache1Lon = restClientLon.cache(CACHE_1);
    RestCacheClient cache2Lon = restClientLon.cache(CACHE_2);
    RestCacheClient cache1Sfo = restClientSfo.cache(CACHE_1);
    RestCacheClient cache2Sfo = restClientSfo.cache(CACHE_2);
    // Take SFO offline for all caches
    assertSuccessful(restClientLon.cacheManager(CACHE_MANAGER).takeOffline(SFO));
    Json backupStatuses = jsonResponseBody(restClientLon.cacheManager(CACHE_MANAGER).backupStatuses());
    assertEquals("offline", backupStatuses.at(SFO).at("status").asString());
    // Write to the caches
    int entries = 10;
    IntStream.range(0, entries).forEach(i -> {
        String key = String.valueOf(i);
        String value = "value";
        assertNoContent(cache1Lon.put(key, value));
        assertNoContent(cache2Lon.put(key, value));
    });
    // Backups should be empty
    assertEquals(0, getCacheSize(cache1Sfo));
    assertEquals(0, getCacheSize(cache2Sfo));
    // Start state push
    assertSuccessful(restClientLon.cacheManager(CACHE_MANAGER).pushSiteState(SFO));
    // Backups go online online immediately
    assertEquals(ONLINE, getBackupStatus(LON, SFO));
    // State push should eventually finish
    eventuallyEquals("OK", () -> pushStateStatus(cache1Lon, SFO));
    eventuallyEquals("OK", () -> pushStateStatus(cache2Lon, SFO));
    // ... and with state
    assertEquals(entries, getCacheSize(cache1Sfo));
    assertEquals(entries, getCacheSize(cache2Sfo));
}
Also used : RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 34 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class XSiteResourceTest method testInvalidInputTakeOffline.

@Test
public void testInvalidInputTakeOffline() {
    RestClient restClient = clientPerSite.get(LON);
    String url = String.format("/rest/v2/caches/%s/x-site/backups/%s/take-offline-config", CACHE_1, NYC);
    assertStatus(400, restClient.raw().putValue(url, new HashMap<>(), "invalid", "application/json"));
}
Also used : HashMap(java.util.HashMap) RestClient(org.infinispan.client.rest.RestClient) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 35 with RestClient

use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.

the class XSiteResourceTest method testInvalidCache.

@Test
public void testInvalidCache() {
    RestClient client = clientPerSite.get(LON);
    assertStatus(404, client.cache("invalid-cache").xsiteBackups());
}
Also used : RestClient(org.infinispan.client.rest.RestClient) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

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