Skip to content

Commit

Permalink
Relax MailHandler constructors
Browse files Browse the repository at this point in the history
DurationFilter count can be greater than records.
Signed-off-by: jmehrens <jason_mehrens@hotmail.com>
  • Loading branch information
jmehrens committed Nov 1, 2023
1 parent fce4693 commit 7826818
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private synchronized boolean accept(final long millis) {
}

//Under the rate if the count has not been reached.
if (count != records) {
if ((records - count) > 0L) {
++count;
allow = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,6 @@ public MailHandler() {
public MailHandler(final int capacity) {
init((Properties) null);
sealed = true;
if (capacity <=0 ) {
throw new IllegalArgumentException();
}
setCapacity0(capacity);
}

Expand All @@ -605,15 +602,11 @@ public MailHandler(final int capacity) {
* documentation. This <code>Handler</code> will also search the
* <code>LogManager</code> for defaults if needed.
*
* @param props a non <code>null</code> properties object.
* @throws NullPointerException if <code>props</code> is <code>null</code>.
* @param props a properties object or null.
* @throws SecurityException if a security manager exists and the
* caller does not have <code>LoggingPermission("control")</code>.
*/
public MailHandler(final Properties props) {
if (props == null) {
throw new NullPointerException();
}
public MailHandler(Properties props) {
init(props);
sealed = true;
setMailProperties0(props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,19 @@ public void testRecords() {
assertEquals(records, one.getRecords());
}

@Test
public void testCountExceedsRecords() {
DurationFilter one = new DurationFilter(10L, 15L * 60L * 1000L);
LogRecord r = new LogRecord(Level.INFO, "");
final long now = r.getMillis();
for (long i = 1L; i <= one.getRecords() / 2L; ++i) {
assertTrue(one.isLoggable(r));
setEpochMilli(r, now + i);
}
one.setRecords(1L);
assertFalse(one.isLoggable(r));
}

@Test
public void testDurationMillis() {
DurationFilter one = new DurationFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3639,30 +3639,22 @@ public void testComparator() {

@Test
public void testCapacity() {
try {
MailHandler h = new MailHandler(-1);
h.getCapacity();
fail("Negative capacity was allowed.");
} catch (IllegalArgumentException pass) {
} catch (RuntimeException RE) {
fail(RE.toString());
}
MailHandler h = new MailHandler(-1);
assertEquals(1000, h.getCapacity());

try {
MailHandler h = new MailHandler(0);
h.getCapacity();
fail("Zero capacity was allowed.");
} catch (IllegalArgumentException pass) {
} catch (RuntimeException RE) {
fail(RE.toString());
}
h = new MailHandler(0);
assertEquals(1000, h.getCapacity());

try {
MailHandler h = new MailHandler(1);
h.getCapacity();
} catch (RuntimeException RE) {
fail(RE.toString());
}
h = new MailHandler(1);
assertEquals(1, h.getCapacity());

h.setCapacity(10);
assertEquals(10, h.getCapacity());
h.close();
assertEquals(10, h.getCapacity());

h.setCapacity(1000);
assertEquals(1000, h.getCapacity());

final int expResult = 20;
MailHandler instance = new MailHandler(20);
Expand Down

0 comments on commit 7826818

Please sign in to comment.