Search in sources :

Example 1 with RestClient

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

the class ForkedInfinispanServerDriver method getRestClient.

private RestClient getRestClient(int server) {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    // Filter driver properties for REST client configuration properties, e.g. security configuration
    // and apply them before applying rest of the dynamically created configuration, e.g. port.
    Properties securityConfigurationProperties = new Properties();
    configuration.properties().entrySet().stream().filter(entry -> entry.getKey().toString().startsWith("infinispan.client.rest.")).forEach(entry -> securityConfigurationProperties.put(entry.getKey(), entry.getValue()));
    builder.withProperties(securityConfigurationProperties);
    // Ensure to not print out the *values*!!!
    log.debugf("Configured client with the following properties: %s", securityConfigurationProperties.keySet().toString());
    builder.addServer().host("localhost").port(getServerPort(server, ForkedServer.DEFAULT_SINGLE_PORT));
    return RestClient.forConfiguration(builder.build());
}
Also used : RestClient(org.infinispan.client.rest.RestClient) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) Server(org.infinispan.server.Server) ConnectException(java.net.ConnectException) Path(java.nio.file.Path) Properties(java.util.Properties) MBeanServerConnection(javax.management.MBeanServerConnection) Log(org.infinispan.commons.logging.Log) RestResponse(org.infinispan.client.rest.RestResponse) Files(java.nio.file.Files) Util(org.infinispan.commons.util.Util) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Paths(java.nio.file.Paths) Exceptions(org.infinispan.commons.test.Exceptions) CommonsTestingUtil(org.infinispan.commons.test.CommonsTestingUtil) OS(org.infinispan.commons.util.OS) LogFactory(org.infinispan.commons.logging.LogFactory) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) Properties(java.util.Properties)

Example 2 with RestClient

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

the class IgnoreCaches method testIgnoreCaches.

@Test
public void testIgnoreCaches() {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
    String testCache = SERVER_TEST.getMethodName();
    assertTrue(getIgnoredCaches(client, CACHE_MANAGER).isEmpty());
    assertCacheResponse(client, testCache, 404);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 404);
    ignoreCache(client, testCache);
    assertEquals(singleton(testCache), getIgnoredCaches(client, CACHE_MANAGER));
    assertCacheResponse(client, testCache, 503);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 404);
    ignoreCache(client, PROTOBUF_METADATA_CACHE_NAME);
    assertEquals(asSet(testCache, PROTOBUF_METADATA_CACHE_NAME), getIgnoredCaches(client, CACHE_MANAGER));
    assertCacheResponse(client, testCache, 503);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 503);
    unIgnoreCache(client, testCache);
    assertEquals(singleton(PROTOBUF_METADATA_CACHE_NAME), getIgnoredCaches(client, CACHE_MANAGER));
    assertCacheResponse(client, testCache, 404);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 503);
    unIgnoreCache(client, PROTOBUF_METADATA_CACHE_NAME);
    assertTrue(getIgnoredCaches(client, CACHE_MANAGER).isEmpty());
    assertCacheResponse(client, testCache, 404);
    assertCacheResponse(client, PROTOBUF_METADATA_CACHE_NAME, 404);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 3 with RestClient

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

the class RestLoggingResource method testManipulateLogger.

@Test
public void testManipulateLogger() {
    RestClient client = SERVER_TEST.rest().create();
    // Create the logger
    RestResponse response = sync(client.server().logging().setLogger("org.infinispan.TESTLOGGER", "WARN", "STDOUT"));
    assertEquals(204, response.getStatus());
    response = sync(client.server().logging().listLoggers());
    assertTrue("Logger not found", findLogger(response, "org.infinispan.TESTLOGGER", "WARN", "STDOUT"));
    // Update it
    response = sync(client.server().logging().setLogger("org.infinispan.TESTLOGGER", "ERROR", "FILE"));
    assertEquals(204, response.getStatus());
    response = sync(client.server().logging().listLoggers());
    assertTrue("Logger not found", findLogger(response, "org.infinispan.TESTLOGGER", "ERROR", "FILE"));
    // Remove it
    response = sync(client.server().logging().removeLogger("org.infinispan.TESTLOGGER"));
    assertEquals(204, response.getStatus());
    response = sync(client.server().logging().listLoggers());
    assertFalse("Logger should not be found", findLogger(response, "org.infinispan.TESTLOGGER", "ERROR"));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 4 with RestClient

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

the class RestLoggingResource method testListAppenders.

@Test
public void testListAppenders() {
    RestClient client = SERVER_TEST.rest().create();
    RestResponse response = sync(client.server().logging().listAppenders());
    String body = response.getBody();
    Json appenders = Json.read(body);
    assertEquals(body, 5, appenders.asMap().size());
}
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 5 with RestClient

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

the class RestLoggingResource method testListLoggers.

@Test
public void testListLoggers() {
    RestClient client = SERVER_TEST.rest().create();
    RestResponse response = sync(client.server().logging().listLoggers());
    Json loggers = Json.read(response.getBody());
    assertTrue(loggers.asJsonList().size() > 0);
}
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)

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