mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 03:57:51 +02:00
Remove unnecessary usage of CircularList (#358)
Implementation of CircularList is an overkill for its stated purpose. Remove an unnecessary usage so that the remaining use case may be refactored in isolation.
This commit is contained in:
parent
cdc7db3bf8
commit
d9b0754dec
3 changed files with 25 additions and 18 deletions
|
@ -27,7 +27,6 @@ import google.registry.monitoring.blackbox.handler.WebWhoisMessageHandler;
|
|||
import google.registry.monitoring.blackbox.message.HttpRequestMessage;
|
||||
import google.registry.monitoring.blackbox.metric.MetricsCollector;
|
||||
import google.registry.monitoring.blackbox.token.WebWhoisToken;
|
||||
import google.registry.util.CircularList;
|
||||
import google.registry.util.Clock;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
|
@ -191,8 +190,8 @@ public class WebWhoisModule {
|
|||
@Singleton
|
||||
@Provides
|
||||
@WebWhoisProtocol
|
||||
CircularList<String> provideTopLevelDomains() {
|
||||
return new CircularList.Builder<String>().add("how", "soy", "xn--q9jyb4c").build();
|
||||
ImmutableList<String> provideTopLevelDomains() {
|
||||
return ImmutableList.of("how", "soy", "xn--q9jyb4c");
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -14,11 +14,15 @@
|
|||
|
||||
package google.registry.monitoring.blackbox.token;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.PeekingIterator;
|
||||
import google.registry.monitoring.blackbox.exception.UndeterminedStateException;
|
||||
import google.registry.monitoring.blackbox.message.OutboundMessageType;
|
||||
import google.registry.monitoring.blackbox.module.WebWhoisModule.WebWhoisProtocol;
|
||||
import google.registry.util.CircularList;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -33,19 +37,21 @@ public class WebWhoisToken extends Token {
|
|||
/** For each top level domain (tld), we probe "prefix.tld". */
|
||||
private static final String PREFIX = "whois.nic.";
|
||||
|
||||
/** {@link ImmutableList} of all top level domains to be probed. */
|
||||
private CircularList<String> topLevelDomainsList;
|
||||
/** {@link PeekingIterator} over a cycle of all top level domains to be probed. */
|
||||
private final PeekingIterator<String> tldCycleIterator;
|
||||
|
||||
@Inject
|
||||
public WebWhoisToken(@WebWhoisProtocol CircularList<String> topLevelDomainsList) {
|
||||
public WebWhoisToken(@WebWhoisProtocol ImmutableList<String> topLevelDomainsList) {
|
||||
checkArgument(!topLevelDomainsList.isEmpty(), "topLevelDomainsList must not be empty.");
|
||||
|
||||
this.topLevelDomainsList = topLevelDomainsList;
|
||||
this.tldCycleIterator =
|
||||
Iterators.peekingIterator(Iterables.cycle(topLevelDomainsList).iterator());
|
||||
}
|
||||
|
||||
/** Moves on to next top level domain in {@code topLevelDomainsList}. */
|
||||
/** Moves on to next top level domain in {@code tldCycleIterator}. */
|
||||
@Override
|
||||
public WebWhoisToken next() {
|
||||
topLevelDomainsList = topLevelDomainsList.next();
|
||||
tldCycleIterator.next();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -62,6 +68,6 @@ public class WebWhoisToken extends Token {
|
|||
*/
|
||||
@Override
|
||||
public String host() {
|
||||
return PREFIX + topLevelDomainsList.get();
|
||||
return PREFIX + tldCycleIterator.peek();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ package google.registry.monitoring.blackbox.token;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.monitoring.blackbox.exception.UndeterminedStateException;
|
||||
import google.registry.monitoring.blackbox.message.HttpRequestMessage;
|
||||
import google.registry.util.CircularList;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
@ -32,8 +32,8 @@ public class WebWhoisTokenTest {
|
|||
private static final String FIRST_TLD = "first_test";
|
||||
private static final String SECOND_TLD = "second_test";
|
||||
private static final String THIRD_TLD = "third_test";
|
||||
private final CircularList<String> testDomains =
|
||||
new CircularList.Builder<String>().add(FIRST_TLD, SECOND_TLD, THIRD_TLD).build();
|
||||
private final ImmutableList<String> testDomains =
|
||||
ImmutableList.of(FIRST_TLD, SECOND_TLD, THIRD_TLD);
|
||||
|
||||
public Token webToken = new WebWhoisToken(testDomains);
|
||||
|
||||
|
@ -48,10 +48,12 @@ public class WebWhoisTokenTest {
|
|||
assertThat(secondMessage.headers().get("host")).isEqualTo(PREFIX + FIRST_TLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* As Circular Linked List has not been implemented yet, we cannot yet wrap around, so we don't
|
||||
* test that in testing {@code next}.
|
||||
*/
|
||||
@Test
|
||||
public void testHostOfToken() {
|
||||
assertThat(webToken.host()).isEqualTo(PREFIX + FIRST_TLD);
|
||||
assertThat(webToken.host()).isEqualTo(PREFIX + FIRST_TLD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextToken() {
|
||||
assertThat(webToken.host()).isEqualTo(PREFIX + FIRST_TLD);
|
||||
|
|
Loading…
Add table
Reference in a new issue