Search in sources :

Example 51 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class AUTHTest method testFixedMembershipTokenIPv4.

public void testFixedMembershipTokenIPv4() throws Exception {
    FixedMembershipToken tok = new FixedMembershipToken();
    tok.setMemberList("192.168.1.6,10.1.1.1/7500,localhost/7800");
    assert !tok.isInMembersList(new IpAddress("192.168.1.3", 7500));
    assert !tok.isInMembersList(new IpAddress("10.1.1.1", 7000));
    assert tok.isInMembersList(new IpAddress("10.1.1.1", 7500));
    // port is not matched
    assert tok.isInMembersList(new IpAddress("192.168.1.6", 7500));
    // port is not matched
    assert tok.isInMembersList(new IpAddress("192.168.1.6", 0));
}
Also used : FixedMembershipToken(org.jgroups.auth.FixedMembershipToken) IpAddress(org.jgroups.stack.IpAddress)

Example 52 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class TCPPING_Test method testSettingInitialHostsProgrammatically.

/**
 * Tests https://issues.jboss.org/browse/JGRP-2168
 */
public void testSettingInitialHostsProgrammatically() throws Exception {
    TCP transport = new TCP();
    transport.setBindAddress(InetAddress.getLoopbackAddress());
    transport.setBindPort(9600);
    TCPPING ping = new TCPPING();
    TCPGOSSIP gossip = new TCPGOSSIP();
    List<InetSocketAddress> gossip_router = Collections.singletonList(new InetSocketAddress(InetAddress.getLoopbackAddress(), 12000));
    gossip.setInitialHosts(gossip_router);
    ping.setInitialHosts(Collections.singletonList(new IpAddress(transport.getBindAddress(), transport.getBindPort())));
    ch = new JChannel(transport, ping, gossip);
    assert !ping.getInitialHosts().isEmpty() : "No initial hosts!";
    assert !gossip.getInitialHosts().isEmpty() : "no initial hosts!";
}
Also used : JChannel(org.jgroups.JChannel) InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress)

Example 53 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class DefaultDNSResolverTest method test_parsing_srv_entries.

@Test
public void test_parsing_srv_entries() throws Exception {
    // given
    MockDirContext mockDirContext = MockDirContext.newDefault().addEntry("test", "10 100 8888 9089f34a.jgroups-dns-ping.local.", DNSResolver.DNSRecordType.SRV).addEntry("9089f34a.jgroups-dns-ping.local", "192.168.0.1", DNSResolver.DNSRecordType.A).addEntry("9089f34a.jgroups-dns-ping.local", "192.168.0.2", DNSResolver.DNSRecordType.A);
    DefaultDNSResolver resolver = new DefaultDNSResolver(mockDirContext);
    // when
    List<Address> addresses = resolver.resolveIps("test", DNSResolver.DNSRecordType.SRV);
    // then
    List<Address> expectedResults = Arrays.asList(new IpAddress("192.168.0.1"), new IpAddress("192.168.0.2"));
    Assert.assertEquals(addresses, expectedResults);
}
Also used : Address(org.jgroups.Address) IpAddress(org.jgroups.stack.IpAddress) IpAddress(org.jgroups.stack.IpAddress) Test(org.testng.annotations.Test)

Example 54 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class IpAddressTest method setUp.

@BeforeClass
void setUp() throws Exception {
    StackType type = Util.getIpStackType();
    if (type == StackType.IPv6) {
        a = new IpAddress("::1", 5555);
        b = new IpAddress("::1", 5555);
        d = new IpAddress("::1", 5556);
        e = new IpAddress("::1", 5555);
        f = new IpAddress("2001:0db8:0000:0000:0000:002e:0370:2334", 80);
        g = new IpAddress("2001:0db8:0000:0000:0000:002e:0370:2334", 8080);
        h = new IpAddress("ff0e::3:4:5", 5555);
        j = new IpAddressUUID("::1", 5555);
        k = new IpAddressUUID("::1", 5555);
    } else {
        a = new IpAddress("localhost", 5555);
        b = new IpAddress("localhost", 5555);
        d = new IpAddress("localhost", 5556);
        e = new IpAddress("127.0.0.1", 5555);
        f = new IpAddress("www.ibm.com", 80);
        g = new IpAddress("www.ibm.com", 8080);
        h = new IpAddress("224.0.0.1", 5555);
        j = new IpAddressUUID("localhost", 5555);
        k = new IpAddressUUID("localhost", 5555);
    }
    c = b;
}
Also used : StackType(org.jgroups.util.StackType) IpAddress(org.jgroups.stack.IpAddress) IpAddressUUID(org.jgroups.stack.IpAddressUUID) BeforeClass(org.testng.annotations.BeforeClass)

Example 55 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class IpAddressTest method testStreamable.

public void testStreamable() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream oos = new DataOutputStream(bos);
    byte[] buf = null;
    ByteArrayInputStream bis = null;
    DataInputStream ois;
    IpAddress a2, b2, x, x2, y, y2;
    x = createStackConformantAddress(5555);
    y = createStackConformantAddress(1111);
    a.writeTo(oos);
    b.writeTo(oos);
    x.writeTo(oos);
    y.writeTo(oos);
    buf = bos.toByteArray();
    bis = new ByteArrayInputStream(buf);
    ois = new DataInputStream(bis);
    a2 = new IpAddress();
    a2.readFrom(ois);
    b2 = new IpAddress();
    b2.readFrom(ois);
    x2 = new IpAddress();
    x2.readFrom(ois);
    y2 = new IpAddress();
    y2.readFrom(ois);
    Assert.assertEquals(a, a2);
    Assert.assertEquals(b, b2);
    assert y2.getIpAddress() != null;
    Assert.assertEquals(1111, y2.getPort());
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream();
    j.writeTo(out);
    k.writeTo(out);
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer(), 0, out.position());
    IpAddressUUID tmp = new IpAddressUUID();
    tmp.readFrom(in);
    assert tmp.equals(j);
    tmp = new IpAddressUUID();
    tmp.readFrom(in);
    assert tmp.equals(k);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream) IpAddress(org.jgroups.stack.IpAddress) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream) IpAddressUUID(org.jgroups.stack.IpAddressUUID)

Aggregations

IpAddress (org.jgroups.stack.IpAddress)68 InetSocketAddress (java.net.InetSocketAddress)12 Address (org.jgroups.Address)9 IpAddressUUID (org.jgroups.stack.IpAddressUUID)8 Event (org.jgroups.Event)6 ByteArrayDataOutputStream (org.jgroups.util.ByteArrayDataOutputStream)6 ByteArrayDataInputStream (org.jgroups.util.ByteArrayDataInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 InetAddress (java.net.InetAddress)4 PhysicalAddress (org.jgroups.PhysicalAddress)4 Test (org.testng.annotations.Test)4 UUID (org.jgroups.util.UUID)3 ServerSocket (java.net.ServerSocket)2 Socket (java.net.Socket)2 ByteBuffer (java.nio.ByteBuffer)2 ManagedOperation (org.jgroups.annotations.ManagedOperation)2 FixedMembershipToken (org.jgroups.auth.FixedMembershipToken)2