Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tkountis committed Feb 17, 2024
1 parent 1cab48e commit 07e0d16
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ DefaultDnsServiceDiscovererBuilder srvHostNameRepeatDelay(
Duration initialDelay, Duration jitter) {
this.srvHostNameRepeatInitialDelay = requireNonNull(initialDelay);
this.srvHostNameRepeatJitter = requireNonNull(jitter);
ensurePositive(srvHostNameRepeatInitialDelay, "srvHostNameRepeatInitialDelay");
ensurePositive(srvHostNameRepeatJitter, "srvHostNameRepeatJitter");
if (srvHostNameRepeatJitter.toNanos() >= srvHostNameRepeatInitialDelay.toNanos()) {
throw new IllegalArgumentException("The jitter value should be less than the initial delay.");
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import static io.servicetalk.transport.netty.internal.NettyIoExecutors.createIoExecutor;
import static java.net.InetAddress.getByName;
import static java.time.Duration.ofMillis;
import static java.time.Duration.ofNanos;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.function.Function.identity;
Expand Down Expand Up @@ -461,14 +462,15 @@ void srvFailResumesCorrectly() throws Exception {
assertHasEvent(signals, ip1, targetPort, AVAILABLE);

// Fail subsequent A queries with SERVFAIL
final TestRecordStore.ServFail fail = new TestRecordStore.ServFail("target1", RecordType.A);
recordStore.addFail(fail);
final TestRecordStore.ServFail aFail = new TestRecordStore.ServFail(targetDomain1, RecordType.A);
recordStore.addFail(aFail);
advanceTime();

// Expect no changes (SERVFAIL should be retried indefinitely)
assertThat(subscriber.pollOnNext(50, MILLISECONDS), is(nullValue()));

// Restore functionality for A queries
recordStore.removeFail(fail);
recordStore.removeFail(aFail);
advanceTime();

List<ServiceDiscovererEvent<InetSocketAddress>> resumeSignals = subscriber.takeOnNext(1);
Expand Down Expand Up @@ -1231,7 +1233,8 @@ private DefaultDnsServiceDiscovererBuilder dnsClientBuilder() {
.dnsServerAddressStreamProvider(new SingletonDnsServerAddressStreamProvider(dnsServer.localAddress()))
.ndots(1)
.ttl(1, 5, 0, 0)
.ttlJitter(Duration.ofNanos(1));
.ttlJitter(Duration.ofNanos(1))
.srvHostNameRepeatDelay(ofNanos(10), ofNanos(1));
}

private static void assertEvent(@Nullable ServiceDiscovererEvent<InetSocketAddress> event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -61,6 +62,31 @@ static class ServFail {
static ServFail of(final QuestionRecord question) {
return new ServFail(question.getDomainName(), question.getRecordType());
}

@Override
public String toString() {
return "ServFail{" +
"name='" + name + '\'' +
", type=" + type +
'}';
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final ServFail fail = (ServFail) o;
return Objects.equals(name, fail.name) && type == fail.type;
}

@Override
public int hashCode() {
return Objects.hash(name, type);
}
}

private final Set<ServFail> failSet = new HashSet<>();
Expand Down

0 comments on commit 07e0d16

Please sign in to comment.