use of org.infinispan.server.router.routes.hotrod.SniNettyRouteSource 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.routes.hotrod.SniNettyRouteSource in project infinispan by infinispan.
the class TwoServersWithSslSni method initRoutes.
@Override
public Optional<Set<Route<? extends RouteSource, ? extends RouteDestination>>> initRoutes(List<HotRodServer> servers) {
Set<Route<? extends RouteSource, ? extends RouteDestination>> routes = new HashSet<>();
HotRodServerRouteDestination hotrod1Destination = new HotRodServerRouteDestination("hotrod1", servers.get(0));
SniNettyRouteSource hotrod1Source = new SniNettyRouteSource("hotrod1", KEYSTORE_LOCATION_FOR_HOTROD_1, KEYSTORE_PASSWORD);
routes.add(new Route<>(hotrod1Source, hotrod1Destination));
HotRodServerRouteDestination hotrod2Destination = new HotRodServerRouteDestination("hotrod2", servers.get(1));
SniNettyRouteSource hotrod2Source = new SniNettyRouteSource("hotrod2", KEYSTORE_LOCATION_FOR_HOTROD_2, KEYSTORE_PASSWORD);
routes.add(new Route<>(hotrod2Source, hotrod2Destination));
return Optional.of(routes);
}
Aggregations