Search in sources :

Example 1 with SocketAddressPreference

use of org.wildfly.clustering.singleton.election.SocketAddressPreference in project wildfly by wildfly.

the class SocketAddressPreferenceTestCase method test.

@Test
public void test() throws UnknownHostException {
    InetSocketAddress preferredAddress = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 1);
    InetSocketAddress otherAddress1 = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2);
    InetSocketAddress otherAddress2 = new InetSocketAddress(InetAddress.getByName("127.0.0.2"), 1);
    Preference preference = new SocketAddressPreference(preferredAddress);
    Node preferredNode = mock(Node.class);
    Node otherNode1 = mock(Node.class);
    Node otherNode2 = mock(Node.class);
    when(preferredNode.getSocketAddress()).thenReturn(preferredAddress);
    when(otherNode1.getSocketAddress()).thenReturn(otherAddress1);
    when(otherNode2.getSocketAddress()).thenReturn(otherAddress2);
    assertTrue(preference.preferred(preferredNode));
    assertFalse(preference.preferred(otherNode1));
    assertFalse(preference.preferred(otherNode2));
}
Also used : SocketAddressPreference(org.wildfly.clustering.singleton.election.SocketAddressPreference) SocketAddressPreference(org.wildfly.clustering.singleton.election.SocketAddressPreference) Preference(org.wildfly.clustering.singleton.election.Preference) InetSocketAddress(java.net.InetSocketAddress) Node(org.wildfly.clustering.group.Node) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.Test)1 Node (org.wildfly.clustering.group.Node)1 Preference (org.wildfly.clustering.singleton.election.Preference)1 SocketAddressPreference (org.wildfly.clustering.singleton.election.SocketAddressPreference)1