Search in sources :

Example 36 with IpAddress

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

the class BuffersTest method readCookieVersionAndAddress.

protected static void readCookieVersionAndAddress(final Buffers bufs, final byte[] cookie, final IpAddress addr) throws Exception {
    // cookie
    ByteBuffer cookie_buf = bufs.get(0);
    byte[] cookie2 = new byte[cookie_buf.position()];
    cookie_buf.flip();
    cookie_buf.get(cookie2, 0, cookie2.length);
    assert Arrays.equals(cookie, cookie2);
    // version
    ByteBuffer version_buf = bufs.get(1);
    short ver = version_buf.getShort(0);
    assert Version.version == ver;
    // address
    ByteBuffer addr_buf = bufs.get(2);
    addr_buf.flip();
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(addr_buf);
    IpAddress address = new IpAddress();
    address.readFrom(in);
    assert addr.equals(address);
}
Also used : IpAddress(org.jgroups.stack.IpAddress) ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteBuffer(java.nio.ByteBuffer)

Example 37 with IpAddress

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

the class BuffersTest method testRead2.

public void testRead2() throws Exception {
    byte[] cookie = { 'b', 'e', 'l', 'a' };
    IpAddress addr = new IpAddress(7500);
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream();
    addr.writeTo(out);
    MockSocketChannel ch = new MockSocketChannel().bytesToRead(ByteBuffer.allocate(cookie.length + Global.SHORT_SIZE + out.position()).put(cookie).putShort(Version.version).put(out.buffer(), 0, out.position()).flip());
    Buffers bufs = new Buffers(ByteBuffer.allocate(cookie.length), ByteBuffer.allocate(Global.SHORT_SIZE), ByteBuffer.allocate(out.position()));
    boolean rc = bufs.read(ch);
    assert rc;
    readCookieVersionAndAddress(bufs, cookie, addr);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) IpAddress(org.jgroups.stack.IpAddress) Buffers(org.jgroups.nio.Buffers) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 38 with IpAddress

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

the class DNS_PINGTest method test_get_members.

@Test
public void test_get_members() throws Exception {
    // given
    final DNS_PING ping = new DNS_PING();
    final MockDirContext mockDirContext = MockDirContext.newDefault().addEntry("test-1", "192.168.0.1", DNSResolver.DNSRecordType.A).addEntry("test-2", "192.168.0.2", DNSResolver.DNSRecordType.A).addEntry("test-2", "192.168.1.1", DNSResolver.DNSRecordType.A).addEntry("test-2", "192.168.1.2", DNSResolver.DNSRecordType.A).addEntry("test-2", "192.168.1.3", DNSResolver.DNSRecordType.A).addEntry("test-3", "192.168.2.1", DNSResolver.DNSRecordType.A);
    ping.dns_resolver = new AddressedDNSResolver(mockDirContext);
    // when
    final List<Address> addresses = ping.getMembers("test-1, test-2, test-3", DNSResolver.DNSRecordType.A);
    // then
    final List<Address> expectedResults = Arrays.asList(new IpAddress("192.168.0.1"), new IpAddress("192.168.0.2"), new IpAddress("192.168.1.1"), new IpAddress("192.168.1.2"), new IpAddress("192.168.1.3"), new IpAddress("192.168.2.1"));
    Assert.assertEquals(addresses, expectedResults);
}
Also used : InetAddress(java.net.InetAddress) Address(org.jgroups.Address) IpAddress(org.jgroups.stack.IpAddress) IpAddress(org.jgroups.stack.IpAddress) Test(org.testng.annotations.Test)

Example 39 with IpAddress

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

the class DNS_PINGTest method test_valid_dns_response.

@Test
public void test_valid_dns_response() throws Exception {
    // given
    DNSDiscoveryTester dns_discovery_tester = new DNSDiscoveryTester(2, PORT_START, 10, TimeUnit.SECONDS).add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), PORT_START)).add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), PORT_START + 1));
    // when
    boolean was_view_received = dns_discovery_tester.runTestAndCheckIfViewWasReceived("test", "A");
    // then
    Assert.assertTrue(was_view_received);
}
Also used : IpAddress(org.jgroups.stack.IpAddress) Test(org.testng.annotations.Test)

Example 40 with IpAddress

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

the class DNS_PINGTest method test_not_matching_dns_response.

@Test
public void test_not_matching_dns_response() throws Exception {
    // given
    DNSDiscoveryTester dns_discovery_tester = new DNSDiscoveryTester(2, PORT_START, 1, TimeUnit.SECONDS).add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), 6666));
    // when
    boolean was_view_received = dns_discovery_tester.runTestAndCheckIfViewWasReceived("test", "A");
    // then
    Assert.assertFalse(was_view_received);
}
Also used : IpAddress(org.jgroups.stack.IpAddress) Test(org.testng.annotations.Test)

Aggregations

IpAddress (org.jgroups.stack.IpAddress)87 InetSocketAddress (java.net.InetSocketAddress)15 Address (org.jgroups.Address)13 InetAddress (java.net.InetAddress)7 Test (org.testng.annotations.Test)7 Event (org.jgroups.Event)6 PhysicalAddress (org.jgroups.PhysicalAddress)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 IOException (java.io.IOException)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 JChannel (org.jgroups.JChannel)3 ManagedOperation (org.jgroups.annotations.ManagedOperation)3 DefaultSocketFactory (org.jgroups.util.DefaultSocketFactory)3 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 ServerSocket (java.net.ServerSocket)2