diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-08-29 14:06:41 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-08-29 14:06:41 +0200 |
commit | ff75785574b30677ce17984551328990a991869e (patch) | |
tree | 85b7245827d2bc308b597e930bd14c476c5b2497 /container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java | |
parent | 89e6983eb08238e4912aeabb7b001ad966cfb23b (diff) |
Be down initially
Before ths change containers used to come up in the initial VIP state of up
("in rotation") before having any information about downstream cløusters.
This is problematic if the node determines that it should be
down when learning the state of downstream clusters, especially
when it is determining that it should be down due to failing to complete
pings timely due to initialization load.
This changes to starting in the down state. Crucially, this requires
tracking the current state of clusters in a separate component
such that the state survives reconfiguration and we avoid setting the
state down briefly on each reconfiguration.
In addition to the case where there are downstream clusters deciding
the VIP state oif a container, there are two others:
- There are no such clusters. In this case the VIP state will be up by default.
- Some other component is explicitly deciding the VIP state. This commit makes
that case clearer.
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java')
-rw-r--r-- | container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java | 104 |
1 files changed, 51 insertions, 53 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java b/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java index ef51a3c0f51..f8de32ee3ff 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java +++ b/container-core/src/test/java/com/yahoo/container/handler/VipStatusHandlerTestCase.java @@ -35,16 +35,16 @@ import static org.junit.Assert.fail; * care about the incoming URI, that's 100% handled in JDIsc by the binding * pattern. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class VipStatusHandlerTestCase { - public static final class MockResponseHandler implements ResponseHandler { + public static class MockResponseHandler implements ResponseHandler { + final ReadableContentChannel channel = new ReadableContentChannel(); @Override - public ContentChannel handleResponse( - final com.yahoo.jdisc.Response response) { + public ContentChannel handleResponse(com.yahoo.jdisc.Response response) { return channel; } } @@ -52,45 +52,44 @@ public class VipStatusHandlerTestCase { Metric metric = Mockito.mock(Metric.class); @Test - public final void testHandleRequest() { - final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false) + public void testHandleRequest() { + VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false) .noSearchBackendsImpliesOutOfService(false)); - final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric); - final MockResponseHandler responseHandler = new MockResponseHandler(); - final HttpRequest request = createRequest(); - final BufferedContentChannel requestContent = createChannel(); + VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric); + MockResponseHandler responseHandler = new MockResponseHandler(); + HttpRequest request = createRequest(); + BufferedContentChannel requestContent = createChannel(); handler.handleRequest(request, requestContent, responseHandler); - final ByteBuffer b = responseHandler.channel.read(); - final byte[] asBytes = new byte[b.remaining()]; + ByteBuffer b = responseHandler.channel.read(); + byte[] asBytes = new byte[b.remaining()]; b.get(asBytes); assertEquals(VipStatusHandler.OK_MESSAGE, Utf8.toString(asBytes)); } - public static final class NotFoundResponseHandler implements - ResponseHandler { + public static class NotFoundResponseHandler implements ResponseHandler { + final ReadableContentChannel channel = new ReadableContentChannel(); @Override - public ContentChannel handleResponse( - final com.yahoo.jdisc.Response response) { - assertEquals(com.yahoo.jdisc.Response.Status.NOT_FOUND, - response.getStatus()); + public ContentChannel handleResponse(com.yahoo.jdisc.Response response) { + assertEquals(com.yahoo.jdisc.Response.Status.NOT_FOUND, response.getStatus()); return channel; } + } @Test - public final void testFileNotFound() { - final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true) + public void testFileNotFound() { + VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true) .statusfile("/VipStatusHandlerTestCaseFileThatReallyReallyShouldNotExist") .noSearchBackendsImpliesOutOfService(false)); - final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric); - final NotFoundResponseHandler responseHandler = new NotFoundResponseHandler(); - final HttpRequest request = createRequest(); - final BufferedContentChannel requestContent = createChannel(); + VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric); + NotFoundResponseHandler responseHandler = new NotFoundResponseHandler(); + HttpRequest request = createRequest(); + BufferedContentChannel requestContent = createChannel(); handler.handleRequest(request, requestContent, responseHandler); - final ByteBuffer b = responseHandler.channel.read(); - final byte[] asBytes = new byte[b.remaining()]; + ByteBuffer b = responseHandler.channel.read(); + byte[] asBytes = new byte[b.remaining()]; b.get(asBytes); assertEquals( VipStatusHandler.StatusResponse.COULD_NOT_FIND_STATUS_FILE, @@ -98,23 +97,22 @@ public class VipStatusHandlerTestCase { } @Test - public final void testFileFound() throws IOException { - final File statusFile = File.createTempFile("VipStatusHandlerTestCase", - null); + public void testFileFound() throws IOException { + File statusFile = File.createTempFile("VipStatusHandlerTestCase", null); try { - final FileWriter writer = new FileWriter(statusFile); - final String OK = "OK\n"; + FileWriter writer = new FileWriter(statusFile); + String OK = "OK\n"; writer.write(OK); writer.close(); - final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true) + VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(true) .statusfile(statusFile.getAbsolutePath()).noSearchBackendsImpliesOutOfService(false)); - final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric); - final MockResponseHandler responseHandler = new MockResponseHandler(); - final HttpRequest request = createRequest(); - final BufferedContentChannel requestContent = createChannel(); + VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric); + MockResponseHandler responseHandler = new MockResponseHandler(); + HttpRequest request = createRequest(); + BufferedContentChannel requestContent = createChannel(); handler.handleRequest(request, requestContent, responseHandler); - final ByteBuffer b = responseHandler.channel.read(); - final byte[] asBytes = new byte[b.remaining()]; + ByteBuffer b = responseHandler.channel.read(); + byte[] asBytes = new byte[b.remaining()]; b.get(asBytes); assertEquals(OK, Utf8.toString(asBytes)); } finally { @@ -123,34 +121,34 @@ public class VipStatusHandlerTestCase { } @Test - public final void testProgrammaticallyRemovedFromRotation() throws IOException { + public void testExplicitlyRotationControl() { VipStatus vipStatus = new VipStatus(); - final VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false) + VipStatusConfig config = new VipStatusConfig(new VipStatusConfig.Builder().accessdisk(false) .noSearchBackendsImpliesOutOfService(true)); - final VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric, vipStatus); + VipStatusHandler handler = new VipStatusHandler(Executors.newCachedThreadPool(), config, metric, vipStatus); - vipStatus.removeFromRotation(this); + vipStatus.setInRotation(false); { - final MockResponseHandler responseHandler = new MockResponseHandler(); - final HttpRequest request = createRequest(); - final BufferedContentChannel requestContent = createChannel(); + MockResponseHandler responseHandler = new MockResponseHandler(); + HttpRequest request = createRequest(); + BufferedContentChannel requestContent = createChannel(); handler.handleRequest(request, requestContent, responseHandler); - final ByteBuffer b = responseHandler.channel.read(); - final byte[] asBytes = new byte[b.remaining()]; + ByteBuffer b = responseHandler.channel.read(); + byte[] asBytes = new byte[b.remaining()]; b.get(asBytes); assertEquals(VipStatusHandler.StatusResponse.NO_SEARCH_BACKENDS, Utf8.toString(asBytes)); } - vipStatus.addToRotation(this); + vipStatus.setInRotation(true); { - final MockResponseHandler responseHandler = new MockResponseHandler(); - final HttpRequest request = createRequest(); - final BufferedContentChannel requestContent = createChannel(); + MockResponseHandler responseHandler = new MockResponseHandler(); + HttpRequest request = createRequest(); + BufferedContentChannel requestContent = createChannel(); handler.handleRequest(request, requestContent, responseHandler); - final ByteBuffer b = responseHandler.channel.read(); - final byte[] asBytes = new byte[b.remaining()]; + ByteBuffer b = responseHandler.channel.read(); + byte[] asBytes = new byte[b.remaining()]; b.get(asBytes); assertEquals(VipStatusHandler.OK_MESSAGE, Utf8.toString(asBytes)); } |