Skip to content

[SPARK-19534][TESTS] Convert Java tests to use lambdas, Java 8 features#16964

Closed
srowen wants to merge 3 commits intoapache:masterfrom
srowen:SPARK-19534
Closed

[SPARK-19534][TESTS] Convert Java tests to use lambdas, Java 8 features#16964
srowen wants to merge 3 commits intoapache:masterfrom
srowen:SPARK-19534

Conversation

@srowen
Copy link
Member

@srowen srowen commented Feb 16, 2017

What changes were proposed in this pull request?

Convert tests to use Java 8 lambdas, and modest related fixes to surrounding code.

How was this patch tested?

Jenkins tests

@dongjoon-hyun
Copy link
Member

+1, LGTM, too. Very tidy!

Assert.assertEquals(sketch1.totalCount(), 1000);
Assert.assertEquals(sketch1.depth(), 10);
Assert.assertEquals(sketch1.width(), 20);
Assert.assertEquals(1000, sketch1.totalCount());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in a few tests, I fixed the switched ordering on the asserts, while I was touching the code.

TransportServerBootstrap auth = enableAes ? new AuthServerBootstrap(conf, keyHolder)
: new SaslServerBootstrap(conf, keyHolder);
this.server = ctx.createServer(Lists.newArrayList(auth, introspector));
this.server = ctx.createServer(Arrays.asList(auth, introspector));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think we can do away with things like Lists.newArrayList, which used to be a much more concise ways of making a list of things, but by Java 7, is just a non-standard version of the identical Arrays.asList

@Test
public void testFileRegionEncryption() throws Exception {
final Map<String, String> testConf = ImmutableMap.of(
Map<String, String> testConf = ImmutableMap.of(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone wondering about 'final' -- these are no longer needed because lambdas are OK with variables that are effectively final in the enclosing scope.

@SparkQA
Copy link

SparkQA commented Feb 16, 2017

Test build #73011 has finished for PR 16964 at commit 05e95fb.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Feb 17, 2017

Test build #73017 has finished for PR 16964 at commit 6d11cb1.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@zzcclp
Copy link
Contributor

zzcclp commented Feb 17, 2017

@srowen after update to master, in Eclipse IDE, there is an error in JavaConsumerStrategySuite.java line 52:

line 49: final Map<TopicPartition, Long> offsets = new HashMap<>();
line 50: offsets.put(tp1, 23L);
line 51: final scala.collection.Map<TopicPartition, Object> sOffsets =
line 52: JavaConverters.mapAsScalaMapConverter(offsets).asScala().mapValues(
line 53: new scala.runtime.AbstractFunction1<Long, Object>() {
line 54: @Override
line 55: public Object apply(Long x) {
line 56: return (Object) x;
line 57: }
line 58: }
line 59: );

Error is as follows:
The method mapValues(Function1<Long,Object>) is ambiguous for the type Map<TopicPartition,Long>

Is it related to updating Java 7 to 8?

@srowen
Copy link
Member Author

srowen commented Feb 17, 2017

That code didn't change in the update for Java 8, and the error itself doesn't sound directly like a Java language level issue. (Although you see an anonymous function here, actually, this is an instance that could not change.) I don't see a compile error locally or on any Jenkins build either. Check your local env? clean build?

public void testLargeFrame() throws Exception {
// Frame length includes the frame size field, so need to add a few more bytes.
testInvalidFrame(Integer.MAX_VALUE + 9);
testInvalidFrame((long) Integer.MAX_VALUE + 9);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vanzin I 'fixed' this test because as written it was actually testing negative input (this overflows) but that's tested above. However now this doesn't fail as expected. Is the test something I should remove actually?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To unblock you, can you add @Ignore and file a bug to fix or remove this test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this call isn't invalid per se at the moment. There is a check later on in the code that compares a frame size to Integer.MAX_VALUE (but, as a long, so it works) and throws an exception, but that doesn't occur until later.

Copy link
Contributor

@vanzin vanzin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna miss all those anonymous classes and @Overrides...

return new FileSegmentManagedBuffer(conf, file, 0, file.length());
}
});
when(sm.getChunk(anyLong(), anyInt())).thenAnswer(invocation -> new FileSegmentManagedBuffer(conf, file, 0, file.length()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is now too long (although we don't have automatic java style checks.)

import java.util.List;

import scala.Tuple2;
import org.apache.spark.mllib.linalg.DenseVector;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: import order

@SparkQA
Copy link

SparkQA commented Feb 18, 2017

Test build #73103 has finished for PR 16964 at commit 72fe178.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@srowen
Copy link
Member Author

srowen commented Feb 19, 2017

Merged to master

@srowen srowen closed this Feb 19, 2017
@srowen srowen deleted the SPARK-19534 branch February 19, 2017 17:43
asfgit pushed a commit that referenced this pull request Feb 19, 2017
## What changes were proposed in this pull request?

Convert tests to use Java 8 lambdas, and modest related fixes to surrounding code.

## How was this patch tested?

Jenkins tests

Author: Sean Owen <sowen@cloudera.com>

Closes #16964 from srowen/SPARK-19534.
Yunni pushed a commit to Yunni/spark that referenced this pull request Feb 27, 2017
## What changes were proposed in this pull request?

Convert tests to use Java 8 lambdas, and modest related fixes to surrounding code.

## How was this patch tested?

Jenkins tests

Author: Sean Owen <sowen@cloudera.com>

Closes apache#16964 from srowen/SPARK-19534.
@Alanthur
Copy link

@zzcclp@srowen I have the same error. In JavaConsumerStrategySuite.java,error is as follows:
The method mapValues(Function1<Long,Object>) is ambiguous for the type Map<TopicPartition,Long>
I use java 8.I clean build. But the error still exist. What should I do?Any help is appreciated.

@srowen
Copy link
Member Author

srowen commented Oct 16, 2017

This isn't the right place to ask, and master builds fine, so you should probably use that.

@Alanthur
Copy link

@srowen I want to know which IDE do you use? Eclipse or IDEA?

@zzcclp
Copy link
Contributor

zzcclp commented Nov 10, 2017

@dahaian I think this is the issue of Eclipse, you can open 'JavaConsumerStrategySuite.java' file, remove the '.mapValues' and then retype '.mapValues' again, save file to recompile, it will resolve this issue. I resolved it by this way.

@Alanthur
Copy link

@zzcclp I tried, failed. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants