diff options
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/federation')
15 files changed, 0 insertions, 1933 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/GzipDecompressingEntityTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/GzipDecompressingEntityTestCase.java deleted file mode 100644 index 6babba5a36a..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/GzipDecompressingEntityTestCase.java +++ /dev/null @@ -1,212 +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.search.federation.http; - -import static org.junit.Assert.*; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.UnknownHostException; -import java.util.Arrays; -import java.util.Random; -import java.util.zip.GZIPOutputStream; - -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.message.BasicHeader; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.yahoo.text.Utf8; - -/** - * Test GZip support for the HTTP integration introduced in 4.2. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - */ -public class GzipDecompressingEntityTestCase { - private static final String STREAM_CONTENT = "00000000000000000000000000000000000000000000000000"; - private static final byte[] CONTENT_AS_BYTES = Utf8.toBytes(STREAM_CONTENT); - GzipDecompressingEntity testEntity; - - private static final class MockEntity implements HttpEntity { - - private final InputStream inStream; - - MockEntity(InputStream is) { - inStream = is; - } - - @Override - public boolean isRepeatable() { - return false; - } - - @Override - public boolean isChunked() { - return false; - } - - @Override - public long getContentLength() { - return -1; - } - - @Override - public Header getContentType() { - return new BasicHeader("Content-Type", "text/plain"); - } - - @Override - public Header getContentEncoding() { - return new BasicHeader("Content-Encoding", "gzip"); - } - - @Override - public InputStream getContent() throws IOException, - IllegalStateException { - return inStream; - } - - @Override - public void writeTo(OutputStream outstream) throws IOException { - } - - @Override - public boolean isStreaming() { - return false; - } - - @Override - public void consumeContent() throws IOException { - } - } - - @Before - public void setUp() throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - GZIPOutputStream gzip = new GZIPOutputStream(out); - gzip.write(CONTENT_AS_BYTES); - gzip.finish(); - gzip.close(); - byte[] compressed = out.toByteArray(); - InputStream inStream = new ByteArrayInputStream(compressed); - testEntity = new GzipDecompressingEntity(new MockEntity(inStream)); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public final void testGetContentLength() throws UnknownHostException { - assertEquals(STREAM_CONTENT.length(), testEntity.getContentLength()); - } - - @Test - public final void testGetContent() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - byte[] buffer = new byte[CONTENT_AS_BYTES.length]; - int read = in.read(buffer); - assertEquals(CONTENT_AS_BYTES.length, read); - assertArrayEquals(CONTENT_AS_BYTES, buffer); - } - - @Test - public final void testGetContentToBigArray() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - byte[] buffer = new byte[CONTENT_AS_BYTES.length * 2]; - in.read(buffer); - byte[] expected = Arrays.copyOf(CONTENT_AS_BYTES, CONTENT_AS_BYTES.length * 2); - assertArrayEquals(expected, buffer); - } - - @Test - public final void testGetContentAvailable() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - assertEquals(CONTENT_AS_BYTES.length, in.available()); - } - - @Test - public final void testLargeZip() throws IOException { - byte [] input = new byte [10000000]; - Random random = new Random(89); - for (int i = 0; i < input.length; i++) { - input[i] = (byte) random.nextInt(); - } - ByteArrayOutputStream out = new ByteArrayOutputStream(); - GZIPOutputStream gzip = new GZIPOutputStream(out); - gzip.write(input); - gzip.finish(); - gzip.close(); - byte[] compressed = out.toByteArray(); - assertEquals(10003073, compressed.length); - InputStream inStream = new ByteArrayInputStream(compressed); - GzipDecompressingEntity gunzipper = new GzipDecompressingEntity(new MockEntity(inStream)); - assertEquals(input.length, gunzipper.getContentLength()); - byte[] buffer = new byte[input.length]; - InputStream content = gunzipper.getContent(); - assertEquals(input.length, content.available()); - int read = content.read(buffer); - assertEquals(input.length, read); - assertArrayEquals(input, buffer); - } - - @Test - public final void testGetContentReadByte() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - byte[] buffer = new byte[CONTENT_AS_BYTES.length * 2]; - int i = 0; - while (i < buffer.length) { - int r = in.read(); - if (r == -1) { - break; - } else { - buffer[i++] = (byte) r; - } - } - byte[] expected = Arrays.copyOf(CONTENT_AS_BYTES, CONTENT_AS_BYTES.length * 2); - assertEquals(CONTENT_AS_BYTES.length, i); - assertArrayEquals(expected, buffer); - } - - @Test - public final void testGetContentReadWithOffset() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - byte[] buffer = new byte[CONTENT_AS_BYTES.length * 2]; - int read = in.read(buffer, CONTENT_AS_BYTES.length, CONTENT_AS_BYTES.length); - assertEquals(CONTENT_AS_BYTES.length, read); - byte[] expected = new byte[CONTENT_AS_BYTES.length * 2]; - for (int i = 0; i < CONTENT_AS_BYTES.length; ++i) { - expected[CONTENT_AS_BYTES.length + i] = CONTENT_AS_BYTES[i]; - } - assertArrayEquals(expected, buffer); - read = in.read(buffer, 0, CONTENT_AS_BYTES.length); - assertEquals(-1, read); - } - - @Test - public final void testGetContentSkip() throws IllegalStateException, IOException { - InputStream in = testEntity.getContent(); - final long n = 5L; - long skipped = in.skip(n); - assertEquals(n, skipped); - int read = in.read(); - assertEquals(CONTENT_AS_BYTES[(int) n], read); - skipped = in.skip(5000); - assertEquals(CONTENT_AS_BYTES.length - n - 1, skipped); - assertEquals(-1L, in.skip(1L)); - } - - - @Test - public final void testWriteToOutputStream() throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - testEntity.writeTo(out); - assertArrayEquals(CONTENT_AS_BYTES, out.toByteArray()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/HttpParametersTest.java b/container-search/src/test/java/com/yahoo/search/federation/http/HttpParametersTest.java deleted file mode 100644 index 11f5d7d14fd..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/HttpParametersTest.java +++ /dev/null @@ -1,238 +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.search.federation.http; - -import com.yahoo.search.federation.ProviderConfig; -import org.junit.Test; - -import static com.yahoo.search.federation.ProviderConfig.Yca; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -/** - * @author gjoranv - * @author Steinar Knutsen - */ -public class HttpParametersTest { - - @Test - public void create_from_config() throws Exception { - ProviderConfig config = new ProviderConfig(new ProviderConfig.Builder() - .connectionTimeout(1.0) - .maxConnectionPerRoute(2) - .maxConnections(3) - .path("myPath") - .readTimeout(4) - .socketBufferBytes(5) - .yca(new Yca.Builder() - .applicationId("myId") - .host("myYcaHost") - .port(7) - .retry(8) - .ttl(9) - .useProxy(true))); - - HTTPParameters httpParameters = new HTTPParameters(config); - - // Written to configuredConnectionTimeout, but it is not accessible!? - //assertThat(httpParameters.getConnectionTimeout(), is(1000)); - - - // This value is not set from config by the constructor!? - //assertThat(httpParameters.getMaxConnectionsPerRoute(), is(2)); - - // This value is not set from config by the constructor!? - //assertThat(httpParameters.getMaxTotalConnections(), is(3)); - - assertThat(httpParameters.getPath(), is("/myPath")); - - // This value is not set from config by the constructor!? - //assertThat(httpParameters.getReadTimeout(), is(4)); - - // This value is not set from config by the constructor!? - //assertThat(httpParameters.getSocketBufferSizeBytes(), is(5)); - - - assertThat(httpParameters.getYcaUseProxy(), is(true)); - assertThat(httpParameters.getYcaApplicationId(), is("myId")); - assertThat(httpParameters.getYcaProxy(), is("myYcaHost")); - assertThat(httpParameters.getYcaPort(), is(7)); - assertThat(httpParameters.getYcaRetry(), is(8000L)); - assertThat(httpParameters.getYcaTtl(), is(9000L)); - } - - @Test - public void requireFreezeWorksForAccessors() { - HTTPParameters p = new HTTPParameters(); - boolean caught = false; - final int expected = 37; - p.setConnectionTimeout(expected); - assertEquals(expected, p.getConnectionTimeout()); - p.freeze(); - try { - p.setConnectionTimeout(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setReadTimeout(expected); - assertEquals(expected, p.getReadTimeout()); - p.freeze(); - try { - p.setReadTimeout(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setPersistentConnections(true); - assertTrue(p.getPersistentConnections()); - p.freeze(); - try { - p.setPersistentConnections(false); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - assertEquals("http", p.getProxyType()); - - p = new HTTPParameters(); - caught = false; - p.setEnableProxy(true); - assertTrue(p.getEnableProxy()); - p.freeze(); - try { - p.setEnableProxy(false); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setProxyHost("nalle"); - assertEquals("nalle", p.getProxyHost()); - p.freeze(); - try { - p.setProxyHost("jappe"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setProxyPort(expected); - assertEquals(expected, p.getProxyPort()); - p.freeze(); - try { - p.setProxyPort(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setMethod("POST"); - assertEquals("POST", p.getMethod()); - p.freeze(); - try { - p.setMethod("GET"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setSchema("gopher"); - assertEquals("gopher", p.getSchema()); - p.freeze(); - try { - p.setSchema("http"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setInputEncoding("iso-8859-15"); - assertEquals("iso-8859-15", p.getInputEncoding()); - p.freeze(); - try { - p.setInputEncoding("shift-jis"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setOutputEncoding("iso-8859-15"); - assertEquals("iso-8859-15", p.getOutputEncoding()); - p.freeze(); - try { - p.setOutputEncoding("shift-jis"); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setMaxTotalConnections(expected); - assertEquals(expected, p.getMaxTotalConnections()); - p.freeze(); - try { - p.setMaxTotalConnections(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setMaxConnectionsPerRoute(expected); - assertEquals(expected, p.getMaxConnectionsPerRoute()); - p.freeze(); - try { - p.setMaxConnectionsPerRoute(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setSocketBufferSizeBytes(expected); - assertEquals(expected, p.getSocketBufferSizeBytes()); - p.freeze(); - try { - p.setSocketBufferSizeBytes(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - - p = new HTTPParameters(); - caught = false; - p.setRetries(expected); - assertEquals(expected, p.getRetries()); - p.freeze(); - try { - p.setRetries(0); - } catch (IllegalStateException e) { - caught = true; - } - assertTrue(caught); - } -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/HttpPostTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/HttpPostTestCase.java deleted file mode 100644 index e0b2afe4e1f..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/HttpPostTestCase.java +++ /dev/null @@ -1,99 +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.search.federation.http; - -import com.yahoo.component.ComponentId; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.StupidSingleThreadedHttpServer; -import com.yahoo.search.federation.ProviderConfig.PingOption; -import com.yahoo.search.federation.http.Connection; -import com.yahoo.search.federation.http.HTTPProviderSearcher; -import com.yahoo.search.result.Hit; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.statistics.Statistics; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.entity.StringEntity; -import org.junit.Test; - -import java.io.InputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; - -/** - * See bug #3234696. - * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> - */ -public class HttpPostTestCase { - - @Test - public void testPostingSearcher() throws Exception { - StupidSingleThreadedHttpServer server = new StupidSingleThreadedHttpServer(); - server.start(); - - TestPostSearcher searcher = new TestPostSearcher(new ComponentId("foo:1"), - Arrays.asList(new Connection("localhost", server.getServerPort())), - "/"); - Query q = new Query(""); - q.setTimeout(10000000L); - Execution e = new Execution(searcher, Execution.Context.createContextStub()); - - searcher.search(q, e); - - assertThat(server.getRequest(), containsString("My POST body")); - server.stop(); - } - - private static class TestPostSearcher extends HTTPProviderSearcher { - public TestPostSearcher(ComponentId id, List<Connection> connections, String path) { - super(id, connections, httpParameters(path), Statistics.nullImplementation); - } - - private static HTTPParameters httpParameters(String path) { - HTTPParameters httpParameters = new HTTPParameters(path); - httpParameters.setPingOption(PingOption.Enum.DISABLE); - return httpParameters; - } - - @Override - protected HttpUriRequest createRequest(String method, URI uri, HttpEntity entity) { - HttpPost request = new HttpPost(uri); - request.setEntity(entity); - return request; - } - - @Override - protected HttpEntity getRequestEntity(Query query, Hit requestMeta) { - try { - return new StringEntity("My POST body"); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - } - - @Override - public Map<String, String> getCacheKey(Query q) { - return new HashMap<>(0); - } - - @Override - public void unmarshal(final InputStream stream, long contentLength, final Result result) throws IOException { - // do nothing with the result - } - - @Override - protected void fill(Result result, String summaryClass, Execution execution, Connection connection) { - //Empty - } - } -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java deleted file mode 100644 index b4f3c13b8e2..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/HttpTestCase.java +++ /dev/null @@ -1,124 +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.search.federation.http; - -import com.yahoo.component.ComponentId; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.StupidSingleThreadedHttpServer; -import com.yahoo.search.result.Hit; -import com.yahoo.search.result.HitGroup; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.statistics.Statistics; -import com.yahoo.text.Utf8; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.xml.bind.JAXBException; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -/** - * Rudimentary http searcher test. - * - * @author bratseth - */ -public class HttpTestCase { - - private StupidSingleThreadedHttpServer httpServer; - private TestHTTPClientSearcher searcher; - - @Test - public void testSearcher() throws JAXBException { - Result result = searchUsingLocalhost(); - - assertEquals("ok", result.getQuery().properties().get("gotResponse")); - assertEquals(0, result.getQuery().errors().size()); - } - - private Result searchUsingLocalhost() { - searcher = new TestHTTPClientSearcher("test","localhost",getPort()); - Query query = new Query("/?query=test"); - - query.setWindow(0,10); - return searcher.search(query, new Execution(searcher, Execution.Context.createContextStub())); - } - - @Test - public void test_that_ip_address_set_on_meta_hit() { - Result result = searchUsingLocalhost(); - Hit metaHit = getFirstMetaHit(result.hits()); - String ip = (String) metaHit.getField(HTTPSearcher.LOG_IP_ADDRESS); - - assertEquals(ip, "127.0.0.1"); - } - - private Hit getFirstMetaHit(HitGroup hits) { - for (Iterator<Hit> i = hits.unorderedDeepIterator(); i.hasNext();) { - Hit hit = i.next(); - if (hit.isMeta()) - return hit; - } - return null; - } - - @Before - public void setUp() throws Exception { - httpServer = new StupidSingleThreadedHttpServer(0, 0) { - @Override - protected byte[] getResponse(String request) { - return Utf8.toBytes("HTTP/1.1 200 OK\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 5\r\n" + - "\r\n" + - "hello"); - } - }; - httpServer.start(); - } - - private int getPort() { - return httpServer.getServerPort(); - } - - @After - public void tearDown() throws Exception { - httpServer.stop(); - if (searcher != null) { - searcher.shutdownConnectionManagers(); - } - } - - private static class TestHTTPClientSearcher extends HTTPClientSearcher { - - public TestHTTPClientSearcher(String id, String hostName, int port) { - super(new ComponentId(id), toConnections(hostName,port), "", Statistics.nullImplementation); - } - - private static List<Connection> toConnections(String hostName,int port) { - List<Connection> connections=new ArrayList<>(); - connections.add(new Connection(hostName,port)); - return connections; - } - - @Override - public Query handleResponse(InputStream inputStream, long contentLength, Query query) throws IOException { - query.properties().set("gotResponse","ok"); - return query; - } - - @Override - public Map<String, String> getCacheKey(Query q) { - return null; - } - - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java deleted file mode 100644 index 8c1ff69666b..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/PingTestCase.java +++ /dev/null @@ -1,288 +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.search.federation.http; - -import com.yahoo.component.ComponentId; -import com.yahoo.prelude.Ping; -import com.yahoo.prelude.Pong; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.StupidSingleThreadedHttpServer; -import com.yahoo.search.result.ErrorMessage; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.statistics.Statistics; -import com.yahoo.text.Utf8; -import com.yahoo.yolean.Exceptions; -import org.apache.http.HttpEntity; -import org.junit.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Check for different keep-alive scenarios. What we really want to test - * is the server does not hang. - * - * @author Steinar Knutsen - */ -public class PingTestCase { - - private static final int TIMEOUT_MS = 60000; - - @Test - public void testNiceCase() throws Exception { - NiceStupidServer server = new NiceStupidServer(); - server.start(); - checkSearchAndPing(true, true, true, server.getServerPort()); - server.stop(); - } - - private void checkSearchAndPing(boolean firstSearch, boolean pongCheck, boolean secondSearch, int port) { - String resultThing; - String comment; - TestHTTPClientSearcher searcher = new TestHTTPClientSearcher("test", - "localhost", port); - try { - - Query query = new Query("/?query=test"); - - query.setWindow(0, 10); - // high timeout to allow for overloaded test machine - query.setTimeout(TIMEOUT_MS); - Ping ping = new Ping(TIMEOUT_MS); - - long start = System.currentTimeMillis(); - Execution exe = new Execution(searcher, Execution.Context.createContextStub()); - exe.search(query); - - resultThing = firstSearch ? "ok" : null; - comment = firstSearch ? "First search should have succeeded." : "First search should fail."; - assertEquals(comment, resultThing, query.properties().get("gotResponse")); - Pong pong = searcher.ping(ping, searcher.getConnection()); - if (pongCheck) { - assertEquals("Ping should not have failed.", 0, pong.getErrorSize()); - } else { - assertEquals("Ping should have failed.", 1, pong.getErrorSize()); - } - exe = new Execution(searcher, Execution.Context.createContextStub()); - exe.search(query); - - resultThing = secondSearch ? "ok" : null; - comment = secondSearch ? "Second search should have succeeded." : "Second search should fail."; - - assertEquals(resultThing, query.properties().get("gotResponse")); - long duration = System.currentTimeMillis() - start; - // target for duration based on the timeout values + some slack - assertTrue("This test probably hanged.", duration < TIMEOUT_MS + 4000); - searcher.shutdownConnectionManagers(); - } finally { - searcher.deconstruct(); - } - } - - @Test - public void testUselessCase() throws Exception { - UselessStupidServer server = new UselessStupidServer(); - server.start(); - checkSearchAndPing(false, true, false, server.getServerPort()); - server.stop(); - } - - @Test - public void testGrumpyCase() throws Exception { - GrumpyStupidServer server = new GrumpyStupidServer(); - server.start(); - checkSearchAndPing(false, false, false, server.getServerPort()); - server.stop(); - } - - @Test - public void testPassiveAggressiveCase() throws Exception { - PassiveAggressiveStupidServer server = new PassiveAggressiveStupidServer(); - server.start(); - checkSearchAndPing(true, false, true, server.getServerPort()); - server.stop(); - } - - // OK on ping and search - private static class NiceStupidServer extends StupidSingleThreadedHttpServer { - private NiceStupidServer() throws IOException { - super(0, 0); - } - - @Override - protected byte[] getResponse(String request) { - return Utf8.toBytes("HTTP/1.1 200 OK\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 6\r\n" + - "\r\n" + - "hello\n"); - } - } - - // rejects ping and accepts search - private static class PassiveAggressiveStupidServer extends StupidSingleThreadedHttpServer { - - private PassiveAggressiveStupidServer() throws IOException { - super(0, 0); - } - - @Override - protected byte[] getResponse(String request) { - if (request.contains("/ping")) { - return Utf8.toBytes("HTTP/1.1 404 Not found\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 8\r\n" + - "\r\n" + - "go away\n"); - } else { - return Utf8.toBytes("HTTP/1.1 200 OK\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 6\r\n" + - "\r\n" + - "hello\n"); - } - } - } - - // accepts ping and rejects search - private static class UselessStupidServer extends StupidSingleThreadedHttpServer { - private UselessStupidServer() throws IOException { - super(0, 0); - } - - - @Override - protected byte[] getResponse(String request) { - if (request.contains("/ping")) { - return Utf8.toBytes("HTTP/1.1 200 OK\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 6\r\n" + - "\r\n" + - "hello\n"); - } else { - return Utf8.toBytes("HTTP/1.1 404 Not found\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 8\r\n" + - "\r\n" + - "go away\n"); - } - } - } - - // rejects ping and search - private static class GrumpyStupidServer extends StupidSingleThreadedHttpServer { - private GrumpyStupidServer() throws IOException { - super(0, 0); - } - - @Override - protected byte[] getResponse(String request) { - return Utf8.toBytes("HTTP/1.1 404 Not found\r\n" + - "Content-Type: text/xml; charset=UTF-8\r\n" + - "Connection: close\r\n" + - "Content-Length: 8\r\n" + - "\r\n" + - "go away\n"); - } - } - - private static class TestHTTPClientSearcher extends HTTPClientSearcher { - - public TestHTTPClientSearcher(String id, String hostName, int port) { - super(new ComponentId(id), toConnections(hostName,port), "", Statistics.nullImplementation); - } - - private static List<Connection> toConnections(String hostName,int port) { - List<Connection> connections=new ArrayList<>(); - connections.add(new Connection(hostName,port)); - return connections; - } - - @Override - public Query handleResponse(InputStream inputStream, long contentLength, Query query) throws IOException { - query.properties().set("gotResponse","ok"); - return query; - } - - @Override - public Result search(Query query, Execution execution, - Connection connection) { - URI uri; - try { - uri = new URL("http", connection.getHost(), connection - .getPort(), "/search").toURI(); - } catch (MalformedURLException e) { - query.errors().add(createMalformedUrlError(query, e)); - return execution.search(query); - } catch (URISyntaxException e) { - query.errors().add(createMalformedUrlError(query, e)); - return execution.search(query); - } - - HttpEntity entity; - try { - entity = getEntity(uri, query); - } catch (IOException e) { - query.errors().add( - ErrorMessage.createBackendCommunicationError("Error when trying to connect to HTTP backend in " - + this + " using " + connection - + " for " + query + ": " - + Exceptions.toMessageString(e))); - return execution.search(query); - } catch (TimeoutException e) { - query.errors().add(ErrorMessage.createTimeout("No time left for HTTP traffic in " - + this - + " for " + query + ": " + e.getMessage())); - return execution.search(query); - } - if (entity == null) { - query.errors().add( - ErrorMessage.createBackendCommunicationError("No result from connecting to HTTP backend in " - + this + " using " + connection + " for " + query)); - return execution.search(query); - } - - try { - query = handleResponse(entity, query); - } catch (IOException e) { - query.errors().add( - ErrorMessage.createBackendCommunicationError("Error when trying to consume input in " - + this + ": " + Exceptions.toMessageString(e))); - } finally { - cleanupHttpEntity(entity); - } - return execution.search(query); - } - - @Override - public Map<String, String> getCacheKey(Query q) { - return null; - } - - @Override - protected URI getPingURI(Connection connection) - throws MalformedURLException, URISyntaxException { - return new URL("http", connection.getHost(), connection.getPort(), "/ping").toURI(); - } - - Connection getConnection() { - return getHasher().getNodes().select(0, 0); - } - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java deleted file mode 100644 index 19750cf84cc..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/http/QueryParametersTestCase.java +++ /dev/null @@ -1,67 +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.search.federation.http; - -import com.yahoo.component.ComponentId; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.statistics.Statistics; -import com.yahoo.vespa.defaults.Defaults; -import org.junit.Test; - -import java.util.Collections; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -/** - * Tests that source and backend specific parameters from the query are added correctly to the backend requests - * - * @author bratseth - */ -public class QueryParametersTestCase { - - @Test - public void testQueryParameters() { - Query query=new Query(); - query.properties().set("a","a-value"); - query.properties().set("b.c","b.c-value"); - query.properties().set("source.otherSource.d","d-value"); - query.properties().set("source.testSource.e","e-value"); - query.properties().set("source.testSource.f.g","f.g-value"); - query.properties().set("provider.testProvider.h","h-value"); - query.properties().set("provider.testProvider.i.j","i.j-value"); - - query.properties().set("sourceName","testSource"); // Done by federation searcher - query.properties().set("providerName","testProvider"); // Done by federation searcher - - TestHttpProvider searcher=new TestHttpProvider(); - Map<String,String> parameters=searcher.getQueryMap(query); - searcher.deconstruct(); - - assertEquals(4,parameters.size()); // the appropriate 4 of the above - assertEquals(parameters.get("e"),"e-value"); - assertEquals(parameters.get("f.g"),"f.g-value"); - assertEquals(parameters.get("h"),"h-value"); - assertEquals(parameters.get("i.j"),"i.j-value"); - } - - public static class TestHttpProvider extends HTTPProviderSearcher { - - public TestHttpProvider() { - super(new ComponentId("test"), Collections.singletonList(new Connection("host", Defaults.getDefaults().vespaWebServicePort())), "path", Statistics.nullImplementation); - } - - @Override - public Map<String, String> getCacheKey(Query q) { - return Collections.singletonMap("nocaching", String.valueOf(Math.random())); - } - - @Override - protected void fill(Result result, String summaryClass, Execution execution, Connection connection) { - } - - } - -} - diff --git a/container-search/src/test/java/com/yahoo/search/federation/image/.gitignore b/container-search/src/test/java/com/yahoo/search/federation/image/.gitignore deleted file mode 100644 index e69de29bb2d..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/image/.gitignore +++ /dev/null diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryMarshallerTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryMarshallerTestCase.java deleted file mode 100644 index 022177bc42b..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryMarshallerTestCase.java +++ /dev/null @@ -1,160 +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.search.federation.vespa.test; - -import com.yahoo.language.Linguistics; -import com.yahoo.language.simple.SimpleLinguistics; -import com.yahoo.prelude.IndexFacts; -import com.yahoo.prelude.query.*; -import com.yahoo.search.Query; -import com.yahoo.search.federation.vespa.QueryMarshaller; -import com.yahoo.search.searchchain.Execution; -import com.yahoo.search.test.QueryTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class QueryMarshallerTestCase { - - private static final Linguistics linguistics = new SimpleLinguistics(); - - @Test - public void testCommonCommonCase() { - AndItem root = new AndItem(); - addThreeWords(root); - assertEquals("a AND b AND c", new QueryMarshaller().marshal(root)); - } - - @Test - public void testPhrase() { - PhraseItem root = new PhraseItem(); - root.setIndexName("habla"); - addThreeWords(root); - assertEquals("habla:\"a b c\"", new QueryMarshaller().marshal(root)); - } - - @Test - public void testPhraseDefaultIndex() { - PhraseItem root = new PhraseItem(); - addThreeWords(root); - assertEquals("\"a b c\"", new QueryMarshaller().marshal(root)); - } - - @Test - public void testLittleMoreComplex() { - AndItem root = new AndItem(); - addThreeWords(root); - OrItem ambig = new OrItem(); - root.addItem(ambig); - addThreeWords(ambig); - AndItem but = new AndItem(); - addThreeWords(but); - ambig.addItem(but); - assertEquals("a AND b AND c AND ( a OR b OR c OR ( a AND b AND c ) )", - new QueryMarshaller().marshal(root)); - } - - @Test - public void testRank() { - RankItem root = new RankItem(); - addThreeWords(root); - assertEquals("a RANK b RANK c", new QueryMarshaller().marshal(root)); - } - - @Test - public void testNear() { - NearItem near = new NearItem(3); - addThreeWords(near); - assertEquals("a NEAR(3) b NEAR(3) c", new QueryMarshaller().marshal(near)); - } - - @Test - public void testONear() { - ONearItem oNear = new ONearItem(3); - addThreeWords(oNear); - assertEquals("a ONEAR(3) b ONEAR(3) c", new QueryMarshaller().marshal(oNear)); - } - - private void addThreeWords(CompositeItem root) { - root.addItem(new WordItem("a")); - root.addItem(new WordItem("b")); - root.addItem(new WordItem("c")); - } - - @Test - public void testNegativeGroupedTerms() { - testQueryString(new QueryMarshaller(), "a -(b c) -(d e)", - "a ANDNOT ( b AND c ) ANDNOT ( d AND e )"); - } - - @Test - public void testPositiveGroupedTerms() { - testQueryString(new QueryMarshaller(), "a (b c)", "a AND ( b OR c )"); - } - - @Test - public void testInt() { - testQueryString(new QueryMarshaller(), "yahoo 123", "yahoo AND 123"); - } - - @Test - public void testCJKOneWord() { - testQueryString(new QueryMarshaller(), "天龍人"); - } - - @Test - public void testTwoWords() { - testQueryString(new QueryMarshaller(), "John Smith", "John AND Smith", null, new SimpleLinguistics()); - } - - @Test - public void testTwoWordsInPhrase() { - testQueryString(new QueryMarshaller(), "\"John Smith\"", "\"John Smith\"", null, new SimpleLinguistics()); - } - - @Test - public void testCJKTwoSentences() { - testQueryString(new QueryMarshaller(), "是不是這樣的夜晚 你才會這樣地想起我", "是不是這樣的夜晚 AND 你才會這樣地想起我"); - } - - @Test - public void testCJKTwoSentencesWithLanguage() { - testQueryString(new QueryMarshaller(), "助妳好孕 生1胎北市發2萬", "助妳好孕 AND 生1胎北市發2萬", "zh-Hant"); - } - - @Test - public void testCJKTwoSentencesInPhrase() { - QueryMarshaller marshaller = new QueryMarshaller(); - testQueryString(marshaller, "\"助妳好孕 生1胎北市發2萬\"", "\"助妳好孕 生1胎北市發2萬\"", "zh-Hant"); - testQueryString(marshaller, "\"是不是這樣的夜晚 你才會這樣地想起我\"", "\"是不是這樣的夜晚 你才會這樣地想起我\""); - } - - @Test - public void testCJKMultipleSentences() { - testQueryString(new QueryMarshaller(), "염부장님과 함께했던 좋은 추억들은", "염부장님과 AND 함께했던 AND 좋은 AND 추억들은"); - } - - @Test - public void testIndexRestriction() { - /** ticket 3707606, comment #29 */ - testQueryString(new QueryMarshaller(), "site:nytimes.com", "site:\"nytimes com\""); - } - - private void testQueryString(QueryMarshaller marshaller, String uq) { - testQueryString(marshaller, uq, uq, null); - } - - private void testQueryString(QueryMarshaller marshaller, String uq, String mq) { - testQueryString(marshaller, uq, mq, null); - } - - private void testQueryString(QueryMarshaller marshaller, String uq, String mq, String lang) { - testQueryString(marshaller, uq, mq, lang, linguistics); - } - - private void testQueryString(QueryMarshaller marshaller, String uq, String mq, String lang, Linguistics linguistics) { - Query query = new Query("/?query=" + QueryTestCase.httpEncode(uq) + ((lang != null) ? "&language=" + lang : "")); - query.getModel().setExecution(new Execution(new Execution.Context(null, new IndexFacts(), null, null, linguistics))); - assertEquals(mq, marshaller.marshal(query.getModel().getQueryTree().getRoot())); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java deleted file mode 100644 index 8d1ecf4085e..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/QueryParametersTestCase.java +++ /dev/null @@ -1,42 +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.search.federation.vespa.test; - -import com.yahoo.search.Query; -import com.yahoo.search.federation.vespa.VespaSearcher; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -/** - * Tests that source and backend specific parameters from the query are added correctly to the backend requests - * - * @author bratseth - */ -public class QueryParametersTestCase { - - public void testQueryParameters() { - Query query=new Query(); - query.properties().set("a","a-value"); - query.properties().set("b.c","b.c-value"); - query.properties().set("source.otherSource.d","d-value"); - query.properties().set("source.testSource.e","e-value"); - query.properties().set("source.testSource.f.g","f.g-value"); - query.properties().set("provider.testProvider.h","h-value"); - query.properties().set("provider.testProvider.i.j","i.j-value"); - - query.properties().set("sourceName","testSource"); // Done by federation searcher - query.properties().set("providerName","testProvider"); // Done by federation searcher - - VespaSearcher searcher=new VespaSearcher("testProvider","",0,""); - Map<String,String> parameters=searcher.getQueryMap(query); - searcher.deconstruct(); - - assertEquals(9, parameters.size()); // 5 standard + the appropriate 4 of the above - assertEquals(parameters.get("e"),"e-value"); - assertEquals(parameters.get("f.g"),"f.g-value"); - assertEquals(parameters.get("h"),"h-value"); - assertEquals(parameters.get("i.j"),"i.j-value"); - } - -} - diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java deleted file mode 100644 index 50186e03ae8..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/ResultBuilderTestCase.java +++ /dev/null @@ -1,94 +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.search.federation.vespa.test; - -import java.util.Iterator; - -import com.yahoo.net.URI; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.federation.vespa.ResultBuilder; -import com.yahoo.search.result.ErrorHit; -import com.yahoo.search.result.ErrorMessage; -import com.yahoo.search.result.HitGroup; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * Test XML parsing of results. - * - * @author Steinar Knutsen - */ -@SuppressWarnings("deprecation") -public class ResultBuilderTestCase { - - private boolean quickCompare(double a, double b) { - double z = Math.min(Math.abs(a), Math.abs(b)); - if (Math.abs((a - b)) < (z / 1e14)) { - return true; - } else { - return false; - } - } - - @Test - public void testSimpleResult() { - boolean gotErrorDetails = false; - ResultBuilder r = new ResultBuilder(); - Result res = r.parse("file:src/test/java/com/yahoo/prelude/searcher/test/testhit.xml", new Query("?query=a")); - assertEquals(3, res.getConcreteHitCount()); - assertEquals(4, res.getHitCount()); - ErrorHit e = (ErrorHit) res.hits().get(0); - // known problem, if the same error is the main error is - // in details, it'll be added twice. Not sure how to fix that, - // because old Vespa systems give no error details, and there - // is no way of nuking an existing error if the details exist. - for (Iterator<?> i = e.errorIterator(); i.hasNext();) { - ErrorMessage err = (ErrorMessage) i.next(); - assertEquals(5, err.getCode()); - String details = err.getDetailedMessage(); - if (details != null) { - gotErrorDetails = true; - assertEquals("An error as ordered", details.trim()); - } - } - assertTrue("Error details are missing", gotErrorDetails); - assertEquals(new URI("http://def"), res.hits().get(1).getId()); - assertEquals("test/stuff\\tsome/other", res.hits().get(2).getField("category")); - assertEquals("<field>habla</field>" - + "<hi>blbl</hi><br /><>&fdlkkgj</field>;lk<a b=\"1\" c=\"2\" />" - + "<x><y><z /></y></x>", res.hits().get(3).getField("annoying").toString()); - } - - @Test - public void testNestedResult() { - ResultBuilder r = new ResultBuilder(); - Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml", new Query("?query=a")); - assertNull(res.hits().getError()); - assertEquals(3, res.hits().size()); - assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", res.hits().get(0).getField("guid").toString()); - HitGroup g1 = (HitGroup) res.hits().get(1); - HitGroup g2 = (HitGroup) res.hits().get(2); - assertEquals(15, g1.size()); - assertEquals("reward_for_thumb", g1.get(1).getField("id").toString()); - assertEquals(10, g2.size()); - HitGroup g3 = (HitGroup) g2.get(3); - assertEquals("badge", g3.types().iterator().next()); - assertEquals(2, g3.size()); - assertEquals("badge/Topic Explorer 5", g3.get(0).getField("name").toString()); - } - - @Test - public void testWeirdDocumentID() { - ResultBuilder r = new ResultBuilder(); - Result res = r.parse("file:src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml", new Query("?query=a")); - assertNull(res.hits().getError()); - assertEquals(3, res.hits().size()); - assertEquals(new URI("nalle"), res.hits().get(0).getId()); - assertEquals(new URI("tralle"), res.hits().get(1).getId()); - assertEquals(new URI("kalle"), res.hits().get(2).getId()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java deleted file mode 100644 index 7fbe883bfb7..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaIntegrationTestCase.java +++ /dev/null @@ -1,28 +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.search.federation.vespa.test; - -import com.yahoo.component.chain.Chain; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.Searcher; -import com.yahoo.search.federation.vespa.VespaSearcher; -import com.yahoo.search.searchchain.Execution; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * @author bratseth - */ -public class VespaIntegrationTestCase { - - // TODO: Setup the answering vespa searcher from this test.... - @Test - public void testIt() { - if (System.currentTimeMillis() > 0) return; - Chain<Searcher> chain = new Chain<>(new VespaSearcher("test","example.yahoo.com",19010,"")); - Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=test")); - assertEquals(23, result.hits().size()); - } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.java deleted file mode 100644 index cc00c6739fa..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/VespaSearcherTestCase.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.search.federation.vespa.test; - -import com.yahoo.prelude.query.*; -import com.yahoo.search.Query; -import com.yahoo.search.federation.vespa.VespaSearcher; -import com.yahoo.search.query.QueryTree; -import com.yahoo.search.query.parser.Parsable; -import com.yahoo.search.query.parser.Parser; -import com.yahoo.search.query.parser.ParserEnvironment; -import com.yahoo.search.query.parser.ParserFactory; -import com.yahoo.search.result.Hit; -import com.yahoo.search.searchchain.Execution; -import org.apache.http.HttpEntity; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.net.URI; - -import static org.junit.Assert.assertEquals; - -/** - * Check query marshaling in VespaSearcher works. - * - * @author Steinar Knutsen - */ -public class VespaSearcherTestCase { - - private VespaSearcher searcher; - - @Before - public void setUp() { - searcher = new VespaSearcher("cache1","",0,""); - } - - @After - public void tearDown() { - searcher.deconstruct(); - } - - @Test - public void testMarshalQuery() { - RankItem root = new RankItem(); - QueryTree r = new QueryTree(root); - AndItem recall = new AndItem(); - PhraseItem usual = new PhraseItem(); - PhraseItem filterPhrase = new PhraseItem(new String[] {"bloody", "expensive"}); - WordItem filterWord = new WordItem("silly"); - - filterPhrase.setFilter(true); - filterWord.setFilter(true); - - root.addItem(recall); - usual.addItem(new WordItem("new")); - usual.addItem(new WordItem("york")); - recall.addItem(usual); - recall.addItem(new WordItem("shoes")); - root.addItem(new WordItem("nike")); - root.addItem(new WordItem("adidas")); - root.addItem(filterPhrase); - recall.addItem(filterWord); - - assertEquals("( \"new york\" AND shoes AND silly ) RANK nike RANK adidas RANK \"bloody expensive\"", searcher.marshalQuery(r)); - } - - @Test - public void testMarshalQuerySmallTree() { - RankItem root = new RankItem(); - QueryTree r = new QueryTree(root); - AndItem recall = new AndItem(); - PhraseItem usual = new PhraseItem(); - PhraseItem filterPhrase = new PhraseItem(new String[] {"bloody", "expensive"}); - WordItem filterWord = new WordItem("silly"); - - filterPhrase.setFilter(true); - filterWord.setFilter(true); - - root.addItem(recall); - usual.addItem(new WordItem("new")); - usual.addItem(new WordItem("york")); - recall.addItem(usual); - recall.addItem(new WordItem("shoes")); - root.addItem(filterPhrase); - recall.addItem(filterWord); - - assertEquals("( \"new york\" AND shoes AND silly ) RANK \"bloody expensive\"", searcher.marshalQuery(r)); - // TODO: Switch to this 2-way check rather than just 1-way and then also make this actually treat filter terms correctly - // assertMarshals(root) - } - - @Test - public void testWandMarshalling() { - WeakAndItem root = new WeakAndItem(); - root.setN(32); - root.addItem(new WordItem("a")); - root.addItem(new WordItem("b")); - root.addItem(new WordItem("c")); - assertMarshals(root); - } - - @Test - public void testWandMarshalling2() { - // AND (WAND(10) a!1 the!10) source:yahoonews - AndItem root = new AndItem(); - WeakAndItem wand = new WeakAndItem(10); - wand.addItem(newWeightedWordItem("a",1)); - wand.addItem(newWeightedWordItem("the",10)); - root.addItem(wand); - root.addItem(new WordItem("yahoonews","source")); - assertMarshals(root); - } - - private WordItem newWeightedWordItem(String word,int weight) { - WordItem wordItem=new WordItem(word); - wordItem.setWeight(weight); - return wordItem; - } - - private void assertMarshals(Item root) { - QueryTree r = new QueryTree(root); - String marshalledQuery=searcher.marshalQuery(r); - assertEquals("Marshalled form '" + marshalledQuery + "' recreates the original", - r,parseQuery(marshalledQuery,"")); - } - - private static Item parseQuery(String query, String filter) { - Parser parser = ParserFactory.newInstance(Query.Type.ADVANCED, new ParserEnvironment()); - return parser.parse(new Parsable().setQuery(query).setFilter(filter)); - } - - @Test - public void testSourceProviderProperties() throws Exception { - /* TODO: update test - Server httpServer = new Server(); - try { - SocketConnector listener = new SocketConnector(); - listener.setHost("0.0.0.0"); - httpServer.addConnector(listener); - httpServer.setHandler(new DummyHandler()); - httpServer.start(); - - int port=httpServer.getConnectors()[0].getLocalPort(); - - List<SourcesConfig.Source> sourcesConfig = new ArrayList<SourcesConfig.Source>(); - SourcesConfig.Source sourceConfig = new SourcesConfig.Source(); - sourceConfig.chain.setValue("news"); - sourceConfig.provider.setValue("news"); - sourceConfig.id.setValue("news"); - sourceConfig.timelimit.value = 10000; - sourcesConfig.add(sourceConfig); - FederationSearcher federator = - new FederationSearcher(ComponentId.createAnonymousComponentId(), - new ArrayList<SourcesConfig.Source>(sourcesConfig)); - SearchChain mainChain=new OrderedSearchChain(federator); - - SearchChainRegistry registry=new SearchChainRegistry(); - SearchChain sourceChain=new SearchChain(new ComponentId("news"),new VespaSearcher("test","localhost",port,"")); - registry.register(sourceChain); - Query query=new Query("?query=hans&hits=20&provider.news.a=a1&source.news.b=b1"); - Result result=new Execution(mainChain,registry).search(query); - assertNull(result.hits().getError()); - Hit testHit=result.hits().get("testHit"); - assertNotNull(testHit); - assertEquals("testValue",testHit.fields().get("testField")); - assertEquals("a1",testHit.fields().get("a")); - assertEquals("b1",testHit.fields().get("b")); - } - finally { - httpServer.stop(); - } - */ - } - - @Test - public void testVespaSearcher() { - VespaSearcher v=new VespaSearcherValidatingSubclass(); - new Execution(v, Execution.Context.createContextStub()).search(new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&filter=myfilter"))); - } - - private class VespaSearcherValidatingSubclass extends VespaSearcher { - - public VespaSearcherValidatingSubclass() { - super("configId","host",80,"path"); - } - - @Override - protected HttpEntity getEntity(URI uri, Hit requestMeta, Query query) throws IOException { - assertEquals("http://host:80/path?query=test+RANK+myfilter&type=adv&offset=0&hits=10&presentation.format=xml",uri.toString()); - return super.getEntity(uri,requestMeta,query); - } - - } - - // used by the old testSourceProviderProperties() -// private class DummyHandler extends AbstractHandler { -// public void handle(String s, Request request, HttpServletRequest httpServletRequest, -// HttpServletResponse httpServletResponse) throws IOException, ServletException { -// -// try { -// Response httpResponse = httpServletResponse instanceof Response ? (Response) httpServletResponse : HttpConnection.getCurrentConnection().getResponse(); -// -// httpResponse.setStatus(HttpStatus.OK_200); -// httpResponse.setContentType("text/xml"); -// httpResponse.setCharacterEncoding("UTF-8"); -// Result r=new Result(new Query()); -// Hit testHit=new Hit("testHit"); -// testHit.setField("uri","testHit"); // That this is necessary is quite unfortunate... -// testHit.setField("testField","testValue"); -// // Write back all incoming properties: -// for (Object e : httpServletRequest.getParameterMap().entrySet()) { -// Map.Entry entry=(Map.Entry)e; -// testHit.setField(entry.getKey().toString(),getFirstValue(entry.getValue())); -// } -// -// r.hits().add(testHit); -// -// //StringWriter sw=new StringWriter(); -// //r.render(sw); -// //System.out.println(sw.toString()); -// -// SearchRendererAdaptor.callRender(httpResponse.getWriter(), r); -// httpResponse.complete(); -// } -// catch (Exception e) { -// System.out.println("WARNING: Could not respond to request: " + Exceptions.toMessageString(e)); -// e.printStackTrace(); -// } -// } -// -// private String getFirstValue(Object entry) { -// if (entry instanceof String[]) -// return ((String[])entry)[0].toString(); -// else -// return entry.toString(); -// } -// } - -} diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml deleted file mode 100644 index c17bbf8474d..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/idhits.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> -<result total-hit-count="3"> - <hit relevancy="75" source="test" type="summary"> - <field name="uri">nalle</field> - <field name="relevancy">75</field> - <field name="collapseId">0</field> - </hit> - <hit relevancy="73" source="test" type="summary test other"> - <field name="documentId">tralle</field> - <field name="relevancy">73</field> - <field name="collapseId">0</field> - <field name="category">test/stuff\tsome/other</field> - <field name="bsumtitle">dklf øæå sdf > & < -Ipsum, etc.</field> - </hit> - <hit relevancy="70" source="test" type="summary"> - <field name="DOCUMENTID">kalle</field> - <field name="relevancy">75</field> - <field name="collapseId">0</field> - <field name="annoying"><field>habla</field><hi>blbl</hi><br /><![CDATA[<>&fdlkkgj</field>]]>;lk<a b="1" c="2" /><x><y><z /></y></x></field> - </hit> -</result> diff --git a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml b/container-search/src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml deleted file mode 100644 index 8b5ab710378..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/vespa/test/nestedhits.xml +++ /dev/null @@ -1,318 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> -<result total-hit-count="36"> -<hit type="user_reputation"> -<field name="guid">ABCDEFGHIJKLMNOPQRSTUVWXYZ</field> -<field name="level">zero</field> -<field name="points">0</field> -<field name="created">1287600988</field> -<field name="updated">1287600988</field> -</hit> -<group type="actions"> -<hit type="action"> -<field name="id">thumb</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> -<hit type="action"> -<field name="id">reward_for_thumb</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> -<hit type="action"> -<field name="id">undo_thumb</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">buzz</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">undo_reward_for_thumb</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">vote</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">report_abuse</field> -<field name="created">1287600992</field> -<field name="updated">1287600992</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">reward_for_vote</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">signup</field> -<field name="created">1287600993</field> -<field name="updated">1287600993</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">registered</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">get_points</field> -<field name="created">1287600989</field> -<field name="updated">1287600989</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">contrib_SignedUp</field> -<field name="created">1287600993</field> -<field name="updated">1287600993</field> -<field name="points">0</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">contrib_AgreedToTos</field> -<field name="created">1287600993</field> -<field name="updated">1287600993</field> -<field name="points">500</field> -<field name="level">zero</field> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">Create Feature</field> -<field name="created"/> -<field name="updated"/> -<field name="points">0</field> -<field name="level"/> -<field name="isEnabled">1</field> -</hit> - -<hit type="action"> -<field name="id">add_theme</field> -<field name="created"/> -<field name="updated"/> -<field name="points">0</field> -<field name="level"/> -<field name="isEnabled">1</field> -</hit> -</group> - -<group type="awards"> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/First Feature</field> -<field name="description">You’ve created your First Feature!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/1stfeature.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/25th Feature</field> -<field name="description">You’ve created your 25th Feature!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/25thfeature.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/50th Feature</field> -<field name="description">You’ve created your 50th Feature!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/10thfeature.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Topic Explorer 5</field> -<field name="description">You’ve added a Feature to your 5th Topic Page!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/5thtopic.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Topic Explorer 15</field> -<field name="description">You’ve added a Feature to your 15th Topic Page!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/15thtopic.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Topic Explorer 30</field> -<field name="description">You’ve added a Feature to your 30th Topic Page!</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/30thtopic.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> - -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> - -<group type="badge"> - -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Pollster</field> -<field name="description">You’ve created your 5th Poll Feature.</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/pollster.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> -<group type="badge"> -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Reporter</field> -<field name="description">You’ve created your 5th Article Feature.</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/newsreporter.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> -<group type="badge"> -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Paparazzi</field> -<field name="description">You’ve created your 5th Image Feature.</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/paparazzi.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> -<group type="badge"> -<hit type="info"> -<field name="type">badge</field> -<field name="name">badge/Video Reporter</field> -<field name="description">You’ve created your 5th Video Feature.</field> -<field name="status">active</field> -<field name="imageUrl">http://example.yahoo.com/director.png</field> -<field name="imageHeight">57</field> -<field name="imageWidth">57</field> -</hit> -<hit type="earned"> -<field name="date">1283981088</field> -<field name="context">topic/Jennifer_Aniston</field> -</hit> -</group> -</group> -</result> diff --git a/container-search/src/test/java/com/yahoo/search/federation/ysm/.gitignore b/container-search/src/test/java/com/yahoo/search/federation/ysm/.gitignore deleted file mode 100644 index e69de29bb2d..00000000000 --- a/container-search/src/test/java/com/yahoo/search/federation/ysm/.gitignore +++ /dev/null |