diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-04-25 15:06:55 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-04-25 15:06:55 +0200 |
commit | 77f8522cf3a0a8a62fd3971455042815380b7fc7 (patch) | |
tree | 0a9dc0c0074949bf96b4cf0b7a1084073e716095 /vespa_feed_perf/src/test | |
parent | a8949c869c613d671886b87ab684b2dfef9d9ca5 (diff) |
Add a binary format too.
Diffstat (limited to 'vespa_feed_perf/src/test')
-rw-r--r-- | vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/FeederParamsTest.java | 28 | ||||
-rw-r--r-- | vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java | 59 |
2 files changed, 75 insertions, 12 deletions
diff --git a/vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/FeederParamsTest.java b/vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/FeederParamsTest.java index b2800110a39..ab1eb27e416 100644 --- a/vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/FeederParamsTest.java +++ b/vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/FeederParamsTest.java @@ -11,7 +11,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.io.PrintStream; import static org.junit.Assert.assertEquals; @@ -25,7 +24,9 @@ import static org.junit.Assert.assertTrue; * @author Simon Thoresen Hult */ public class FeederParamsTest { - static final String TESTFILE = "test.json"; + static final String TESTFILE_JSON = "test.json"; + static final String TESTFILE_VESPA = "test.vespa"; + static final String TESTFILE_UNKNOWN = "test.xyz"; @Test public void requireThatAccessorsWork() { @@ -94,10 +95,25 @@ public class FeederParamsTest { @Test public void requireThatDumpStreamAreParsed() throws ParseException, IOException { assertNull(new FeederParams().getDumpStream()); - OutputStream dumpStream = new FeederParams().parseArgs("-o " + TESTFILE).getDumpStream(); - assertNotNull(dumpStream); - dumpStream.close(); - assertTrue(new File(TESTFILE).delete()); + + FeederParams p = new FeederParams().parseArgs("-o " + TESTFILE_JSON); + assertNotNull(p.getDumpStream()); + assertEquals(FeederParams.DumpFormat.JSON, p.getDumpFormat()); + p.getDumpStream().close(); + + p = new FeederParams().parseArgs("-o " + TESTFILE_VESPA); + assertNotNull(p.getDumpStream()); + assertEquals(FeederParams.DumpFormat.VESPA, p.getDumpFormat()); + p.getDumpStream().close(); + + p = new FeederParams().parseArgs("-o " + TESTFILE_UNKNOWN); + assertNotNull(p.getDumpStream()); + assertEquals(FeederParams.DumpFormat.JSON, p.getDumpFormat()); + p.getDumpStream().close(); + + assertTrue(new File(TESTFILE_JSON).delete()); + assertTrue(new File(TESTFILE_VESPA).delete()); + assertTrue(new File(TESTFILE_UNKNOWN).delete()); } } diff --git a/vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java b/vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java index f93657138ca..1c2cac3bcee 100644 --- a/vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java +++ b/vespa_feed_perf/src/test/java/com/yahoo/vespa/feed/perf/SimpleFeederTest.java @@ -11,7 +11,6 @@ import com.yahoo.messagebus.ErrorCode; import com.yahoo.messagebus.Message; import com.yahoo.messagebus.MessageHandler; import com.yahoo.messagebus.Reply; -import com.yahoo.messagebus.SourceSession; import com.yahoo.messagebus.StaticThrottlePolicy; import com.yahoo.messagebus.ThrottlePolicy; import org.junit.Test; @@ -19,6 +18,7 @@ import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; @@ -131,6 +131,46 @@ public class SimpleFeederTest { } @Test + public void requireThatDualPutXML2VespaFeederWorks() throws Throwable { + ByteArrayOutputStream dump = new ByteArrayOutputStream(); + assertFeed(new FeederParams().setDumpStream(dump).setDumpFormat(FeederParams.DumpFormat.VESPA), + "<vespafeed>" + + " <document documenttype='simple' documentid='id:simple:simple::0'>" + + " <my_str>foo</my_str>" + + " </document>" + + " <document documenttype='simple' documentid='id:simple:simple::1'>" + + " <my_str>bar</my_str>" + + " </document>" + + " <remove documenttype='simple' documentid='id:simple:simple::2'/>" + + "</vespafeed>", + new MessageHandler() { + + @Override + public void handleMessage(Message msg) { + Reply reply = ((DocumentMessage)msg).createReply(); + reply.swapState(msg); + reply.popHandler().handleReply(reply); + } + }, + "", + "(.+\n)+" + + "\\s*\\d+,\\s*3,.+\n"); + assertEquals(178, dump.size()); + assertFeed(new ByteArrayInputStream(dump.toByteArray()), + new MessageHandler() { + @Override + public void handleMessage(Message msg) { + Reply reply = ((DocumentMessage)msg).createReply(); + reply.swapState(msg); + reply.popHandler().handleReply(reply); + } + }, + "", + "(.+\n)+" + + "\\s*\\d+,\\s*3,.+\n"); + } + + @Test public void requireThatJsonFeederWorks() throws Throwable { assertFeed("[" + " { \"put\": \"id:simple:simple::0\", \"fields\": { \"my_str\":\"foo\"}}," + @@ -243,8 +283,13 @@ public class SimpleFeederTest { private static void assertFeed(String in, MessageHandler validator, String expectedErr, String expectedOut) throws Throwable { assertFeed(new FeederParams(), in, validator, expectedErr, expectedOut); } - private static void assertFeed(FeederParams params, String in, MessageHandler validator, String expectedErr, String expectedOut) - throws Throwable { + private static void assertFeed(InputStream in, MessageHandler validator, String expectedErr, String expectedOut) throws Throwable { + assertFeed(new FeederParams(), in, validator, expectedErr, expectedOut); + } + private static void assertFeed(FeederParams params, String in, MessageHandler validator, String expectedErr, String expectedOut) throws Throwable { + assertFeed(params, new ByteArrayInputStream(in.getBytes(StandardCharsets.UTF_8)), validator, expectedErr, expectedOut); + } + private static void assertFeed(FeederParams params, InputStream in, MessageHandler validator, String expectedErr, String expectedOut) throws Throwable { TestDriver driver = new TestDriver(params, in, validator); driver.run(); assertMatches(expectedErr, new String(driver.err.toByteArray(), StandardCharsets.UTF_8)); @@ -265,12 +310,14 @@ public class SimpleFeederTest { final SimpleFeeder feeder; final SimpleServer server; - TestDriver(FeederParams params, String in, MessageHandler validator) - throws IOException, ListenFailedException { + TestDriver(FeederParams params, String in, MessageHandler validator) throws IOException, ListenFailedException { + this(params, new ByteArrayInputStream(in.getBytes(StandardCharsets.UTF_8)), validator); + } + TestDriver(FeederParams params, InputStream in, MessageHandler validator) throws IOException, ListenFailedException { server = new SimpleServer(CONFIG_DIR, validator); feeder = new SimpleFeeder(params.setConfigId("dir:" + CONFIG_DIR) .setStdErr(new PrintStream(err)) - .setStdIn(new ByteArrayInputStream(in.getBytes(StandardCharsets.UTF_8))) + .setStdIn(in) .setStdOut(new PrintStream(out))); } |