use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.
the class LocalRouteLocatorTestCase method test.
@Test
public void test() {
String route = "route";
RouteLocator locator = new LocalRouteLocator(route);
String result = locator.locate("abc123");
Assert.assertSame(route, result);
}
use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.
the class LocalRouteLocatorServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceName name = this.getServiceName();
ServiceBuilder<?> builder = target.addService(name);
Consumer<RouteLocator> locator = this.route.register(builder).provides(name);
Service service = new FunctionalService<>(locator, Function.identity(), this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.
the class NullRouteLocatorServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceName name = this.getServiceName();
ServiceBuilder<?> builder = target.addService(name);
Consumer<RouteLocator> locator = builder.provides(name);
Service service = Service.newInstance(locator, new NullRouteLocator());
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.
the class PrimaryOwnerRouteLocatorServiceConfigurator method build.
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceName name = this.getServiceName();
ServiceBuilder<?> builder = new AsyncServiceConfigurator(name).build(target);
Consumer<RouteLocator> locator = new CompositeDependency(this.registry, this.cache, this.factory).register(builder).provides(name);
Service service = new FunctionalService<>(locator, Function.identity(), this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.
the class PrimaryOwnerRouteLocatorTestCase method test.
@Test
public void test() {
Function<GroupedKey<String>, Node> locator = mock(Function.class);
Registry<String, Void> registry = mock(Registry.class);
Group group = mock(Group.class);
Node primary = mock(Node.class);
Node local = mock(Node.class);
Node missing = mock(Node.class);
String primaryRoute = "primary";
String localRoute = "local";
when(registry.getGroup()).thenReturn(group);
when(group.getLocalMember()).thenReturn(local);
when(registry.getEntry(local)).thenReturn(new SimpleImmutableEntry<>(localRoute, null));
RouteLocator routeLocator = new PrimaryOwnerRouteLocator(locator, registry);
when(locator.apply(new GroupedKey<>("session"))).thenReturn(primary);
when(registry.getEntry(primary)).thenReturn(new SimpleImmutableEntry<>(primaryRoute, null));
String result = routeLocator.locate("session");
assertSame(primaryRoute, result);
when(locator.apply(new GroupedKey<>("missing"))).thenReturn(missing);
when(registry.getEntry(missing)).thenReturn(null);
result = routeLocator.locate("missing");
assertSame(localRoute, result);
}
Aggregations