Search in sources :

Example 56 with RestCacheClient

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

the class AbstractMultiClusterIT method addSchema.

protected void addSchema(RestClient client) {
    RestCacheClient cache = client.cache(PROTOBUF_METADATA_CACHE_NAME);
    RestResponse response = join(cache.put("schema.proto", "message Person {required string name = 1;}"));
    assertEquals(204, response.getStatus());
    RestResponse errorResponse = join(client.cache(PROTOBUF_METADATA_CACHE_NAME).get("schema.proto.errors"));
    assertEquals(404, errorResponse.getStatus());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 57 with RestCacheClient

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

the class BackupManagerIT method assertWildcardContent.

private void assertWildcardContent(RestClient client) {
    String cacheName = "cache1";
    RestCacheClient cache = client.cache(cacheName);
    assertEquals(Integer.toString(NUM_ENTRIES), await(cache.size()).getBody());
    for (int i = 0; i < NUM_ENTRIES; i++) {
        String index = String.valueOf(i);
        assertEquals("Val-" + index, join(cache.get(index)).getBody());
    }
    assertCounter(client, "weak-volatile", Element.WEAK_COUNTER, Storage.VOLATILE, 0);
    assertCounter(client, "weak-persistent", Element.WEAK_COUNTER, Storage.PERSISTENT, -100);
    assertCounter(client, "strong-volatile", Element.STRONG_COUNTER, Storage.VOLATILE, 50);
    assertCounter(client, "strong-persistent", Element.STRONG_COUNTER, Storage.PERSISTENT, 0);
    RestResponse rsp = await(client.schemas().get("schema.proto"));
    assertEquals(200, rsp.getStatus());
    assertTrue(rsp.getBody().contains("message Person"));
    rsp = await(client.tasks().list(RestTaskClient.ResultType.USER));
    assertEquals(200, rsp.getStatus());
    Json json = Json.read(rsp.getBody());
    assertTrue(json.isArray());
    List<Json> tasks = json.asJsonList();
    assertEquals(1, tasks.size());
    assertEquals("scripts/test.js", tasks.get(0).at("name").asString());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json)

Example 58 with RestCacheClient

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

the class BackupManagerIT method populateContainer.

private void populateContainer(RestClient client) throws Exception {
    String cacheName = "cache1";
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC);
    createCache(cacheName, builder, client);
    RestCacheClient cache = client.cache(cacheName);
    for (int i = 0; i < NUM_ENTRIES; i++) {
        join(cache.put(String.valueOf(i), "Val-" + i));
    }
    assertEquals(NUM_ENTRIES, getCacheSize(cacheName, client));
    createCounter("weak-volatile", Element.WEAK_COUNTER, Storage.VOLATILE, client, 0);
    createCounter("weak-persistent", Element.WEAK_COUNTER, Storage.PERSISTENT, client, -100);
    createCounter("strong-volatile", Element.STRONG_COUNTER, Storage.VOLATILE, client, 50);
    createCounter("strong-persistent", Element.STRONG_COUNTER, Storage.PERSISTENT, client, 0);
    addSchema(client);
    try (InputStream is = BackupManagerIT.class.getResourceAsStream("/scripts/test.js")) {
        String script = CommonsTestingUtil.loadFileAsString(is);
        RestResponse rsp = await(client.tasks().uploadScript("scripts/test.js", RestEntity.create(MediaType.APPLICATION_JAVASCRIPT, script)));
        assertEquals(200, rsp.getStatus());
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) InputStream(java.io.InputStream) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 59 with RestCacheClient

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

the class RollingUpgradeDynamicStoreIT method connectTargetCluster.

protected void connectTargetCluster() throws IOException {
    RestCacheClient client = target.getClient().cache(CACHE_NAME);
    ConfigurationBuilder builder = new ConfigurationBuilder();
    addRemoteStore(builder);
    RemoteStoreConfiguration remoteStore = (RemoteStoreConfiguration) builder.build().persistence().stores().iterator().next();
    RestEntity restEntity = RestEntity.create(MediaType.APPLICATION_JSON, SerializationUtils.toJson(remoteStore));
    RestResponse response = join(client.connectSource(restEntity));
    assertEquals(response.getBody(), 204, response.getStatus());
    response = join(client.sourceConnection());
    RemoteStoreConfiguration remoteStoreConfiguration = SerializationUtils.fromJson(response.getBody());
    List<RemoteServerConfiguration> servers = remoteStoreConfiguration.servers();
    assertEquals(1, servers.size());
    RemoteServerConfiguration initialConfig = remoteStore.servers().iterator().next();
    assertEquals(initialConfig.host(), servers.get(0).host());
    assertEquals(initialConfig.port(), servers.get(0).port());
}
Also used : RemoteServerConfiguration(org.infinispan.persistence.remote.configuration.RemoteServerConfiguration) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RemoteStoreConfiguration(org.infinispan.persistence.remote.configuration.RemoteStoreConfiguration) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 60 with RestCacheClient

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

the class RollingUpgradeIT method populateCluster.

public void populateCluster(RestClient client) {
    RestCacheClient cache = client.cache(CACHE_NAME);
    for (int i = 0; i < ENTRIES; i++) {
        String person = createPerson("name-" + i);
        join(cache.put(String.valueOf(i), person));
    }
    assertEquals(ENTRIES, getCacheSize(CACHE_NAME, client));
}
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