Search in sources :

Example 1 with GroupedKey

use of org.wildfly.clustering.ee.infinispan.GroupedKey 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)

Aggregations

Test (org.junit.Test)1 GroupedKey (org.wildfly.clustering.ee.infinispan.GroupedKey)1 Group (org.wildfly.clustering.group.Group)1 Node (org.wildfly.clustering.group.Node)1 RouteLocator (org.wildfly.clustering.web.routing.RouteLocator)1