Skip to content
Permalink
Browse files
Format tweaks, Javadoc. remove default code.
  • Loading branch information
Gary Gregory committed Apr 21, 2022
1 parent d879b41 commit cb5e9289d6ed1f92b46dc61bbb8bb43861f70eb3
Showing 4 changed files with 32 additions and 5 deletions.
@@ -31,8 +31,10 @@

@Disabled
public class PoolTest {

private static class Foo {
}

private static class PooledFooFactory implements PooledObjectFactory<Foo, RuntimeException> {
private static final long VALIDATION_WAIT_IN_MILLIS = 1000;

@@ -17,11 +17,12 @@
package org.apache.commons.pool2;

/**
* Test pooled object class. Keeps track of how many times it has been
* validated, activated, passivated.
* Test pooled object class. Keeps track of how many times it has been validated, activated, passivated.
*
* @param <K> The key type.
*/
public class VisitTracker<K> {

private int validateCount;
private int activateCount;
private int passivateCount;
@@ -50,42 +51,53 @@ public void activate() {
}
activateCount++;
}

public void destroy() {
destroyed = true;
}

private void fail(final String message) {
throw new IllegalStateException(message);
}

public int getActivateCount() {
return activateCount;
}

public int getId() {
return id;
}

public K getKey() {
return key;
}

public int getPassivateCount() {
return passivateCount;
}

public int getValidateCount() {
return validateCount;
}

public boolean isDestroyed() {
return destroyed;
}

public void passivate() {
if (destroyed) {
fail("attempted to passivate a destroyed object");
}
passivateCount++;
}

public void reset() {
validateCount = 0;
activateCount = 0;
passivateCount = 0;
destroyed = false;
}

@Override
public String toString() {
return "Key: " + key + " id: " + id;
@@ -22,13 +22,12 @@
/**
* Factory that creates VisitTracker instances. Used to test Evictor runs.
*
* @param <K> The VisitTracker key type.
*/
public class VisitTrackerFactory<K>
implements PooledObjectFactory<VisitTracker<K>, RuntimeException>, KeyedPooledObjectFactory<K, VisitTracker<K>, RuntimeException> {
private int nextId;

public VisitTrackerFactory() {
}
private int nextId;

@Override
public void activateObject(final K key, final PooledObject<VisitTracker<K>> ref) {
@@ -272,10 +272,12 @@ public SimpleFactory() {
public SimpleFactory(final boolean valid) {
this(valid,valid);
}

public SimpleFactory(final boolean evalid, final boolean ovalid) {
evenValid = evalid;
oddValid = ovalid;
}

@Override
public void activateObject(final PooledObject<String> obj) throws Exception {
final boolean hurl;
@@ -292,6 +294,7 @@ public void activateObject(final PooledObject<String> obj) throws Exception {
throw new Exception();
}
}

@Override
public void destroyObject(final PooledObject<String> obj) throws Exception {
final long waitLatency;
@@ -310,18 +313,23 @@ public void destroyObject(final PooledObject<String> obj) throws Exception {
throw new Exception();
}
}

private void doWait(final long latency) {
Waiter.sleepQuietly(latency);
}

public synchronized int getMakeCounter() {
return makeCounter;
}

public synchronized boolean isThrowExceptionOnActivate() {
return exceptionOnActivate;
}

public synchronized boolean isValidationEnabled() {
return enableValidation;
}

@Override
public PooledObject<String> makeObject() {
final long waitLatency;
@@ -342,6 +350,7 @@ public PooledObject<String> makeObject() {
}
return new DefaultPooledObject<>(String.valueOf(counter));
}

@Override
public void passivateObject(final PooledObject<String> obj) throws Exception {
final boolean hurl;
@@ -352,18 +361,23 @@ public void passivateObject(final PooledObject<String> obj) throws Exception {
throw new Exception();
}
}

public synchronized void setDestroyLatency(final long destroyLatency) {
this.destroyLatency = destroyLatency;
}

public synchronized void setEvenValid(final boolean valid) {
evenValid = valid;
}

public synchronized void setMakeLatency(final long makeLatency) {
this.makeLatency = makeLatency;
}

public synchronized void setMaxTotal(final int maxTotal) {
this.maxTotal = maxTotal;
}

public synchronized void setOddValid(final boolean valid) {
oddValid = valid;
}

0 comments on commit cb5e928

Please sign in to comment.