diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-01-31 11:13:51 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-01-31 11:13:51 +0100 |
commit | a44edeba9f38c38c431d7b9b6e1ac454e2a0e610 (patch) | |
tree | 21600936cfe396492965764911652b49b4c22731 /config-model/src/test/java/com/yahoo | |
parent | 9c4ba9bf5b96b8c62a9b8c5a6c20a9175c698b70 (diff) |
Verify macros
Diffstat (limited to 'config-model/src/test/java/com/yahoo')
-rw-r--r-- | config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java | 104 |
1 files changed, 41 insertions, 63 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java index 89f1a9f785c..c24e886c83d 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorFlowTestCase.java @@ -49,14 +49,8 @@ public class RankingExpressionWithTensorFlowTestCase { @Test public void testMinimalTensorFlowReference() throws ParseException { - StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); - RankProfileSearchFixture search = new RankProfileSearchFixture( - application, - " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: tensorflow('mnist_softmax/saved')" + - " }\n" + - " }"); + RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)", + "tensorflow('mnist_softmax/saved')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); assertConstant("Variable_1", search, Optional.of(10L)); assertConstant("Variable", search, Optional.of(7840L)); @@ -64,14 +58,8 @@ public class RankingExpressionWithTensorFlowTestCase { @Test public void testNestedTensorFlowReference() throws ParseException { - StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); - RankProfileSearchFixture search = new RankProfileSearchFixture( - application, - " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: 5 + sum(tensorflow('mnist_softmax/saved'))" + - " }\n" + - " }"); + RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)", + "5 + sum(tensorflow('mnist_softmax/saved'))"); search.assertFirstPhaseExpression("5 + reduce(" + vespaExpression + ", sum)", "my_profile"); assertConstant("Variable_1", search, Optional.of(10L)); assertConstant("Variable", search, Optional.of(7840L)); @@ -79,41 +67,23 @@ public class RankingExpressionWithTensorFlowTestCase { @Test public void testTensorFlowReferenceSpecifyingSignature() throws ParseException { - StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); - RankProfileSearchFixture search = new RankProfileSearchFixture( - application, - " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: tensorflow('mnist_softmax/saved', 'serving_default')" + - " }\n" + - " }"); + RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)", + "tensorflow('mnist_softmax/saved', 'serving_default')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); } @Test public void testTensorFlowReferenceSpecifyingSignatureAndOutput() throws ParseException { - StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); - RankProfileSearchFixture search = new RankProfileSearchFixture( - application, - " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: tensorflow('mnist_softmax/saved', 'serving_default', 'y')" + - " }\n" + - " }"); + RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)", + "tensorflow('mnist_softmax/saved', 'serving_default', 'y')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); } @Test public void testTensorFlowReferenceSpecifyingNonExistingSignature() throws ParseException { try { - StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); - RankProfileSearchFixture search = new RankProfileSearchFixture( - application, - " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: tensorflow('mnist_softmax/saved', 'serving_defaultz')" + - " }\n" + - " }"); + RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)", + "tensorflow('mnist_softmax/saved', 'serving_defaultz')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); fail("Expecting exception"); } @@ -128,14 +98,8 @@ public class RankingExpressionWithTensorFlowTestCase { @Test public void testTensorFlowReferenceSpecifyingNonExistingOutput() throws ParseException { try { - StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); - RankProfileSearchFixture search = new RankProfileSearchFixture( - application, - " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: tensorflow('mnist_softmax/saved', 'serving_default', 'x')" + - " }\n" + - " }"); + RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)", + "tensorflow('mnist_softmax/saved', 'serving_default', 'x')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); fail("Expecting exception"); } @@ -149,14 +113,8 @@ public class RankingExpressionWithTensorFlowTestCase { @Test public void testImportingFromStoredExpressions() throws ParseException, IOException { - StoringApplicationPackage application = new StoringApplicationPackage(applicationDir); - RankProfileSearchFixture search = new RankProfileSearchFixture( - application, - " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: tensorflow('mnist_softmax/saved', 'serving_default')" + - " }\n" + - " }"); + RankProfileSearchFixture search = fixtureWith("tensor(d0[2],d1[784])(0.0)", + "tensorflow('mnist_softmax/saved')"); search.assertFirstPhaseExpression(vespaExpression, "my_profile"); assertConstant("Variable_1", search, Optional.of(10L)); assertConstant("Variable", search, Optional.of(7840L)); @@ -168,13 +126,9 @@ public class RankingExpressionWithTensorFlowTestCase { IOUtils.copyDirectory(applicationDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile(), storedApplicationDirectory.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); StoringApplicationPackage storedApplication = new StoringApplicationPackage(storedApplicationDirectory); - RankProfileSearchFixture searchFromStored = new RankProfileSearchFixture( - storedApplication, - " rank-profile my_profile {\n" + - " first-phase {\n" + - " expression: tensorflow('mnist_softmax/saved', 'serving_default')" + - " }\n" + - " }"); + RankProfileSearchFixture searchFromStored = fixtureWith("tensor(d0[2],d1[784])(0.0)", + "tensorflow('mnist_softmax/saved')", + storedApplication); searchFromStored.assertFirstPhaseExpression(vespaExpression, "my_profile"); // Verify that the constants exists, but don't verify the content as we are not // simulating file distribution in this test @@ -212,6 +166,30 @@ public class RankingExpressionWithTensorFlowTestCase { } } + private RankProfileSearchFixture fixtureWith(String placeholderExpression, String firstPhaseExpression) { + return fixtureWith(placeholderExpression, firstPhaseExpression, new StoringApplicationPackage(applicationDir)); + } + + private RankProfileSearchFixture fixtureWith(String placeholderExpression, + String firstPhaseExpression, + StoringApplicationPackage application) { + try { + return new RankProfileSearchFixture( + application, + " rank-profile my_profile {\n" + + " macro Placeholder() {\n" + + " expression: " + placeholderExpression + + " }\n" + + " first-phase {\n" + + " expression: " + firstPhaseExpression + + " }\n" + + " }"); + } + catch (ParseException e) { + throw new IllegalArgumentException(e); + } + } + private static class StoringApplicationPackage extends MockApplicationPackage { private final File root; |