def test_variables_atts_ds2_ds3(self): # Convert to a message self.msg1 = dap_tools.ds2dap_msg(self.ds1) # Convert back to a dataset self.ds2 = dap_tools.dap_msg2ds(self.msg1) # Convert back to a message self.msg2 = dap_tools.ds2dap_msg(self.ds2) # Convert back to a dataste self.ds3 = dap_tools.dap_msg2ds(self.msg2) # Test the var_atts self._test_variable_atts(self.ds2, self.ds3)
def test_variables_atts_ds2_ds3(self): # Convert to a message self.msg1 = dap_tools.ds2dap_msg(self.ds1) # Convert back to a dataset self.ds2 = dap_tools.dap_msg2ds(self.msg1) # Convert back to a message self.msg2 = dap_tools.ds2dap_msg(self.ds2) # Convert back to a dataste self.ds3 = dap_tools.dap_msg2ds(self.msg2) # Test the var_atts self._test_variable_atts(self.ds2,self.ds3)
def test_variables_ds1_ds2(self): # Convert to a message self.msg1 = dap_tools.ds2dap_msg(self.ds1) # Convert back to a dataset self.ds2 = dap_tools.dap_msg2ds(self.msg1) # Test teh variables self._test_variables(self.ds1, self.ds2)
def test_global_atts_ds1_ds2(self): # Convert to a message self.msg1 = dap_tools.ds2dap_msg(self.ds1) # Convert back to a dataset self.ds2 = dap_tools.dap_msg2ds(self.msg1) # test the global atts! self._test_global_atts(self.ds1, self.ds2)
def test_global_atts_ds1_ds2(self): # Convert to a message self.msg1 = dap_tools.ds2dap_msg(self.ds1) # Convert back to a dataset self.ds2 = dap_tools.dap_msg2ds(self.msg1) # test the global atts! self._test_global_atts(self.ds1,self.ds2)
def test_variables_ds1_ds2(self): # Convert to a message self.msg1 = dap_tools.ds2dap_msg(self.ds1) # Convert back to a dataset self.ds2 = dap_tools.dap_msg2ds(self.msg1) # Test teh variables self._test_variables(self.ds1,self.ds2)
def stream(self): sz = 10 time = numpy.arange(float(self.index), float(self.index + sz)) self.index += sz data = numpy.arange(float(sz)) for ind in range(sz): data[ind] = numpy.random.random() ds = DatasetType(name='SimpleGridData') g = GridType(name='Time Series') # The name in the dictionary must match the name in the basetype g['timeseries'] = BaseType(name='timeseries', data=data, shape=data.shape, type=Float32, dimensions=('time')) g['time'] = BaseType(name='time', data=time, shape=(sz, ), type=Float32) ds[g.name] = g msg = dap_tools.ds2dap_msg(ds) yield self.send(self.deliver, 'data', msg.encode())
def test_send_dap_msg(self): yield self._start_container() services = [ {'name':'responder','module':'ion.data.test.test_dataobject','class':'ResponseService'}, ] sup = yield self._spawn_processes(services) rsc = ResponseServiceClient(sup) # Simple Send and Check value: self.msg1 = dap_tools.ds2dap_msg(self.ds1) response = yield rsc.send_data_object(self.msg1) self.assertEqual(self.msg1, response) yield self._stop_container()
def publish(self, publisher_proc, topic_ref, data): """ @Brief Publish something... @param publisher_proc - the publishing process passes self to the publish client @param topic_ref is a topic reference for which the publisher is registered for (checked before sending) @param data is a dataobject which is being published @Todo move the actual publish command back to this client! Don't send the data to the service! """ yield self._check_init() logging.info(self.__class__.__name__ + '; Calling: publish') publication = dm_resource_descriptions.Publication() #Load the args and pass to the publisher if isinstance(data, dm_resource_descriptions.DataMessageObject): do = data elif isinstance(data, DatasetType): do = dap_tools.ds2dap_msg(data) elif isinstance(data, dict): do = dm_resource_descriptions.DictionaryMessageObject() do.data = data elif isinstance(data, str): do = dm_resource_descriptions.StringMessageObject() do.data = data else: logging.info('%s; publish: Failed! Invalid DataType: %s' % (self.__class__.__name__, type(data))) raise RuntimeError('%s; publish: Invalid DataType: %s' % (self.__class__.__name__, type(data))) publication.data = do publication.topic_ref = topic_ref publication.publisher = publisher_proc.receiver.spawned.id.full (content, headers, msg) = yield self.rpc_send('publish', publication.encode()) logging.debug(self.__class__.__name__ + ': publish; Result:' + str(headers)) if content['status'] == 'OK': logging.info(self.__class__.__name__ + '; publish: Success!') defer.returnValue('sent') else: logging.info(self.__class__.__name__ + '; publish: Failed!') defer.returnValue('error sending message!')
def publish(self, publisher_proc, topic_ref, data): """ @Brief Publish something... @param publisher_proc - the publishing process passes self to the publish client @param topic_ref is a topic reference for which the publisher is registered for (checked before sending) @param data is a dataobject which is being published @Todo move the actual publish command back to this client! Don't send the data to the service! """ yield self._check_init() logging.info(self.__class__.__name__ + '; Calling: publish') publication = dm_resource_descriptions.Publication() #Load the args and pass to the publisher if isinstance(data, dm_resource_descriptions.DataMessageObject): do = data elif isinstance(data, DatasetType): do = dap_tools.ds2dap_msg(data) elif isinstance(data, dict): do = dm_resource_descriptions.DictionaryMessageObject() do.data=data elif isinstance(data, str): do = dm_resource_descriptions.StringMessageObject() do.data=data else: logging.info('%s; publish: Failed! Invalid DataType: %s' % (self.__class__.__name__, type(data))) raise RuntimeError('%s; publish: Invalid DataType: %s' % (self.__class__.__name__, type(data))) publication.data = do publication.topic_ref = topic_ref publication.publisher = publisher_proc.receiver.spawned.id.full (content, headers, msg) = yield self.rpc_send('publish', publication.encode()) logging.debug(self.__class__.__name__ + ': publish; Result:' + str(headers)) if content['status']=='OK': logging.info(self.__class__.__name__ + '; publish: Success!') defer.returnValue('sent') else: logging.info(self.__class__.__name__ + '; publish: Failed!') defer.returnValue('error sending message!')
def test_send_dap_msg(self): yield self._start_container() services = [ { 'name': 'responder', 'module': 'ion.data.test.test_dataobject', 'class': 'ResponseService' }, ] sup = yield self._spawn_processes(services) rsc = ResponseServiceClient(sup) # Simple Send and Check value: self.msg1 = dap_tools.ds2dap_msg(self.ds1) response = yield rsc.send_data_object(self.msg1) self.assertEqual(self.msg1, response) yield self._stop_container()
def queue_result(self,queue, data=None, notification=''): if isinstance(data, DatasetType): msg = dap_tools.ds2dap_msg(data) elif isinstance(data, str): msg = StringMessageObject() msg.data=data elif isinstance(data, dict): msg = DictionaryMessageObject() msg.data=data elif not data: msg = DataMessageObject() else: raise RuntimeError('Invalid data type passed to send_result in class %s: type:' % (self.__class__.__name__, type(data))) if not notification: notification = self.__class__.__name__ + ' received a message!' msg.notification = notification msg.timestamp = pu.currenttime() self.msgs_to_send.append((queue, msg.encode()))
def test_persister_consumer_dap(self): msg = dap_tools.ds2dap_msg(self.ds) yield self.test_sup.send(self.queue1, 'data', msg.encode()) yield pu.asleep(1) msg_cnt = yield self.child1.get_msg_count() received = msg_cnt.get('received', {}) sent = msg_cnt.get('sent', {}) self.assertEqual(sent, {}) self.assertEqual(received.get(self.queue1), 1) yield self.test_sup.send(self.queue1, 'data', msg.encode()) yield pu.asleep(1) msg_cnt = yield self.child1.get_msg_count() received = msg_cnt.get('received', {}) sent = msg_cnt.get('sent', {}) self.assertEqual(sent, {}) self.assertEqual(received.get(self.queue1), 2)
def test_persister_consumer_dap(self): msg=dap_tools.ds2dap_msg(self.ds) yield self.test_sup.send(self.queue1,'data',msg.encode()) yield pu.asleep(1) msg_cnt = yield self.child1.get_msg_count() received = msg_cnt.get('received',{}) sent = msg_cnt.get('sent',{}) self.assertEqual(sent,{}) self.assertEqual(received.get(self.queue1),1) yield self.test_sup.send(self.queue1,'data',msg.encode()) yield pu.asleep(1) msg_cnt = yield self.child1.get_msg_count() received = msg_cnt.get('received',{}) sent = msg_cnt.get('sent',{}) self.assertEqual(sent,{}) self.assertEqual(received.get(self.queue1),2)
def stream(self): sz=10 time = numpy.arange(float(self.index),float(self.index+sz)) self.index += sz data = numpy.arange(float(sz)) for ind in range(sz): data[ind] = numpy.random.random() ds = DatasetType(name='SimpleGridData') g = GridType(name='Time Series') # The name in the dictionary must match the name in the basetype g['timeseries'] = BaseType(name='timeseries', data=data, shape=data.shape, type=Float32, dimensions=('time')) g['time'] = BaseType(name='time', data=time, shape=(sz,), type=Float32) ds[g.name]=g msg = dap_tools.ds2dap_msg(ds) yield self.send(self.deliver,'data',msg.encode())