Ejemplo n.º 1
0
class TestData(unittest.TestCase):
  def setUp(self):
    self.proxy = Server()
    (success, body) = self.proxy.put("shape/pet", {"name": {"type": "string"}})
    self.assertTrue(success)
  def tearDown(self):
    (success, body) = self.proxy.delete("shape/pet")
    self.assertTrue(success)
  def test_retrieve(self):
    (success, body) = self.proxy.post("data/pet", {"name": "Spot"})
    self.assertTrue(success)
    self.assertTrue('id' in body)
    self.assertTrue(isinstance(body['id'], int))
    dataId = body['id']

    moreData = True
    offset = 0
    while moreData:
      (success, body) = self.proxy.get("data?offset=" + str(offset))
      self.assertTrue(success)
      self.assertTrue('data' in body)
      for datum in body['data']:
        self.assertTrue('id' in datum)
        self.assertTrue('shape' in datum)
        if datum['id'] == dataId:
          self.assertTrue('name' in datum)
          self.assertEqual(datum['shape'], 'pet')
          self.assertEqual(datum['name'], 'Spot')
          moreData = False
          break
      if moreData and len(body['data']) == 20:
        offset = offset + 20

    (success, body) = self.proxy.delete("data/pet/" + str(dataId))
    self.assertTrue(success)
Ejemplo n.º 2
0
class TestShape(unittest.TestCase):
  def setUp(self):
    self.proxy = Server()
  def test_post(self):
    (success, body) = self.proxy.post("shape", {})
    self.assertFalse(success)
  def test_retrieve(self):
    (success, body) = self.proxy.put("shape/person", {"first" : {"type": "string"}, "last": {"type": "string"}})
    self.assertTrue(success)
    (success, body) = self.proxy.put("shape/pet", {"name": {"type": "string"}})
    self.assertTrue(success)
    (success, body) = self.proxy.get("shape")
    self.assertTrue(success)
    self.assertTrue("person" in body)
    self.assertTrue("first" in body["person"])
    self.assertTrue("type" in body["person"]["first"])
    self.assertEqual(body["person"]["first"]["type"], "string")
    self.assertTrue("last" in body["person"])
    self.assertTrue("type" in body["person"]["last"])
    self.assertEqual(body["person"]["last"]["type"], "string")
    self.assertTrue("pet" in body)
    self.assertTrue("name" in body["pet"])
    self.assertTrue("type" in body["pet"]["name"])
    self.assertEqual(body["pet"]["name"]["type"], "string")

    (success, body) = self.proxy.delete("shape/person")
    self.assertTrue(success)
    (success, body) = self.proxy.delete("shape/pet")
    self.assertTrue(success)
  def test_update(self):
    (success, body) = self.proxy.put("shape", {})
    self.assertFalse(success)
  def test_delete(self):
    (success, body) = self.proxy.delete("shape")
    self.assertFalse(success)
Ejemplo n.º 3
0
 def setUp(self):
   self.proxy = Server()
   (success, body) = self.proxy.put("shape/pet", {"name": {"type": "string"}})
   self.assertTrue(success)
   (success, body) = self.proxy.post("data/pet", {"name": "Spot"})
   self.assertTrue(success)
   self.assertTrue('id' in body)
   self.dataId = body['id']
Ejemplo n.º 4
0
def init():
    global reg,server
    reg = packetmq.PacketRegistry()
    reg.registerDefaultPackets()
    
    reg.addPacket("chat:msg",ChatMsgPacket(),17)
    reg.addPacket("chat:pubmsg",ChatPubMsgPacket(),18)
    reg.addPacket("chat:sendcmd",ChatSendCmdPacket(),19)
    
    server = Server(reg)
    
    server.listen(PORT)
    
    #reactor.callInThread(_main)
    #reactor.run()
    _main()
    reactor.callInThread(reactor.run)
Ejemplo n.º 5
0
 def setUp(self):
   self.proxy = Server()
   (success, body) = self.proxy.put("shape/pet", {"name": {"type": "string"}})
   self.assertTrue(success)
