@Test void loadDnsRecords() throws Exception { String service = "_couchbase._tcp.couchbase.com"; BasicAttributes basicAttributes = new BasicAttributes(true); BasicAttribute basicAttribute = new BasicAttribute("SRV"); basicAttribute.add("0 0 0 node2.couchbase.com."); basicAttribute.add("0 0 0 node1.couchbase.com."); basicAttribute.add("0 0 0 node3.couchbase.com."); basicAttribute.add("0 0 0 node4.couchbase.com."); basicAttributes.put(basicAttribute); DirContext mockedContext = mock(DirContext.class); when(mockedContext.getAttributes(service, new String[] { "SRV" })) .thenReturn(basicAttributes); List<String> records = DnsSrv.loadDnsRecords(service, mockedContext); assertEquals(4, records.size()); assertEquals("node2.couchbase.com", records.get(0)); assertEquals("node1.couchbase.com", records.get(1)); assertEquals("node3.couchbase.com", records.get(2)); assertEquals("node4.couchbase.com", records.get(3)); }
static List<String> loadDnsRecords(final String serviceName, final DirContext ctx) throws NamingException { Attributes attrs = ctx.getAttributes(serviceName, new String[] { "SRV" }); NamingEnumeration<?> servers = attrs.get("srv").getAll(); List<String> records = new ArrayList<>(); while (servers.hasMore()) { DnsRecord record = DnsRecord.fromString((String) servers.next()); records.add(record.getHost()); } return records; }
DnsSrv { static List<String> loadDnsRecords(final String serviceName, final DirContext ctx) throws NamingException { Attributes attrs = ctx.getAttributes(serviceName, new String[] { "SRV" }); NamingEnumeration<?> servers = attrs.get("srv").getAll(); List<String> records = new ArrayList<>(); while (servers.hasMore()) { DnsRecord record = DnsRecord.fromString((String) servers.next()); records.add(record.getHost()); } return records; } }
DnsSrv { static List<String> loadDnsRecords(final String serviceName, final DirContext ctx) throws NamingException { Attributes attrs = ctx.getAttributes(serviceName, new String[] { "SRV" }); NamingEnumeration<?> servers = attrs.get("srv").getAll(); List<String> records = new ArrayList<>(); while (servers.hasMore()) { DnsRecord record = DnsRecord.fromString((String) servers.next()); records.add(record.getHost()); } return records; } private  DnsSrv(); }
DnsSrv { static List<String> loadDnsRecords(final String serviceName, final DirContext ctx) throws NamingException { Attributes attrs = ctx.getAttributes(serviceName, new String[] { "SRV" }); NamingEnumeration<?> servers = attrs.get("srv").getAll(); List<String> records = new ArrayList<>(); while (servers.hasMore()) { DnsRecord record = DnsRecord.fromString((String) servers.next()); records.add(record.getHost()); } return records; } private  DnsSrv(); static void setDnsEnvParameter(final String key, final String value); static List<String> fromDnsSrv(final String serviceName, boolean full, boolean secure); static List<String> fromDnsSrv(final String serviceName, boolean full, boolean secure,
                                        final String nameServerIP); }
DnsSrv { static List<String> loadDnsRecords(final String serviceName, final DirContext ctx) throws NamingException { Attributes attrs = ctx.getAttributes(serviceName, new String[] { "SRV" }); NamingEnumeration<?> servers = attrs.get("srv").getAll(); List<String> records = new ArrayList<>(); while (servers.hasMore()) { DnsRecord record = DnsRecord.fromString((String) servers.next()); records.add(record.getHost()); } return records; } private  DnsSrv(); static void setDnsEnvParameter(final String key, final String value); static List<String> fromDnsSrv(final String serviceName, boolean full, boolean secure); static List<String> fromDnsSrv(final String serviceName, boolean full, boolean secure,
                                        final String nameServerIP); static final String DEFAULT_DNS_SERVICE; static final String DEFAULT_DNS_SECURE_SERVICE; }