use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.
the class ConfigurationTest method shouldBuildProperRouterConfiguration.
@Test
public void shouldBuildProperRouterConfiguration() {
// given
RouterConfigurationBuilder multiTenantConfigurationBuilder = new RouterConfigurationBuilder();
RouteSource s1 = new RouteSource() {
};
RouteDestination d1 = () -> null;
// when
multiTenantConfigurationBuilder.hotrod().tcpKeepAlive(true).receiveBufferSize(1).sendBufferSize(1).tcpNoDelay(false).port(1010).ip(InetAddress.getLoopbackAddress()).rest().port(1111).ip(InetAddress.getLoopbackAddress()).routing().add(new Route(s1, d1));
RouterConfiguration routerConfiguration = multiTenantConfigurationBuilder.build();
HotRodRouterConfiguration hotRodRouterConfiguration = routerConfiguration.hotRodRouter();
RestRouterConfiguration restRouterConfiguration = routerConfiguration.restRouter();
// then
assertThat(hotRodRouterConfiguration.getPort()).isEqualTo(1010);
assertThat(hotRodRouterConfiguration.getIp()).isEqualTo(InetAddress.getLoopbackAddress());
assertThat(hotRodRouterConfiguration.tcpKeepAlive()).isTrue();
assertThat(hotRodRouterConfiguration.tcpNoDelay()).isFalse();
assertThat(hotRodRouterConfiguration.sendBufferSize()).isEqualTo(1);
assertThat(hotRodRouterConfiguration.receiveBufferSize()).isEqualTo(1);
assertThat(restRouterConfiguration.getPort()).isEqualTo(1111);
assertThat(restRouterConfiguration.getIp()).isEqualTo(InetAddress.getLoopbackAddress());
assertThat(routerConfiguration.routingTable().routesCount()).isEqualTo(1);
}
use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.
the class ProtocolServerEndpointRouterTest method shouldRouteToProperHotRodServerBasedOnSniHostName.
/**
* In this scenario we create 2 HotRod servers, each one with different credentials and SNI name. We also create a
* new client for each server. The clients use proper TrustStores as well as SNI names.
* <p>
* The router should match properly SNI based routes and connect clients to proper server instances.
*/
@Test
public void shouldRouteToProperHotRodServerBasedOnSniHostName() {
// given
hotrodServer1 = HotRodTestingUtil.startHotRodServerWithoutTransport("default");
hotrodServer2 = HotRodTestingUtil.startHotRodServerWithoutTransport("default");
HotRodServerRouteDestination hotrod1Destination = new HotRodServerRouteDestination("HotRod1", hotrodServer1);
SniNettyRouteSource hotrod1Source = new SniNettyRouteSource("hotrod1", KEYSTORE_LOCATION_FOR_HOTROD_1, "secret".toCharArray());
Route<SniNettyRouteSource, HotRodServerRouteDestination> routeToHotrod1 = new Route<>(hotrod1Source, hotrod1Destination);
HotRodServerRouteDestination hotrod2Destination = new HotRodServerRouteDestination("HotRod2", hotrodServer2);
SniNettyRouteSource hotrod2Source = new SniNettyRouteSource("hotrod2", KEYSTORE_LOCATION_FOR_HOTROD_2, "secret".toCharArray());
Route<SniNettyRouteSource, HotRodServerRouteDestination> routeToHotrod2 = new Route<>(hotrod2Source, hotrod2Destination);
RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
routerConfigurationBuilder.hotrod().port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToHotrod1).add(routeToHotrod2);
router = new Router(routerConfigurationBuilder.build());
router.start();
InetAddress routerIp = router.getRouter(EndpointRouter.Protocol.HOT_ROD).get().getIp();
int routerPort = router.getRouter(EndpointRouter.Protocol.HOT_ROD).get().getPort();
// when
hotrod1Client = HotRodClientTestingUtil.createWithSni(routerIp, routerPort, "hotrod1", TRUSTSTORE_LOCATION_FOR_HOTROD_1, "secret".toCharArray());
hotrod2Client = HotRodClientTestingUtil.createWithSni(routerIp, routerPort, "hotrod2", TRUSTSTORE_LOCATION_FOR_HOTROD_2, "secret".toCharArray());
hotrod1Client.getCache("default").put("test", "hotrod1");
hotrod2Client.getCache("default").put("test", "hotrod2");
// then
Cache<String, String> hotrod1Cache = hotrodServer1.getCacheManager().getCache("default");
Cache<String, String> hotrod2Cache = hotrodServer2.getCacheManager().getCache("default");
assertThat(hotrod1Cache.size()).isEqualTo(1);
assertThat(hotrod2Cache.size()).isEqualTo(1);
assertThat(hotrod1Cache.get("test")).isEqualTo("hotrod1");
assertThat(hotrod2Cache.get("test")).isEqualTo("hotrod2");
}
use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.
the class RestEndpointRouterTest method shouldRouteToProperRestServerBasedOnPath.
/**
* In this scenario we create 2 REST servers, each one with different REST Path: <ul> <li>REST1 -
* http://127.0.0.1:8080/rest/rest1</li> <li>REST2 - http://127.0.0.1:8080/rest/rest2</li> </ul>
* <p>
* The router should match requests based on path and redirect them to proper server.
*/
@Test
public void shouldRouteToProperRestServerBasedOnPath() {
// given
restServer1 = RestTestingUtil.createDefaultRestServer("rest1", "default");
restServer2 = RestTestingUtil.createDefaultRestServer("rest2", "default");
RestServerRouteDestination rest1Destination = new RestServerRouteDestination("rest1", restServer1);
RestRouteSource rest1Source = new RestRouteSource("rest1");
Route<RestRouteSource, RestServerRouteDestination> routeToRest1 = new Route<>(rest1Source, rest1Destination);
RestServerRouteDestination rest2Destination = new RestServerRouteDestination("rest2", restServer2);
RestRouteSource rest2Source = new RestRouteSource("rest2");
Route<RestRouteSource, RestServerRouteDestination> routeToRest2 = new Route<>(rest2Source, rest2Destination);
RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
routerConfigurationBuilder.rest().port(8080).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest1).add(routeToRest2);
router = new Router(routerConfigurationBuilder.build());
router.start();
int port = router.getRouter(EndpointRouter.Protocol.REST).get().getPort();
// when
ServerConfigurationBuilder builder = new RestClientConfigurationBuilder().addServer().host("127.0.0.1").port(port);
restClient = RestClient.forConfiguration(builder.build());
RestRawClient rawClient = restClient.raw();
String path1 = "/rest/rest1/v2/caches/default/test";
String path2 = "/rest/rest2/v2/caches/default/test";
join(rawClient.putValue(path1, emptyMap(), "rest1", TEXT_PLAIN_TYPE));
join(rawClient.putValue(path2, emptyMap(), "rest2", TEXT_PLAIN_TYPE));
String valueReturnedFromRest1 = join(rawClient.get(path1)).getBody();
String valueReturnedFromRest2 = join(rawClient.get(path2)).getBody();
// then
assertThat(valueReturnedFromRest1).isEqualTo("rest1");
assertThat(valueReturnedFromRest2).isEqualTo("rest2");
}
use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.
the class SinglePortTest method shouldUpgradeThroughALPN.
@Test
public void shouldUpgradeThroughALPN() throws Exception {
checkForOpenSSL();
// given
restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
RestServerRouteDestination restDestination = new RestServerRouteDestination("rest", restServer);
SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
SslContextFactory sslContextFactory = new SslContextFactory();
RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
routerConfigurationBuilder.singlePort().sslContext(sslContextFactory.keyStoreFileName(KEY_STORE_PATH).keyStorePassword(KEY_STORE_PASSWORD.toCharArray()).getContext()).port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest);
router = new Router(routerConfigurationBuilder.build());
router.start();
EndpointRouter singlePortRouter = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get();
// when
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.addServer().host(singlePortRouter.getHost()).port(singlePortRouter.getPort()).protocol(Protocol.HTTP_20).security().ssl().trustStoreFileName(TRUST_STORE_PATH).trustStorePassword("secret".toCharArray()).hostnameVerifier((hostname, session) -> true);
httpClient = RestClient.forConfiguration(builder.build());
CompletionStage<RestResponse> response = httpClient.cache("default").post("test", VALUE);
// then
ResponseAssertion.assertThat(response).hasNoContent();
}
use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.
the class SinglePortTest method shouldUpgradeThroughHTTP11UpgradeHeaders.
@Test
public void shouldUpgradeThroughHTTP11UpgradeHeaders() {
// given
restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
RestServerRouteDestination restDestination = new RestServerRouteDestination("rest1", restServer);
SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
routerConfigurationBuilder.singlePort().port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest);
router = new Router(routerConfigurationBuilder.build());
router.start();
int port = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get().getPort();
// when
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.addServer().host("localhost").port(port).protocol(Protocol.HTTP_20);
httpClient = RestClient.forConfiguration(builder.build());
CompletionStage<RestResponse> response = httpClient.cache("default").post("test", VALUE);
// then
ResponseAssertion.assertThat(response).hasNoContent();
}
Aggregations