|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object junit.framework.Assert junit.framework.TestCase net.sf.farrago.test.FarragoObjectCacheTest
public class FarragoObjectCacheTest
FarragoObjectCacheTest
is a unit test for FarragoObjectCache
.
Premise: inner class RentalCarAgency maintains a fleet of rental cars and assigns them to customers as requested. The agency is lucky enough to be able to manufacture new cars on demand! (It uses a private factory to do this.) However, it has a fixed number of tires it can outfit them with (due to a terrible rubber tree blight). So, it sometimes has to destroy old cars to salvage their tires. (For real usage patterns, read "object memory usage" for "tires".)
TODO:
Nested Class Summary | |
---|---|
private class |
FarragoObjectCacheTest.CustomerThread
CustomerThread exemplifies a thread which uses objects from the cache. |
private class |
FarragoObjectCacheTest.LemonException
|
private class |
FarragoObjectCacheTest.RentalCar
RentalCar exemplifies a reusable object. |
private class |
FarragoObjectCacheTest.RentalCarAgency
RentalCarAgency exemplifies a cache of reusable objects. |
private class |
FarragoObjectCacheTest.RentalCarAgreement
RentalCarAgreement encapsulates the assignment of a car to a customer for a duration. |
Field Summary | |
---|---|
(package private) FarragoObjectCacheTest.RentalCarAgency |
agency
|
(package private) static int |
MAX_MILEAGE
Mileage limit after which a car should be discarded. |
(package private) static int |
MAX_TIRES
Default cache size limit. |
(package private) AtomicInteger |
nCarsCreated
|
(package private) AtomicInteger |
nCarsDestroyed
|
Constructor Summary | |
---|---|
FarragoObjectCacheTest(String testName)
Creates a new FarragoObjectCacheTest object. |
Method Summary | |
---|---|
private void |
runMultipleThreads(boolean exclusive)
|
private void |
runOneThreadSequential(String description,
int milesToDrive,
boolean expectNew)
|
void |
tearDown()
|
void |
testMultipleThreadsExclusive()
Tests a multi-threaded scenario with objects pinned exclusively. |
void |
testMultipleThreadsShared()
Tests a multi-threaded scenario with objects pinned as shared. |
void |
testOneThreadFailedInitialization()
Tests a scenario where an exception is thrown during initialization. |
void |
testOneThreadOverlappingExclusive()
Tests a scenario where two cars are rented at the same time. |
void |
testOneThreadSequential()
Tests a scenario where a single car is rented, returned, and then rented and returned again. |
void |
testOneThreadSequentialNonReusable()
Tests a scenario where a car is rented, smoked in, and then returned, so that a subsequent rental request forces creation of a new car (discarding the old one). |
void |
testOneThreadSequentialStale()
Tests a scenario where a car is rented, driven a long way, and then returned, so that a subsequent rental request forces creation of a new car (discarding the old one). |
void |
testOneThreadShared()
Tests a scenario where the same car is rented by two customers at the same time. |
void |
testOneThreadVictimization()
Tests a scenario where new cars are constantly requested and then returned, causing old cars to be recycled for their tires. |
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, toString |
Methods inherited from class junit.framework.Assert |
---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static final int MAX_TIRES
static final int MAX_MILEAGE
FarragoObjectCacheTest.RentalCarAgency agency
AtomicInteger nCarsCreated
AtomicInteger nCarsDestroyed
Constructor Detail |
---|
public FarragoObjectCacheTest(String testName) throws Exception
Exception
Method Detail |
---|
public void tearDown()
tearDown
in class TestCase
public void testOneThreadOverlappingExclusive()
public void testOneThreadSequential()
public void testOneThreadSequentialStale()
public void testOneThreadSequentialNonReusable()
private void runOneThreadSequential(String description, int milesToDrive, boolean expectNew)
public void testOneThreadShared()
public void testOneThreadVictimization()
public void testOneThreadFailedInitialization()
public void testMultipleThreadsExclusive()
public void testMultipleThreadsShared()
private void runMultipleThreads(boolean exclusive)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |