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

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

public final class SystemVariablesTest
extends junit.framework.TestCase

Test the behaviour of system variables. This includes as stand-alone objects, in variable-manager caches, in pipelines and tunnels, etc.


Nested Class Summary
(package private) static class SystemVariablesTest.BasicVarMgrEndpoint
          Simple final pipeline stage (a master endpoint) variable values.
(package private) static class SystemVariablesTest.EventValueRequestMonitor
          Observe upstream accesses to event values.
(package private) static class SystemVariablesTest.LocalTunnelServer
          Class to encapsulate "local" tunnel "server".
(package private) static class SystemVariablesTest.LocalTunnelSource
          Local tunnel client/source, for connecting to LocalTunnelServer.
(package private) static class SystemVariablesTest.TestVarCacheStage
          Simple pipeline stage that caches variable values.
 
Field Summary
private static SimpleLoggerIF logger
           
private static boolean RANDOMISE_VARIABLE_TEST_ORDER
          If true, randomise order of variable tests (and skip some if we are short of time).
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.
 
Constructor Summary
SystemVariablesTest(java.lang.String name)
           
 
Method Summary
private static void _checkGlobalMerge(java.util.List<BasicVarMgrInterface[]> livePipes, long stopBy)
          Check global variable propagation and merge.
private static void _setUpLocalVars(SimpleVariableDefinition[] localWritableTestVars, BasicVarMgrInterface[][] pipelines, int nPipes, java.util.List<SimpleVariableDefinition>[] what, SimpleVariableValue[] values)
          Set random variables on random pipes for testing later.
private static void _testLocalNonPropagation(SimpleVariableValue[] values, int nPipes, BasicVarMgrInterface[][] pipelines, java.util.List[] what)
          Run after _setUpLocalVars() to ensure that locals did NOT propagate between pipelines.
private static void checkIllegalGetSetOpsVetoedCorrectly(BasicVarMgrInterface[] pipeline, long stopBy)
          This checks that operations are vetoed when they should be.
private  void checkShortPipelineVarMgr(boolean writeThrough)
          Check a short pipeline with a single PipelineVarMgr stage.
private static void checkSimpleSetGet(SimpleVariablePipelineIF[] pipeline, long stopBy)
          Test set and get of globals and locals.
private static InstanceID checkSystemIDHandling(BasicVarMgrInterface[] pipeline, long stopBy)
          Check that the pipeline handles system ID correctly.
static boolean checkValuePresent(SimpleVariableValue[] vars, SimpleVariableValue svv)
          Returns true iff the specified variable is present in the array with the specified value.
(package private) static SimpleVariableDefinition makeRandomSimpleVariableDefinition()
          Makes a random definition; never returns null.
(package private) static SimpleVariableValue makeRandomSimpleVariableValue(SimpleVariableDefinition def)
          Given a variable definition, make a random value for it; never null.
private static boolean notAfter(long stopBy)
          Returns true if time is not after that stated.
static void pipelineVariableTest(SimpleVariablePipelineIF[] slave1, SimpleVariablePipelineIF[] slave2, SimpleVariablePipelineIF[] master, long stopBy)
          Driver routine to test variable handling in pipelines.
protected  void setUp()
          Do any setup needed for the tests.
static InstanceID singlePipelineTest(SimpleVariablePipelineIF[] pipeline, long stopBy)
          Run variable tests on one pipeline ans returns the InstanceID; never null.
