[
https://issues.apache.org/jira/browse/GOBBLIN-677?focusedWorklogId=198239&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-198239
]
ASF GitHub Bot logged work on GOBBLIN-677:
------------------------------------------
Author: ASF GitHub Bot
Created on: 13/Feb/19 17:50
Start Date: 13/Feb/19 17:50
Worklog Time Spent: 10m
Work Description: sv2000 commented on pull request #2548: [GOBBLIN-677] -
Allow early termination of Gobblin jobs based on a predicate on the job progress
URL: https://github.com/apache/incubator-gobblin/pull/2548#discussion_r256513391
##########
File path:
gobblin-runtime/src/test/java/org/apache/gobblin/util/ReflectivePredicateEvaluatorTest.java
##########
@@ -0,0 +1,108 @@
+package org.apache.gobblin.util;
+
+import org.junit.Assert;
+import org.testng.annotations.Test;
+
+import lombok.Data;
+
+public class ReflectivePredicateEvaluatorTest {
+
+ @Test
+ public void simpleTest() throws Exception {
+ ReflectivePredicateEvaluator evaluator = new
ReflectivePredicateEvaluator(
+ "SELECT anInt = 1 FROM myInterface",
MyInterface.class);
+
+ Assert.assertTrue(evaluator.evaluate(new MyImplementation(1,
"foo")));
+ Assert.assertFalse(evaluator.evaluate(new MyImplementation(2,
"foo")));
+
+ Assert.assertTrue(evaluator.evaluate("SELECT anInt = 1 OR
aString = 'foo' FROM myInterface",
+ new MyImplementation(1, "bar")));
+ Assert.assertTrue(evaluator.evaluate("SELECT anInt = 1 OR
aString = 'foo' FROM myInterface",
+ new MyImplementation(2, "foo")));
+ Assert.assertFalse(evaluator.evaluate("SELECT anInt = 1 OR
aString = 'foo' FROM myInterface",
+ new MyImplementation(2, "bar")));
+ }
+
+ @Test
+ public void testWithAggregations() throws Exception {
+ ReflectivePredicateEvaluator evaluator = new
ReflectivePredicateEvaluator(
+ "SELECT sum(anInt) = 5 FROM myInterface",
MyInterface.class);
+
+ Assert.assertFalse(evaluator.evaluate(new MyImplementation(1,
"foo")));
+ Assert.assertTrue(evaluator.evaluate(new MyImplementation(1,
"foo"), new MyImplementation(4, "foo")));
+ Assert.assertFalse(evaluator.evaluate(new MyImplementation(2,
"foo"), new MyImplementation(4, "foo")));
+ }
+
+ @Test
+ public void testWithAggregationsAndFilter() throws Exception {
+ ReflectivePredicateEvaluator evaluator = new
ReflectivePredicateEvaluator(
+ "SELECT sum(anInt) = 5 FROM myInterface WHERE
aString = 'foo'", MyInterface.class);
+
+ Assert.assertFalse(evaluator.evaluate(new MyImplementation(1,
"foo")));
+ Assert.assertTrue(evaluator.evaluate(new MyImplementation(1,
"foo"), new MyImplementation(4, "foo"), new MyImplementation(4, "bar")));
+ Assert.assertFalse(evaluator.evaluate(new MyImplementation(1,
"foo"), new MyImplementation(4, "foo"), new MyImplementation(4, "foo")));
+ }
+
+ @Test
+ public void testMultipleInterfaces() throws Exception {
+ ReflectivePredicateEvaluator evaluator = new
ReflectivePredicateEvaluator(
+ "SELECT true = ALL (SELECT sum(anInt) = 2 AS
satisfied FROM myInterface UNION SELECT sum(anInt) = 3 AS satisfied FROM
myInterface2)",
+ MyInterface.class, MyInterface2.class);
+ Assert.assertFalse(evaluator.evaluate(new MyImplementation(2,
"foo")));
+ Assert.assertTrue(evaluator.evaluate(new MyImplementation(2,
"foo"), new MyImplementation2(3)));
+ Assert.assertTrue(evaluator.evaluate(new MyImplementation(1,
"foo"), new MyImplementation2(3), new MyImplementation(1, "foo")));
+ }
+
+ @Test
+ public void testMultipleOutputs() throws Exception {
+ ReflectivePredicateEvaluator evaluator =
+ new ReflectivePredicateEvaluator("SELECT anInt
= 1 FROM myInterface", MyInterface.class);
+ Assert.assertTrue(evaluator.evaluate(new MyImplementation(1,
"bar"), new MyImplementation(1, "foo")));
+ Assert.assertFalse(evaluator.evaluate(new MyImplementation(1,
"bar"), new MyImplementation(2, "foo")));
+ }
+
+ @Test
+ public void testInvalidSQL() throws Exception {
+ try {
+ ReflectivePredicateEvaluator evaluator =
+ new
ReflectivePredicateEvaluator("SELECT anInt FROM myInterface",
MyInterface.class);
+ Assert.fail();
+ } catch (IllegalArgumentException exc) {
+ // Expected
+ }
+ }
+
+ @Test
+ public void testNoOutputs() throws Exception {
+ try {
+ ReflectivePredicateEvaluator evaluator =
+ new
ReflectivePredicateEvaluator("SELECT anInt = 1 FROM myInterface WHERE aString =
'foo'",
+ MyInterface.class);
+ evaluator.evaluate(new MyImplementation(1, "bar"));
+ Assert.fail();
+ } catch (IllegalArgumentException exc) {
+ // Expected
+ }
+ }
+
+ public interface MyInterface {
Review comment:
Can this be private?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 198239)
Time Spent: 1.5h (was: 1h 20m)
> Allow for early termination of Gobblin jobs based on a predicate on job
> progress
> --------------------------------------------------------------------------------
>
> Key: GOBBLIN-677
> URL: https://issues.apache.org/jira/browse/GOBBLIN-677
> Project: Apache Gobblin
> Issue Type: Improvement
> Reporter: Issac Buenrostro
> Assignee: Issac Buenrostro
> Priority: Major
> Time Spent: 1.5h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)