Search in sources :

Example 21 with RestClient

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

the class RollingUpgradeIT method testRollingUpgrade.

@Test
public void testRollingUpgrade() throws Exception {
    RestClient restClientSource = source.getClient();
    RestClient restClientTarget = target.getClient();
    // Create cache in the source cluster
    createSourceClusterCache();
    // Create cache in the target cluster pointing to the source cluster via remote-store
    createTargetClusterCache();
    // Register proto schema
    addSchema(restClientSource);
    addSchema(restClientTarget);
    // Populate source cluster
    populateCluster(restClientSource);
    // Make sure data is accessible from the target cluster
    assertEquals("name-20", getPersonName("20", restClientTarget));
    // Do a rolling upgrade from the target
    doRollingUpgrade(restClientTarget);
    // Do a second rolling upgrade, should be harmless and simply override the data
    doRollingUpgrade(restClientTarget);
    // Disconnect source from the remote store
    disconnectSource(restClientTarget);
    // Stop source cluster
    stopSourceCluster();
    // Assert all nodes are disconnected and data was migrated successfully
    for (int i = 0; i < target.getMembers().size(); i++) {
        RestClient restClient = target.getClient(i);
        assertEquals(ENTRIES, getCacheSize(CACHE_NAME, restClient));
        assertEquals("name-35", getPersonName("35", restClient));
    }
}
Also used : RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 22 with RestClient

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

the class XSiteHotRodCacheOperations method getTotalMemoryEntries.

private int getTotalMemoryEntries(String lonXML) {
    RestClient restClient = SERVER_TEST.rest(LON).withServerConfiguration(new StringConfiguration(lonXML)).get();
    RestCacheClient client = restClient.cache(SERVER_TEST.getMethodName());
    Json json = Json.read(sync(client.stats()).getBody());
    return json.asJsonMap().get("current_number_of_entries_in_memory").asInteger();
}
Also used : StringConfiguration(org.infinispan.commons.configuration.StringConfiguration) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json)

Example 23 with RestClient

use of org.infinispan.client.rest.RestClient 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 24 with RestClient

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

the class XSiteResourceTest method startServers.

@BeforeClass
public void startServers() {
    sites.forEach(site -> {
        String siteName = site.getSiteName();
        EmbeddedCacheManager cm = site.cacheManagers().iterator().next();
        RestServerHelper restServerHelper = new RestServerHelper(cm);
        restServerHelper.start(TestResourceTracker.getCurrentTestShortName());
        restServerPerSite.put(siteName, restServerHelper);
        RestClientConfiguration clientConfig = new RestClientConfigurationBuilder().addServer().host("127.0.0.1").port(restServerHelper.getPort()).build();
        RestClient client = RestClient.forConfiguration(clientConfig);
        clientPerSite.put(siteName, client);
    });
}
Also used : RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) BeforeClass(org.testng.annotations.BeforeClass)

Example 25 with RestClient

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

the class RestAccessLoggingTest method setup.

@Override
protected void setup() throws Exception {
    super.setup();
    testShortName = TestResourceTracker.getCurrentTestShortName();
    logAppender = new StringLogAppender("org.infinispan.REST_ACCESS_LOG", Level.TRACE, t -> t.getName().startsWith("non-blocking-thread-" + testShortName), PatternLayout.newBuilder().withPattern(LOG_FORMAT).build());
    logAppender.install();
    restServer = new RestServerHelper(cacheManager);
    restServer.start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort());
    restClient = RestClient.forConfiguration(builder.create());
    cacheClient = restClient.cache("default");
}
Also used : CompletionStages.join(org.infinispan.util.concurrent.CompletionStages.join) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) TestResourceTracker(org.infinispan.commons.test.TestResourceTracker) Level(org.apache.logging.log4j.Level) RestClient(org.infinispan.client.rest.RestClient) Test(org.testng.annotations.Test) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) RestCacheClient(org.infinispan.client.rest.RestCacheClient) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) StringLogAppender(org.infinispan.commons.test.skip.StringLogAppender) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) StringLogAppender(org.infinispan.commons.test.skip.StringLogAppender) RestServerHelper(org.infinispan.rest.helper.RestServerHelper)

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