protected  void tearDown()
          Do any clearup needed after the tests.
 void testArbitraryVarConstruction()
          Test that variables of fairly arbitrary names/types can be constructed.
 void testAuthEventValueGenerationAndCacheing()
          Test correct generation and handling of authoritative event values.
 void testBasicEventHandling()
          Do very basic event-handling tests.
 void testBasicVarMgrAsEndPoint()
          Test basic variable manager behaviour for the endpoint.
 void testBasicVarMgrAsPipelineEndpoint()
          Check BasicVarMgr embedded at the end of a pipeline.
 void testEPCMComputationDoesNotRefetchEventHistory()
          Test that (re)computing ExhibitPropsComputableMutable data does not cause redundant event data fetches.
 void testEventBucketting()
          Check that events are correctly split into multiple periods.
 void testEventCollectionSerialisation()
          Check that the various event objects/collections can be (de)serialised.
 void testEventHistoryPeristence()
          Test that we can persist the event histories.
 void testGlobalVariableOps()
          Test basic setting/getting of global variables.
 void testInstanceID()
          Do simple tests on InstanceID type...
 void testLocalTunnelEventSimple()
          Do simple test of tunnel connectivity for set()ting and get()ting events.
 void testLocalTunnelFull()
          Run full tunnel variable test.
 void testLocalTunnelSimple()
          Do simple test of tunnel connectivity.
 void testLocalVariableOps()
          Test basic setting/getting of local variables.
 void testPipelineVarMgrLong()
          Test several PipelineVarMgr stages in a long pipeline.
 void testPipelineVarMgrSimpleNonWriteThrough()
          Test PipelineVarMgr in pipeline in non-write-through mode.
 void testPipelineVarMgrSimpleWriteThrough()
          Test PipelineVarMgr in pipeline in write-through mode.
 void testSimpleExhibitPipelineFilterVariableHandling()
          Check vanilla SimpleExhibitPipelineFilter embedded in a pipeline.
 void testSimpleNumberStats()
          Test that we can correctly generate stats safely.
 void testSimpleSerialisation()
          Check some simple (de)serialistion works as expected.
 void testSimpleVarStats()
          Test simple variable stats.
 void testTypeNumber()
          Test handling of TYPE_NUMBER values.
 
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 static final SimpleLoggerIF logger

t

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


RANDOMISE_VARIABLE_TEST_ORDER

private static final boolean RANDOMISE_VARIABLE_TEST_ORDER
If true, randomise order of variable tests (and skip some if we are short of time). This can only be done if we quieten the pipelines between tests so that tests don't conflict with one another by having updates from one test still bouncing around during the next.

This allows us to do as few as one test each time, on the grounds that we will test the entire range over time.

See Also:
Constant Field Values

rnd

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

Constructor Detail

SystemVariablesTest

public SystemVariablesTest(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 clearup needed after the tests.

Overrides:
tearDown in class junit.framework.TestCase

testSimpleSerialisation

public void testSimpleSerialisation()
                             throws java.lang.Exception
Check some simple (de)serialistion works as expected. In particular, deserialising one of the canonical system variable definition should yield the canonical instance, ie that we our providing instance control.

However, it should still be possible to (de)serialise definitions (and compound values containing them) that are no longer legitimate system variable (and do not conflict with them) so that we can examine historical data for example.

Throws:
java.lang.Exception

testInstanceID

public void testInstanceID()
                    throws java.lang.Exception
Do simple tests on InstanceID type... Such as making sure that all instance are unique, sort correctly, etc.

Throws:
java.lang.Exception

testArbitraryVarConstruction

public void testArbitraryVarConstruction()
                                  throws java.lang.Exception
Test that variables of fairly arbitrary names/types can be constructed. This means, for example, that we can ship any variables between systems across HTTP tunnels, etc, providing that any stored values type-check, (even if we are then not allowed to set the values in a local variable store).

Throws:
java.lang.Exception

testBasicVarMgrAsEndPoint

public void testBasicVarMgrAsEndPoint()
Test basic variable manager behaviour for the endpoint. Instances not marked as an endpoint should not have a system ID defined, whereas an endpoint should have one defined.


testLocalVariableOps

public void testLocalVariableOps()
                          throws java.lang.Exception
Test basic setting/getting of local variables. It is assumed that the endPoint setting should be irrelevant.

Throws:
java.lang.Exception

testGlobalVariableOps

public void testGlobalVariableOps()
                           throws java.lang.Exception
Test basic setting/getting of global variables. This will have to be an end-point to set global variables.

Throws:
java.lang.Exception

testTypeNumber

public void testTypeNumber()
                    throws java.lang.Exception
Test handling of TYPE_NUMBER values. We want to ensure that all java.lang.XXX Number extensions are allowed, but not any user-defined ones.

Throws:
java.lang.Exception

testBasicVarMgrAsPipelineEndpoint

public void testBasicVarMgrAsPipelineEndpoint()
                                       throws java.lang.Exception
Check BasicVarMgr embedded at the end of a pipeline. We're prepared to spend some time running this (though in fact it should be fast) since it is so basic to correct behaviour.

Throws:
java.lang.Exception

testSimpleExhibitPipelineFilterVariableHandling

public void testSimpleExhibitPipelineFilterVariableHandling()
                                                     throws java.lang.Exception
Check vanilla SimpleExhibitPipelineFilter embedded in a pipeline. This is only checking the variable-handling aspects.

Throws:
java.lang.Exception

testPipelineVarMgrSimpleWriteThrough

public void testPipelineVarMgrSimpleWriteThrough()
                                          throws java.lang.Exception
Test PipelineVarMgr in pipeline in write-through mode. Checks that we can build a simple pipeline with:

testPipelineVarMgrSimpleNonWriteThrough

public void testPipelineVarMgrSimpleNonWriteThrough()
                                             throws java.lang.Exception
Test PipelineVarMgr in pipeline in non-write-through mode. Checks that we can build a simple pipeline with:

checkShortPipelineVarMgr

private void checkShortPipelineVarMgr(boolean writeThrough)
                               throws java.lang.InterruptedException,
                                      java.io.IOException
Check a short pipeline with a single PipelineVarMgr stage. This can be run in write-through or non-write-through mode.

We run this stand-alonw because as of 20040808 the non-write-though implementation was buggy/lossy.

Parameters:
writeThrough -
Throws:
java.lang.InterruptedException
java.io.IOException

testPipelineVarMgrLong

public void testPipelineVarMgrLong()
                            throws java.lang.Exception
Test several PipelineVarMgr stages in a long pipeline. Checks that we can build a simple pipeline with:

checkValuePresent

public static boolean checkValuePresent(SimpleVariableValue[] vars,
                                        SimpleVariableValue svv)
Returns true iff the specified variable is present in the array with the specified value. Checks name, type and value.

Parameters:
svv - variable/value to check for; must not be null

pipelineVariableTest

public static void pipelineVariableTest(SimpleVariablePipelineIF[] slave1,
                                        SimpleVariablePipelineIF[] slave2,
                                        SimpleVariablePipelineIF[] master,
                                        long stopBy)
                                 throws java.io.IOException,
                                        java.lang.InterruptedException
Driver routine to test variable handling in pipelines. This makes sure that values are correctly propagated, globals correctly merged, etc.

The pipeline order is downstream-first, end-point-last, eg the persistent store or tunnel for a pipeline would be at the highest-numbered index, and the normal access point for the tunnel (eg as exposed by the DataSourceBean) is at index 0.

Takes in-order lists of taps/entrypoints on a data pipeline, the first (two) being separate slaves (before a tunnel) and the last being in a master (after a tunnel). All but one of the lists can be null (but never empty).

Internal correctness tests will be run on each of the constituent slave/master pipelines.

The parameter arrays must not be altered while the tests are running.

This checks that:

Parameters:
slave1 - pipeline for slave 1; null or non-empty
slave2 - pipeline for slave 2; null or non-empty
master - pipeline for master; null or non-empty
Throws:
java.io.IOException - if an inappropriate IOException is thrown by the pipeline under test
java.lang.InterruptedException

_checkGlobalMerge

private static void _checkGlobalMerge(java.util.List<BasicVarMgrInterface[]> livePipes,
                                      long stopBy)
                               throws java.lang.InterruptedException
Check global variable propagation and merge. Check that if I set a test global in each pipeline, then in all pipelines I can see a merged globalMap within the allowed latency.

This does not alter its parameters, though sets/gets values in them.

Parameters:
livePipes - list of pipelines of participating systems; no pipelines are null or empty
stopBy - time to attempt to stop by
Throws:
java.lang.InterruptedException

makeRandomSimpleVariableValue

static SimpleVariableValue makeRandomSimpleVariableValue(SimpleVariableDefinition def)
Given a variable definition, make a random value for it; never null. This attempts to return values distributed across the entire legitimate range for a given type; where that type has a large range then the values generated should be unique within a given test run (unless the random number source behaves poorly).

Conversely, for restricted types such as TYPE_NONE, little or no practical variation is possible.

Non-local values are generated without a globalMap; the results of several calls to this function can be merged with put() to generate a non-empty globalMap if desired.

Package-visible so as to be available to other test routines.

Parameters:
def - definition for which value is wanted; never null
Returns:
random value for that definition.

_testLocalNonPropagation

private static void _testLocalNonPropagation(SimpleVariableValue[] values,
                                             int nPipes,
                                             BasicVarMgrInterface[][] pipelines,
                                             java.util.List[] what)
Run after _setUpLocalVars() to ensure that locals did NOT propagate between pipelines.

Parameters:
values -
nPipes -
pipelines -
what -

_setUpLocalVars

private static void _setUpLocalVars(SimpleVariableDefinition[] localWritableTestVars,
                                    BasicVarMgrInterface[][] pipelines,
                                    int nPipes,
                                    java.util.List<SimpleVariableDefinition>[] what,
                                    SimpleVariableValue[] values)
Set random variables on random pipes for testing later. This records which variables and values were set on each pipeline for later testing by _testLocalNonPropagation() later.

There must be at least a master and one slave for this to be meaningful.

Parameters:
localWritableTestVars -
pipelines -
nPipes -
what -
values -

singlePipelineTest

public static InstanceID singlePipelineTest(SimpleVariablePipelineIF[] pipeline,
                                            long stopBy)
                                     throws java.io.IOException,
                                            java.lang.InterruptedException
Run variable tests on one pipeline ans returns the InstanceID; never null. Runs a whole suite of tests on one individual pipeline within one system.

Used by pipelineVariableTest().

Throws an exception, assertion or fail()s upon discovering a problem.

Tests that:

The pipeline order is downstream-first, end-point-last, eg the persistent store or tunnel for a pipeline would be at the highest-numbered index, and the normal access point for the tunnel (eg as exposed by the DataSourceBean) is at index 0.

Parameters:
pipeline - one or more stages/taps on a pipeline in order, downstream first, never null nor empty nor containing null or duplicate entries
stopBy - stop testing by or soon after this time, having done at least one of each type of test
Returns:
the system ID for the pipeline.
Throws:
java.io.IOException - if an inappropriate IOException is thrown by the pipeline under test
java.lang.InterruptedException

checkSimpleSetGet

private static void checkSimpleSetGet(SimpleVariablePipelineIF[] pipeline,
                                      long stopBy)
                               throws java.lang.InterruptedException
Test set and get of globals and locals. Tests simple set/get operations work and preserve timestamps, and that values do not get "lost" due to races, cache errors, etc.

Also tests that variable set operations are not visibly reordered, eg that cacheing and tunnel (etc) staged do not cause re-ordering.

Tests that locals (that we set) never get a (non-null) globalMap.

Parameters:
pipeline - pipeline; non-null, non-zero-length
stopBy - time to stop running tests by, if possible
Throws:
java.lang.InterruptedException

checkSystemIDHandling

private static InstanceID checkSystemIDHandling(BasicVarMgrInterface[] pipeline,
                                                long stopBy)
                                         throws java.io.IOException
Check that the pipeline handles system ID correctly. Mainly that the value can be fetched from any stage at any time, and that it is always the same for a given pipeline.

Parameters:
pipeline - pipeline; non-null, non-zero-length
stopBy - time to stop running tests by, if possible
Throws:
java.io.IOException

checkIllegalGetSetOpsVetoedCorrectly

private static void checkIllegalGetSetOpsVetoedCorrectly(BasicVarMgrInterface[] pipeline,
                                                         long stopBy)
This checks that operations are vetoed when they should be. This also checks that an appriopiate mechanism is used, eg the correct exception type so that the caller can understand the propblem.

Parameters:
pipeline - pipeline; non-null, non-zero-length
stopBy - time to stop running tests by, if possible

makeRandomSimpleVariableDefinition

static SimpleVariableDefinition makeRandomSimpleVariableDefinition()
Makes a random definition; never returns null. This randomly generates a variable definition with:

Package-visible so as to be available to other test routines.


testLocalTunnelSimple

public void testLocalTunnelSimple()
                           throws java.lang.Exception
Do simple test of tunnel connectivity. We do this with and without real serialisation, so in passing we are testing the on-the-wire protocol too.

We explicitly check that getting/setting a novel variable on the slave (ie not known to the master) is quietly ignored and does not cause any exception/failure.

This is a very simple test; look elsewhere for comprehensive tests!

Throws:
java.lang.Exception

testLocalTunnelFull

public void testLocalTunnelFull()
                         throws java.lang.Exception
Run full tunnel variable test. Emulates a reasonably-realistic setup with a master and two slaves, all of which hold a caching stage.

One of the tunnels forces full (de)serialisation of its RPC traffic, thus exercising much of the HTTP tunnel code in passing.

We poll() all the pipelines at different speeds to ensure that rate synchronisation is not critical to correct functioning.

Throws:
java.lang.Exception

testSimpleNumberStats

public void testSimpleNumberStats()
Test that we can correctly generate stats safely. We test that is possible to try to generate a SimpleNumberStats instance, even with weird inputs.

TODO: Test with local value


testSimpleVarStats

public void testSimpleVarStats()
Test simple variable stats. Check that the basic, generic, SimpleVarStats works correctly over a wide range of inputs...


testBasicEventHandling

public void testBasicEventHandling()
                            throws java.lang.Exception
Do very basic event-handling tests. This works on a stand-alone BasicVarMgr end-point for simplicity.

Throws:
java.lang.Exception

testEventBucketting

public void testEventBucketting()
                         throws java.lang.Exception
Check that events are correctly split into multiple periods. We test this on just the very shortest period/interval here in order to keep test times reasonable, on the assumption that processing is uniform for all periods/intervals.

Throws:
java.lang.Exception

testLocalTunnelEventSimple

public void testLocalTunnelEventSimple()
                                throws java.lang.Exception
Do simple test of tunnel connectivity for set()ting and get()ting events. We do this with and without real serialisation, so in passing we are testing the on-the-wire protocol too.

This is a very simple test; look elsewhere for comprehensive tests!

Throws:
java.lang.Exception

testEventCollectionSerialisation

public void testEventCollectionSerialisation()
                                      throws java.lang.Exception
Check that the various event objects/collections can be (de)serialised. Basic sanity checks; nothing very clever or extensive.

Throws:
java.lang.Exception

testEventHistoryPeristence

public void testEventHistoryPeristence()
                                throws java.lang.Exception
Test that we can persist the event histories.

Throws:
java.lang.Exception

testAuthEventValueGenerationAndCacheing

public void testAuthEventValueGenerationAndCacheing()
                                             throws java.io.IOException
Test correct generation and handling of authoritative event values. Check that values (other than the current interval) retrieved from the master store are correctly marked as authoritative. Ensure that absent values are returned as authoritative empty values to help upstream caches avoid re-requesting them.

Check that these are cached correctly by a pipeline cache stage and not redundantly requested from the source. This is important to ensure that slaves do not waste time and bandwidth in redundantly re-requesting past values from the master.

Throws:
java.io.IOException

testEPCMComputationDoesNotRefetchEventHistory

public void testEPCMComputationDoesNotRefetchEventHistory()
                                                   throws java.lang.Exception
Test that (re)computing ExhibitPropsComputableMutable data does not cause redundant event data fetches. We care about this because event data is quite bulky and therefore quite expensive and slow to fetch, so we want to make sure that we fetch each event history at most once.

Throws:
java.lang.Exception

notAfter

private static boolean notAfter(long stopBy)
Returns true if time is not after that stated.


DHD Multimedia Gallery V1.57.21

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