Skip to content

Commit

Permalink
Improve SrvServiceNameResolverTest
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 6, 2023
1 parent 703eb25 commit 0435b4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.*;
import io.vertx.core.net.SocketAddress;
Expand Down Expand Up @@ -34,7 +33,7 @@ public abstract class ServiceResolverTestBase {

@Before
public void setUp() throws Exception {
vertx = Vertx.vertx(new VertxOptions());
vertx = Vertx.vertx();
pods = new ArrayList<>();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.vertx.serviceresolver.srv;

import io.vertx.core.VertxOptions;
import io.vertx.core.dns.AddressResolverOptions;
import io.vertx.ext.unit.TestContext;
import io.vertx.serviceresolver.ServiceAddress;
import io.vertx.serviceresolver.ServiceResolverTestBase;
Expand Down Expand Up @@ -45,16 +47,17 @@ public Set<ResourceRecord> getRecords(QuestionRecord questionRecord) {
Set<ResourceRecord> set = new HashSet<>();
if ("_http._tcp.example.com".equals(questionRecord.getDomainName())) {
for (int i = 0;i < 2;i++) {
ResourceRecordModifier rm = new ResourceRecordModifier();
rm.setDnsClass(RecordClass.IN);
rm.setDnsName("dns.vertx.io." + i);
rm.setDnsTtl(100);
rm.setDnsType(RecordType.SRV);
rm.put(DnsAttribute.SERVICE_PRIORITY, String.valueOf(1));
rm.put(DnsAttribute.SERVICE_WEIGHT, String.valueOf(1));
rm.put(DnsAttribute.SERVICE_PORT, String.valueOf(8080 + i));
rm.put(DnsAttribute.DOMAIN_NAME, "localhost");
set.add(rm.getEntry());
FakeDNSServer.Record record = new FakeDNSServer.Record(
"_http._tcp.example.com",
RecordType.SRV,
RecordClass.IN,
100
)
.set(DnsAttribute.SERVICE_PRIORITY, 1)
.set(DnsAttribute.SERVICE_WEIGHT, 1)
.set(DnsAttribute.SERVICE_PORT, 8080 + i)
.set(DnsAttribute.DOMAIN_NAME, "localhost");
set.add(record);
}
}
return set;
Expand All @@ -66,7 +69,6 @@ public Set<ResourceRecord> getRecords(QuestionRecord questionRecord) {
should.assertEquals(Collections.emptySet(), set);
}

@Ignore("No validity check implemented now...")
@Test
public void testExpiration(TestContext should) throws Exception {
startPods(4, req -> {
Expand All @@ -78,17 +80,18 @@ public void testExpiration(TestContext should) throws Exception {
public Set<ResourceRecord> getRecords(QuestionRecord questionRecord) {
Set<ResourceRecord> set = new HashSet<>();
if ("_http._tcp.example.com".equals(questionRecord.getDomainName())) {
for (int i = 0;i < ports.size();i++) {
ResourceRecordModifier rm = new ResourceRecordModifier();
rm.setDnsClass(RecordClass.IN);
rm.setDnsName("dns.vertx.io." + i);
rm.setDnsTtl(1);
rm.setDnsType(RecordType.SRV);
rm.put(DnsAttribute.SERVICE_PRIORITY, String.valueOf(1));
rm.put(DnsAttribute.SERVICE_WEIGHT, String.valueOf(1));
rm.put(DnsAttribute.SERVICE_PORT, String.valueOf(ports.get(i)));
rm.put(DnsAttribute.DOMAIN_NAME, "localhost");
set.add(rm.getEntry());
for (Integer port : ports) {
FakeDNSServer.Record record = new FakeDNSServer.Record(
"_http._tcp.example.com",
RecordType.SRV,
RecordClass.IN,
1
)
.set(DnsAttribute.SERVICE_PRIORITY, 1)
.set(DnsAttribute.SERVICE_WEIGHT, 1)
.set(DnsAttribute.SERVICE_PORT, port)
.set(DnsAttribute.DOMAIN_NAME, "localhost");
set.add(record);
}
}
return set;
Expand All @@ -100,7 +103,7 @@ public Set<ResourceRecord> getRecords(QuestionRecord questionRecord) {
should.assertTrue(set.remove(get(ServiceAddress.create("_http._tcp.example.com.")).toString()));
should.assertTrue(set.remove(get(ServiceAddress.create("_http._tcp.example.com.")).toString()));
should.assertEquals(Collections.emptySet(), set);
Thread.sleep(1000);
Thread.sleep(1500);
ports.clear();
ports.add(8082);
ports.add(8083);
Expand Down

0 comments on commit 0435b4e

Please sign in to comment.