def test_mid_state_start(self):
        """
        This test exercises setting the state past one chunk, retrieving particles and verify the result of one
        of the particles.
        """

        # Using two concatenated msgpack files to simulate two chunks.
        file_path = os.path.join(RESOURCE_PATH, 'state_test.mpk')
        stream_handle = open(file_path, 'rb')

        stat_info = os.stat(file_path)

        # Moving the file position to the end of the first chunk
        state = {StateKey.PARTICLES_RETURNED: 193}

        parser = Vel3dAMmpCdsParser(self.config, state, stream_handle,
                                    self.state_callback, self.pub_callback)

        particles = parser.get_records(4)

        log.info(len(particles))

        # Should end up with 4 particles
        self.assertTrue(len(particles) == 4)

        test_data = self.get_dict_from_yml('second_data.yml')
        for n in range(3):
            self.assert_result(test_data['data'][n], particles[n])

        stream_handle.close()
    def test_get_many(self):
        """
        This test exercises retrieving 20 particles, verifying the particles, then retrieves 30 particles
         and verifies the 30 particles.
        """

        file_path = os.path.join(RESOURCE_PATH, 'first_data.mpk')
        stream_handle = open(file_path, 'rb')

        parser = Vel3dAMmpCdsParser(self.config, None, stream_handle,
                                    self.state_callback, self.pub_callback)

        particles = parser.get_records(20)

        # Should end up with 20 particles
        self.assertTrue(len(particles) == 20)

        test_data = self.get_dict_from_yml('first_data.yml')
        for n in range(20):
            self.assert_result(test_data['data'][n], particles[n])

        particles = parser.get_records(30)

        # Should end up with 30 particles
        self.assertTrue(len(particles) == 30)

        self.assert_result(test_data['data'][49], particles[29])

        stream_handle.close()
    def test_bad_data_two(self):
        """
        This test verifies that a SampleException is raised when an entire msgpack buffer is not msgpack.
        """

        file_path = os.path.join(RESOURCE_PATH, 'not-msg-pack.mpk')
        stream_handle = open(file_path, 'rb')

        parser = Vel3dAMmpCdsParser(self.config, None, stream_handle,
                                    self.state_callback, self.pub_callback)

        with self.assertRaises(SampleException):
            parser.get_records(1)

        stream_handle.close()
Example #4
0
    def _build_parser(self, stream_handle):

        parser_config = {
            DataSetDriverConfigKeys.PARTICLE_MODULE:
            'mi.dataset.parser.vel3d_a_mmp_cds',
            DataSetDriverConfigKeys.PARTICLE_CLASS:
            'Vel3dAMmpCdsParserDataParticle'
        }

        parser = Vel3dAMmpCdsParser(parser_config, None, stream_handle,
                                    lambda state, ingested: None,
                                    lambda data: None,
                                    self._exception_callback)

        return parser
    def test_bad_data_one(self):
        """
        This test verifies that a SampleException is raised when msgpack data is malformed.
        """

        file_path = os.path.join(RESOURCE_PATH,
                                 'acm_1_20131124T005004_458-BAD.mpk')
        stream_handle = open(file_path, 'rb')

        parser = Vel3dAMmpCdsParser(self.config, None, stream_handle,
                                    self.state_callback, self.pub_callback)

        with self.assertRaises(SampleException):
            parser.get_records(1)

        stream_handle.close()
Example #6
0
    def test_long_stream(self):
        """
        This test exercises retrieve approximately 200 particles.
        """

        # Using two concatenated msgpack files to simulate two chunks to get more particles.
        file_path = os.path.join(RESOURCE_PATH, 'acm_concat.mpk')
        stream_handle = open(file_path, 'rb')

        parser = Vel3dAMmpCdsParser(self.config, None, stream_handle,
                                    self.state_callback, self.pub_callback)

        # Attempt to retrieve 400 particles, but we will retrieve less
        particles = parser.get_records(400)

        # Should end up with 386 particles
        self.assertTrue(len(particles) == 386)

        stream_handle.close()
Example #7
0
 def _build_parser(self, parser_state, infile):
     """
     Build and return the parser
     """
     config = self._parser_config
     config.update({
         DataSetDriverConfigKeys.PARTICLE_MODULE:
         'mi.dataset.parser.vel3d_a_mmp_cds',
         DataSetDriverConfigKeys.PARTICLE_CLASS:
         'Vel3dAMmpCdsParserDataParticle'
     })
     log.debug("My Config: %s", config)
     _parser = Vel3dAMmpCdsParser(config, parser_state, infile,
                                  self._save_parser_state,
                                  self._data_callback,
                                  self._sample_exception_callback)
     if _parser is None:
         raise ConfigurationException(
             'vel3d_a_mmp_cds parser failed instantiation')
     return _parser
    def test_simple(self):
        """
        This test reads in a small number of particles and verifies the result of one of the particles.
        """

        file_path = os.path.join(RESOURCE_PATH, 'first_data.mpk')
        stream_handle = open(file_path, 'rb')

        parser = Vel3dAMmpCdsParser(self.config, None, stream_handle,
                                    self.state_callback, self.pub_callback)

        particles = parser.get_records(6)

        for particle in particles:
            print particle.generate_dict()

        test_data = self.get_dict_from_yml('first_data.yml')

        for n in range(6):
            self.assert_result(test_data['data'][n], particles[n])

        stream_handle.close()
    def test_set_state(self):
        """
        This test exercises setting the state past one chunk, retrieving particles, verifying one
        of the particles, and then setting the state back to the beginning, retrieving a few particles, and
        verifying one of the particles.
        """

        # Using the default mspack test file.
        file_path = os.path.join(RESOURCE_PATH, 'state_test.mpk')
        stream_handle = open(file_path, 'rb')

        # Moving the file position to the end of the first chunk
        state = {StateKey.PARTICLES_RETURNED: 193}

        parser = Vel3dAMmpCdsParser(self.config, state, stream_handle,
                                    self.state_callback, self.pub_callback)

        particles = parser.get_records(4)

        # Should end up with 4 particles
        self.assertTrue(len(particles) == 4)

        log.info(parser._state)

        stat_info = os.stat(file_path)

        test_data = self.get_dict_from_yml('second_data.yml')
        for n in range(4):
            self.assert_result(test_data['data'][n], particles[n])

        state = copy.copy(parser._state)

        log.info(state)

        parser = Vel3dAMmpCdsParser(self.config, state, stream_handle,
                                    self.state_callback, self.pub_callback)

        particles = parser.get_records(4)

        # Should end up with 4 particles
        self.assertTrue(len(particles) == 4)

        for n in range(4):
            self.assert_result(test_data['data'][n + 4], particles[n])

        # goes to start of file
        state = {StateKey.PARTICLES_RETURNED: 0}

        parser = Vel3dAMmpCdsParser(self.config, state, stream_handle,
                                    self.state_callback, self.pub_callback)

        particles = parser.get_records(1000)

        self.assertTrue(len(particles) == 213)

        test_data = self.get_dict_from_yml('second_data.yml')

        self.assert_result(test_data['data'][19], particles[212])

        # Provide a bad particles returned
        state = {StateKey.PARTICLES_RETURNED: 500}

        parser = Vel3dAMmpCdsParser(self.config, state, stream_handle,
                                    self.state_callback, self.pub_callback)

        particles = parser.get_records(1)

        self.assertTrue(len(particles) == 0)

        stream_handle.close()