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);
}
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;
}
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);
}
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);
}
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));
}
}
Aggregations