def runTest(self): m = miner.Miner('localhost', self._server.port, 3, logging.getLogger()) ct = 0 u = m.get_url_by_doc_identity(types.DocIdentity('board', 11244)) self.assertEqual(u, 'board11244') ct += 1 for i in range(20): u = m.get_url_by_doc_identity(types.DocIdentity('board', 11244)) self.assertEqual(u, 'board%d' % 11244) di = m.get_doc_identity_by_url('25377') self.assertTrue(di.board == '25377' and di.idid == 25377) ct += 1 di = m.get_doc_identity_by_url('25357') self.assertTrue(di.board == '25357' and di.idid == 25357) ct += 1 di = m.get_doc_identity_by_url('25353') self.assertTrue(di.board == '25353' and di.idid == 25353) ct += 1 u = m.get_url_by_doc_identity(types.DocIdentity('board', 11244)) self.assertEqual(u, 'board11244') ct += 1 di = m.get_doc_identity_by_url('25353') self.assertTrue(di.board == '25353' and di.idid == 25353) self.assertEqual(ct, self._server.num_queries)
def runTest(self): dri = types.DocRelInfo([], [], [types.DocIdentity('board', 123)]) buf = b'\x00\x00\x00\x00\x00\x00\x00\x00' + \ b'\x00\x00\x00\x00\x00\x00\x00\x00' + \ b'\x01\x00\x00\x00\x00\x00\x00\x00' + \ types.DocIdentity('board', 123).dump() buf2 = dri.dump() self.assertEqual(buf, buf2) dri2 = types.DocRelInfo.load(buf)[0] self.assertEqual(len(dri2.pos_rel_docs), 0) self.assertEqual(len(dri2.neg_rel_docs), 0) self.assertEqual(len(dri2.neutral_rel_docs), 1) self.assertEqual(dri2.neutral_rel_docs[0].board, 'board') self.assertEqual(dri2.neutral_rel_docs[0].idid, 123)
def runTest(self): di = types.DocIdentity('blabla~', 18) buf = b''.join( [b'\x07\x00\x00\x00\x00\x00\x00\x00blabla~', b'\x12\x00\x00\x00']) self.assertEqual(di.dump(), buf) (di, offs) = types.DocIdentity.load(buf) self.assertEqual(offs, 8 + 7 + 4) self.assertEqual(di.board, 'blabla~') self.assertEqual(di.idid, 18)
def _runTest(self, Creater, arr, ct): server = _FakeServer() thr = threading.Thread(target=server.main_loop) thr.start() time.sleep(1) aa = Creater(server.port) for i in arr: iden = types.DocIdentity('board', i) r = aa.get_doc_rel_info(iden) self._check_is_correct_doc_rel_info(iden, r) server.stop() thr.join() self.assertEqual(ct, server.num_queries) self.assertTrue(server.normal)
def runTest(self): server = _FakeServer() thr = threading.Thread(target=server.main_loop) thr.start() time.sleep(1) miner_proxy = miner._MinerProxy('localhost', server.port, logging.getLogger()) u = miner_proxy.get_url_by_doc_identity( types.DocIdentity('board', 1234)) self.assertEqual(u, 'board1234') di = miner_proxy.get_doc_identity_by_url('12345') self.assertEqual(di.board, '12345') self.assertEqual(di.idid, 12345) server.stop() thr.join() self.assertTrue(server.normal)
def get_doc_identity_by_url(self, url): return types.DocIdentity(url, 1)
def _handle_query_id_by_url(self, ph): url, offs = net.StringStruct.unpack(self._recv_all(ph.size)) if offs != ph.size: raise Exception() doc_id = types.DocIdentity(url, int(url)) self._send_type_pkg(net.PackageType.REPLY_ID_BY_URL, doc_id.dump())
def get_id_by_url(self, url): return types.DocIdentity(url, int(url))