def test_stop_resume(self): """ Test the ability to stop and restart the process """ driver_config = self._driver_config()['startup_config'] # Create the data for the Recovered CT parser. # Calculate the Recovered CT file checksum and get the file mod time. rec_ct_filename = 'SBE37-IM_20130704_2013_07_04.hex' self.create_sample_data_set_dir(rec_ct_filename, REC_DIR) rec_ct_file_path = os.path.join( driver_config['harvester'][DataTypeKey.CTDMO_GHQR_CT]['directory'], rec_ct_filename) rec_ct_file_checksum = str(calculate_file_checksum(rec_ct_file_path)) rec_ct_mod_time = os.path.getmtime(rec_ct_file_path) # Create the data for the Telemetered parser. self.create_sample_data_set_dir("node59p1_step1.dat", TEL_DIR, "node59p1.dat") full_file = os.path.join( driver_config['harvester'][DataTypeKey.CTDMO_GHQR_SIO_MULE]['directory'], driver_config['harvester'][DataTypeKey.CTDMO_GHQR_SIO_MULE]['pattern']) mod_time = os.path.getmtime(full_file) # Create the data for the Recovered CO parser. # Calculate the Recovered CO file checksum and get the file mod time. rec_co_filename = 'CTD02002.DAT' self.create_sample_data_set_dir(rec_co_filename, REC_DIR) rec_co_file_path = os.path.join( driver_config['harvester'][DataTypeKey.CTDMO_GHQR_CO]['directory'], rec_co_filename) rec_co_file_checksum = str(calculate_file_checksum(rec_co_file_path)) rec_co_mod_time = os.path.getmtime(rec_co_file_path) # Create and store the new driver state new_state = { DataTypeKey.CTDMO_GHQR_SIO_MULE: { "node59p1.dat": { DriverStateKey.FILE_SIZE: 6000, DriverStateKey.FILE_CHECKSUM: 'aa1cc1aa816e99e11d8e88fc56f887e7', DriverStateKey.FILE_MOD_DATE: mod_time, DriverStateKey.PARSER_STATE: { StateKey.IN_PROCESS_DATA: [], StateKey.UNPROCESSED_DATA: [[0, 12], [336, 394], [5924,6000]], StateKey.FILE_SIZE: 6000 } } }, DataTypeKey.CTDMO_GHQR_CO: { rec_co_filename: { DriverStateKey.FILE_SIZE: 216, DriverStateKey.FILE_CHECKSUM: rec_co_file_checksum, DriverStateKey.FILE_MOD_DATE: rec_co_mod_time, DriverStateKey.INGESTED: False, DriverStateKey.PARSER_STATE: { StateKey.IN_PROCESS_DATA: [], StateKey.UNPROCESSED_DATA: [[58, 146], [146, 216]], StateKey.FILE_SIZE: 216 } } }, DataTypeKey.CTDMO_GHQR_CT: { rec_ct_filename: { DriverStateKey.FILE_SIZE: 704, DriverStateKey.FILE_CHECKSUM: rec_ct_file_checksum, DriverStateKey.FILE_MOD_DATE: rec_ct_mod_time, DriverStateKey.INGESTED: False, DriverStateKey.PARSER_STATE: { CtdmoStateKey.END_CONFIG: True, CtdmoStateKey.POSITION: 0x244, # 15th record of 18 CtdmoStateKey.SERIAL_NUMBER: 20130704 } } } } driver = MflmCtdmoDataSetDriver( self._driver_config()['startup_config'], new_state, self.data_callback, self.state_callback, self.event_callback, self.exception_callback) # create some data to parse self.clear_async_data() self.create_sample_data_set_dir("node59p1_step2.dat", TEL_DIR, "node59p1.dat") driver.start_sampling() # Only the last 4 particles should be read. log.info("=== MID STATE READ END OF REC CT FILE ===") self.assert_data(CtdmoRecoveredInstrumentDataParticle, 'SBE37-IM_20130704_2013_07_04_last4.yml', count=4, timeout=10) # Only the last 4 particles should be read. log.info("=== MID STATE READ END OF REC CO FILE ===") self.assert_data(CtdmoRecoveredOffsetDataParticle, 'CTD02002_last4.yml', count=4, timeout=10) # verify data is produced log.info("=== MID STATE READ TEL FILE ===") self.assert_data(CtdmoTelemeteredInstrumentDataParticle, 'test_data_2.txt.result.yml', count=2, timeout=10)
CtdmoRecoveredInstrumentDataParticle, \ CtdmoRecoveredOffsetDataParticle, \ CtdmoTelemeteredInstrumentDataParticle, \ CtdmoTelemeteredOffsetDataParticle, \ CtdmoStateKey, \ DataParticleType REC_DIR = '/tmp/dsatest_rec' TEL_DIR = '/tmp/dsatest_tel' DataSetTestCase.initialize( driver_module='mi.dataset.driver.mflm.ctd.driver', driver_class="MflmCtdmoDataSetDriver", agent_resource_id = '123xyz', agent_name = 'Agent007', agent_packet_config = MflmCtdmoDataSetDriver.stream_config(), startup_config = { DataSourceConfigKey.HARVESTER: { DataTypeKey.CTDMO_GHQR_CO: { DataSetDriverConfigKeys.DIRECTORY: REC_DIR, DataSetDriverConfigKeys.PATTERN: 'CTD*.DAT', DataSetDriverConfigKeys.FREQUENCY: 1, DataSetDriverConfigKeys.FILE_MOD_WAIT_TIME: 30, }, DataTypeKey.CTDMO_GHQR_CT: { DataSetDriverConfigKeys.DIRECTORY: REC_DIR, DataSetDriverConfigKeys.PATTERN: 'SBE37-IM_*.hex', DataSetDriverConfigKeys.FREQUENCY: 1,