void handle(DnsResponse msg) { DnsResponseCode code = DnsResponseCode.valueOf(msg.code().intValue()); if (code == DnsResponseCode.NOERROR) { inProgressMap.remove(msg.id()); if (timerID >= 0) { vertx.cancelTimer(timerID); } int count = msg.count(DnsSection.ANSWER); List<T> records = new ArrayList<>(count); for (int idx = 0;idx < count;idx++) { DnsRecord a = msg.recordAt(DnsSection.ANSWER, idx); T record = RecordDecoder.decode(a); if (isRequestedType(a.type(), types)) { records.add(record); } } if (records.size() > 0 && (records.get(0) instanceof MxRecordImpl || records.get(0) instanceof SrvRecordImpl)) { Collections.sort((List) records); } actualCtx.executeFromIO(v -> { fut.tryComplete(records); }); } else { actualCtx.executeFromIO(new DnsException(code), this::fail); } }
@Test public void testLookupNonExisting() throws Exception { dnsServer.testLookupNonExisting(); DnsClient dns = prepareDns(); dns.lookup("gfegjegjf.sg1", ar -> { DnsException cause = (DnsException)ar.cause(); assertEquals(DnsResponseCode.NXDOMAIN, cause.code()); testComplete(); }); await(); }
@Test public void testLookupNonExisting() throws Exception { dnsServer.testLookupNonExisting(); DnsClient dns = prepareDns(); dns.lookup("gfegjegjf.sg1", ar -> { DnsException cause = (DnsException)ar.cause(); assertEquals(DnsResponseCode.NXDOMAIN, cause.code()); testComplete(); }); await(); }
void handle(DnsResponse msg) { DnsResponseCode code = DnsResponseCode.valueOf(msg.code().intValue()); if (code == DnsResponseCode.NOERROR) { inProgressMap.remove(msg.id()); if (timerID >= 0) { vertx.cancelTimer(timerID); } int count = msg.count(DnsSection.ANSWER); List<T> records = new ArrayList<>(count); for (int idx = 0;idx < count;idx++) { DnsRecord a = msg.recordAt(DnsSection.ANSWER, idx); T record = RecordDecoder.decode(a); if (isRequestedType(a.type(), types)) { records.add(record); } } if (records.size() > 0 && (records.get(0) instanceof MxRecordImpl || records.get(0) instanceof SrvRecordImpl)) { Collections.sort((List) records); } actualCtx.executeFromIO(v -> { fut.tryComplete(records); }); } else { actualCtx.executeFromIO(new DnsException(code), this::fail); } }