Ejemplo n.º 6
0
class TestDataElement(unittest.TestCase):
  def setUp(self):
    self.proxy = Server()
    (success, body) = self.proxy.put("shape/pet", {"name": {"type": "string"}})
    self.assertTrue(success)
  def tearDown(self):
    (success, body) = self.proxy.delete("shape/pet")
    self.assertTrue(success)
  def test_retrieve_invalid(self):
    """Try to retrieve on element which do not exist"""
    (success, body) = self.proxy.get("data/sdsdfdsfsdfds")
    self.assertFalse(success)
  def test_retrieve(self):
    (success, body) = self.proxy.post("data/pet", {"name": "Spot"})
    self.assertTrue(success)
    self.assertTrue('id' in body)
    self.assertTrue(isinstance(body['id'], int))
    dataId = body['id']

    moreData = True
    offset = 0
    while moreData:
      (success, body) = self.proxy.get("data/pet?offset=" + str(offset))
      self.assertTrue(success)
      self.assertTrue('data' in body)
      for datum in body['data']:
        self.assertTrue('id' in datum)
        self.assertTrue('shape' in datum)
        if datum['id'] == dataId:
          self.assertTrue('name' in datum)
          self.assertEqual(datum['shape'], 'pet')
          self.assertEqual(datum['name'], 'Spot')
          moreData = False
          break
      if moreData and len(body['data']) == 20:
        offset = offset + 20

    (success, body) = self.proxy.delete("data/pet/" + str(dataId))
    self.assertTrue(success)
  def test_create_not_valid(self):
    """ Cannot create with no fields"""
    (success, body) = self.proxy.post("data/pet", {})
    self.assertFalse(success)
    (success, body) = self.proxy.post("data/pet", {"otherfield": "bob"})
    self.assertFalse(success)
    (success, body) = self.proxy.post("data/pet", {"name": 123})
    self.assertFalse(success)
  def test_create(self):
    (success, body) = self.proxy.post("data/pet", {"name": "Spot", "otherfield": "value"})
    self.assertTrue(success)
    self.assertTrue('id' in body)
    self.assertTrue(isinstance(body['id'], int))
    dataId = body['id']

    (success, body) = self.proxy.get("data/pet/" + str(dataId))
    self.assertTrue(success)
    self.assertTrue('id' in body)
    self.assertTrue('shape' in body)
    self.assertTrue('name' in body)
    self.assertFalse('otherfield' in body)
    self.assertEqual(body['id'], dataId)
    self.assertEqual(body['shape'], 'pet')
    self.assertEqual(body['name'], 'Spot')

    (success, body) = self.proxy.delete("data/pet/" + str(dataId))
    self.assertTrue(success)
Ejemplo n.º 7
0
class TestDataSubelement(unittest.TestCase):
  def setUp(self):
    self.proxy = Server()
    (success, body) = self.proxy.put("shape/pet", {"name": {"type": "string"}})
    self.assertTrue(success)
    (success, body) = self.proxy.post("data/pet", {"name": "Spot"})
    self.assertTrue(success)
    self.assertTrue('id' in body)
    self.dataId = body['id']
  def tearDown(self):
    (success, body) = self.proxy.delete("data/pet/" + str(self.dataId))
    self.assertTrue(success)
    (success, body) = self.proxy.delete("shape/pet")
    self.assertTrue(success)
  def test_retrieve_invalid(self):
    """Try to retrieve on ids that do not exist"""
    (success, body) = self.proxy.get("data/pet/aaaaaa")
    self.assertFalse(success)
    (success, body) = self.proxy.get("data/pet/999999999999")
    self.assertFalse(success)
  def test_retrieve(self):
    (success, body) = self.proxy.get("data/pet/" + str(self.dataId))
    self.assertTrue(success)
    self.assertTrue('id' in body)
    self.assertTrue('shape' in body)
    self.assertTrue('name' in body)
    self.assertEqual(body['id'], self.dataId)
    self.assertEqual(body['shape'], 'pet')
    self.assertEqual(body['name'], 'Spot')
  def test_update_valid(self):
    """ Cannot create with no fields"""
    (success, body) = self.proxy.put("data/pet/" + str(self.dataId), {})
    self.assertFalse(success)
    (success, body) = self.proxy.put("data/pet/" + str(self.dataId), {"otherfield": "bob"})
    self.assertFalse(success)
    (success, body) = self.proxy.put("data/pet/" + str(self.dataId), {"name": 123})
    self.assertFalse(success)
  def test_update(self):
    """Can update if correct"""
    (success, body) = self.proxy.put("data/pet/" + str(self.dataId), {"name": "Shiloh", "otherfield": "value"})
    self.assertTrue(success)

    (success, body) = self.proxy.get("data/pet/" + str(self.dataId))
    self.assertTrue(success)
    self.assertTrue('id' in body)
    self.assertTrue('shape' in body)
    self.assertTrue('name' in body)
    self.assertFalse('otherfield' in body)
    self.assertEqual(body['id'], self.dataId)
    self.assertEqual(body['shape'], 'pet')
    self.assertEqual(body['name'], 'Shiloh')
  def test_delete_invalid(self):
    """Cannot delete an element which does not exist"""
    (success, body) = self.proxy.delete("data/pet/aaaaaa")
    self.assertFalse(success)
    (success, body) = self.proxy.delete("data/pet/999999999999")
    self.assertFalse(success)
  def test_delete(self):
    """Successful deletion"""
    (success, body) = self.proxy.post("data/pet", {"name": "Tim"})
    self.assertTrue(success)
    self.assertTrue('id' in body)
    dataId = body['id']
    (success, body) = self.proxy.get("data/pet/" + str(dataId))
    self.assertTrue(success)

    (success, body) = self.proxy.delete("data/pet/" + str(dataId))
    self.assertTrue(success)

    (success, body) = self.proxy.get("data/pet/" + str(dataId))
    self.assertFalse(success)
