-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4270 from vespa-engine/hmusum/move-test-2
Move test from internal repo
- Loading branch information
Showing
5 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<services> | ||
|
||
<container version="1.0" id="container"> | ||
<handler id="com.yahoo.test.TestHandler" bundle="app"> | ||
<binding>http://*/test/*</binding> | ||
<config name="com.yahoo.test.test"> | ||
<myurl>https://data.vespa-cloud.com/onnx_models/bert-base-uncased-vocab.txt</myurl> | ||
<arrayOfUrls> | ||
<item>https://data.vespa-cloud.com/onnx_models/bert-base-uncased-vocab.txt</item> | ||
</arrayOfUrls> | ||
<mapOfUrls> | ||
<item key="constant_tensor_1">https://data.vespa-cloud.com/onnx_models/bert-base-uncased-vocab.txt</item> | ||
</mapOfUrls> | ||
</config> | ||
</handler> | ||
</container> | ||
|
||
</services> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.yahoo.test</groupId> | ||
<artifactId>app</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>container-plugin</packaging> <!-- Use Vespa packaging --> | ||
|
||
<parent> | ||
<groupId>com.yahoo.vespa.systemtest</groupId> | ||
<artifactId>test-apps-parent</artifactId> | ||
<version>8-SNAPSHOT</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.yahoo.vespa</groupId> | ||
<artifactId>container</artifactId> | ||
<version>${vespa.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.yahoo.vespa</groupId> | ||
<artifactId>bundle-plugin</artifactId> | ||
<version>${vespa.version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
92 changes: 92 additions & 0 deletions
92
tests/config/urldownload/bundle/src/main/java/com/yahoo/test/TestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.yahoo.test; | ||
|
||
import com.yahoo.container.jdisc.HttpRequest; | ||
import com.yahoo.container.jdisc.HttpResponse; | ||
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class TestHandler extends ThreadedHttpRequestHandler { | ||
|
||
private final File contents; | ||
private final List<File> arrayOfUrls; | ||
private final Map<String, File> mapOfUrls; | ||
|
||
public TestHandler(TestConfig testConfig, Context context) { | ||
super(context); | ||
contents = testConfig.myurl(); | ||
arrayOfUrls = testConfig.arrayOfUrls(); | ||
mapOfUrls = testConfig.mapOfUrls(); | ||
} | ||
|
||
@Override | ||
public HttpResponse handle(HttpRequest httpRequest) { | ||
try { | ||
if (httpRequest.getUri().getPath().endsWith("numfiles")) { | ||
return handleNumFiles(); | ||
} | ||
return handleFileContents(); | ||
} catch (Exception e) { | ||
return new HttpResponse(500) { | ||
@Override | ||
public void render(OutputStream outputStream) throws IOException { | ||
outputStream.write(("Internal server error: " + e.getMessage()).getBytes()); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
private HttpResponse handleFileContents() { | ||
final String fileContents = readContents(); | ||
return new HttpResponse(200) { | ||
@Override | ||
public void render(OutputStream outputStream) throws IOException { | ||
outputStream.write(fileContents.getBytes()); | ||
} | ||
}; | ||
} | ||
|
||
private HttpResponse handleNumFiles() { | ||
return new HttpResponse(200) { | ||
@Override | ||
public void render(OutputStream outputStream) throws IOException { | ||
int numFiles = 0; | ||
if (contents.exists()) numFiles += 1; | ||
for (File f : arrayOfUrls) { | ||
if (f.exists()) | ||
numFiles += 1; | ||
} | ||
for (File f : mapOfUrls.values()) { | ||
if (f.exists()) | ||
numFiles += 1; | ||
} | ||
outputStream.write(String.format("%d", numFiles).getBytes()); | ||
} | ||
}; | ||
} | ||
|
||
private String readContents() { | ||
if (contents.exists() && contents.length() > 0) { | ||
try (BufferedReader br = new BufferedReader(new FileReader(contents))) { | ||
StringBuilder sb = new StringBuilder(); | ||
String line = br.readLine(); | ||
while (line != null) { | ||
sb.append(line); sb.append("\n"); | ||
line = br.readLine(); | ||
} | ||
return sb.toString(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Exception reading file", e); | ||
} | ||
} | ||
throw new RuntimeException("Downloaded URL could not be found."); | ||
} | ||
|
||
} | ||
|
6 changes: 6 additions & 0 deletions
6
tests/config/urldownload/bundle/src/main/resources/configdefinitions/test.def
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package=com.yahoo.test | ||
|
||
myurl url | ||
arrayOfUrls[] url | ||
mapOfUrls{} url | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Private reason: Depends on artifactory | ||
|
||
require 'config_test' | ||
require 'app_generator/search_app' | ||
|
||
class UrlDownloadTest < ConfigTest | ||
|
||
def setup | ||
set_owner("lesters") | ||
set_description("Tests downloading files from urls") | ||
@valgrind = false | ||
end | ||
|
||
def teardown | ||
stop | ||
end | ||
|
||
def test_url_downloading | ||
add_bundle_dir(selfdir + "bundle", "app") | ||
deploy(selfdir + "/app") | ||
start | ||
container = vespa.container.values.first | ||
|
||
result = container.http_get2("/test/numfiles") | ||
puts "Number of downloaded files: " + result.body | ||
|
||
assert(result.code == "200") | ||
assert(result.body.to_i == 3) | ||
|
||
result = container.http_get2("/test/") | ||
|
||
assert(result.code == "200") | ||
assert(result.body.length > 0) | ||
assert(result.body.include? "cells") | ||
end | ||
|
||
end |