Search in sources :

Example 26 with HttpClientFactory

use of com.linkedin.r2.transport.http.client.HttpClientFactory in project voldemort by voldemort.

the class RestServerAPITest method oneTimeSetUp.

@BeforeClass
public static void oneTimeSetUp() {
    voldemortConfig = VoldemortConfig.loadFromVoldemortHome("config/single_node_rest_server/");
    key = new ByteArray("key1".getBytes());
    vectorClock = new VectorClock();
    vectorClock.incrementVersion(voldemortConfig.getNodeId(), System.currentTimeMillis());
    value = new Versioned<byte[]>("value1".getBytes(), vectorClock);
    server = new VoldemortServer(voldemortConfig);
    if (!server.isStarted())
        server.start();
    logger.info("********************Starting REST Server********************");
    restClientConfig = new RESTClientConfig();
    restClientConfig.setHttpBootstrapURL("http://localhost:8085").setTimeoutMs(1500, TimeUnit.MILLISECONDS).setMaxR2ConnectionPoolSize(100);
    clientFactory = new HttpClientFactory();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(HttpClientFactory.HTTP_POOL_SIZE, Integer.toString(restClientConfig.getMaxR2ConnectionPoolSize()));
    transportClient = clientFactory.getClient(properties);
    r2store = new R2Store("test", restClientConfig.getHttpBootstrapURL(), "2", transportClient, restClientConfig, 0);
    store = r2store;
    deleteCreatedKeys(key);
}
Also used : RESTClientConfig(voldemort.restclient.RESTClientConfig) HashMap(java.util.HashMap) VectorClock(voldemort.versioning.VectorClock) R2Store(voldemort.restclient.R2Store) ByteArray(voldemort.utils.ByteArray) VoldemortServer(voldemort.server.VoldemortServer) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) BeforeClass(org.junit.BeforeClass)

Example 27 with HttpClientFactory

use of com.linkedin.r2.transport.http.client.HttpClientFactory in project voldemort by voldemort.

the class RestServiceR2StoreTest method setUp.

@Override
@Before
public void setUp() throws IOException {
    logger.info(" Initial SEED used for random number generator: " + TestUtils.SEED);
    final int numServers = 1;
    this.nodeId = 0;
    servers = new VoldemortServer[numServers];
    // Setup the cluster
    Properties props = new Properties();
    props.setProperty("rest.enable", "true");
    props.setProperty("http.enable", "true");
    Cluster customCluster = clusterMapper.readCluster(new FileReader(clusterXmlFile), false);
    logger.info(" Node " + customCluster.getNodes().iterator().next().getStateString());
    cluster = ServerTestUtils.startVoldemortCluster(servers, null, clusterXmlFile, storesXmlfile, props, customCluster);
    // Creating R2Store
    RESTClientConfig restClientConfig = new RESTClientConfig();
    restClientConfig.setHttpBootstrapURL("http://localhost:" + cluster.getNodeById(0).getRestPort()).setTimeoutMs(10000, TimeUnit.MILLISECONDS).setMaxR2ConnectionPoolSize(100);
    clientFactory = new HttpClientFactory();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(HttpClientFactory.HTTP_POOL_SIZE, Integer.toString(restClientConfig.getMaxR2ConnectionPoolSize()));
    TransportClient transportClient = clientFactory.getClient(properties);
    R2Store r2Store = new R2Store(STORE_NAME, restClientConfig.getHttpBootstrapURL(), "0", transportClient, restClientConfig, 0);
    store = r2Store;
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) RESTClientConfig(voldemort.restclient.RESTClientConfig) HashMap(java.util.HashMap) R2Store(voldemort.restclient.R2Store) Cluster(voldemort.cluster.Cluster) FileReader(java.io.FileReader) Properties(java.util.Properties) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) Before(org.junit.Before)

Example 28 with HttpClientFactory

use of com.linkedin.r2.transport.http.client.HttpClientFactory in project rest.li by linkedin.

the class RestLiIntegrationTest method initClient.

private void initClient(String uriPrefix) {
    _clientFactory = new HttpClientFactory();
    _transportClients = new ArrayList<Client>();
    Client client = newTransportClient(Collections.<String, String>emptyMap());
    _restClient = new RestClient(client, uriPrefix);
}
Also used : RestClient(com.linkedin.restli.client.RestClient) RestClient(com.linkedin.restli.client.RestClient) Client(com.linkedin.r2.transport.common.Client) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory)

Example 29 with HttpClientFactory

use of com.linkedin.r2.transport.http.client.HttpClientFactory in project rest.li by linkedin.

the class MockLBFactory method createLoadBalancer.