Ejemplo n.º 8
0
def main():
    # clock instances
    ptp_clocks = []
    ptp_clocks.append(PtpClock(SLAVE_1_NAME, SLAVE_1_MAC, 'b'))

    # connect to a remote host where ptp4l is running, slave or master to
    # reach the ptp management channel
    server = Server(1, SERVER_USER, SERVER_PWD, SERVER_IP)
    server.connect()

    # interactive plot mode with labeled axis and legend
    fig, offset_graph = plt.subplots()
    path_delay_graph = offset_graph.twinx()

    for clk in ptp_clocks:
        offset_graph.plot(range(len(clk.offset_buffer)),
                          clk.offset_buffer,
                          "".join([clk.color, "-"]),
                          label=" ".join([clk.name, "offset"]))
        path_delay_graph.plot(range(len(clk.mean_path_delay_buffer)),
                              clk.mean_path_delay_buffer,
                              "".join([clk.color, "."]),
                              label=" ".join([clk.name, "path delay"]))
        offset_graph.legend(loc='upper left', shadow=True)
        path_delay_graph.legend(loc='upper right', shadow=True)

    offset_graph.set_xlabel("samples")
    offset_graph.set_ylabel("master offset (ns)")
    path_delay_graph.set_ylabel("mean path delay (ns)")

    for i in range(N):
        measurement_list = get_ptp_stat(server)

        for clk in ptp_clocks:
            clk.set_default_values()

            # parse incoming data from pmc
            iterator = iter(measurement_list)
            for c, n, o, p in zip(iterator, iterator, iterator, iterator):
                mac = c.split('-')[0]
                offset = re.sub('offsetFromMaster +', '', o)
                path_delay = re.sub('meanPathDelay +', '', p)

                if mac == clk.mac:
                    clk.put_values(float(offset), float(path_delay))

            # append buffers and plot
            clk.update_buffers()
            offset_graph.plot(range(len(clk.offset_buffer)),
                              clk.offset_buffer,
                              clk.color + "-",
                              label=clk.name + " offset")
            offset_graph.autoscale(True, 'both', True)
            path_delay_graph.plot(range(len(clk.mean_path_delay_buffer)),
                                  clk.mean_path_delay_buffer,
                                  clk.color + ".",
                                  label=clk.name)

        plt.pause(1)

    plt.show()
Ejemplo n.º 9
0
def startServer(port=51999):
    parser = Parser.TransDataParser()
    controler = Server.ControlServer(r"D:\develop\ptpweb\db\trans.db")
    controler.setParser(parser)
    controler.start(port)
Ejemplo n.º 10
0
class TestShapeSubelement(unittest.TestCase):
  def setUp(self):
    self.proxy = Server()
    (success, body) = self.proxy.put("shape/pet", {"name": {"type": "string"}})
    self.assertTrue(success)
  def tearDown(self):
    (success, body) = self.proxy.delete("shape/pet")
    self.assertTrue(success)
  def test_put_no_body(self):
    """Creation with no body should return an error"""
    (success, body) = self.proxy.put("shape/pet/color")
    self.assertFalse(success)
    (success, body) = self.proxy.put("shape/pet/color", {})
    self.assertFalse(success)
  def test_put_bad_fields(self):
    """Creation with bad fields"""
    (success, body) = self.proxy.put("shape/pet/color", {"type": "something"})
    self.assertFalse(success)
    (success, body) = self.proxy.put("shape/pet/color", {"type": 1})
    self.assertFalse(success)
  def test_put(self):
    """Successful creation"""
    (success, body) = self.proxy.put("shape/pet/color", {"type": "string"})
    self.assertTrue(success)
  def test_retrieve_bad(self):
    """Retrieval of bad content is a 404"""
    (success, body) = self.proxy.get("shape/pet/asdsdsafdf")
    self.assertFalse(success)
  def test_retrieve(self):
    """Retrieval works"""
    (success, body) = self.proxy.get("shape/pet/name")
    self.assertTrue(success)
    self.assertTrue('type' in body)
    self.assertEqual(body['type'], 'string')
  def test_delete_bad(self):
    """Delete of bad content is a 404"""
    (success, body) = self.proxy.delete("shape/pet/asdsdsafdf")
    self.assertFalse(success)
  def test_delete(self):
    """Correct use of delete"""
    (success, body) = self.proxy.put("shape/pet/color", {"type": "string"})
    self.assertTrue(success)
    (success, body) = self.proxy.get("shape/pet/color")
    self.assertTrue(success)

    (success, body) = self.proxy.delete("shape/pet/color")
    self.assertTrue(success)
    (success, body) = self.proxy.get("shape/pet/color")
    self.assertFalse(success)
Ejemplo n.º 11
0
 def setUp(self):
   self.proxy = Server()
Ejemplo n.º 12
0
'''
@author: jun
'''
from common import Master
from common import Parser
from common import Server

if __name__ == '__main__':
    master = Master.Master()
    parser = Parser.CmdParser()
    agent = Server.AgentServer()
    agent.setMaster(master)
    agent.setParser(parser)
    agent.start(51888)
    print 'exit.'