Search in sources :

Example 6 with RouteLocator

use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.

the class NullRouteLocatorTestCase method test.

@Test
public void test() {
    RouteLocator locator = new NullRouteLocator();
    Assert.assertNull(locator.locate("abc123"));
}
Also used : RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) Test(org.junit.Test)

Example 7 with RouteLocator

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);
}
Also used : Group(org.wildfly.clustering.group.Group) RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) Node(org.wildfly.clustering.group.Node) GroupedKey(org.wildfly.clustering.ee.infinispan.GroupedKey) Test(org.junit.Test)

Example 8 with RouteLocator

use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.

the class RankedRouteLocatorTestCase method test.

@Test
public void test() {
    KeyDistribution distribution = mock(KeyDistribution.class);
    NodeFactory<Address> factory = mock(NodeFactory.class);
    Registry<String, Void> registry = mock(Registry.class);
    Group group = mock(Group.class);
    Address owner1 = mock(Address.class);
    Address owner2 = mock(Address.class);
    Address owner3 = mock(Address.class);
    Address owner4 = mock(Address.class);
    Address unregistered = mock(Address.class);
    Address local = mock(Address.class);
    Node member1 = mock(Node.class);
    Node member2 = mock(Node.class);
    Node member3 = mock(Node.class);
    Node member4 = mock(Node.class);
    Node unregisteredMember = mock(Node.class);
    Node localMember = mock(Node.class);
    when(registry.getGroup()).thenReturn(group);
    when(group.getLocalMember()).thenReturn(localMember);
    when(registry.getEntry(member1)).thenReturn(new SimpleImmutableEntry<>("member1", null));
    when(registry.getEntry(member2)).thenReturn(new SimpleImmutableEntry<>("member2", null));
    when(registry.getEntry(member3)).thenReturn(new SimpleImmutableEntry<>("member3", null));
    when(registry.getEntry(member4)).thenReturn(new SimpleImmutableEntry<>("member4", null));
    when(registry.getEntry(localMember)).thenReturn(new SimpleImmutableEntry<>("local", null));
    when(registry.getEntry(unregisteredMember)).thenReturn(null);
    when(factory.createNode(owner1)).thenReturn(member1);
    when(factory.createNode(owner2)).thenReturn(member2);
    when(factory.createNode(owner3)).thenReturn(member3);
    when(factory.createNode(owner4)).thenReturn(member4);
    when(factory.createNode(local)).thenReturn(localMember);
    when(factory.createNode(unregistered)).thenReturn(unregisteredMember);
    RouteLocator locator = new RankedRouteLocator(distribution, registry, factory, ".", 3);
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, owner2, owner3, owner4));
    assertEquals("member1.member2.member3", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, owner2, owner3, local));
    assertEquals("member1.member2.member3", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, owner2, unregistered, owner4));
    assertEquals("member1.member2.member4", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, local, owner3));
    assertEquals("member1.local.member3", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1, owner2));
    assertEquals("member1.member2.local", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(local, owner2));
    assertEquals("local.member2", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(owner1));
    assertEquals("member1.local", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(local));
    assertEquals("local", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Arrays.asList(unregistered));
    assertEquals("local", locator.locate("key"));
    when(distribution.getOwners(new GroupedKey<>("key"))).thenReturn(Collections.emptyList());
    assertEquals("local", locator.locate("key"));
}
Also used : Group(org.wildfly.clustering.group.Group) RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) Address(org.infinispan.remoting.transport.Address) Node(org.wildfly.clustering.group.Node) KeyDistribution(org.wildfly.clustering.infinispan.distribution.KeyDistribution) Test(org.junit.Test)

Example 9 with RouteLocator

use of org.wildfly.clustering.web.routing.RouteLocator in project wildfly by wildfly.

the class DistributableSessionIdentifierCodecServiceConfigurator method build.

@Override
public ServiceBuilder<?> build(ServiceTarget target) {
    this.configurator.build(target).install();
    ServiceBuilder<?> builder = target.addService(this.getServiceName());
    Consumer<SessionIdentifierCodec> codec = builder.provides(this.getServiceName());
    Supplier<RouteLocator> locator = builder.requires(this.configurator.getServiceName());
    Service service = new FunctionalService<>(codec, this, locator);
    return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Also used : RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) FunctionalService(org.wildfly.clustering.service.FunctionalService) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service) SessionIdentifierCodec(org.jboss.as.web.session.SessionIdentifierCodec)

Example 10 with RouteLocator

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);
}
Also used : RouteLocator(org.wildfly.clustering.web.routing.RouteLocator) PrimaryOwnerRouteLocator(org.wildfly.clustering.web.infinispan.routing.PrimaryOwnerRouteLocator) FunctionalService(org.wildfly.clustering.service.FunctionalService) ServiceName(org.jboss.msc.service.ServiceName) AsyncServiceConfigurator(org.wildfly.clustering.service.AsyncServiceConfigurator) FunctionalService(org.wildfly.clustering.service.FunctionalService) Service(org.jboss.msc.Service) CompositeDependency(org.wildfly.clustering.service.CompositeDependency)

Aggregations

RouteLocator (org.wildfly.clustering.web.routing.RouteLocator)11 Service (org.jboss.msc.Service)7 ServiceName (org.jboss.msc.service.ServiceName)6 FunctionalService (org.wildfly.clustering.service.FunctionalService)5 Test (org.junit.Test)4 Group (org.wildfly.clustering.group.Group)2 Node (org.wildfly.clustering.group.Node)2 AsyncServiceConfigurator (org.wildfly.clustering.service.AsyncServiceConfigurator)2 CompositeDependency (org.wildfly.clustering.service.CompositeDependency)2 Address (org.infinispan.remoting.transport.Address)1 SessionIdentifierCodec (org.jboss.as.web.session.SessionIdentifierCodec)1 GroupedKey (org.wildfly.clustering.ee.infinispan.GroupedKey)1 KeyDistribution (org.wildfly.clustering.infinispan.distribution.KeyDistribution)1 LocalRouteLocator (org.wildfly.clustering.web.cache.routing.LocalRouteLocator)1 NullRouteLocator (org.wildfly.clustering.web.cache.routing.NullRouteLocator)1 PrimaryOwnerRouteLocator (org.wildfly.clustering.web.infinispan.routing.PrimaryOwnerRouteLocator)1