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

8316412: javax/print tests fail without printer set up #15821

Closed
wants to merge 5 commits into from

Conversation

msobiers
Copy link
Contributor

@msobiers msobiers commented Sep 19, 2023

For NullClipARGB we are throwing SkippedException only if instance of caught exception is PrinterException. All other exceptions are considered unrelated to printer configuration.

For CountPrintServices we want to throw SkippedException in the case when lpstat is not installed, where an IOException is caught in that case.

For ExceptionTest we want to throw SkippedException for all PrinterExceptions which were not caused by IndexOutOfBoundsException.

For rest of the tests if PrintService was not created instead RuntimeException we are throwing now SkippedException.

Tested on environment without printer installed.
Test are passing with skipped exception as expected.

Passed: java/awt/print/PrinterJob/ExceptionTest.java
Passed: java/awt/print/PrinterJob/ImagePrinting/NullClipARGB.java
Passed: java/awt/print/PrinterJob/PrtException.java
Passed: javax/print/attribute/AttributeTest.java
Passed: javax/print/attribute/GetCopiesSupported.java
Passed: javax/print/attribute/SidesPageRangesTest.java
Passed: javax/print/attribute/SupportedPrintableAreas.java
Passed: javax/print/PrintServiceLookup/CountPrintServices.java
Passed: javax/print/CheckDupFlavor.java

Additionally unused imports have been removed.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8316412: javax/print tests fail without printer set up (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15821/head:pull/15821
$ git checkout pull/15821

Update a local copy of the PR:
$ git checkout pull/15821
$ git pull https://git.openjdk.org/jdk.git pull/15821/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15821

View PR using the GUI difftool:
$ git pr show -t 15821

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15821.diff

Webrev

Link to Webrev Comment

Sorry, something went wrong.

For NullClipARGB we are throwing SkippedException only if instance of
caught exception is PrinterException. All other exceptions are
considered unrelated to printer configuration.

For CountPrintServices we want to throw SkippedException in the case
when lpstat is not installed, where an IOException is caught in that
case.

For ExceptionTest we want to throw SkippedException for all
PrinterExceptions which were not caused by IndexOutOfBoundsException.

For rest of the tests if PrintService was not created instead
RuntimeException we are throwing now SkippedException.

Tested on environment without printer installed.
Test are passing with skipped exception as expected.

Passed: java/awt/print/PrinterJob/ExceptionTest.java
Passed: java/awt/print/PrinterJob/ImagePrinting/NullClipARGB.java
Passed: java/awt/print/PrinterJob/PrtException.java
Passed: javax/print/attribute/AttributeTest.java
Passed: javax/print/attribute/GetCopiesSupported.java
Passed: javax/print/attribute/SidesPageRangesTest.java
Passed: javax/print/attribute/SupportedPrintableAreas.java
Passed: javax/print/PrintServiceLookup/CountPrintServices.java
Passed: javax/print/CheckDupFlavor.java
@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label Sep 19, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Sep 19, 2023

Hi @msobiers, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user msobiers" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@openjdk
Copy link

openjdk bot commented Sep 19, 2023

@msobiers The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Sep 19, 2023
@msobiers
Copy link
Contributor Author

/covered

@bridgekeeper bridgekeeper bot added the oca-verify Needs verification of OCA signatory status label Sep 19, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Sep 19, 2023

Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

The copyright years need to be adjusted a bit.

Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.

...should become:

Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.

throw new RuntimeException(ex);
} catch (Exception ex) {
if (ex instanceof PrinterException) {
throw new SkippedException("Printer is required for this test. TEST ABORTED");
Copy link
Member

Choose a reason for hiding this comment

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

I think for this test, we need to check PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);, like other tests do it. Let's not assume that PrinterException is thrown here only when printer is not configured. Add the block right at the beginning of main?

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Apart from stylistic comments, this looks good.

}
}

public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException{
throws PrinterException{
Copy link
Member

Choose a reason for hiding this comment

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

Redundant whitespace change.

@@ -59,7 +68,7 @@ public int print(Graphics g, PageFormat pf, int pageIndex)
g2.setColor( Color.BLACK );
g2.drawString("This text should be visible through the image", 0, 20);
BufferedImage bi = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_ARGB );
BufferedImage.TYPE_INT_ARGB );
Copy link
Member

Choose a reason for hiding this comment

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

Redundant whitespace change.


public class NullClipARGB implements Printable {

public static void main( String[] args ) {
PrintService[] svc = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to ask for DocFlavor.SERVICE_FORMATTED.PRINTABLE here? Can we just ask for null?

Copy link
Contributor Author

@msobiers msobiers Sep 20, 2023

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but I think if we ask for null here it may find a PrintService that does not support PRINTABLE flavor so SkippedException will not be thrown because svc.length will be greater than 0 and we may end up with an exception thrown later in pj.print().

Copy link
Member

Choose a reason for hiding this comment

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

Oh, OK. So the idea is that if we use setPrintable, we need to lookup the service that accepts .PRINTABLE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is my understanding.


try {
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(new NullClipARGB());
pj.print();
} catch (Exception ex) {
Copy link
Member

Choose a reason for hiding this comment

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

I see this is a cleanup, but we don't need to do it here, to keep patch simple and backportable.

* @run main CheckDupFlavor
*/

import javax.print.*;
import javax.print.attribute.*;
Copy link
Member

Choose a reason for hiding this comment

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

Here and later, keep the imports in place, for the same reason: targeted backportable patch.


try {
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(new NullClipARGB());
pj.print();
} catch (Exception ex) {
throw new RuntimeException(ex);
throw new RuntimeException(ex);
Copy link
Member

Choose a reason for hiding this comment

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

One more redundant whitespace change.

}
}

public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException{
throws PrinterException{
Copy link
Member

Choose a reason for hiding this comment

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

One more redundant whitespace change.

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Looks good to me. Once OCA clears, someone familiar with this area would need to take a look too.

/reviewers 2

@openjdk
Copy link

openjdk bot commented Sep 20, 2023

@shipilev
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@bridgekeeper bridgekeeper bot removed oca Needs verification of OCA signatory status oca-verify Needs verification of OCA signatory status labels Sep 20, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 20, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 20, 2023

Webrevs

@prrace
Copy link
Contributor

prrace commented Sep 25, 2023

Just like
@key headful
is used for headful tests, these tests have
@key printer
which you are supposed to use to exclude them if you don't have a printer configured., eg

jtreg -k:!printer ...

In other words none of these changes should be necessary and I'm fairly sure are actually undesirable in some cases.
Notably skipping if lpstat isn't installed and you are trying to test printing is bad.

@shipilev
Copy link
Member

In other words none of these changes should be necessary and I'm fairly sure are actually undesirable in some cases.
Notably skipping if lpstat isn't installed and you are trying to test printing is bad.

Right! Argh, I missed that the tests have keywords on them. I think we can close this as WNF, @msobiers. Sorry for leading you the wrong way here.

@msobiers
Copy link
Contributor Author

In other words none of these changes should be necessary and I'm fairly sure are actually undesirable in some cases.
Notably skipping if lpstat isn't installed and you are trying to test printing is bad.

Right! Argh, I missed that the tests have keywords on them. I think we can close this as WNF, @msobiers. Sorry for leading you the wrong way here.

Np. Closing now.

@msobiers msobiers closed this Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

None yet

3 participants