Commit 76fb5806 authored by Philipp Gast's avatar Philipp Gast
Browse files

removed the server treatSig() function and moved the functionality to...

removed the server treatSig() function and moved the functionality to handle(). On serverside send() and waitForSignal() are not used. keep them for testing purposes? I still do not understand why both (wfile.close() and disconnect() are needed on client side. Will dig into that...
parent 1c1e2c7a
Pipeline #471 failed with stage
in 4 minutes and 15 seconds
......@@ -27,7 +27,7 @@ class MplClient2():
def disconnect(self):
''' shutdown socket. Warning: If server and client are local the client can not shut down the port because the server has still a handle on it'''
print('closing the connection...')
#~ self.sock.shutdown(socket.SHUT_WR)
self.sock.shutdown(socket.SHUT_WR)
self.sock.close()
self.connected = False
print('closing the connection... DONE')
......
......@@ -160,82 +160,49 @@ class MplHandler(SocketServer.StreamRequestHandler):
else :
return Status(False,'Dataname not found in index of the server side...')
def send(self,sig):
# pickel the signal
# send the str
wf = self.server.socket.makefile(mode='wb')
if debug:
print('sending ',type(sig),' with content \"',sig.content,'\"')
try :
pickle.dump(sig,wf)
except Exception as e:
if DEBUG:
print(SPCE+"SERVER: Exception details where:",e.message, e.args )
return False
wf.close()
return True
def waitForSignal(self):
# wait for signal
# unpickel
# Actually not used anymore. Keep for testing?
# def send(self,sig):
# # pickel the signal
# # send the str
# wf = self.server.socket.makefile(mode='wb')
# if debug:
# print('sending ',type(sig),' with content \"',sig.content,'\"')
# try :
# pickle.dump(sig,wf)
# except Exception as e:
# if DEBUG:
# print(SPCE+"SERVER: Exception details where:",e.message, e.args )
# return False
# wf.close()
# return True
rf = self.server.socket.makefile(mode='rb')
try :
unpickler = MplUnpickler(rf)
response = unpickler.load()
if DEBUG and isinstance(response,Signal):
print('CLIENT Received: {} with content \"{}\"'.format(type(response),response.content))
except EOFError :
print('no answer received - or connection closed unexpectedly')
response = None
except Exception as e:
print('unknown error while waiting for response')
print(SPCE+"SERVER: Exception details where:",e.message, e.args )
response = None
rf.close()
if isinstance(response,Signal) :
return response
def treatSig(self,sig):
if isinstance(sig,Query) :
if sig.queryType == sig.READDATA :
return self.treatReadData(sig.content)
elif sig.queryType == sig.NEWSYNCFIGURE :
return self.treatNewSyncFigure(sig.content)
elif sig.queryType == sig.UPDATESYNCFIGURE :
return self.treatUpdateSyncFigure(sig.content)
elif sig.queryType == sig.SYNCFIGFORMATRAWDATA :
return self.treatSyncFigFormatRawData(sig.content)
elif sig.queryType == sig.DELETESYNCFIGURE :
return self.treatDeleteSyncFigure(sig.content)
elif sig.queryType == sig.LISTDATA :
return self.treatListData(sig.content)
elif sig.queryType == sig.GETDATA :
return self.treatGetData(sig.content)
else :
self.servPrint('received unknown query type')
return Status(False,"received unknown query type")
elif isinstance(sig, Status) :
if sig.value :
pass #if it is just a positiv status message do nothing
else :
self.servPrint('the client Side reported of an error:')
self.servPrint('----'+sig.content)
elif isinstance(sig, Answer) :
#~ #needed for server???
pass
elif isinstance(sig, Signal) :
self.servPrint('received unknown signal')
return Status(False,"received unknown signal")
else :
self.servPrint('what is happening here??? received Object of type:')
self.servPrint(str(sig))
return Status(False,"received something totally diffenent")
# Actually not used anymore. Keep for testing?
# def waitForSignal(self):
# # wait for signal
# # unpickel
#
# rf = self.server.socket.makefile(mode='rb')
# try :
# unpickler = MplUnpickler(rf)
# response = unpickler.load()
# if DEBUG and isinstance(response,Signal):
# print('CLIENT Received: {} with content \"{}\"'.format(type(response),response.content))
# except EOFError :
# print('no answer received - or connection closed unexpectedly')
# response = None
# except Exception as e:
# print('unknown error while waiting for response')
# print(SPCE+"SERVER: Exception details where:",e.message, e.args )
# response = None
# rf.close()
# if isinstance(response,Signal) :
# return response
def handle(self):
print('HANDLING...')
reply = None
if DEBUG:
print('SERVER: ' + str(self.wfile._sock.getsockname()))
......@@ -244,15 +211,56 @@ class MplHandler(SocketServer.StreamRequestHandler):
try:
unpickler = MplUnpickler(self.rfile)
request = unpickler.load()
reply = self.treatSig(request)
if isinstance(request,Query) :
if request.queryType == request.READDATA :
reply = self.treatReadData(request.content)
elif request.queryType == request.NEWSYNCFIGURE :
reply = self.treatNewSyncFigure(request.content)
elif request.queryType == request.UPDATESYNCFIGURE :
reply = self.treatUpdateSyncFigure(request.content)
elif request.queryType == request.SYNCFIGFORMATRAWDATA :
reply = self.treatSyncFigFormatRawData(request.content)
elif request.queryType == request.DELETESYNCFIGURE :
reply = self.treatDeleteSyncFigure(request.content)
elif request.queryType == request.LISTDATA :
reply = self.treatListData(request.content)
elif request.queryType == request.GETDATA :
reply = self.treatGetData(request.content)
else :
self.servPrint('received unknown query type')
reply = Status(False,"received unknown query type")
elif isinstance(request, Status) :
if request.value :
pass #if it is just a positiv status message do nothing
else :
self.servPrint('the client Side reported of an error:')
self.servPrint('----'+request.content)
elif isinstance(request, Answer) :
#needed for server???
pass
elif isinstance(request, requestnal) :
self.servPrint('received unknown requestnal')
reply = Status(False,"received unknown requestnal")
else :
self.servPrint('what is happening here??? received Object of type:')
self.servPrint(str(request))
reply = Status(False,"received something totally diffenent")
if isinstance(reply,Signal) :
if DEBUG:
self.servPrint("returning {}-Signal:".format(type(reply)))
pickle.dump(reply,self.wfile)
except EOFError:
print("could not unpickle, noting in the file")
except Exception as e:
print("An unspecified error occured. ")
reply = Status(False,"An unspecified error occured." + e.message + e.args)
finally :
if reply :
pickle.dump(reply,self.wfile)
self.wfile.close()
self.rfile.close()
......
......@@ -10,5 +10,4 @@ from .test_server import ServerTestCase
from .test_client import ClientTestCase
from .test_com import ComSetupTestCase
from .test_com import ReadDataTestCase
from .test_com import RemoteFigTestCase
......@@ -32,13 +32,9 @@ states = {}
suite_com = unittest.TestLoader().loadTestsFromTestCase(ComSetupTestCase)
states.update({'Communication': unittest.TextTestRunner(verbosity=verbose).run(suite_com).wasSuccessful()})
# Remote data read
suite_readremote = unittest.TestLoader().loadTestsFromTestCase(ReadDataTestCase)
states.update({'ReadData': unittest.TextTestRunner(verbosity=verbose).run(suite_readremote).wasSuccessful()})
#~ # Remote fig creation
#~ suite_figcreation = unittest.TestLoader().loadTestsFromTestCase(RemoteFigTestCase)
#~ states.update({'FigCreation': unittest.TextTestRunner(verbosity=verbose).run(suite_figcreation).wasSuccessful()})
# Remote fig creation
suite_figcreation = unittest.TestLoader().loadTestsFromTestCase(RemoteFigTestCase)
states.update({'FigCreation': unittest.TextTestRunner(verbosity=verbose).run(suite_figcreation).wasSuccessful()})
for success in states.items():
if not success[1]:
......
......@@ -45,31 +45,6 @@ class ComSetupTestCase(unittest.TestCase):
del self.server
del self.client
class ReadDataTestCase(unittest.TestCase):
def setUp(self):
self.server = mpl_server.MplServer2(port=12345, knownFunctions=SERVER_IOFUNCTIONS, knownFigures=SERVER_FIGURES)
self.client = mpl_client.MplClient2()
self.server.run(as_daemon=True)
self.client.host = 'localhost'
self.client.port = 12345
# self.client.connect(('localhost', 12346))
def test_Readdata(self):
datanames = ['data1','data2']
self.client.readData('readStupidData', datanames[0])
self.client.readData('readStupidData2', datanames[1])
rm_data = self.client.listRemoteData()
self.assertEqual(rm_data,datanames)
def tearDown(self) :
# self.client.disconnect()
self.server.server_close()
self.server.shutdown()
del self.server
del self.client
class RemoteFigTestCase(unittest.TestCase):
def setUp(self):
......@@ -82,23 +57,27 @@ class RemoteFigTestCase(unittest.TestCase):
self.server.run(as_daemon=True)
self.client.connect(('localhost', 12347))
datanames = ['data1','data2']
self.client.readData('readStupidData', datanames[0])
self.client.readData('readStupidData2', datanames[1])
self.datanames = ['data1','data2']
self.client.readData('readStupidData', self.datanames[0])
self.client.readData('readStupidData2', self.datanames[1])
def test_NewSyncFig(self):
fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
def test_MultiFig(self):
fig2 = self.client.newSyncFigure(FigTestc2, ('data1','data2'), xRange_p1=[-2.0, 2.0], xRange_p2=[-3, 3], yRange=[-2.0, 2.0])
def test_Update(self):
fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
fig1.update(xRange=[-2, 2],yRange=[-2, 2])
def test_Readdata(self):
rm_data = self.client.listRemoteData()
self.assertEqual(rm_data,self.datanames)
def test_ReSync(self):
fig1.deSyncFig()
fig1.reSyncFig()
#~ def test_NewSyncFig(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
#~
#~ def test_MultiFig(self):
#~ fig2 = self.client.newSyncFigure(FigTestc2, ('data1','data2'), xRange_p1=[-2.0, 2.0], xRange_p2=[-3, 3], yRange=[-2.0, 2.0])
#~
#~ def test_Update(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
#~ fig1.update(xRange=[-2, 2],yRange=[-2, 2])
#~
#~ def test_ReSync(self):
#~ fig1.deSyncFig()
#~ fig1.reSyncFig()
def tearDown(self) :
self.client.disconnect()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment