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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations