org.tranche.util
Class TestUtil

java.lang.Object
  extended by org.tranche.util.TestUtil

public class TestUtil
extends java.lang.Object

A helper class for the code to determine if it is being run in test mode or not. If the code is run in test mode, it shouldn't spawn unneeded background threads or otherwise use resources intended solely for a live environment.

Author:
Jayson Falkner - jfalkner@umich.edu, Bryan Smith - bryanesmith@gmail.com

Field Summary
static boolean addFileToolAutoRecoverFromOOM
          Flag to simulate how a tool might recover from an OutOfMemoryError.
static boolean addFileToolSimulateOOM
          Flag to simulate an OutOfMemoryError.
 
Constructor Summary
TestUtil()
           
 
Method Summary
static boolean addListener(TestUtilListener tul)
          Add TestUtilListener to TestUtil.
static void addServerToHostTestMap(java.lang.String host, java.lang.String trancheURL)
          Add a map entry for a single server.
static void assertDirectoriesEquivalent(java.io.File dir1, java.io.File dir2)
           
static void assertFilesAreEqual(java.io.File fileA, java.io.File fileB)
           
static void assertFilesAreEquivalent(java.io.File fileA, java.io.File fileB)
           
static void clearFFTSForURL()
          Map of URL (e.g., tranche://127.0.0.1:1501) to associated FlatFileTrancheServer instance from a running TestNetwork.
static void clearListeners()
          Clear all TestUtilListener objects.
static void clearServerToHostTestMap()
          Clears the collection.
static FlatFileTrancheServer getFFTSForURL(java.lang.String url)
          Map of URL (e.g., tranche://127.0.0.1:1501) to associated FlatFileTrancheServer instance from a running TestNetwork.
static java.lang.String getOstensibleHostForURL(java.lang.String url)
          Returns the ostensible host for a Tranche server given its actual url.
static java.lang.String getServerTestURL(java.lang.String host)
          Returns a Tranche url for an (ostensible) host.
static java.util.Map<java.lang.String,java.lang.String> getServerToHostTestMap()
          Returns unmodifiable map.
static boolean isAddFileToolChunkFailOnce()
          If set to true, every chunk in batch uploads will fail once: fail first time, but retry should succeed.
static boolean isAddFileToolChunkFailTwice()
          If set to true, every chunk in batch uploads will fail twice: fail first time, and fail retry.
static boolean isTesting()
          Flag to determine whether tests are running.
static boolean isTestingActivityLogs()
          If testing, activity logs won't be recorded unless this is set.
static boolean isTestingHashSpanFixingThread()
          Can turn the HashSpanFixingThread on or off.
static boolean isTestingManualNetworkStatusTable()
          If set to true, then the network status table is being tested.
static boolean isTestingServerStartupThread()
          If testing, the Server won't start the ServerStartupThread unless this is set.
static boolean isTestingServerTracker()
          If set to true, the ServerTracker in ServerUtil will run for tests.
static boolean isTestingTargetHashSpan()
          TargetHashSpanThread only runs if true.
static boolean isTestingTimeout()
          If testing timeout, want to make sure scavengar thread can operate.
static boolean isTestingTurnOffProjectFindingThread()
          Used to turn off project-finding thread.
static boolean isTestUsingFakeCoreServers()
          Flag to simulate core servers.
static void printRecursiveDirectoryStructure(java.io.File root)
          Prints out breadth-first directory structure for humans.
static void printTitle(java.lang.String title)
           
static FlatFileTrancheServer removeFFTSForURL(java.lang.String url)
          Map of URL (e.g., tranche://127.0.0.1:1501) to associated FlatFileTrancheServer instance from a running TestNetwork.
static boolean removeListener(TestUtilListener tul)
          Remove specific TestUtilListener from TestUtil.
static void setAddFileToolChunkFailOnce(boolean aAddFileToolChunkFailOnce)
          If set to true, every chunk in batch uploads will fail once: fail first time, but retry should succeed.
static void setAddFileToolChunkFailTwice(boolean aAddFileToolChunkFailTwice)
          If set to true, every chunk in batch uploads will fail twice: fail first time, and fail retry.
static void setFFTSForURL(java.lang.String url, FlatFileTrancheServer ffts)
          Map of URL (e.g., tranche://127.0.0.1:1501) to associated FlatFileTrancheServer instance from a running TestNetwork.
static void setTesting(boolean testing)
          Flag to determine whether tests are running.
static void setTestingActivityLogs(boolean aTestingActivityLogs)
          If testing, activity logs won't be recorded unless this is set.
static void setTestingHashSpanFixingThread(boolean aTestingHashSpanFixingThread)
          Can turn the HashSpanFixingThread on or off.
static void setTestingManualNetworkStatusTable(boolean aTestingManualNetworkStatusTable)
          If set to true, then the network status table is being tested.
static void setTestingServerStartupThread(boolean aTestingServerStartupThread)
          If testing, the Server won't start the ServerStartupThread unless this is set.
static void setTestingServerTracker(boolean aTestingServerTracker)
          If set to true, the ServerTracker in ServerUtil will run for tests.
static void setTestingTargetHashSpan(boolean aTestingTargetHashSpan)
          TargetHashSpanThread only runs if true.
static void setTestingTimeout(boolean aTestingTimeout)
          If testing timeout, want to make sure scavengar thread can operate.
static void setTestingTurnOffProjectFindingThread(boolean aTestingTurnOffProjectFindingThread)
          Used to turn off project-finding thread.
static void setTestUsingFakeCoreServers(boolean aTestUsingFakeCoreServers)
          Flag to simulate core servers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

addFileToolSimulateOOM

public static boolean addFileToolSimulateOOM

Flag to simulate an OutOfMemoryError.


addFileToolAutoRecoverFromOOM

public static boolean addFileToolAutoRecoverFromOOM

Flag to simulate how a tool might recover from an OutOfMemoryError.

Constructor Detail

TestUtil

public TestUtil()
Method Detail

isTesting

public static boolean isTesting()

Flag to determine whether tests are running.

Returns:

setTesting

public static void setTesting(boolean testing)

Flag to determine whether tests are running.

Parameters:
testing -

isTestUsingFakeCoreServers

public static boolean isTestUsingFakeCoreServers()

Flag to simulate core servers. Tests can add servers.

Returns:

setTestUsingFakeCoreServers

public static void setTestUsingFakeCoreServers(boolean aTestUsingFakeCoreServers)

Flag to simulate core servers. Tests can add servers.

Parameters:
aTestUsingFakeCoreServers -

isTestingHashSpanFixingThread

public static boolean isTestingHashSpanFixingThread()

Can turn the HashSpanFixingThread on or off. By default, it is off (false).

Returns:

setTestingHashSpanFixingThread

public static void setTestingHashSpanFixingThread(boolean aTestingHashSpanFixingThread)

Can turn the HashSpanFixingThread on or off. By default, it is off (false).

Parameters:
aTestingHashSpanFixingThread -

isTestingTurnOffProjectFindingThread

public static boolean isTestingTurnOffProjectFindingThread()

Used to turn off project-finding thread. Useful if want to test healing thread's capability for fixing broken data blocks.

Returns:

setTestingTurnOffProjectFindingThread

public static void setTestingTurnOffProjectFindingThread(boolean aTestingTurnOffProjectFindingThread)

Used to turn off project-finding thread. Useful if want to test healing thread's capability for fixing broken data blocks.

Parameters:
aTestingTurnOffProjectFindingThread -

isAddFileToolChunkFailOnce

public static boolean isAddFileToolChunkFailOnce()

If set to true, every chunk in batch uploads will fail once: fail first time, but retry should succeed.

Returns:

setAddFileToolChunkFailOnce

public static void setAddFileToolChunkFailOnce(boolean aAddFileToolChunkFailOnce)

If set to true, every chunk in batch uploads will fail once: fail first time, but retry should succeed.

Parameters:
aAddFileToolChunkFailOnce -

isAddFileToolChunkFailTwice

public static boolean isAddFileToolChunkFailTwice()

If set to true, every chunk in batch uploads will fail twice: fail first time, and fail retry.

Returns:

setAddFileToolChunkFailTwice

public static void setAddFileToolChunkFailTwice(boolean aAddFileToolChunkFailTwice)

If set to true, every chunk in batch uploads will fail twice: fail first time, and fail retry.

Parameters:
aAddFileToolChunkFailTwice -

isTestingServerTracker

public static boolean isTestingServerTracker()

If set to true, the ServerTracker in ServerUtil will run for tests.

Returns:

setTestingServerTracker

public static void setTestingServerTracker(boolean aTestingServerTracker)

If set to true, the ServerTracker in ServerUtil will run for tests.

Parameters:
aTestingServerTracker -

isTestingTimeout

public static boolean isTestingTimeout()

If testing timeout, want to make sure scavengar thread can operate.

Returns:

setTestingTimeout

public static void setTestingTimeout(boolean aTestingTimeout)

If testing timeout, want to make sure scavengar thread can operate.

Parameters:
aTestingTimeout -

isTestingActivityLogs

public static boolean isTestingActivityLogs()

If testing, activity logs won't be recorded unless this is set.

Returns:

setTestingActivityLogs

public static void setTestingActivityLogs(boolean aTestingActivityLogs)

If testing, activity logs won't be recorded unless this is set.

Parameters:
aTestingActivityLogs -

isTestingServerStartupThread

public static boolean isTestingServerStartupThread()

If testing, the Server won't start the ServerStartupThread unless this is set.

Returns:

setTestingServerStartupThread

public static void setTestingServerStartupThread(boolean aTestingServerStartupThread)

If testing, the Server won't start the ServerStartupThread unless this is set.

Parameters:
aTestingServerStartupThread -

isTestingManualNetworkStatusTable

public static boolean isTestingManualNetworkStatusTable()

If set to true, then the network status table is being tested. Automatic updates to the table will be disabled.

Returns:

setTestingManualNetworkStatusTable

public static void setTestingManualNetworkStatusTable(boolean aTestingManualNetworkStatusTable)

If set to true, then the network status table is being tested. Automatic updates to the table will be disabled.

Parameters:
aTestingManualNetworkStatusTable -

addListener

public static boolean addListener(TestUtilListener tul)

Add TestUtilListener to TestUtil.

Parameters:
tul -
Returns:

removeListener

public static boolean removeListener(TestUtilListener tul)

Remove specific TestUtilListener from TestUtil.

Parameters:
tul -
Returns:

clearListeners

public static void clearListeners()

Clear all TestUtilListener objects.


printTitle

public static final void printTitle(java.lang.String title)
Parameters:
title -

addServerToHostTestMap

public static void addServerToHostTestMap(java.lang.String host,
                                          java.lang.String trancheURL)

Add a map entry for a single server.

Holds a map of hosts to Tranche urls. This is done so can unit test.

Note that there is a maximum of one host per JVM. This is done so port and other information can be changed.

When test, need more than one server. This allows us to do this.

Only works when TestUtil.isTestingManualNetworkStatusTable() returns true. For this to work, must manually create status table.

Parameters:
host - The ostensible host name
trancheURL - The actual Tranche server URL

getServerToHostTestMap

public static java.util.Map<java.lang.String,java.lang.String> getServerToHostTestMap()

Returns unmodifiable map.

Holds a map of hosts to Tranche urls. This is done so can unit test.

Note that there is a maximum of one host per JVM. This is done so port and other information can be changed.

When test, need more than one server. This allows us to do this.

Only works when TestUtil.isTestingManualNetworkStatusTable() returns true. For this to work, must manually create status table.

Returns:

clearServerToHostTestMap

public static void clearServerToHostTestMap()

Clears the collection.

Holds a map of hosts to Tranche urls. This is done so can unit test.

Note that there is a maximum of one host per JVM. This is done so port and other information can be changed.

When test, need more than one server. This allows us to do this.

Only works when TestUtil.isTestingManualNetworkStatusTable() returns true. For this to work, must manually create status table.


getServerTestURL

public static java.lang.String getServerTestURL(java.lang.String host)

Returns a Tranche url for an (ostensible) host. If doesn't exist, returns null.

Holds a map of hosts to Tranche urls. This is done so can unit test.

Note that there is a maximum of one host per JVM. This is done so port and other information can be changed.

When test, need more than one server. This allows us to do this.

Only works when TestUtil.isTestingManualNetworkStatusTable() returns true. For this to work, must manually create status table.

Parameters:
host -
Returns:

getOstensibleHostForURL

public static java.lang.String getOstensibleHostForURL(java.lang.String url)

Returns the ostensible host for a Tranche server given its actual url. If doesn't exist, returns null.

Holds a map of hosts to Tranche urls. This is done so can unit test.

Note that there is a maximum of one host per JVM. This is done so port and other information can be changed.

When test, need more than one server. This allows us to do this.

Only works when TestUtil.isTestingManualNetworkStatusTable() returns true. For this to work, must manually create status table.

Parameters:
url -
Returns:

assertDirectoriesEquivalent

public static final void assertDirectoriesEquivalent(java.io.File dir1,
                                                     java.io.File dir2)
                                              throws java.lang.Exception
Parameters:
dir1 -
dir2 -
Throws:
java.lang.Exception

assertFilesAreEqual

public static void assertFilesAreEqual(java.io.File fileA,
                                       java.io.File fileB)
                                throws java.lang.Exception
Parameters:
fileA -
fileB -
Throws:
java.lang.Exception

assertFilesAreEquivalent

public static void assertFilesAreEquivalent(java.io.File fileA,
                                            java.io.File fileB)
                                     throws java.lang.Exception
Parameters:
fileA -
fileB -
Throws:
java.lang.Exception

isTestingTargetHashSpan

public static boolean isTestingTargetHashSpan()

TargetHashSpanThread only runs if true.

Returns:

setTestingTargetHashSpan

public static void setTestingTargetHashSpan(boolean aTestingTargetHashSpan)

TargetHashSpanThread only runs if true.

Parameters:
aTestingTargetHashSpan -

setFFTSForURL

public static void setFFTSForURL(java.lang.String url,
                                 FlatFileTrancheServer ffts)

Map of URL (e.g., tranche://127.0.0.1:1501) to associated FlatFileTrancheServer instance from a running TestNetwork.

This is needed to test propagation in tests. If server items use remote server when propagating, might end up behind another request from client (clients and servers share remote connections), and will hence time out.

Parameters:
url -
ffts -

getFFTSForURL

public static FlatFileTrancheServer getFFTSForURL(java.lang.String url)

Map of URL (e.g., tranche://127.0.0.1:1501) to associated FlatFileTrancheServer instance from a running TestNetwork.

This is needed to test propagation in tests. If server items use remote server when propagating, might end up behind another request from client (clients and servers share remote connections), and will hence time out.

Parameters:
url -
Returns:

removeFFTSForURL

public static FlatFileTrancheServer removeFFTSForURL(java.lang.String url)

Map of URL (e.g., tranche://127.0.0.1:1501) to associated FlatFileTrancheServer instance from a running TestNetwork.

This is needed to test propagation in tests. If server items use remote server when propagating, might end up behind another request from client (clients and servers share remote connections), and will hence time out.

Parameters:
url -
Returns:

clearFFTSForURL

public static void clearFFTSForURL()

Map of URL (e.g., tranche://127.0.0.1:1501) to associated FlatFileTrancheServer instance from a running TestNetwork.

This is needed to test propagation in tests. If server items use remote server when propagating, might end up behind another request from client (clients and servers share remote connections), and will hence time out.


printRecursiveDirectoryStructure

public static void printRecursiveDirectoryStructure(java.io.File root)

Prints out breadth-first directory structure for humans. Nice to see files quickly.

Parameters:
root -


This code is free for use both commercially and non-commercially as stated in the project's license