Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-924] Add JarFileCreator tests for anonymous classes and Java 8…
… lambdas This closes #35
- Loading branch information
Showing
16 changed files
with
617 additions
and
80 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
flink-java8/src/test/java/org/apache/flink/runtime/util/JarFileCreatorLambdaTest.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,111 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.flink.runtime.util; | |||
|
|||
|
|||
import org.apache.flink.runtime.util.jartestprogram.FilterLambda1; | |||
import org.apache.flink.runtime.util.jartestprogram.FilterLambda2; | |||
import org.apache.flink.runtime.util.jartestprogram.FilterLambda3; | |||
import org.apache.flink.runtime.util.jartestprogram.FilterLambda4; | |||
|
|||
import org.junit.Assert; | |||
import org.junit.Test; | |||
|
|||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.util.HashSet; | |||
import java.util.Set; | |||
import java.util.jar.JarInputStream; | |||
import java.util.zip.ZipEntry; | |||
|
|||
public class JarFileCreatorLambdaTest { | |||
@Test | |||
public void TestFilterFunctionOnLambda1() throws Exception { | |||
File out = new File(System.getProperty("java.io.tmpdir"), "jarcreatortest.jar"); | |||
JarFileCreator jfc = new JarFileCreator(out); | |||
jfc.addClass(FilterLambda1.class) | |||
.createJarFile(); | |||
|
|||
Set<String> ans = new HashSet<String>(); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/FilterLambda1.class"); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/WordFilter.class"); | |||
|
|||
Assert.assertTrue("Jar file for java 8 lambda is not correct", validate(ans, out)); | |||
out.delete(); | |||
} | |||
|
|||
@Test | |||
public void TestFilterFunctionOnLambda2() throws Exception{ | |||
File out = new File(System.getProperty("java.io.tmpdir"), "jarcreatortest.jar"); | |||
JarFileCreator jfc = new JarFileCreator(out); | |||
jfc.addClass(FilterLambda2.class) | |||
.createJarFile(); | |||
|
|||
Set<String> ans = new HashSet<String>(); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/FilterLambda2.class"); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/WordFilter.class"); | |||
|
|||
Assert.assertTrue("Jar file for java 8 lambda is not correct", validate(ans, out)); | |||
out.delete(); | |||
} | |||
|
|||
@Test | |||
public void TestFilterFunctionOnLambda3() throws Exception { | |||
File out = new File(System.getProperty("java.io.tmpdir"), "jarcreatortest.jar"); | |||
JarFileCreator jfc = new JarFileCreator(out); | |||
jfc.addClass(FilterLambda3.class) | |||
.createJarFile(); | |||
|
|||
Set<String> ans = new HashSet<String>(); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/FilterLambda3.class"); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/WordFilter.class"); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/UtilFunction.class"); | |||
|
|||
Assert.assertTrue("Jar file for java 8 lambda is not correct", validate(ans, out)); | |||
out.delete(); | |||
} | |||
|
|||
@Test | |||
public void TestFilterFunctionOnLambda4() throws Exception { | |||
File out = new File(System.getProperty("java.io.tmpdir"), "jarcreatortest.jar"); | |||
JarFileCreator jfc = new JarFileCreator(out); | |||
jfc.addClass(FilterLambda4.class) | |||
.createJarFile(); | |||
|
|||
Set<String> ans = new HashSet<String>(); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/FilterLambda4.class"); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/WordFilter.class"); | |||
ans.add("org/apache/flink/runtime/util/jartestprogram/UtilFunctionWrapper$UtilFunction.class"); | |||
|
|||
Assert.assertTrue("Jar file for java 8 lambda is not correct", validate(ans, out)); | |||
out.delete(); | |||
} | |||
|
|||
public boolean validate(Set<String> expected, File out) throws Exception { | |||
|
|||
JarInputStream jis = new JarInputStream(new FileInputStream(out)); | |||
ZipEntry ze; | |||
int count = expected.size(); | |||
while ((ze = jis.getNextEntry()) != null) { | |||
count--; | |||
expected.remove(ze.getName()); | |||
} | |||
return count == 0 && expected.size() == 0; | |||
} | |||
} |
39 changes: 39 additions & 0 deletions
39
flink-java8/src/test/java/org/apache/flink/runtime/util/jartestprogram/FilterLambda1.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.flink.runtime.util.jartestprogram; | |||
|
|||
|
|||
import org.apache.flink.api.common.functions.FilterFunction; | |||
import org.apache.flink.api.java.DataSet; | |||
import org.apache.flink.api.java.ExecutionEnvironment; | |||
|
|||
public class FilterLambda1 { | |||
|
|||
public static void main(String[] args) throws Exception { | |||
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); | |||
DataSet<String> input = env.fromElements("Please filter", "the words", "but not this"); | |||
|
|||
FilterFunction<String> filter = (v) -> WordFilter.filter(v); | |||
|
|||
DataSet<String> output = input.filter(filter); | |||
output.print(); | |||
|
|||
env.execute(); | |||
} | |||
} |
35 changes: 35 additions & 0 deletions
35
flink-java8/src/test/java/org/apache/flink/runtime/util/jartestprogram/FilterLambda2.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.flink.runtime.util.jartestprogram; | |||
|
|||
import org.apache.flink.api.java.DataSet; | |||
import org.apache.flink.api.java.ExecutionEnvironment; | |||
|
|||
public class FilterLambda2 { | |||
|
|||
public static void main(String[] args) throws Exception { | |||
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); | |||
DataSet<String> input = env.fromElements("Please filter", "the words", "but not this"); | |||
|
|||
DataSet<String> output = input.filter((v) -> WordFilter.filter(v)); | |||
output.print(); | |||
|
|||
env.execute(); | |||
} | |||
} |
36 changes: 36 additions & 0 deletions
36
flink-java8/src/test/java/org/apache/flink/runtime/util/jartestprogram/FilterLambda3.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.flink.runtime.util.jartestprogram; | |||
|
|||
import org.apache.flink.api.java.DataSet; | |||
import org.apache.flink.api.java.ExecutionEnvironment; | |||
|
|||
public class FilterLambda3 { | |||
|
|||
public static void main(String[] args) throws Exception { | |||
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); | |||
DataSet<String> input = env.fromElements("Please filter", "the words", "but not this"); | |||
|
|||
DataSet<String> output = input.filter(UtilFunction.getWordFilter()); | |||
output.print(); | |||
|
|||
env.execute(); | |||
} | |||
|
|||
} |
35 changes: 35 additions & 0 deletions
35
flink-java8/src/test/java/org/apache/flink/runtime/util/jartestprogram/FilterLambda4.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,35 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.flink.runtime.util.jartestprogram; | |||
|
|||
import org.apache.flink.api.java.DataSet; | |||
import org.apache.flink.api.java.ExecutionEnvironment; | |||
|
|||
public class FilterLambda4 { | |||
|
|||
public static void main(String[] args) throws Exception { | |||
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); | |||
DataSet<String> input = env.fromElements("Please filter", "the words", "but not this"); | |||
|
|||
DataSet<String> output = input.filter(UtilFunctionWrapper.UtilFunction.getWordFilter()); | |||
output.print(); | |||
|
|||
env.execute(); | |||
} | |||
} |
27 changes: 27 additions & 0 deletions
27
flink-java8/src/test/java/org/apache/flink/runtime/util/jartestprogram/UtilFunction.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.flink.runtime.util.jartestprogram; | |||
|
|||
import org.apache.flink.api.common.functions.FilterFunction; | |||
|
|||
public class UtilFunction { | |||
public static FilterFunction<String> getWordFilter() { | |||
return (v) -> WordFilter.filter(v); | |||
} | |||
} |
29 changes: 29 additions & 0 deletions
29
...java8/src/test/java/org/apache/flink/runtime/util/jartestprogram/UtilFunctionWrapper.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.flink.runtime.util.jartestprogram; | |||
|
|||
import org.apache.flink.api.common.functions.FilterFunction; | |||
|
|||
public class UtilFunctionWrapper { | |||
public static class UtilFunction { | |||
public static FilterFunction<String> getWordFilter() { | |||
return (v) -> WordFilter.filter(v); | |||
} | |||
} | |||
} |
25 changes: 25 additions & 0 deletions
25
flink-java8/src/test/java/org/apache/flink/runtime/util/jartestprogram/WordFilter.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package org.apache.flink.runtime.util.jartestprogram; | |||
|
|||
public class WordFilter { | |||
public static boolean filter(String value) { | |||
return !value.contains("not"); | |||
} | |||
} |
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
Oops, something went wrong.