Ejemplo n.º 1
0
class MultiSensorAdaptor():
    '''
    classdocs
    '''

    #initialize TempSensorAdaptorTask
    tempSensorAdaptorTask = TempSensorAdaptorTask()

    def __init__(self):
        '''
        Constructor
        '''
        #start the Dbms listener from PersistenceUtil
        self.pUtil = PersistenceUtil()
        self.pUtil.registerActuatorDataDbmsListener()

    #method for creating and running the thread
    def run(self):

        #log the initial message
        logging.info("Starting getTemperature thread()")

        #try the running thread
        try:

            #enable the temperature fetcher
            self.tempSensorAdaptorTask.enableFetcher = True

            #create the thread that calls the getTemperature() method of the tempSensorAdaptorTask
            threadTempSensorAdaptor = threading.Thread(
                target=self.tempSensorAdaptorTask.getTemperature())

            #set the temp sensor adaptor daemon to true (enable main thread to exit when done)
            threadTempSensorAdaptor.daemon = True

        #if found error
        except:

            #return false
            return False

        #return true for running successfully
        return True
Ejemplo n.º 2
0
class PersistenceUtilTest(unittest.TestCase):
    """
	Use this to setup your tests. This is where you may want to load configuration
	information (if needed), initialize class-scoped variables, create class-scoped
	instances of complex objects, initialize any requisite connections, etc.
	"""
    def setUp(self):

        #instantiate persistenceUtil
        self.persistenceUtil = PersistenceUtil()

    """
	Use this to tear down any allocated resources after your tests are complete. This
	is where you may want to release connections, zero out any long-term data, etc.
	"""

    def tearDown(self):

        #set the reference to the variables to none to release any resources
        self.persistenceUtil = None

    """
	/**
	 * Tests the writeActuatorDataToDbms() method of PersistenceUtil class. 
	 * Checks whether it is able to write to redis and doesn't
	 * break if it cannot set up the connection to the server
	 */
	"""

    def testWriteActuatorDataToDbms(self):

        #Create ActuatorData instance
        actuatorData = ActuatorData()

        #write to redis and check if it returns true
        self.assertEqual(
            True, self.persistenceUtil.writeActuatorDataToDbms(actuatorData))

        #add an invalid port to the jedisActuator
        self.persistenceUtil.r_actuator = Redis(host="localhost", port=6379)

        #write to redis and check if it returns false
        self.assertEqual(
            True, self.persistenceUtil.writeActuatorDataToDbms(actuatorData))

    """	
	/**
	 * Tests the writeSensorDataToDbms() method of PersistenceUtil class. 
	 * Checks whether it is able to write to redis and doesn't
	 * break if it cannot set up the connection to the server
	 */
	"""

    def testWriteSensorDataToDbms(self):

        #Create ActuatorData instance
        sensorData = SensorData()

        #write to redis and check if it returns true
        self.assertEqual(
            True, self.persistenceUtil.writeSensorDataToDbms(sensorData))

        #add an invalid port to the jedisSensor
        self.persistenceUtil.r_sensor = Redis(host="localhost", port=6890)

        #write to redis and check if it returns false
        self.assertEqual(
            False, self.persistenceUtil.writeSensorDataToDbms(sensorData))

    """	
	/**
	 * Tests the registerSensorDataDbmsListener() method of PersistenceUtil class. 
	 * Checks whether it is able to register and doesn't
	 * break if it cannot set up the connection to the server
	 */
	"""

    def testRegisterSensorDataDbmsListener(self):

        #check for true when the connection variables are ok
        self.assertEqual(True,
                         self.persistenceUtil.registerSensorDataDbmsListener())

        #add an invalid port to the jedisSensor
        self.persistenceUtil.r_sensor = Redis(host="localhost", port=6890)

        #check for false when connection variables are invalid
        self.assertEqual(False,
                         self.persistenceUtil.registerSensorDataDbmsListener())

    """	
	/**
	 * Tests the registerActuatorDataDbmsListener() method of PersistenceUtil class. 
	 * Checks whether it is able to register and doesn't
	 * break if it cannot set up the connection to the server
	 */
	"""

    def testRegisterActuatorDataDbmsListener(self):

        #check for true when the connection variables are ok
        self.assertEqual(
            True, self.persistenceUtil.registerActuatorDataDbmsListener())

        #add an invalid port to the jedisSensor
        self.persistenceUtil.r_actuator = Redis(host="localhost", port=6890)

        #check for false when connection variables are invalid
        self.assertEqual(
            False, self.persistenceUtil.registerActuatorDataDbmsListener())