static SimpleLoadBalancer createLoadBalancer() {
    // define the load balancing strategies that we support (round robin, etc)
    Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>>();
    loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV3());
    Map<String, TransportClientFactory> clientFactories = new HashMap<String, TransportClientFactory>();
    clientFactories.put("http", new HttpClientFactory());
    SynchronousExecutorService executorService = new SynchronousExecutorService();
    MockStore<ServiceProperties> serviceRegistry = new MockStore<ServiceProperties>();
    MockStore<ClusterProperties> clusterRegistry = new MockStore<ClusterProperties>();
    MockStore<UriProperties> uriRegistry = new MockStore<UriProperties>();
    SimpleLoadBalancerState state = new SimpleLoadBalancerState(executorService, uriRegistry, clusterRegistry, serviceRegistry, clientFactories, loadBalancerStrategyFactories);
    state.listenToService("greetings", new LoadBalancerState.NullStateListenerCallback());
    state.listenToService("groups", new LoadBalancerState.NullStateListenerCallback());
    state.listenToCluster("testcluster", new LoadBalancerState.NullStateListenerCallback());
    state.listenToCluster("badcluster", new LoadBalancerState.NullStateListenerCallback());
    List<String> schemes = new ArrayList<String>();
    schemes.add("http");
    Map<String, Object> metadataProperties = new HashMap<String, Object>();
    metadataProperties.put(RestConstants.RESTLI_PROTOCOL_VERSION_PROPERTY, AllProtocolVersions.BASELINE_PROTOCOL_VERSION.toString());
    serviceRegistry.put("greetings", new ServiceProperties("greetings", "testcluster", "/greetings", Arrays.asList("degrader"), Collections.<String, Object>emptyMap(), null, null, schemes, null, metadataProperties));
    serviceRegistry.put("groups", new ServiceProperties("groups", "badcluster", "/groups", Arrays.asList("degrader"), Collections.<String, Object>emptyMap(), null, null, schemes, null, metadataProperties));
    clusterRegistry.put("testcluster", new ClusterProperties("testcluster"));
    clusterRegistry.put("badcluster", new ClusterProperties("badcluster"));
    uriRegistry.put("testcluster", new UriProperties("testcluster", createUriData("http://localhost:1338")));
    uriRegistry.put("badcluster", new UriProperties("badcluster", createUriData("http://localhost:1337")));
    // create the load balancer
    return new SimpleLoadBalancer(state);
}
Also used : HashMap(java.util.HashMap) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) ArrayList(java.util.ArrayList) SimpleLoadBalancerState(com.linkedin.d2.balancer.simple.SimpleLoadBalancerState) LoadBalancerState(com.linkedin.d2.balancer.LoadBalancerState) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) SynchronousExecutorService(com.linkedin.d2.discovery.event.SynchronousExecutorService) SimpleLoadBalancerState(com.linkedin.d2.balancer.simple.SimpleLoadBalancerState) SimpleLoadBalancer(com.linkedin.d2.balancer.simple.SimpleLoadBalancer) LoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 30 with HttpClientFactory

use of com.linkedin.r2.transport.http.client.HttpClientFactory in project rest.li by linkedin.

the class TestResponseCompression method testResponseCompression.

@Test(dataProvider = "requestData")
public void testResponseCompression(Boolean useResponseCompression, CompressionConfig responseCompressionConfig, RestliRequestOptions restliRequestOptions, int idCount, String expectedAcceptEncoding, String expectedCompressionThreshold, boolean responseShouldBeCompressed) throws RemoteInvocationException, CloneNotSupportedException {
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("R2 Netty Scheduler"));
    Map<String, CompressionConfig> responseCompressionConfigs = new HashMap<String, CompressionConfig>();
    if (responseCompressionConfig != null) {
        responseCompressionConfigs.put(SERVICE_NAME, responseCompressionConfig);
    }
    HttpClientFactory httpClientFactory = new HttpClientFactory(FilterChains.empty(), new NioEventLoopGroup(0, /* use default settings */
    new NamedThreadFactory("R2 Nio Event Loop")), true, executor, true, executor, false, AbstractJmxManager.NULL_JMX_MANAGER, Integer.MAX_VALUE, Collections.<String, CompressionConfig>emptyMap(), responseCompressionConfigs, true);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(HttpClientFactory.HTTP_SERVICE_NAME, SERVICE_NAME);
    if (useResponseCompression != null) {
        properties.put(HttpClientFactory.HTTP_USE_RESPONSE_COMPRESSION, String.valueOf(useResponseCompression));
    }
    TransportClientAdapter clientAdapter1 = new TransportClientAdapter(httpClientFactory.getClient(properties));
    RestClient client = new RestClient(clientAdapter1, FILTERS_URI_PREFIX);
    Long[] ids = new Long[idCount];
    for (int i = 0; i < ids.length; i++) {
        ids[i] = (long) i;
    }
    BatchGetRequestBuilder<Long, Greeting> builder = new GreetingsBuilders(restliRequestOptions).batchGet().ids(Arrays.asList(ids)).setHeader(EXPECTED_ACCEPT_ENCODING, expectedAcceptEncoding);
    if (expectedCompressionThreshold != null) {
        builder.setHeader(EXPECTED_COMPRESSION_THRESHOLD, expectedCompressionThreshold);
    }
    Request<BatchResponse<Greeting>> request = builder.build();
    Response<BatchResponse<Greeting>> response = client.sendRequest(request).getResponse();
    if (responseShouldBeCompressed) {
        Assert.assertEquals(response.getHeader(TestCompressionServer.CONTENT_ENCODING_SAVED), EncodingType.GZIP.getHttpName());
    } else {
        Assert.assertNull(response.getHeader(TestCompressionServer.CONTENT_ENCODING_SAVED));
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HashMap(java.util.HashMap) NamedThreadFactory(com.linkedin.r2.util.NamedThreadFactory) BatchResponse(com.linkedin.restli.common.BatchResponse) RestClient(com.linkedin.restli.client.RestClient) GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) CompressionConfig(com.linkedin.r2.filter.CompressionConfig) Test(org.testng.annotations.Test)

Aggregations

HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)23 HashMap (java.util.HashMap)23 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)18 None (com.linkedin.common.util.None)15 Test (org.testng.annotations.Test)14 FutureCallback (com.linkedin.common.callback.FutureCallback)13 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)11 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)10 URI (java.net.URI)9 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)8 LoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory)8 DegraderLoadBalancerStrategyFactoryV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3)8 RestRequest (com.linkedin.r2.message.rest.RestRequest)8 Client (com.linkedin.r2.transport.common.Client)8 RequestContext (com.linkedin.r2.message.RequestContext)7 HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)7 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)7 ArrayList (java.util.ArrayList)7 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)6