org.hd.d.pg2k.test.dev
Class SimpleCacheTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.hd.d.pg2k.test.dev.SimpleCacheTest
All Implemented Interfaces:
junit.framework.Test

public final class SimpleCacheTest
extends junit.framework.TestCase

Test the ExhibitSimpleDataCache.


Nested Class Summary
(package private) static class SimpleCacheTest.DataConcurrencyAccessMonitor
          Thread-safe monitor of data-read activity.
static class SimpleCacheTest.DummyDataSource
          Dummy data source.
(package private) static class SimpleCacheTest.RawDataAccessMonitor
          Thread-safe monitor of data-read activity.
 
Field Summary
private  SimpleLoggerIF logger
           
private static java.util.Random rnd
          Private source of OK pseudo-random numbers.
private  java.util.Timer t
          Timer that we can use to run pipelines; never null during tests.
private  java.io.File tempDir
          Temporary directory in which we build a cache; null if not needed.
 
Constructor Summary
SimpleCacheTest(java.lang.String name)
           
 
Method Summary
private  int checkCacheInstance(boolean firstRun, int prevCachedCount, java.util.List<SimpleCacheTest.RawDataAccessMonitor.GetRawDataEvent> eventsFromTestStart, long stopBy)
          Check behaviour of single cache instance, mainly for persistence.
protected  void setUp()
          Do any setup needed for the tests.
protected  void tearDown()
          Do any clear-up needed after the tests.
 void testBasicCacheBehaviour()
          Check that we can construct a cache wrapped round a (dummy) source.
 void testCacheFileReadConcurrency()
          Test that cache has indefinite (file read) concurrency.
 void testCachePersistence()
          Test cacheing and resilience after restart.
 void testCacheVarHandling()
          Test that variables work properly with the cache.
static void testDummyDataSource()
          Internal test that DummyDataSource behaves as expected.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private final SimpleLoggerIF logger

tempDir

private java.io.File tempDir
Temporary directory in which we build a cache; null if not needed. We only chose a directory name (which we store in absolute form in case we change working directory) and delete any existing content before and after the tests run. The test routines must create the directory if they want it.


t

private java.util.Timer t
Timer that we can use to run pipelines; never null during tests.


rnd

private static final java.util.Random rnd
Private source of OK pseudo-random numbers.

Constructor Detail

SimpleCacheTest

public SimpleCacheTest(java.lang.String name)
Method Detail

setUp

protected void setUp()
Do any setup needed for the tests.

Overrides:
setUp in class junit.framework.TestCase

tearDown

protected void tearDown()
Do any clear-up needed after the tests.

Overrides:
tearDown in class junit.framework.TestCase

testDummyDataSource

public static void testDummyDataSource()
                                throws java.lang.Exception
Internal test that DummyDataSource behaves as expected. Essentially we ensure that basic routines return legitimate non-null values.

Throws:
java.lang.Exception

testBasicCacheBehaviour

public void testBasicCacheBehaviour()
                             throws java.lang.Exception
Check that we can construct a cache wrapped round a (dummy) source. And check that we can do some basic superficial operations on it.

Look elsewhere for a thorough test to behaviour.

Throws:
java.lang.Exception

testCacheVarHandling

public void testCacheVarHandling()
                          throws java.lang.Exception
Test that variables work properly with the cache. This is just to make sure that its semantics are correct.

Throws:
java.lang.Exception

testCachePersistence

public void testCachePersistence()
                          throws java.lang.Exception
Test cacheing and resilience after restart. This test attempts to test that precacheing works and that the cache remains intact after a restart.

This relies on the test data set being present and being easily small enough to fit into cache.

Throws:
java.lang.Exception

checkCacheInstance

private int checkCacheInstance(boolean firstRun,
                               int prevCachedCount,
                               java.util.List<SimpleCacheTest.RawDataAccessMonitor.GetRawDataEvent> eventsFromTestStart,
                               long stopBy)
                        throws java.io.IOException,
                               java.lang.InterruptedException
Check behaviour of single cache instance, mainly for persistence. This checks for different things on the first and subsequent runs, but in all cases makes sure that the cache behaves properly and does not lose data upon restart, whether it gets shut down properly or not.

The number of exhibits partially or fully cached must not go down and must be greater than zero when we return if there are exhibits.

This tests the cache's use of its upstream data source knowing that this should read and cache exhibit prefixes (ie it will/may only cache activity that reads starting at the beginning of an exhibit, as a normal download should), and that having read such a prefix it should never have to go back to the underlying source for anything within that prefix again, even when the cache is shut down an restarted, assuming that our cache area is big enough to hold all the exhibits.

Parameters:
firstRun - if true, this is the first run on a new cache area
prevCachedCount - number of exhibits previously cached; non-negative
eventsFromTestStart - List of events collected so far in order; we will append to this (the content is opaque to the caller); must be non-null and appendable-to
stopBy - target time to stop by
Returns:
number of exhibits partially or fully cached; non-negative
Throws:
java.io.IOException
java.lang.InterruptedException

testCacheFileReadConcurrency

public void testCacheFileReadConcurrency()
                                  throws java.lang.Exception
Test that cache has indefinite (file read) concurrency. The aim is to demonstrate that we can scale well to serve exhibit data, eg on a highly-threadable system such as Niagara/CoolThreads.

Throws:
java.lang.Exception

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.