diff options
Diffstat (limited to 'vespaclient-container-plugin/src/test/java/com/yahoo/vespa')
5 files changed, 29 insertions, 1181 deletions
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2ErrorsInResultTestCase.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2ErrorsInResultTestCase.java deleted file mode 100644 index 47745b29032..00000000000 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2ErrorsInResultTestCase.java +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.http.server; - -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.container.jdisc.messagebus.SessionCache; -import com.yahoo.container.logging.AccessLog; -import com.yahoo.document.DocumentTypeManager; -import com.yahoo.document.config.DocumentmanagerConfig; -import com.yahoo.jdisc.ReferencedResource; -import com.yahoo.jdisc.References; -import com.yahoo.jdisc.http.HttpRequest.Method; -import com.yahoo.messagebus.*; -import com.yahoo.messagebus.Error; -import com.yahoo.messagebus.shared.SharedMessageBus; -import com.yahoo.messagebus.shared.SharedSourceSession; -import com.yahoo.metrics.simple.MetricReceiver; -import com.yahoo.text.Utf8; -import com.yahoo.text.Utf8String; -import com.yahoo.vespa.http.client.core.Headers; -import com.yahoo.vespa.http.client.core.OperationStatus; -import com.yahoo.vespaxmlparser.MockFeedReaderFactory; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static org.junit.Assert.assertEquals; - -/** - * Check FeedHandler APIs. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class V2ErrorsInResultTestCase { - - LessConfiguredHandler handler; - ExecutorService workers; - - @Before - public void setUp() throws Exception { - workers = Executors.newCachedThreadPool(); - handler = new LessConfiguredHandler(workers); - } - - @After - public void tearDown() throws Exception { - handler.destroy(); - workers.shutdown(); - } - - private static class LessConfiguredHandler extends FeedHandler { - - public LessConfiguredHandler(Executor executor) throws Exception { - super(new FeedHandler.Context(executor, - AccessLog.voidAccessLog(), - new DummyMetric()), - null, null, null, MetricReceiver.nullImplementation); - } - - - @Override - protected Feeder createFeeder(HttpRequest request, InputStream requestInputStream, - BlockingQueue<OperationStatus> operations, String clientId, - boolean sessionIdWasGeneratedJustNow, int protocolVersion) - throws Exception { - return new LessConfiguredFeeder(requestInputStream, operations, - popClient(clientId), new FeederSettings(request), clientId, sessionIdWasGeneratedJustNow, - sourceSessionParams(request), null, this, this.feedReplyHandler, ""); - } - - @Override - protected DocumentTypeManager createDocumentManager( - DocumentmanagerConfig documentManagerConfig) { - return null; - } - } - - private static class MockSharedSession extends SharedSourceSession { - int count; - - public MockSharedSession(SourceSessionParams params) { - super(new SharedMessageBus(new MessageBus(new MockNetwork(), - new MessageBusParams())), params); - count = 0; - } - - @Override - public Result sendMessageBlocking(Message msg) throws InterruptedException { - return sendMessage(msg); - } - - @Override - public Result sendMessage(Message msg) { - Result r; - ReplyHandler handler = msg.popHandler(); - - switch (count++) { - case 0: - r = new Result(ErrorCode.FATAL_ERROR, - "boom"); - break; - case 1: - r = new Result(ErrorCode.TRANSIENT_ERROR, - "transient boom"); - break; - case 2: - final FailedReply reply = new FailedReply(msg.getContext()); - reply.addError(new Error( - ErrorCode.FATAL_ERROR, - "bad mojo, dude")); - handler.handleReply(reply); - r = Result.ACCEPTED; - break; - default: - handler.handleReply(new MockReply(msg.getContext())); - r = Result.ACCEPTED; - } - return r; - } - - } - - private static class FailedReply extends Reply { - Object context; - - public FailedReply(Object context) { - this.context = context; - } - - @Override - public Utf8String getProtocol() { - return null; - } - - @Override - public int getType() { - return 0; - } - - @Override - public Object getContext() { - return context; - } - } - - private static class LessConfiguredFeeder extends Feeder { - - public LessConfiguredFeeder(InputStream stream, - BlockingQueue<OperationStatus> operations, - ClientState storedState, FeederSettings settings, - String clientId, boolean sessionIdWasGeneratedJustNow, SourceSessionParams sessionParams, - SessionCache sessionCache, FeedHandler handler, ReplyHandler feedReplyHandler, - String localHostname) throws Exception { - super(stream, new MockFeedReaderFactory(), null, operations, storedState, settings, clientId, sessionIdWasGeneratedJustNow, - sessionParams, sessionCache, handler, new DummyMetric(), feedReplyHandler, localHostname); - } - - protected ReferencedResource<SharedSourceSession> retainSession( - SourceSessionParams sessionParams, SessionCache sessionCache) { - final SharedSourceSession session = new MockSharedSession(sessionParams); - return new ReferencedResource<>(session, References.fromResource(session)); - } - } - - @Test - public final void test() throws IOException { - String sessionId; - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - sessionId = r.headers().getFirst(Headers.SESSION_ID); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 ERROR boom \n", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 TRANSIENT_ERROR transient{20}boom \n", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 ERROR bad{20}mojo,{20}dude \n", - Utf8.toString(out.toByteArray())); - } - - } - -} diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2ExternalFeedTestCase.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2ExternalFeedTestCase.java deleted file mode 100644 index 9960d98f7f1..00000000000 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2ExternalFeedTestCase.java +++ /dev/null @@ -1,530 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.http.server; - -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.container.jdisc.messagebus.SessionCache; -import com.yahoo.container.logging.AccessLog; -import com.yahoo.document.DocumentTypeManager; -import com.yahoo.document.config.DocumentmanagerConfig; -import com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage; -import com.yahoo.jdisc.ReferencedResource; -import com.yahoo.jdisc.References; -import com.yahoo.jdisc.http.HttpRequest.Method; -import com.yahoo.messagebus.Message; -import com.yahoo.messagebus.MessageBus; -import com.yahoo.messagebus.MessageBusParams; -import com.yahoo.messagebus.ReplyHandler; -import com.yahoo.messagebus.Result; -import com.yahoo.messagebus.SourceSessionParams; -import com.yahoo.messagebus.network.Network; -import com.yahoo.messagebus.shared.SharedMessageBus; -import com.yahoo.messagebus.shared.SharedSourceSession; -import com.yahoo.metrics.simple.MetricReceiver; -import com.yahoo.text.Utf8; -import com.yahoo.vespa.http.client.config.FeedParams.DataFormat; -import com.yahoo.vespa.http.client.core.Headers; -import com.yahoo.vespa.http.client.core.OperationStatus; -import com.yahoo.vespaxmlparser.MockFeedReaderFactory; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -/** - * Check FeedHandler APIs. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class V2ExternalFeedTestCase { - - LessConfiguredHandler handler; - ExecutorService workers; - Level logLevel; - Logger logger; - boolean initUseParentHandlers; - LogBuffer logChecker; - - @Before - public void setUp() throws Exception { - workers = Executors.newCachedThreadPool(); - handler = new LessConfiguredHandler(workers); - logger = Logger.getLogger(Feeder.class.getName()); - logLevel = logger.getLevel(); - logger.setLevel(Level.ALL); - initUseParentHandlers = logger.getUseParentHandlers(); - logChecker = new LogBuffer(); - logger.setUseParentHandlers(false); - logger.addHandler(logChecker); - } - - @After - public void tearDown() throws Exception { - handler.destroy(); - workers.shutdown(); - logger.setLevel(logLevel); - logger.removeHandler(logChecker); - logger.setUseParentHandlers(initUseParentHandlers); - } - - private static class LogBuffer extends Handler { - public final BlockingQueue<LogRecord> records = new LinkedBlockingQueue<>(); - - @Override - public void publish(LogRecord record) { - try { - records.put(record); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - @Override - public void flush() { - } - - @Override - public void close() throws SecurityException { - } - } - - private static class LessConfiguredHandler extends FeedHandler { - volatile DataFormat lastFormatSeen; - - public LessConfiguredHandler(Executor executor) throws Exception { - super(new FeedHandler.Context(executor, - AccessLog.voidAccessLog(), - new DummyMetric()), - null, null, null, MetricReceiver.nullImplementation); - } - - @Override - protected Feeder createFeeder(HttpRequest request, - InputStream requestInputStream, - BlockingQueue<OperationStatus> operations, - String clientId, - boolean sessionIdWasGeneratedJustNow, int protocolVersion) - throws Exception { - LessConfiguredFeeder f = new LessConfiguredFeeder(requestInputStream, operations, - popClient(clientId), new FeederSettings(request), clientId, sessionIdWasGeneratedJustNow, - sourceSessionParams(request), null, this, this.feedReplyHandler, "ourHostname"); - lastFormatSeen = f.settings.dataFormat; - return f; - } - - @Override - protected DocumentTypeManager createDocumentManager( - DocumentmanagerConfig documentManagerConfig) { - return null; - } - } - - private static class MockSharedSession extends SharedSourceSession { - - public MockSharedSession(SourceSessionParams params) { - super(new SharedMessageBus(new MessageBus(new MockNetwork(), - new MessageBusParams())), params); - } - - @Override - public Result sendMessageBlocking(Message msg) throws InterruptedException { - return sendMessage(msg); - } - - @Override - public Result sendMessage(Message msg) { - ReplyHandler handler = msg.popHandler(); - MockReply mockReply = new MockReply(msg.getContext()); - if (msg instanceof Feeder.FeedErrorMessage) { - mockReply.addError(new com.yahoo.messagebus.Error(123, "Could not feed this")); - } - if (msg instanceof PutDocumentMessage) { - assert(msg.getTrace().getLevel() == 4); - assert(((PutDocumentMessage) msg).getPriority().name().equals("LOWEST")); - } - handler.handleReply(mockReply); - return Result.ACCEPTED; - } - - } - - private static class LessConfiguredFeeder extends Feeder { - public LessConfiguredFeeder(InputStream stream, - BlockingQueue<OperationStatus> operations, - ClientState storedState, FeederSettings settings, - String clientId, boolean sessionIdWasGeneratedJustNow, SourceSessionParams sessionParams, - SessionCache sessionCache, FeedHandler handler, ReplyHandler feedReplyHandler, - String localHostname) throws Exception { - super(stream, new MockFeedReaderFactory(), null, operations, storedState, settings, clientId, sessionIdWasGeneratedJustNow, - sessionParams, sessionCache, handler, new DummyMetric(), feedReplyHandler, localHostname); - } - - protected ReferencedResource<SharedSourceSession> retainSession( - SourceSessionParams sessionParams, SessionCache sessionCache) { - final SharedSourceSession session = new MockSharedSession(sessionParams); - return new ReferencedResource<>(session, References.fromResource(session)); - } - } - - @Test - public final void test() throws IOException, InterruptedException { - String sessionId; - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - sessionId = r.headers().getFirst(Headers.SESSION_ID); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[]{1, 3, 2}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.TIMEOUT, "1000000000"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.PRIORITY, "LOWEST"); - nalle.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "4"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n", - Utf8.toString(out.toByteArray())); - assertEquals("text/plain", r.getContentType()); - assertEquals(StandardCharsets.US_ASCII.name(), r.getCharacterEncoding()); - assertEquals(7, logChecker.records.size()); - String actualHandshake = logChecker.records.take().getMessage(); - assertThat(actualHandshake, actualHandshake.matches("Handshake completed for client (-?)(.+?)-#(.*?)\\."), is(true)); - assertEquals("Successfully deserialized document id: id:banana:banana::doc1", - logChecker.records.take().getMessage()); - assertEquals("Sent message successfully, document id: id:banana:banana::doc1", - logChecker.records.take().getMessage()); - } - - //test session ID without #, i.e. something fishy related to VIPs is going on - sessionId = "something"; - - { - InputStream in = new MetaStream(new byte[]{1, 3, 2}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.TIMEOUT, "1000000000"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - nalle.getJDiscRequest().headers().add(Headers.PRIORITY, "LOWEST"); - nalle.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "4"); - nalle.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "2"); - - HttpResponse r = handler.handle(nalle); - r.render(out); - String expectedErrorMsg = "Got request from client with id 'something', but found no session for this client."; - assertThat(Utf8.toString(out.toByteArray()), containsString(expectedErrorMsg)); - assertEquals("text/plain", r.getContentType()); - assertEquals(StandardCharsets.UTF_8.name(), r.getCharacterEncoding()); - } - - //test session ID with trailing # but no hostname - sessionId = "something#"; - - { - InputStream in = new MetaStream(new byte[]{1, 3, 2}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.TIMEOUT, "1000000000"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - nalle.getJDiscRequest().headers().add(Headers.PRIORITY, "LOWEST"); - nalle.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "4"); - HttpResponse r = handler.handle(nalle); - r.render(out); - String expectedErrorMsg = "Got request from client with id 'something#', but found no session for this client."; - assertThat(Utf8.toString(out.toByteArray()), containsString(expectedErrorMsg)); - assertEquals("text/plain", r.getContentType()); - assertEquals(StandardCharsets.UTF_8.name(), r.getCharacterEncoding()); - } - - //test session ID with trailing # and some unknown hostname at the end - sessionId = "something#thisHostnameDoesNotExistAnywhere"; - - { - InputStream in = new MetaStream(new byte[]{1, 3, 2}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.TIMEOUT, "1000000000"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - nalle.getJDiscRequest().headers().add(Headers.PRIORITY, "LOWEST"); - nalle.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "4"); - HttpResponse r = handler.handle(nalle); - r.render(out); - String expectedErrorMsg = "Got request from client with id 'something#thisHostnameDoesNotExistAnywhere', " + - "but found no session for this client. Session was originally established " + - "towards host thisHostnameDoesNotExistAnywhere, but our hostname is " + - "ourHostname."; - assertThat(Utf8.toString(out.toByteArray()), containsString(expectedErrorMsg)); - assertEquals("text/plain", r.getContentType()); - assertEquals(StandardCharsets.UTF_8.name(), r.getCharacterEncoding()); - } - - //test session ID with trailing # and some unknown hostname at the end - sessionId = "something#ourHostname"; - - { - InputStream in = new MetaStream(new byte[]{1, 3, 2}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.TIMEOUT, "1000000000"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.PRIORITY, "LOWEST"); - nalle.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "4"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 OK Document{20}processed. \n" + - "id:banana:banana::doc1 OK Document{20}processed. \n" + - "id:banana:banana::doc1 OK Document{20}processed. \n", - Utf8.toString(out.toByteArray())); - assertEquals("text/plain", r.getContentType()); - assertEquals(StandardCharsets.US_ASCII.name(), r.getCharacterEncoding()); - Thread.sleep(1000); - } - } - - @Test - public final void testFailedReading() throws IOException { - String sessionId; - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - sessionId = r.headers().getFirst(Headers.SESSION_ID); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[] { 4 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 ERROR Could{20}not{20}feed{20}this \n", - Utf8.toString(out.toByteArray())); - } - } - - @Test - public final void testCleaningDoesNotBlowUp() throws IOException { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - handler.forceRunCleanClients(); - } - - @Test - public final void testMockNetworkDoesNotBlowUp() { - Network n = new MockNetwork(); - n.registerSession(null); - n.unregisterSession(null); - assertTrue(n.allocServiceAddress(null)); - n.freeServiceAddress(null); - n.send(null, null); - assertNull(n.getConnectionSpec()); - assertNull(n.getMirror()); - } - - @Test - public final void testMockReplyDoesNotBlowUp() { - MockReply r = new MockReply(null); - assertNull(r.getProtocol()); - assertEquals(0, r.getType()); - assertFalse(r.hasFatalErrors()); - } - - @Test - public final void testFlush() throws IOException { - String sessionId; - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - sessionId = r.headers().getFirst(Headers.SESSION_ID); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[] { 1, 1, 1, 1, 1, 1, 1}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.PRIORITY, "LOWEST"); - nalle.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "4"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n", - Utf8.toString(out.toByteArray())); - } - } - - @Test - public final void testIllegalVersion() throws IOException { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers() - .add(Headers.VERSION, Integer.toString(Integer.MAX_VALUE)); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals(Headers.HTTP_NOT_ACCEPTABLE, r.getStatus()); - } - - @Test - public final void testSettings() { - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - nalle.getJDiscRequest().headers().add(Headers.ROUTE, "bamse brakar"); - nalle.getJDiscRequest().headers().add(Headers.DENY_IF_BUSY, "true"); - FeederSettings settings = new FeederSettings(nalle); - assertEquals(false, settings.drain); - assertEquals(2, settings.route.getNumHops()); - assertEquals(true, settings.denyIfBusy); - } - - @Test - public final void testJsonInputFormat() throws IOException, InterruptedException { - String sessionId; - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - sessionId = r.headers().getFirst(Headers.SESSION_ID); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[]{1, 3, 2}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.TIMEOUT, "1000000000"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DATA_FORMAT, DataFormat.JSON_UTF8.name()); - nalle.getJDiscRequest().headers().add(Headers.PRIORITY, "LOWEST"); - nalle.getJDiscRequest().headers().add(Headers.TRACE_LEVEL, "4"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n" - + "id:banana:banana::doc1 OK Document{20}processed. \n", - Utf8.toString(out.toByteArray())); - assertEquals("text/plain", r.getContentType()); - assertEquals(StandardCharsets.US_ASCII.name(), r.getCharacterEncoding()); - assertEquals(7, logChecker.records.size()); - String actualHandshake = logChecker.records.take().getMessage(); - assertThat(actualHandshake, actualHandshake.matches("Handshake completed for client (-?)(.+?)-#(.*?)\\."), is(true)); - assertEquals("Successfully deserialized document id: id:banana:banana::doc1", - logChecker.records.take().getMessage()); - assertEquals("Sent message successfully, document id: id:banana:banana::doc1", - logChecker.records.take().getMessage()); - assertSame(DataFormat.JSON_UTF8, handler.lastFormatSeen); - } - } - -} diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2FailingMessagebusTestCase.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2FailingMessagebusTestCase.java deleted file mode 100644 index 6290c22f694..00000000000 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2FailingMessagebusTestCase.java +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.http.server; - -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.container.jdisc.messagebus.SessionCache; -import com.yahoo.container.logging.AccessLog; -import com.yahoo.document.DocumentTypeManager; -import com.yahoo.document.config.DocumentmanagerConfig; -import com.yahoo.jdisc.ReferencedResource; -import com.yahoo.jdisc.References; -import com.yahoo.jdisc.http.HttpRequest.Method; -import com.yahoo.messagebus.*; -import com.yahoo.messagebus.shared.SharedMessageBus; -import com.yahoo.messagebus.shared.SharedSourceSession; -import com.yahoo.metrics.simple.MetricReceiver; -import com.yahoo.text.Utf8; -import com.yahoo.vespa.http.client.core.Headers; -import com.yahoo.vespa.http.client.core.OperationStatus; -import com.yahoo.vespaxmlparser.MockFeedReaderFactory; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static org.junit.Assert.assertEquals; - -/** - * Check FeedHandler APIs. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class V2FailingMessagebusTestCase { - - LessConfiguredHandler handler; - ExecutorService workers; - int mbus; - - @Before - public void setUp() throws Exception { - workers = Executors.newCachedThreadPool(); - handler = new LessConfiguredHandler(workers); - mbus = 0; - } - - @After - public void tearDown() throws Exception { - handler.destroy(); - workers.shutdown(); - mbus = 0; - } - - private class LessConfiguredHandler extends FeedHandler { - - public LessConfiguredHandler(Executor executor) throws Exception { - super(new FeedHandler.Context(executor, AccessLog.voidAccessLog(), new DummyMetric()), - null, null, null, MetricReceiver.nullImplementation); - } - - @Override - protected Feeder createFeeder(HttpRequest request, - InputStream requestInputStream, - BlockingQueue<OperationStatus> operations, - String clientId, - boolean sessionIdWasGeneratedJustNow, int protocolVersion) throws Exception { - return new LessConfiguredFeeder(requestInputStream, operations, - popClient(clientId), new FeederSettings(request), clientId, sessionIdWasGeneratedJustNow, - sourceSessionParams(request), null, this, this.feedReplyHandler, ""); - } - - @Override - protected DocumentTypeManager createDocumentManager( - DocumentmanagerConfig documentManagerConfig) { - return null; - } - } - - private class MockSharedSession extends SharedSourceSession { - - public MockSharedSession(SourceSessionParams params) { - super(new SharedMessageBus(new MessageBus(new MockNetwork(), - new MessageBusParams())), params); - } - - @Override - public Result sendMessageBlocking(Message msg) throws InterruptedException { - return sendMessage(msg); - } - - @Override - public Result sendMessage(Message msg) { - ReplyHandler handler = msg.popHandler(); - - switch (mbus) { - case 0: - throw new RuntimeException("boom"); - case 1: - Result r = new Result(ErrorCode.SEND_QUEUE_FULL, "tralala"); - mbus = 2; - return r; - case 2: - handler.handleReply(new MockReply(msg.getContext())); - return Result.ACCEPTED; - default: - throw new IllegalStateException("WTF?!"); - } - } - } - - private class LessConfiguredFeeder extends Feeder { - - public LessConfiguredFeeder(InputStream inputStream, - BlockingQueue<OperationStatus> operations, - ClientState storedState, FeederSettings settings, - String clientId, boolean sessionIdWasGeneratedJustNow, SourceSessionParams sessionParams, - SessionCache sessionCache, FeedHandler handler, ReplyHandler feedReplyHandler, - String localHostname) throws Exception { - super(inputStream, new MockFeedReaderFactory(), null, operations, storedState, settings, clientId, sessionIdWasGeneratedJustNow, - sessionParams, sessionCache, handler, new DummyMetric(), feedReplyHandler, localHostname); - } - - protected ReferencedResource<SharedSourceSession> retainSession( - SourceSessionParams sessionParams, SessionCache sessionCache) { - final SharedSourceSession session = new MockSharedSession(sessionParams); - return new ReferencedResource<>(session, References.fromResource(session)); - } - } - - @Test - public final void testFailingMbus() throws IOException { - String sessionId; - { - InputStream in = new MetaStream(new byte[]{1}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - sessionId = r.headers().getFirst(Headers.SESSION_ID); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[]{1}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 ERROR boom \n", - Utf8.toString(out.toByteArray())); - } - } - - @Test - public final void testBusyMbus() throws IOException { - String sessionId; - { - InputStream in = new MetaStream(new byte[]{1}); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - mbus = 2; - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - sessionId = r.headers().getFirst(Headers.SESSION_ID); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - mbus = 1; - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - nalle.getJDiscRequest().headers() - .add(Headers.DENY_IF_BUSY, "false"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 OK Document{20}processed. \n", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - mbus = 1; - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - nalle.getJDiscRequest().headers().add(Headers.DENY_IF_BUSY, "true"); - HttpResponse r = handler.handle(nalle); - r.render(out); - assertEquals("id:banana:banana::doc1 TRANSIENT_ERROR tralala \n", - Utf8.toString(out.toByteArray())); - } - } - -} diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2NoXmlReaderTestCase.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2NoXmlReaderTestCase.java deleted file mode 100644 index 633477dcc79..00000000000 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/V2NoXmlReaderTestCase.java +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.http.server; - -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.container.jdisc.messagebus.SessionCache; -import com.yahoo.container.logging.AccessLog; -import com.yahoo.document.DocumentTypeManager; -import com.yahoo.document.config.DocumentmanagerConfig; -import com.yahoo.jdisc.ReferencedResource; -import com.yahoo.jdisc.References; -import com.yahoo.jdisc.http.HttpRequest.Method; -import com.yahoo.messagebus.*; -import com.yahoo.messagebus.Error; -import com.yahoo.messagebus.shared.SharedMessageBus; -import com.yahoo.messagebus.shared.SharedSourceSession; -import com.yahoo.metrics.simple.MetricReceiver; -import com.yahoo.text.Utf8; -import com.yahoo.vespa.http.client.core.Headers; -import com.yahoo.vespa.http.client.core.OperationStatus; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import static org.junit.Assert.assertEquals; - -/** - * Check FeedHandler APIs. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class V2NoXmlReaderTestCase { - - LessConfiguredHandler handler; - ExecutorService workers; - - @Before - public void setUp() throws Exception { - workers = Executors.newCachedThreadPool(); - handler = new LessConfiguredHandler(workers); - } - - @After - public void tearDown() throws Exception { - handler.destroy(); - workers.shutdown(); - } - - private static class LessConfiguredHandler extends FeedHandler { - - public LessConfiguredHandler(Executor executor) throws Exception { - super(new FeedHandler.Context(executor, AccessLog.voidAccessLog(), new DummyMetric()), - null, null, null, MetricReceiver.nullImplementation); - } - - - @Override - protected Feeder createFeeder(HttpRequest request, InputStream requestInputStream, - BlockingQueue<OperationStatus> operations, String clientId, - boolean sessionIdWasGeneratedJustNow, int protocolVersion) - throws Exception { - return new LessConfiguredFeeder(requestInputStream, operations, - popClient(clientId), new FeederSettings(request), clientId, sessionIdWasGeneratedJustNow, - sourceSessionParams(request), null, this, this.feedReplyHandler, ""); - } - - @Override - protected DocumentTypeManager createDocumentManager( - DocumentmanagerConfig documentManagerConfig) { - return null; - } - } - - private static class MockSharedSession extends SharedSourceSession { - - public MockSharedSession(SourceSessionParams params) { - super(new SharedMessageBus(new MessageBus(new MockNetwork(), - new MessageBusParams())), params); - } - - @Override - public Result sendMessageBlocking(Message msg) throws InterruptedException { - return sendMessage(msg); - } - - @Override - public Result sendMessage(Message msg) { - ReplyHandler handler = msg.popHandler(); - MockReply mockReply = new MockReply(msg.getContext()); - if (msg instanceof Feeder.FeedErrorMessage) { - mockReply.addError(new Error(123, "Could not feed this")); - } - handler.handleReply(mockReply); - return Result.ACCEPTED; - } - - } - - private static class LessConfiguredFeeder extends Feeder { - - public LessConfiguredFeeder(InputStream inputStream, - BlockingQueue<OperationStatus> operations, - ClientState storedState, FeederSettings settings, - String clientId, boolean sessionIdWasGeneratedJustNow, SourceSessionParams sessionParams, - SessionCache sessionCache, FeedHandler handler, ReplyHandler feedReplyHandler, - String localHostname) throws Exception { - super(inputStream, null, null, operations, storedState, settings, clientId, sessionIdWasGeneratedJustNow, - sessionParams, sessionCache, handler, new DummyMetric(), feedReplyHandler, localHostname); - } - - protected ReferencedResource<SharedSourceSession> retainSession( - SourceSessionParams sessionParams, SessionCache sessionCache) { - final SharedSourceSession session = new MockSharedSession(sessionParams); - return new ReferencedResource<>(session, References.fromResource(session)); - } - } - - @Test - public final void test() throws IOException { - String sessionId; - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest - .createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "false"); - HttpResponse r = handler.handle(nalle); - sessionId = r.headers().getFirst(Headers.SESSION_ID); - r.render(out); - assertEquals("", - Utf8.toString(out.toByteArray())); - } - { - InputStream in = new MetaStream(new byte[] { 1 }); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HttpRequest nalle = HttpRequest.createTestRequest( - "http://test4-steinar:19020/reserved-for-internal-use/feedapi", - Method.POST, in); - nalle.getJDiscRequest().headers().add(Headers.VERSION, "2"); - nalle.getJDiscRequest().headers().add(Headers.SESSION_ID, sessionId); - nalle.getJDiscRequest().headers().add(Headers.DRAIN, "true"); - HttpResponse r = handler.handle(nalle); - r.render(out); - //This is different from v1. If we cannot parse XML, we will still get response code 200, but with a sensible - //error message in the response. - assertEquals(200, r.getStatus()); - assertEquals("id:banana:banana::doc1 ERROR Could{20}not{20}feed{20}this \n", - Utf8.toString(out.toByteArray())); - } - } - -} diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/VersionsTestCase.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/VersionsTestCase.java index d6f605b0379..128664dda9e 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/VersionsTestCase.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/VersionsTestCase.java @@ -23,13 +23,14 @@ public class VersionsTestCase { private static final List<String> EMPTY = Collections.emptyList(); private static final List<String> ONE_TWO = Arrays.asList("1", "2"); + private static final List<String> ONE_THREE = Arrays.asList("1", "3"); private static final List<String> TWO_THREE = Arrays.asList("3", "2"); - private static final List<String> ONE_NULL_TWO = Arrays.asList("1", null, "2"); - private static final List<String> ONE_COMMA_TWO = Collections.singletonList("1, 2"); - private static final List<String> ONE_EMPTY_TWO = Arrays.asList("1", "", "2"); + private static final List<String> ONE_NULL_THREE = Arrays.asList("1", null, "3"); + private static final List<String> ONE_COMMA_THREE = Collections.singletonList("1, 3"); + private static final List<String> ONE_EMPTY_THREE = Arrays.asList("1", "", "3"); private static final List<String> TOO_LARGE_NUMBER = Collections.singletonList("1000000000"); - private static final List<String> TWO_TOO_LARGE_NUMBER = Arrays.asList("2", "1000000000"); - private static final List<String> TWO_COMMA_TOO_LARGE_NUMBER = Arrays.asList("2,1000000000"); + private static final List<String> THREE_TOO_LARGE_NUMBER = Arrays.asList("3", "1000000000"); + private static final List<String> THREE_COMMA_TOO_LARGE_NUMBER = Arrays.asList("3,1000000000"); private static final List<String> GARBAGE = Collections.singletonList("garbage"); @Test @@ -42,8 +43,15 @@ public class VersionsTestCase { @Test public void testOneTwo() throws Exception { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_TWO); + assertThat(v.first, instanceOf(ErrorHttpResponse.class)); + assertThat(v.second, is(-1)); + } + + @Test + public void testOneThree() throws Exception { + Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_THREE); assertThat(v.first, nullValue()); - assertThat(v.second, is(2)); + assertThat(v.second, is(3)); } @Test @@ -54,24 +62,24 @@ public class VersionsTestCase { } @Test - public void testOneNullTwo() throws Exception { - Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_NULL_TWO); + public void testOneNullThree() throws Exception { + Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_NULL_THREE); assertThat(v.first, nullValue()); - assertThat(v.second, is(2)); + assertThat(v.second, is(3)); } @Test - public void testOneCommaTwo() throws Exception { - Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_COMMA_TWO); + public void testOneCommaThree() throws Exception { + Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_COMMA_THREE); assertThat(v.first, nullValue()); - assertThat(v.second, is(2)); + assertThat(v.second, is(3)); } @Test - public void testOneEmptyTwo() throws Exception { - Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_EMPTY_TWO); + public void testOneEmptyThree() throws Exception { + Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_EMPTY_THREE); assertThat(v.first, nullValue()); - assertThat(v.second, is(2)); + assertThat(v.second, is(3)); } @Test @@ -83,22 +91,22 @@ public class VersionsTestCase { errorResponse.render(errorMsg); assertThat(errorMsg.toString(), is("Could not parse X-Yahoo-Feed-Protocol-Versionheader of request (values: [1000000000]). " + - "Server supports protocol versions [2, 3]")); + "Server supports protocol versions [3]")); assertThat(v.second, is(-1)); } @Test - public void testTwoTooLarge() throws Exception { - Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(TWO_TOO_LARGE_NUMBER); + public void testThreeTooLarge() throws Exception { + Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(THREE_TOO_LARGE_NUMBER); assertThat(v.first, nullValue()); - assertThat(v.second, is(2)); + assertThat(v.second, is(3)); } @Test public void testTwoCommaTooLarge() throws Exception { - Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(TWO_COMMA_TOO_LARGE_NUMBER); + Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(THREE_COMMA_TOO_LARGE_NUMBER); assertThat(v.first, nullValue()); - assertThat(v.second, is(2)); + assertThat(v.second, is(3)); } @Test |