Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-2480][test]Add tests for PrintSinkFunction #991

Closed
wants to merge 4 commits into from

Conversation

HuangWHWHW
Copy link
Contributor

Test PrintSinkFunction:
set number of subtasks with 0 in runtime ctx to make prefix null.
1.set STD.OUT and test print system.out
2.set STD.ERR and test print system.err

@HuangWHWHW
Copy link
Contributor Author

I still cannot see the CI.
Does any one can help to support this CI info??

import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.JobID;
import org.apache.flink.api.common.accumulators.Accumulator;
//import org.apache.flink.api.common.functions.RuntimeContext;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the imports which are commented out.

@HuangWHWHW
Copy link
Contributor Author

@fhueske
Thank you!I`ll fix it.

@mxm
Copy link
Contributor

mxm commented Aug 12, 2015

Your pull request doesn't compile: https://s3.amazonaws.com/archive.travis-ci.org/jobs/74504427/log.txt

printSink.setTargetToStandardOut();
printSink.invoke("hello world!");

assertEquals("Print to System.out", printSink.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

You're not testing whether the sink actually prints to stdout. You're just checking if the toString() methods returns the correct mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I see, the sink actually prints is printSink.invoke("hello world!");.
And in the function invoke, it just calls stream.println(record.toString());.
Could you tell me how to get the prints from the stream?
Because I think assertEquals("hello world!", record); is just like assertEquals("hello world!", "hello world!"); and it`s not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, ignore this.
I just have got the way.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can replace stdout using System.setOut(..) by a PrintStream which writes to a ByteArrayOutputStream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I did this in my new change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, didn't see that. Great!

@HuangWHWHW HuangWHWHW force-pushed the FLINK-2480 branch 2 times, most recently from 4dbfc28 to 702b4b1 Compare August 14, 2015 06:58
@HuangWHWHW
Copy link
Contributor Author

Hi, I have done a new changes.

public void testPrintSinkStdOut(){

printStreamMock stream = new printStreamMock(out);
System.setOut(stream);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you save and restore System.out in an @After shutdown method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I add this in my new change.

@mxm
Copy link
Contributor

mxm commented Aug 25, 2015

Thanks for the updates! Looks good and I think we can merge your changes.

@HuangWHWHW
Copy link
Contributor Author

@mxm
Thank you.
Sorry for that I haven`t updated the code in this branch for a long time.
So you can wait the CI to pass.

@StephanEwen
Copy link
Contributor

@HuangWHWHW Can you access the CI reports now? Has the Travis team fixed the problem?

@HuangWHWHW
Copy link
Contributor Author

@StephanEwen
Hi,
Not yet.
I will ask the travis support again.


@After
public void restoreSystemOut() {
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you restore the original PrintStream here? You can save it in a variable like PrintStream original = System.out and restore it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I add this in my new change.

}
};

public PrintStream PrintStreamOriginal = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be private PrintStream PrintStreamOriginal = System.out;. Then you don't need the null check later on and simply restore it in the @After method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixed these two comments.

*/
public class PrintSinkFunctionTest<IN> extends RichSinkFunction<IN> {

public PrintStream PrintStreamOriginal = System.out;
Copy link
Contributor

Choose a reason for hiding this comment

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

By convention, the variable name should be lower case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AhAh......
Sorry, I get you now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed public PrintStream PrintStreamOriginal = System.out; to private PrintStream printStreamOriginal = System.out; now. :)

@HuangWHWHW
Copy link
Contributor Author

@mxm
Hi,
sorry for a careless again.
Now I fix the problem which the CI was failed.

@mxm
Copy link
Contributor

mxm commented Aug 26, 2015

Thanks @HuangWHWHW. I'll merge your changes when Travis has completed.

@HuangWHWHW
Copy link
Contributor Author

@mxm
Hi,
the CI is pass.
Did it probability failure?

}
}

private Environment envForPrefixNull = new Environment() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can replace all this by private Environment envForPrefixNull = Mockito.mock(Environment.class).

@asfgit asfgit closed this in d08733d Aug 27, 2015
@mxm
Copy link
Contributor

mxm commented Aug 27, 2015

Thank you @HuangWHWHW. I merged your pull request with a few minor changes (see new comments).

nikste pushed a commit to nikste/flink that referenced this pull request Sep 29, 2015
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fde7c49 on HuangWHWHW:FLINK-2480 into ** on apache:master**.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants