Search in sources :

Example 11 with RestCacheClient

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

the class XSiteResourceTest method testPushState.

@Test
public void testPushState() {
    RestCacheClient cache = getCacheClient(LON);
    RestCacheClient backupCache = getCacheClient(NYC);
    String key = "key";
    String value = "value";
    Function<String, Integer> keyOnBackup = k -> responseStatus(backupCache.get(key));
    takeBackupOffline(LON, NYC);
    assertEquals(OFFLINE, getBackupStatus(LON, NYC));
    assertEquals(ONLINE, getBackupStatus(LON, SFO));
    assertNoContent(cache.put(key, value));
    assertEquals(404, (int) keyOnBackup.apply(key));
    assertSuccessful(cache.pushSiteState(NYC));
    assertEquals(ONLINE, getBackupStatus(LON, NYC));
    eventuallyEquals("OK", () -> pushStateStatus(cache, NYC));
    assertEquals(200, responseStatus(backupCache.get(key)));
}
Also used : XSiteResponse(org.infinispan.remoting.transport.XSiteResponse) Arrays(java.util.Arrays) XSiteResponseImpl(org.infinispan.remoting.transport.impl.XSiteResponseImpl) RestResponses.assertSuccessful(org.infinispan.rest.helper.RestResponses.assertSuccessful) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) TimeoutException(java.util.concurrent.TimeoutException) RestClient(org.infinispan.client.rest.RestClient) Test(org.testng.annotations.Test) Cache(org.infinispan.Cache) AfterMethod(org.testng.annotations.AfterMethod) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) RestResponses.assertStatus(org.infinispan.rest.helper.RestResponses.assertStatus) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) EmbeddedCacheManagerAdmin(org.infinispan.manager.EmbeddedCacheManagerAdmin) Map(java.util.Map) ONLINE(org.infinispan.xsite.XSiteAdminOperations.ONLINE) TestingUtil(org.infinispan.test.TestingUtil) RestResponses.jsonResponseBody(org.infinispan.rest.helper.RestResponses.jsonResponseBody) XSiteBackup(org.infinispan.xsite.XSiteBackup) RestResponses.responseStatus(org.infinispan.rest.helper.RestResponses.responseStatus) BeforeClass(org.testng.annotations.BeforeClass) RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) List(java.util.List) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) GuardedBy(net.jcip.annotations.GuardedBy) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest) IntStream(java.util.stream.IntStream) TestResourceTracker(org.infinispan.commons.test.TestResourceTracker) RestResponses.responseBody(org.infinispan.rest.helper.RestResponses.responseBody) BackupConfiguration(org.infinispan.configuration.cache.BackupConfiguration) TestingUtil.wrapGlobalComponent(org.infinispan.test.TestingUtil.wrapGlobalComponent) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) VOLATILE(org.infinispan.commons.api.CacheContainerAdmin.AdminFlag.VOLATILE) TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager) TestingUtil.extractGlobalComponent(org.infinispan.test.TestingUtil.extractGlobalComponent) AfterClass(org.testng.annotations.AfterClass) Transport(org.infinispan.remoting.transport.Transport) XSiteReplicateCommand(org.infinispan.xsite.XSiteReplicateCommand) RestResponses.assertNoContent(org.infinispan.rest.helper.RestResponses.assertNoContent) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) XSiteStatePushCommand(org.infinispan.xsite.statetransfer.XSiteStatePushCommand) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) Json(org.infinispan.commons.dataconversion.internal.Json) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TimeUnit(java.util.concurrent.TimeUnit) RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) CacheMode(org.infinispan.configuration.cache.CacheMode) Configuration(org.infinispan.configuration.cache.Configuration) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) OFFLINE(org.infinispan.xsite.XSiteAdminOperations.OFFLINE) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 12 with RestCacheClient

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

the class XSiteResourceTest method testTakeOfflineConfig.

@Test
public void testTakeOfflineConfig() {
    RestCacheClient cacheClient = getCacheClient(LON);
    Json takeOfflineConfig = jsonResponseBody(cacheClient.getXSiteTakeOfflineConfig(NYC));
    assertEquals(0, takeOfflineConfig.at("after_failures").asInteger());
    assertEquals(0, takeOfflineConfig.at("min_wait").asInteger());
    assertNoContent(cacheClient.updateXSiteTakeOfflineConfig(NYC, 5, 1000));
    takeOfflineConfig = jsonResponseBody(cacheClient.getXSiteTakeOfflineConfig(NYC));
    assertEquals(5, takeOfflineConfig.at("after_failures").asInteger());
    assertEquals(1000, takeOfflineConfig.at("min_wait").asInteger());
}
Also used : RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 13 with RestCacheClient

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

the class XSiteResourceTest method testCancelPushAllCaches.

@Test
public void testCancelPushAllCaches() throws Exception {
    RestClient restClientLon = clientPerSite.get(LON);
    RestCacheClient cache1Lon = restClientLon.cache(CACHE_1);
    RestCacheClient cache2Lon = restClientLon.cache(CACHE_2);
    assertNoContent(cache1Lon.put("k1", "v1"));
    assertNoContent(cache2Lon.put("k2", "v2"));
    // Block before pushing state on both caches
    BlockXSitePushStateTransport transport = BlockXSitePushStateTransport.replace(cache(LON, CACHE_1, 0));
    transport.startBlocking();
    // Trigger a state push
    assertSuccessful(restClientLon.cacheManager(CACHE_MANAGER).pushSiteState(SFO));
    transport.waitForCommand();
    // Cancel state push
    assertSuccessful(restClientLon.cacheManager(CACHE_MANAGER).cancelPushState(SFO));
    transport.stopBlocking();
    // Verify that push was cancelled for both caches
    Json pushStatusCache1 = jsonResponseBody(cache1Lon.pushStateStatus());
    Json pushStatusCache2 = jsonResponseBody(cache2Lon.pushStateStatus());
    assertEquals("CANCELED", pushStatusCache1.at(SFO).asString());
    assertEquals("CANCELED", pushStatusCache2.at(SFO).asString());
}
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 14 with RestCacheClient

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

the class XSiteResourceTest method testBackups.

@Test
public void testBackups() {
    RestCacheClient cache = getCacheClient(LON);
    Json status = jsonResponseBody(cache.xsiteBackups());
    assertEquals(ONLINE, status.at(NYC).at("status").asString());
    // add a second node
    TestSite site = site(LON);
    EmbeddedCacheManager cm = site.addCacheManager(null, defaultGlobalConfigurationForSite(site.getSiteIndex()), defaultConfigurationForSite(site.getSiteIndex()), false);
    site.waitForClusterToForm(CACHE_1);
    site.waitForClusterToForm(CACHE_2);
    TakeOfflineManager takeOfflineManager = TestingUtil.extractComponent(cm.getCache(CACHE_1), TakeOfflineManager.class);
    takeOfflineManager.takeSiteOffline(NYC);
    String node1 = String.valueOf(site.cacheManagers().get(0).getAddress());
    String node2 = String.valueOf(cm.getAddress());
    status = jsonResponseBody(cache.xsiteBackups());
    assertEquals("mixed", status.at(NYC).at("status").asString());
    assertEquals(status.at(NYC).at("online").asJsonList().iterator().next().asString(), node1);
    assertEquals(status.at(NYC).at("offline").asJsonList().iterator().next().asString(), node2);
    assertFalse(status.at(NYC).has("mixed"));
    status = jsonResponseBody(cache.backupStatus(NYC));
    assertEquals(ONLINE, status.at(node1).asString());
    assertEquals(OFFLINE, status.at(node2).asString());
    // bring NYC online
    takeOfflineManager.bringSiteOnline(NYC);
    status = jsonResponseBody(cache.xsiteBackups());
    assertEquals(ONLINE, status.at(NYC).at("status").asString());
    status = jsonResponseBody(cache.backupStatus(NYC));
    assertEquals(ONLINE, status.at(node1).asString());
    assertEquals(ONLINE, status.at(node2).asString());
}
Also used : RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 15 with RestCacheClient

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

the class XSiteResourceTest method takeBackupOffline.

private void takeBackupOffline(String site, String backup) {
    RestCacheClient client = getCacheClient(site);
    assertSuccessful(client.takeSiteOffline(backup));
}
Also used : RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Aggregations

RestCacheClient (org.infinispan.client.rest.RestCacheClient)66 RestResponse (org.infinispan.client.rest.RestResponse)41 Test (org.testng.annotations.Test)34 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)16 RestEntity (org.infinispan.client.rest.RestEntity)14 Json (org.infinispan.commons.dataconversion.internal.Json)13 RestClient (org.infinispan.client.rest.RestClient)11 Test (org.junit.Test)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 TestClass (org.infinispan.rest.TestClass)5 TestUser (org.infinispan.server.test.api.TestUser)5 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 HashMap (java.util.HashMap)2 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)2 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2