Search in sources :

Example 31 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class Http2Test method shouldUseHTTP1.

@Test
public void shouldUseHTTP1() {
    restServer = RestServerHelper.defaultRestServer().start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort()).protocol(HTTP_11);
    client = RestClient.forConfiguration(builder.build());
    CompletionStage<RestResponse> response = client.cacheManager("default").info();
    ResponseAssertion.assertThat(response).isOk();
    RestEntity value = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "test".getBytes(CharsetUtil.UTF_8));
    response = client.cache("defaultcache").put("test", value);
    Assertions.assertThat(join(response).getStatus()).isEqualTo(204);
    Assertions.assertThat(restServer.getCacheManager().getCache().size()).isEqualTo(1);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 32 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class EndpointInteroperabilityTest method setup.

@BeforeClass
protected void setup() throws Exception {
    cacheManager = TestCacheManagerFactory.createServerModeCacheManager();
    cacheManager.defineConfiguration(DEFAULT_CACHE_NAME, getDefaultCacheConfiguration().build());
    cacheManager.defineConfiguration(MARSHALLED_CACHE_NAME, getMarshalledCacheConfiguration().build());
    cacheManager.defineConfiguration(STRING_CACHE_NAME, getStringsCacheConfiguration().build());
    RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder();
    builder.port(findFreePort());
    restServer = new RestServer();
    restServer.setServerManagement(new DummyServerManagement(), true);
    restServer.start(builder.build(), cacheManager);
    RestClientConfigurationBuilder clientBuilder = new RestClientConfigurationBuilder();
    RestClientConfiguration configuration = clientBuilder.addServer().host(restServer.getHost()).port(restServer.getPort()).build();
    restClient = RestClient.forConfiguration(configuration);
    HotRodServerConfigurationBuilder serverBuilder = new HotRodServerConfigurationBuilder();
    serverBuilder.adminOperationsHandler(new EmbeddedServerAdminOperationHandler());
    hotRodServer = startHotRodServer(cacheManager, serverBuilder);
    defaultRemoteCache = createRemoteCacheManager(IdentityMarshaller.INSTANCE).getCache(DEFAULT_CACHE_NAME);
    defaultMarshalledRemoteCache = createRemoteCacheManager(null).getCache(MARSHALLED_CACHE_NAME);
    stringRemoteCache = createRemoteCacheManager(new UTF8StringMarshaller()).getCache(STRING_CACHE_NAME);
}
Also used : RestServer(org.infinispan.rest.RestServer) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) EmbeddedServerAdminOperationHandler(org.infinispan.server.core.admin.embeddedserver.EmbeddedServerAdminOperationHandler) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DummyServerManagement(org.infinispan.server.core.DummyServerManagement) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder) BeforeClass(org.testng.annotations.BeforeClass)

Example 33 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class EndpointsCacheFactory method createRestCache.

private void createRestCache() {
    RestServer restServer = startProtocolServer(findFreePort(), p -> {
        RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder();
        builder.port(p);
        rest = new RestServer();
        rest.setServerManagement(new DummyServerManagement(), true);
        rest.start(builder.build(), cacheManager);
        return rest;
    });
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort());
    restClient = RestClient.forConfiguration(builder.build());
    restCacheClient = restClient.cache(cacheName);
}
Also used : RestServer(org.infinispan.rest.RestServer) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) DummyServerManagement(org.infinispan.server.core.DummyServerManagement)

Example 34 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class HttpBenchmark method setup.

@Setup
public void setup() {
    RestURI uri = RestURI.create(this.uri);
    RestClientConfigurationBuilder builder = uri.toConfigurationBuilder();
    client = RestClient.forConfiguration(builder.build());
    cache = client.cache(cacheName);
    try (RestResponse response = uncheckedAwait(cache.exists())) {
        switch(response.getStatus()) {
            case RestResponse.OK:
            case RestResponse.NO_CONTENT:
                break;
            case RestResponse.NOT_FOUND:
                Util.close(client);
                throw new IllegalArgumentException("Could not find cache '" + cacheName + "'");
            case RestResponse.UNAUTHORIZED:
                Util.close(client);
                throw new SecurityException(response.getBody());
            default:
                Util.close(client);
                throw new RuntimeException(response.getBody());
        }
    }
    value = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, new byte[valueSize]);
    keySet = new ArrayList<>(keySetSize);
    // We always use the same seed to make things repeatable
    Random r = new Random(17);
    byte[] keyBytes = new byte[keySize / 2];
    for (int i = 0; i < keySetSize; i++) {
        r.nextBytes(keyBytes);
        String key = Util.toHexString(keyBytes);
        keySet.add(key);
        cache.put(key, value);
    }
    nextIndex = new AtomicInteger();
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RestResponse(org.infinispan.client.rest.RestResponse) RestURI(org.infinispan.client.rest.RestURI) Setup(org.openjdk.jmh.annotations.Setup)

Example 35 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class BaseJsonTest method setup.

@BeforeClass
protected void setup() throws Exception {
    cacheManager = TestCacheManagerFactory.createServerModeCacheManager(EndpointITSCI.INSTANCE, new ConfigurationBuilder());
    cacheManager.getClassWhiteList().addRegexps(".*");
    cacheManager.defineConfiguration(CACHE_NAME, getIndexCacheConfiguration().build());
    RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder();
    int restPort = findFreePort();
    builder.port(restPort);
    restServer = new RestServer();
    restServer.setServerManagement(new DummyServerManagement(), true);
    restServer.start(builder.build(), cacheManager);
    restClient = RestClient.forConfiguration(new RestClientConfigurationBuilder().addServer().host(restServer.getHost()).port(restServer.getPort()).build());
    restCacheClient = restClient.cache(CACHE_NAME);
    hotRodServer = startHotRodServer(cacheManager);
    remoteCacheManager = createRemoteCacheManager();
    remoteCache = remoteCacheManager.getCache(CACHE_NAME);
}
Also used : RestServer(org.infinispan.rest.RestServer) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) DummyServerManagement(org.infinispan.server.core.DummyServerManagement) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)56 Test (org.junit.Test)26 RestClient (org.infinispan.client.rest.RestClient)25 RestResponse (org.infinispan.client.rest.RestResponse)22 RestClientConfiguration (org.infinispan.client.rest.configuration.RestClientConfiguration)8 RestServerHelper (org.infinispan.rest.helper.RestServerHelper)6 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)5 InetSocketAddress (java.net.InetSocketAddress)4 RestCacheClient (org.infinispan.client.rest.RestCacheClient)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 RestServer (org.infinispan.rest.RestServer)4 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)4 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)4 DummyServerManagement (org.infinispan.server.core.DummyServerManagement)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RestEntity (org.infinispan.client.rest.RestEntity)3 Json (org.infinispan.commons.dataconversion.internal.Json)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 Router (org.infinispan.server.router.Router)3