Class HubTester


  • public class HubTester
    extends Tester
    Tester for a running hub. Attempts to test as much of the SAMP standard as possible for an existing hub implementation.
    Since:
    18 Jul 2008
    Author:
    Mark Taylor
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  HubTester.ClientWatcher
      CallableClient implementation which watches hub.event messages concerning the registration and attributes of other clients.
      private static class  HubTester.TestCallableClient
      CallableClient implementation for testing.
      private static class  HubTester.WatchedClient
      Struct-type utility class which aggregates mutable information about a client, to be updated in response to hub event messages.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void assertTestClients​(HubConnection conn, java.lang.String[] otherIds)
      Assert that the given list of registered clients has a certain content.
      private static char[] createAlphaCharacters()
      Returns a character array containing each distinct alphanumeric character.
      private static char[] createGeneralCharacters()
      Returns a character array containing every character which is legal for inclusion in a SAMP string.
      java.lang.Object createRandomObject​(int level, boolean ugly)
      Generates an object with random content for transmission using SAMP.
      java.lang.String createRandomString​(boolean ugly)
      Creates a new random string for transmission using SAMP.
      private static void delay​(int millis)
      Waits for a given number of milliseconds.
      static void main​(java.lang.String[] args)
      Main method.
      private HubConnection register()
      Registers with the hub, performing various checks.
      void run()
      Perform a wide variety of tests on a running hub.
      static int runMain​(java.lang.String[] args)
      Does the work for the main method.
      private void testClients()
      Performs a wide variety of tests on a running hub from a limited number of clients.
      private void testLockInfo​(LockInfo lockInfo)
      Does tests on a LockInfo object used by the profile.
      private void testStandardLockfile()
      Tests the content of the SAMP Standard Profile lockfile.
      private void testStress()
      Runs a lot of clients throwing a lot of messages at each other simultaneously.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • hubId_

        private final java.lang.String hubId_
      • ignoreClients_

        private final Client[] ignoreClients_
      • selfIds_

        private final java.util.Set selfIds_
      • privateKeys_

        private final java.util.Set privateKeys_
      • random_

        private final java.util.Random random_
      • UNREGISTER_MTYPE

        private static final java.lang.String UNREGISTER_MTYPE
        See Also:
        Constant Field Values
      • SUBSCRIPTIONS_MTYPE

        private static final java.lang.String SUBSCRIPTIONS_MTYPE
        See Also:
        Constant Field Values
      • ALPHA_CHARS

        private static final char[] ALPHA_CHARS
      • GENERAL_CHARS

        private static final char[] GENERAL_CHARS
      • logger_

        private static java.util.logging.Logger logger_
    • Constructor Detail

      • HubTester

        public HubTester​(ClientProfile profile)
                  throws java.io.IOException
        Constructor.
        Parameters:
        profile - hub discovery object
        Throws:
        java.io.IOException
    • Method Detail

      • register

        private HubConnection register()
                                throws SampException
        Registers with the hub, performing various checks.
        Returns:
        new hub connection representing a newly-registered client
        Throws:
        SampException
      • run

        public void run()
                 throws java.io.IOException
        Perform a wide variety of tests on a running hub.
        Throws:
        java.io.IOException
      • testStandardLockfile

        private void testStandardLockfile()
                                   throws java.io.IOException
        Tests the content of the SAMP Standard Profile lockfile. Does not currently test the permissions on it - that would be nice but is hard to do from java since it's rather platform-specific.
        Throws:
        java.io.IOException
      • testLockInfo

        private void testLockInfo​(LockInfo lockInfo)
                           throws java.io.IOException
        Does tests on a LockInfo object used by the profile. This is specific to a Standard-like (though not necessarily Standard) profile, and will simply be skipped for non-standard profiles.
        Parameters:
        lockInfo - lock info object describing a running hub
        Throws:
        java.io.IOException
      • testClients

        private void testClients()
                          throws java.io.IOException
        Performs a wide variety of tests on a running hub from a limited number of clients.
        Throws:
        java.io.IOException
      • testStress

        private void testStress()
                         throws java.io.IOException
        Runs a lot of clients throwing a lot of messages at each other simultaneously.
        Throws:
        java.io.IOException
      • assertTestClients

        private void assertTestClients​(HubConnection conn,
                                       java.lang.String[] otherIds)
                                throws java.io.IOException
        Assert that the given list of registered clients has a certain content.
        Parameters:
        conn - connection from which to call getRegisteredClients
        otherIds - array of client public IDs that getRegisteredClients should return - will not contain ID associated with conn itself
        Throws:
        java.io.IOException
      • createRandomObject

        public java.lang.Object createRandomObject​(int level,
                                                   boolean ugly)
        Generates an object with random content for transmission using SAMP. This may be a structure containing strings, lists and maps with any legal values as defined by the SAMP data encoding rules.
        Parameters:
        level - maximum level of nesting (how deeply lists/maps may appear within other lists/maps)
        ugly - if true, any legal SAMP content will be used; if false, the returned object should be reasonably human-readable if printed (toString)
        Returns:
        random SAMP object
      • createRandomString

        public java.lang.String createRandomString​(boolean ugly)
        Creates a new random string for transmission using SAMP. This may have any legal content according to the SAMP data encoding rules.
        Parameters:
        ugly - if true, any legal SAMP content will be used; if false, the returned object should be reasonably human-readable if printed (toString)
      • delay

        private static void delay​(int millis)
        Waits for a given number of milliseconds.
        Parameters:
        millis - number of milliseconds
      • createAlphaCharacters

        private static char[] createAlphaCharacters()
        Returns a character array containing each distinct alphanumeric character.
        Returns:
        array of alphanumeric characters
      • createGeneralCharacters

        private static char[] createGeneralCharacters()
        Returns a character array containing every character which is legal for inclusion in a SAMP string.
        Returns:
        array of string characters
      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        Main method. Tests a hub which is currently running.
        Throws:
        java.io.IOException
      • runMain

        public static int runMain​(java.lang.String[] args)
                           throws java.io.IOException
        Does the work for the main method. Use -help flag.
        Throws:
        java.io.IOException