On 23 February 2015 at 10:35, Benedikt Ritter <brit...@apache.org> wrote: > Hello Phil, > > 2015-02-22 21:43 GMT+01:00 <pste...@apache.org>: > >> Author: psteitz >> Date: Sun Feb 22 20:43:30 2015 >> New Revision: 1661559 >> >> URL: http://svn.apache.org/r1661559 >> Log: >> Added (disabled) tests for JIRA: DBCP-283 and DBCP-284. >> >> Modified: >> >> commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java >> >> Modified: >> commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java >> URL: >> http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java?rev=1661559&r1=1661558&r2=1661559&view=diff >> >> ============================================================================== >> --- >> commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java >> (original) >> +++ >> commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericObjectPool.java >> Sun Feb 22 20:43:30 2015 >> @@ -26,6 +26,7 @@ import static org.junit.Assert.fail; >> >> import java.lang.management.ManagementFactory; >> import java.util.ArrayList; >> +import java.util.HashSet; >> import java.util.List; >> import java.util.NoSuchElementException; >> import java.util.Random; >> @@ -2398,6 +2399,44 @@ public class TestGenericObjectPool exten >> >> Assert.assertEquals(1, factory.validateCounter); >> } >> + >> + /** >> + * Verifies that when a factory's makeObject produces instances that >> are not >> + * discernible by equals, the pool can handle them. >> + * >> + * JIRA: POOL-283 >> + */ >> + //@Test >> > > IMHO it's better to use the @Ignore annotation, because this way ignored > tests will at least show up in reports generated by maven. You can even add > a description why a test is ignored like this: > > @Ignore("See POOL-283 in JIRA") >
+1 >> + public void testEqualsIndiscernible() throws Exception { >> + final HashSetFactory factory = new HashSetFactory(); >> + final GenericObjectPool<HashSet<String>> pool = new >> GenericObjectPool<HashSet<String>>( >> + factory, new GenericObjectPoolConfig()); >> + final HashSet<String> s1 = pool.borrowObject(); >> + final HashSet<String> s2 = pool.borrowObject(); >> + pool.returnObject(s1); >> + pool.returnObject(s2); >> + pool.close(); >> + } >> + >> + /** >> + * Verifies that when a borrowed object is mutated in a way that does >> not >> + * preserve equality and hashcode, the pool can recognized it on >> return. >> + * >> + * JIRA: POOL-284 >> + */ >> + //@Test >> + public void testMutable() throws Exception { >> + final HashSetFactory factory = new HashSetFactory(); >> + final GenericObjectPool<HashSet<String>> pool = new >> GenericObjectPool<HashSet<String>>( >> + factory, new GenericObjectPoolConfig()); >> + final HashSet<String> s1 = pool.borrowObject(); >> + final HashSet<String> s2 = pool.borrowObject(); >> + s1.add("One"); >> + s2.add("One"); >> + pool.returnObject(s1); >> + pool.returnObject(s2); >> + pool.close(); >> + } >> >> private static final class DummyFactory >> extends BasePooledObjectFactory<Object> { >> @@ -2410,7 +2449,23 @@ public class TestGenericObjectPool exten >> return new DefaultPooledObject<Object>(value); >> } >> } >> - >> + >> + /** >> + * Factory that creates HashSets. Note that this means >> + * 0) All instances are initially equal (not discernible by equals) >> + * 1) Instances are mutable and mutation can cause change in >> identity / hashcode. >> + */ >> + private static final class HashSetFactory >> + extends BasePooledObjectFactory<HashSet<String>> { >> + @Override >> + public HashSet<String> create() throws Exception { >> + return new HashSet<String>(); >> + } >> + @Override >> + public PooledObject<HashSet<String>> wrap(HashSet<String> value) { >> + return new DefaultPooledObject<HashSet<String>>(value); >> + } >> + } >> >> private static class InvalidFactory >> extends BasePooledObjectFactory<Object> { >> >> >> > > > -- > http://people.apache.org/~britter/ > http://www.systemoutprintln.de/ > http://twitter.com/BenediktRitter > http://github.com/britter --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org