HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
ftest_ClientInterfaceServiceDC.py
Go to the documentation of this file.
1 '''
2 Created on Apr 9, 2014
3 
4 @package: dc
5 @author: scorp
6 @link: http://hierarchical-cluster-engine.com/
7 @copyright: Copyright © 2013-2014 IOIX Ukraine
8 @license: http://hierarchical-cluster-engine.com/license/
9 @since: 0.1
10 '''
11 from transport.Event import Event
12 from transport.Event import EventBuilder
13 from transport.ConnectionBuilderLight import ConnectionBuilderLight
14 from app.BaseServerManager import BaseServerManager
15 from dc.ClientInterfaceService import ClientInterfaceService
16 from dc.Constants import EVENT_TYPES, LOGGER_NAME
17 import dc.EventObjects
18 import dtm.EventObjects
19 import ConfigParser
20 import transport.Consts
21 import unittest
22 import logging
23 import time
24 
25 
26 logger = logging.getLogger(__name__)
27 
28 class TestClientInterfaceServiceDC(unittest.TestCase):
29 
30 
31  def setUp(self):
32  self.servIndex = 1
34  self.localConnectionDCC = None
37  self.adminServerConnection = self.connectionBuilder.build(transport.Consts.SERVER_CONNECT,
38  BaseServerManager.ADMIN_CONNECT_ENDPOINT)
39  self.config = ConfigParser.ConfigParser()
40  self.config.read("./dc.ini")
45  self.recvEvent = None
46  self.event = None
47  self.reply_event = None
49 
50 
52  try:
53  serverHost = self.config.get(ClientInterfaceService.CONFIG_SECTION, ClientInterfaceService.CONFIG_SERVER_HOST)
54  serverPort = self.config.get(ClientInterfaceService.CONFIG_SECTION, ClientInterfaceService.CONFIG_SERVER_PORT)
55  server = serverHost + ":" + str(serverPort)
56 
57  self.localConnectionDCC = self.connectionBuilder.build(transport.Consts.CLIENT_CONNECT, \
58  server, transport.Consts.TCP_TYPE)
59  self.servIndex = self.servIndex + 1
60  except ConfigParser.NoSectionError:
61  logger.error(">>> TasksDataManager can't read config - Section Error")
62  except ConfigParser.NoOptionError:
63  logger.error(">>> TasksDataManager can't read config - Option Error")
64 
65 
67  try:
68  URLManager = self.config.get(ClientInterfaceService.CONFIG_SECTION, ClientInterfaceService.CONFIG_URL_MANAGER)
69  sitesManager = self.config.get(ClientInterfaceService.CONFIG_SECTION, ClientInterfaceService.CONFIG_SITES_MANAGER)
70 
71  self.localConnectionURLManager = self.connectionBuilder.build(transport.Consts.SERVER_CONNECT, URLManager)
72  self.localConnectionSitesManager = self.connectionBuilder.build(transport.Consts.SERVER_CONNECT, sitesManager)
73  self.servIndex = self.servIndex + 1
74  except ConfigParser.NoSectionError:
75  logger.error(">>> TasksDataManager can't read config - Section Error")
76  except ConfigParser.NoOptionError:
77  logger.error(">>> TasksDataManager can't read config - Option Error")
78 
79 
80  def tearDown(self):
81  self.clientInterfaceService.exit_flag = True
83  for connection in self.clientInterfaceService.connections.values():
84  connection.close()
85  self.adminServerConnection.close()
86  self.localConnectionDCC.close()
87  self.localConnectionURLManager.close()
88  self.localConnectionSitesManager.close()
89  time.sleep(3)
90 
91 
92  def commonTestTimeout(self, eventObj, eventType, excptStr):
93  siteEvent = self.eventBuilder.build(eventType, eventObj)
94  self.localConnectionDCC.send(siteEvent)
95  if self.localConnectionDCC.poll(3000) == 0:
96  self.assertTrue(True, ">>> " + excptStr + "Was timeout")
97  else:
98  self.localConnectionDCC.recv()
99 
100 
101  def commonTest(self, eventObject, eventObjectResponse, eventType, eventTypeResponse, excptStr):
102  event = self.eventBuilder.build(eventType, eventObject)
103  responseEvent = self.eventBuilder.build(eventTypeResponse, eventObjectResponse)
104  responseEvent.uid = event.uid
105  self.localConnectionDCC.send(event)
106  time.sleep(1)
107  self.clientInterfaceService.onDCClientRoute(responseEvent)
108  if self.localConnectionDCC.poll(3000) == 0:
109  self.assertTrue(False, ">>> " + excptStr + " Was timeout")
110  else:
111  ret = self.localConnectionDCC.recv()
112  if ret.eventType != eventTypeResponse:
113  self.assertTrue(False, ">>> " + excptStr + " Bad ret event type")
114 
115 
117  newSiteObj = dc.EventObjects.Site("intel.com")
118  self.commonTestTimeout(newSiteObj, EVENT_TYPES.SITE_NEW, "[testNewSiteTimeout]")
119 
120 
122  updateSiteObj = dc.EventObjects.SiteUpdate(1000)
123  self.commonTestTimeout(updateSiteObj, EVENT_TYPES.SITE_UPDATE, "[testUpdateSiteTimeout]")
124 
125 
127  statusSiteObj = dc.EventObjects.SiteStatus(1000)
128  self.commonTestTimeout(statusSiteObj, EVENT_TYPES.SITE_STATUS, "[testStatusSiteTimeout]")
129 
130 
132  deleteSiteObj = dc.EventObjects.SiteDelete(1000)
133  self.commonTestTimeout(deleteSiteObj, EVENT_TYPES.SITE_DELETE, "[testDeleteSiteTimeout]")
134 
135 
137  cleanupSiteObj = dc.EventObjects.SiteCleanup(1000)
138  self.commonTestTimeout(cleanupSiteObj, EVENT_TYPES.SITE_CLEANUP, "[testCleanupSiteTimeout]")
139 
140 
141  def testNewURLTimeout(self):
142  newURLObj = dc.EventObjects.URL(1000, "intel.com")
143  self.commonTestTimeout(newURLObj, EVENT_TYPES.URL_NEW, "[testNewURLTimeout]")
144 
145 
147  updateURLObj = []
148  updateURLObj.append(dc.EventObjects.URLUpdate(0, "intel.com"))
149  self.commonTestTimeout(updateURLObj, EVENT_TYPES.URL_UPDATE, "[testUpdateURLTimeout]")
150 
151 
153  statusURLObj = []
154  statusURLObj.append(dc.EventObjects.URLStatus(1000, "intel.com"))
155  self.commonTestTimeout(statusURLObj, EVENT_TYPES.URL_STATUS, "[testStatusURLTimeout]")
156 
157 
159  deleteURLObj = []
160  deleteURLObj.append(dc.EventObjects.URLDelete(1, "intel.com"))
161  self.commonTestTimeout(deleteURLObj, EVENT_TYPES.URL_DELETE, "[testDeleteURLTimeout]")
162 
163 
165  cleanupURLObj = []
166  cleanupURLObj.append(dc.EventObjects.URLCleanup(1, "intel.com"))
167  self.commonTestTimeout(cleanupURLObj, EVENT_TYPES.URL_CLEANUP, "[testCleanupURLTimeout]")
168 
169 
171  fetchURLObj = dc.EventObjects.URLFetch()
172  self.commonTestTimeout(fetchURLObj, EVENT_TYPES.URL_FETCH, "[testFetchURLTimeout]")
173 
174 
176  contentURLObj = []
177  contentURLObj.append(dc.EventObjects.URLContentRequest(1, "intel.com"))
178  self.commonTestTimeout(contentURLObj, EVENT_TYPES.URL_CONTENT, "[testContentURLTimeout]")
179 
180 
181  def testNewSite(self):
182  newSiteObj = dc.EventObjects.Site("intel.com")
183  generalResponse = dtm.EventObjects.GeneralResponse()
184  self.commonTest(newSiteObj, generalResponse, EVENT_TYPES.SITE_NEW, EVENT_TYPES.SITE_NEW_RESPONSE,
185  "[testNewSiteTimeout]")
186 
187 
188  def testUpdateSite(self):
189  updateSiteObj = dc.EventObjects.SiteUpdate(1000)
190  generalResponse = dtm.EventObjects.GeneralResponse()
191  self.commonTest(updateSiteObj, generalResponse, EVENT_TYPES.SITE_UPDATE, EVENT_TYPES.SITE_UPDATE_RESPONSE,
192  "[testUpdateSiteTimeout]")
193 
194 
195  def testStatusSite(self):
196  statusSiteObj = dc.EventObjects.SiteStatus(1000)
197  siteResponse = dc.EventObjects.Site("ibmn.com")
198  self.commonTest(statusSiteObj, siteResponse, EVENT_TYPES.SITE_STATUS, EVENT_TYPES.SITE_STATUS_RESPONSE,
199  "[testStatusSiteTimeout]")
200 
201 
202  def testDeleteSite(self):
203  deleteSiteObj = dc.EventObjects.SiteDelete(1000)
204  generalResponse = dtm.EventObjects.GeneralResponse()
205  self.commonTest(deleteSiteObj, generalResponse, EVENT_TYPES.SITE_DELETE, EVENT_TYPES.SITE_DELETE_RESPONSE,
206  "[testDeleteSiteTimeout]")
207 
208 
209  def testCleanupSite(self):
210  cleanupSiteObj = dc.EventObjects.SiteCleanup(1000)
211  generalResponse = dtm.EventObjects.GeneralResponse()
212  self.commonTest(cleanupSiteObj, generalResponse, EVENT_TYPES.SITE_CLEANUP, EVENT_TYPES.SITE_CLEANUP_RESPONSE,
213  "[testCleanupSiteTimeout]")
214 
215 
216  def testNewURL(self):
217  newURLObj = dc.EventObjects.URL(1000, "intel.com")
218  generalResponse = dtm.EventObjects.GeneralResponse()
219  self.commonTest(newURLObj, generalResponse, EVENT_TYPES.URL_NEW, EVENT_TYPES.URL_NEW_RESPONSE,
220  "[testNewURLTimeout]")
221 
222 
223  def testUpdateURL(self):
224  updateURLObj = []
225  updateURLObj.append(dc.EventObjects.URLUpdate(2, "intel.com"))
226  generalResponse = dtm.EventObjects.GeneralResponse()
227  self.commonTest(updateURLObj, generalResponse, EVENT_TYPES.URL_UPDATE, EVENT_TYPES.URL_UPDATE_RESPONSE,
228  "[testUpdateURLTimeout]")
229 
230 
231  def testStatusURL(self):
232  statusURLObj = []
233  statusURLObj.append(dc.EventObjects.URLStatus(1000, "intel.com"))
234  urlResponse = []
235  urlResponse.append(dc.EventObjects.URL(1000, "intel.com"))
236  self.commonTest(statusURLObj, urlResponse, EVENT_TYPES.URL_STATUS, EVENT_TYPES.URL_STATUS_RESPONSE,
237  "[testStatusURLTimeout]")
238 
239 
240  def testDeleteURL(self):
241  deleteURLObj = []
242  deleteURLObj.append(dc.EventObjects.URLDelete(1, "intel.com"))
243  generalResponse = dtm.EventObjects.GeneralResponse()
244  self.commonTest(deleteURLObj, generalResponse, EVENT_TYPES.URL_DELETE, EVENT_TYPES.URL_DELETE_RESPONSE,
245  "[testDeleteURLTimeout]")
246 
247 
248  def testCleanupURL(self):
249  cleanupURLObj = []
250  cleanupURLObj.append(dc.EventObjects.URLCleanup(1, "intel.com"))
251  generalResponse = dtm.EventObjects.GeneralResponse()
252  self.commonTest(cleanupURLObj, generalResponse, EVENT_TYPES.URL_CLEANUP, EVENT_TYPES.URL_CLEANUP_RESPONSE,
253  "[testCleanupURLTimeout]")
254 
255 
256  def testFetchURL(self):
257  fetchURLObj = dc.EventObjects.URLFetch()
258  urlsResponse = []
259  urlsResponse.append(dc.EventObjects.URL(1000, "intel.com"))
260  self.commonTest(fetchURLObj, urlsResponse, EVENT_TYPES.URL_FETCH, EVENT_TYPES.URL_FETCH_RESPONSE,
261  "[testFetchURLTimeout]")
262 
263 
264  def testContentURL(self):
265  contentURLObj = []
266  contentURLObj.append(dc.EventObjects.URLContentRequest(1, "intel.com"))
267  contentResponse = []
268  contentResponse.append(dc.EventObjects.URLContentResponse(1, "intel.com"))
269  self.commonTest(contentURLObj, contentResponse, EVENT_TYPES.URL_CONTENT, EVENT_TYPES.URL_CONTENT_RESPONSE,
270  "[testContentURLTimeout]")
271 
272 
273 if __name__ == "__main__":
274  #import sys;sys.argv = ['', 'Test.testName']
275  unittest.main()
def commonTest(self, eventObject, eventObjectResponse, eventType, eventTypeResponse, excptStr)
GeneralResponse event object, represents general state response for multipurpose usage.
Class hides routines of bulding connection objects.
Definition: join.py:1