예제 #1
0
    def test_fragmented_complete_sample(self):
        """
        Simulate a complete sample that arrives in separate invocations of got_data();
        result should be a complete sample published 
        """

        """
        Create a mock port agent
        """
        mock_port_agent = Mock(spec=LoggerClient)

        """
        Instantiate the driver class directly (no driver client, no driver
        client, no zmq driver process, no driver process; just own the driver)
        """
        test_driver = ooicoreInstrumentDriver(self.test_event_callback)

        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED)

        """
        Now configure the driver with the mock_port_agent, verifying
        that the driver transitions to that state
        """
        config = {"mock_port_agent": mock_port_agent}
        test_driver.configure(config=config)
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverConnectionState.DISCONNECTED)

        """
        Invoke the connect method of the driver: should connect to mock
        port agent.  Verify that the connection FSM transitions to CONNECTED,
        (which means that the FSM should now be reporting the ProtocolState).
        """
        test_driver.connect()
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        """
        Force the driver into AUTOSAMPLE state so that it will parse and 
        publish samples
        """
        test_driver.execute_force_state(state=DriverProtocolState.AUTOSAMPLE)
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE)

        """
        - Reset test verification variables.
        - Construct a fragment of a sample dark full frame stream
        - Pass to got_data()
        - Verify that raw and parsed streams have NOT been received
        """
        self.reset_test_vars()
        test_sample = (
            "SATNDF0196,2012219,18.770632,0.00,0.00,0.00,0.00,0.000000,24.38,23.31,18.53,255095,19.41,12.04,"
            + "4.95,11.57,1087.36,217.87,929.20,951.43,933,939,929,921,924,926,919,933,934,923,925,913,910,933,922,930,"
            + "914,918,919,925,930,919,929,926,927,921,949,922,932,924,929,931,929,943,921,938,921,914,933,913,920,929,"
            + "931,922,929,927,926,934,923,945,938,941,929,933,920,926,919,931,935,953,939,936,953,947,956,942,941,931,"
            + "935,938,951,943,921,936,934,949,933,933,938,953,949,939,942,944,951,929,935,935,945,949,938,937,948,952,"
            + "945,950,952,961,946,954,945,954,957,941,948,939,948,938,937,939,933,945,926,940,953,949,933,948,923,925,"
        )

        test_driver._protocol.got_data(test_sample)

        self.assertFalse(self.raw_stream_received)
        self.assertFalse(self.parsed_stream_received)

        """
        - Construct the remaining fragment of the sample dark full frame stream
        - Pass to got_data()
        - Verify that raw and parsed streams have been received
        """
        test_sample = (
            "941,954,947,955,965,951,965,937,949,939,929,955,958,954,970,967,973,976,979,985,993,970,966,973,988,966,"
            + "964,978,970,991,981,983,994,990,980,985,981,978,971,974,974,987,985,982,977,980,953,953,964,964,959,954,"
            + "947,966,950,963,961,967,964,977,973,974,979,977,984,966,960,957,948,970,968,980,967,979,984,970,967,979,"
            + "963,961,969,963,988,979,989,991,977,982,977,969,965,971,961,978,972,984,977,971,979,987,965,964,970,973,"
            + "949,938,945,953,959,951,957,976,952,953,953,949,949,951,945,961,945,953,949,956,970,974,973,957,948,954,"
            + "956,957,946,948,946,946,247\r\n"
        )

        test_driver._protocol.got_data(test_sample)

        self.assertTrue(self.raw_stream_received)
        self.assertTrue(self.parsed_stream_received)
예제 #2
0
    def test_concatenated_fragmented_sample(self):
        """
        Simulate a complete sample that arrives in with a fragment concatenated.  The concatenated fragment
        should have have a terminator.  A separate invocations of got_data() will have the remainder;
        result should be a complete sample published 
        """

        """
        Create a mock port agent
        """
        mock_port_agent = Mock(spec=LoggerClient)

        """
        Instantiate the driver class directly (no driver client, no driver
        client, no zmq driver process, no driver process; just own the driver)
        """
        test_driver = ooicoreInstrumentDriver(self.test_event_callback)

        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED)

        """
        Now configure the driver with the mock_port_agent, verifying
        that the driver transitions to that state
        """
        config = {"mock_port_agent": mock_port_agent}
        test_driver.configure(config=config)
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverConnectionState.DISCONNECTED)

        """
        Invoke the connect method of the driver: should connect to mock
        port agent.  Verify that the connection FSM transitions to CONNECTED,
        (which means that the FSM should now be reporting the ProtocolState).
        """
        test_driver.connect()
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        """
        Force the driver into AUTOSAMPLE state so that it will parse and 
        publish samples
        """
        test_driver.execute_force_state(state=DriverProtocolState.AUTOSAMPLE)
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE)

        """
        - Reset test verification variables.
        - Construct a sample dark full frame stream with a concatenated fragment
        - Pass to got_data()
        - Verify that raw and parsed streams have been received
        - Later, when the final fragment has been send, verify that raw and
          parsed streams have been received.
        """
        self.reset_test_vars()
        test_sample = (
            "SATNDF0196,2012219,18.770632,0.00,0.00,0.00,0.00,0.000000,24.38,23.31,18.53,255095,19.41,12.04,"
            + "4.95,11.57,1087.36,217.87,929.20,951.43,933,939,929,921,924,926,919,933,934,923,925,913,910,933,922,930,"
            + "914,918,919,925,930,919,929,926,927,921,949,922,932,924,929,931,929,943,921,938,921,914,933,913,920,929,"
            + "931,922,929,927,926,934,923,945,938,941,929,933,920,926,919,931,935,953,939,936,953,947,956,942,941,931,"
            + "935,938,951,943,921,936,934,949,933,933,938,953,949,939,942,944,951,929,935,935,945,949,938,937,948,952,"
            + "945,950,952,961,946,954,945,954,957,941,948,939,948,938,937,939,933,945,926,940,953,949,933,948,923,925,"
            + "941,954,947,955,965,951,965,937,949,939,929,955,958,954,970,967,973,976,979,985,993,970,966,973,988,966,"
            + "964,978,970,991,981,983,994,990,980,985,981,978,971,974,974,987,985,982,977,980,953,953,964,964,959,954,"
            + "947,966,950,963,961,967,964,977,973,974,979,977,984,966,960,957,948,970,968,980,967,979,984,970,967,979,"
            + "963,961,969,963,988,979,989,991,977,982,977,969,965,971,961,978,972,984,977,971,979,987,965,964,970,973,"
            + "949,938,945,953,959,951,957,976,952,953,953,949,949,951,945,961,945,953,949,956,970,974,973,957,948,954,"
            + "956,957,946,948,946,946,247\r\n"
        )

        """
        - Construct the beginning of a fragment of a sample light full frame stream
        - Pass to got_data()
        """
        test_sample += (
            "SATNLF0196,2012219,18.770960,82.83,52.29,-1201.21,2.99,0.000026,23.62,23.31,18.51,255096,19.43,"
            + "12.04,5.01,11.57,10434.65,248.53,940.20,951.43,933,937,951,939,941,939,933,947,938,931,931,926,937,958,"
            + "979,1070,1162,1321,1438,1543,1628,1716,1791,1879,1965,2086,2215,2382,2602,2827,3081,3369,3686,4032,4363,"
            + "4705,4994,5262,5473,5655,5786,5924,6024,6147,6301,6503,6748,7049,7415,7871,8389,9002,9721,10522,11440,"
            + "12425,13479,14601,15706,16805,17858,18786,19545,20131,20478,20574,20449,20146,19638,19031,18349,17653,"
            + "16981,16342,15767,15278,14862,14542,14279,14124,13996,13969,13985,14095,14245,14461,14742,15091,15464,"
            + "15903,16377,16869,17390,17861,18322,18762,19109,19370,19451,19449,19351,19083,18692,18225,17681,17097,"
            + "16509,15941,15362,14866,14421,14024,13707,13450,13227,13094,13019,12994,13019,13097,13223,13443,13662,"
        )

        test_driver._protocol.got_data(test_sample)

        self.assertTrue(self.raw_stream_received)
        self.assertTrue(self.parsed_stream_received)

        """
        - Reset teset verification variables
        - Construct the final fragment of a sample light full frame stream
        - Pass to got_data()
        - Verify that raw and parsed streams have been received
        """
        self.reset_test_vars()
        test_sample = (
            "13991,14377,14809,15301,15861,16477,17141,17839,18549,19323,20085,20867,21642,22429,23163,23770,24420,"
            + "24959,25409,25784,26054,26208,26225,26190,26050,25792,25458,25041,24602,24096,23560,23040,22475,21925,"
            + "21401,20862,20404,19922,19509,19125,18769,18431,18135,17873,17621,17391,17142,16929,16709,16514,16324,"
            + "16167,16044,15923,15842,15737,15741,15725,15747,15789,15847,15897,15959,16037,16108,16178,16211,16246,"
            + "16289,16293,16383,16402,16437,16425,16428,16408,16387,16366,16315,16253,16154,16065,15943,15811,15638,"
            + "15444,15238,14999,14728,14439,14172,13849,13549,13239,12946,12631,12355,12069,11746,11398,11086,10761,"
            + "10486,10255,10023,9832,9661,9511,9356,9247,9171,9119,8986,8809,8656,8520,8411,8293,8196,8107,8026,8020,"
            + "7991,7960,7866,7829,7872,7882,7750,7361,6756,6098,6098,170\r\n"
        )

        test_driver._protocol.got_data(test_sample)

        self.assertTrue(self.raw_stream_received)
        self.assertTrue(self.parsed_stream_received)
예제 #3
0
    def test_invalid_sample(self):
        # instantiate a mock object for port agent client
        # not sure doing that here is that helpful...

        """
        Currently passing mocked port agent client.  To test fragmentation,
        I should be able to call the got_data method directly.
        """
        """
        Create a mock port agent
        """
        mock_port_agent = Mock(spec=LoggerClient)

        """
        Instantiate the driver class directly (no driver client, no driver
        client, no zmq driver process, no driver process; just own the driver)
        """
        test_driver = ooicoreInstrumentDriver(self.test_event_callback)

        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverConnectionState.UNCONFIGURED)

        """
        Now configure the driver with the mock_port_agent, verifying
        that the driver transitions to that state
        """
        config = {"mock_port_agent": mock_port_agent}
        test_driver.configure(config=config)
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverConnectionState.DISCONNECTED)

        """
        Invoke the connect method of the driver: should connect to mock
        port agent.  Verify that the connection FSM transitions to CONNECTED,
        (which means that the FSM should now be reporting the ProtocolState).
        """
        test_driver.connect()
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverProtocolState.UNKNOWN)

        test_driver.execute_force_state(state=DriverProtocolState.AUTOSAMPLE)
        current_state = test_driver.get_current_state()
        print "DHE: DriverConnectionState: " + str(current_state)
        self.assertEqual(current_state, DriverProtocolState.AUTOSAMPLE)

        """
        - Reset test verification variables.
        - Construct a bogus stream
        - Pass to got_data()
        - Verify that raw and parsed streams have NOT been received
        """
        self.reset_test_vars()
        test_sample = "this is a bogus test\r\n"

        test_driver._protocol.got_data(test_sample)

        self.assertFalse(self.raw_stream_received)
        self.assertFalse(self.parsed_stream_received)