-
Notifications
You must be signed in to change notification settings - Fork 45
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
#87 Grouping stack traces into single log statements for sub-processes #90
base: master
Are you sure you want to change the base?
Changes from all commits
3bd48e8
a52948b
828ee4f
534bb5c
fcb0007
80df3b6
2975b06
1d48789
fed0c7d
256d4f3
6e07c94
a3bfd27
12c800b
0516292
cc2ab93
e2a9c1b
0c00490
ed7a354
5c92779
c2873ae
9f257d7
1ea04f2
bbc143b
9ad8ac3
74be2fa
8a10cf9
2a1b9cc
4a4a465
85cfd53
4dc1ca1
6b8e6f4
6deffec
c8c1efa
df9445a
63c19a2
8e4a50f
d14e4da
ac89ad5
c796d56
399c3ed
c4d4ac1
0b0ebe6
308aec4
61d46ab
699ad4d
25f2849
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/** | ||
* Copyright (c) 2012-2016, jcabi.com | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: 1) Redistributions of source code must retain the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer. 2) Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. 3) Neither the name of the jcabi.com nor | ||
* the names of its contributors may be used to endorse or promote | ||
* products derived from this software without specific prior written | ||
* permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | ||
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.jcabi.log; | ||
|
||
/** | ||
* Example application to help test {@link VerboseProcess}. | ||
* @author Dean Clark ([email protected]) | ||
* @version $Id: 97615996e8472494c4561b6d9d5bca0e7f6992dc $ | ||
* @since 1.20.1 | ||
*/ | ||
@SuppressWarnings("PMD.DefaultPackage") | ||
public final class VerboseProcessExample { | ||
|
||
/** | ||
* System output line 1. | ||
*/ | ||
static final String SYSOUT_1 = "sysout line 1"; | ||
|
||
/** | ||
* System output line 2. | ||
*/ | ||
static final String SYSOUT_2 = "sysout line 2"; | ||
|
||
/** | ||
* Error output line 1. | ||
*/ | ||
static final String SYSERR_1 = "syserr line 1"; | ||
|
||
/** | ||
* Error output line 2. | ||
*/ | ||
static final String SYSERR_2 = "syserr line 2"; | ||
|
||
/** | ||
* Exception to be thrown and caught. | ||
*/ | ||
static final String CAUGHT_ERR_MSG = "throw/catch me"; | ||
|
||
/** | ||
* Exception to be thrown. | ||
*/ | ||
static final String THROWN_ERR_MSG = "just throw me"; | ||
|
||
/** | ||
* Private constructor. Intentionally empty. | ||
*/ | ||
private VerboseProcessExample() { } | ||
|
||
/** | ||
* Instantiates instance of this class and calls primary method. | ||
* @param args Any args passed to main method | ||
*/ | ||
public static void main(final String... args) { | ||
final VerboseProcessExample instance = new VerboseProcessExample(); | ||
instance.doWork(); | ||
} | ||
|
||
/** | ||
* Will log to standard output and error and then intentionally fail with a | ||
* stack trace. | ||
*/ | ||
@SuppressWarnings("PMD.SystemPrintln") | ||
private void doWork() { | ||
System.out.println(SYSOUT_1); | ||
System.err.println(SYSERR_1); | ||
System.out.println(SYSOUT_2); | ||
System.err.println(SYSERR_2); | ||
catchAndThrow(); | ||
} | ||
|
||
/** | ||
* Call a method which will throw an exception. Then catch and re-throw it. | ||
*/ | ||
private static void catchAndThrow() { | ||
try { | ||
countdownAndThrow(2); | ||
} catch (final IllegalStateException ex) { | ||
throw new IllegalStateException(THROWN_ERR_MSG, ex); | ||
} | ||
} | ||
|
||
/** | ||
* Recursively loops and then throws an exception. | ||
* @param loops Times to loop | ||
*/ | ||
private static void countdownAndThrow(final int loops) { | ||
if (loops == 0) { | ||
throw new IllegalStateException(CAUGHT_ERR_MSG); | ||
} | ||
countdownAndThrow(loops - 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkordas There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dean-e-clark right, thanks for explaining |
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dean-e-clark for so complex logic added in this PR I'd expect at least dozen of unit tests, but I don't see any 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you read this: http://www.yegor256.com/2017/03/24/tdd-that-works.html?
What about writing unit tests only when bugs will appear?