コード例 #1
0
 def testHBTFile(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     hbtFile = service.getElement(StorageServiceTest.testSpacePath).resolve(
         'HBTFileTest.hbt').toHBTFileElement()
     hbtFile.initialize([["Column 1", HBTFileElement.BYTE],
                         ["Column 2", HBTFileElement.SHORT],
                         ["Column 3", HBTFileElement.INT],
                         ["Column 4", HBTFileElement.LONG],
                         ["Column 5", HBTFileElement.FLOAT],
                         ["Column 6", HBTFileElement.DOUBLE]])
     hbtFile.appendRow([1, 2, 3, 4, 5, 6])
     hbtFile.appendRows([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6],
                         [1, 2, 3, 4, 5, 6], [1.1, 2.2, 3.3, 4.4, 5.5, 6.6],
                         [1.1, 2.2, 3.3, 4.4, 5.5, 6.6]])
     self.assertEqual(hbtFile.readRows(0, 1)[0], [1, 2, 3, 4, 5, 6])
     self.assertEqual(hbtFile.readRow(1), [1, 2, 3, 4, 5, 6])
     self.assertEqual(hbtFile.readRow(2), [1, 2, 3, 4, 5, 6])
     self.assertEqual(hbtFile.readRow(3), [1, 2, 3, 4, 5, 6])
     self.assertEqual(hbtFile.readRow(4), [1, 2, 3, 4, 5.5, 6.6])
     self.assertEqual(hbtFile.readRow(5), [1, 2, 3, 4, 5.5, 6.6])
     self.assertEqual(hbtFile.getColumnCount(), 6)
     self.assertEqual(hbtFile.getRowCount(), 6)
     self.assertEqual(hbtFile.getHeadNames(), [
         'Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5',
         'Column 6'
     ])
     mc.stop()
コード例 #2
0
 def testWrite(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     A1 = testRoot.resolve('_A1')
     A1.write(b"ABCDE", 10)
     self.assertEqual(
         A1.metaData(), {
             "Name": "_A1",
             "Path": "{}_A1".format(StorageServiceTest.testSpacePath),
             "Type": "Content",
             "Size": 36
         })
     self.assertEqual(A1.readAsString(0, 16), "1234567890ABCDEf")
     self.assertEqual(A1.readAllAsString(),
                      "1234567890ABCDEfghijklmnopqrstuvwxyz")
     A1.write(b"defghi", 39)
     self.assertEqual(
         A1.metaData(), {
             "Name": "_A1",
             "Path": "{}_A1".format(StorageServiceTest.testSpacePath),
             "Type": "Content",
             "Size": 45
         })
     self.assertEqual(A1.readAsString(35, 10), "z\0\0\0defghi")
     self.assertEqual(A1.readAsString(0, 16), "1234567890ABCDEf")
     mc.stop()
コード例 #3
0
    def testInvokeOtherClient(self):
        class Target:
            def v8(self): return "V8 great!"

            def v9(self): raise ProtocolException("V9 not good.")

            def v10(self): raise IOError("V10 have problems.")

            def v(self, i, b): return "OK"

        mc1 = Session((MessageTransportTest.addr, MessageTransportTest.port), Target(), name="T1-Benz")
        mc1.start()
        checker = Session.newSession((MessageTransportTest.addr, MessageTransportTest.port), None, "T1-Checher")
        benzChecker = checker.blockingInvoker(u"T1-Benz", 10)
        v8r = benzChecker.v8()
        self.assertEqual(v8r, "V8 great!")
        try:
            benzChecker.v9()
            self.assertTrue(False)
        except ProtocolException as e:
            self.assertEqual(e.__str__(), "V9 not good.")
        try:
            benzChecker.v10()
            self.assertTrue(False)
        except ProtocolException as e:
            self.assertEqual(e.__str__(), "V10 have problems.")
        self.assertEqual(benzChecker.v(1, False), "OK")
        try:
            benzChecker.v11()
            self.assertTrue(False)
        except ProtocolException as e:
            self.assertEqual(e.__str__(), "InvokeError: Command v11 not found.")
        mc1.stop()
        checker.stop()
コード例 #4
0
 def testList(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     a = service.listElements(StorageServiceTest.testSpacePath)
     self.assertEqual(a, ["_A1", "_A2", "a1", "a2", "a3", "a4", "a5"])
     mc.stop()
コード例 #5
0
 def testCreateDirectory(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     testRoot.resolve('a2').resolve('NewDir').createDirectory()
     self.assertEqual(testRoot.resolve('a2').listElements(), ["NewDir"])
     mc.stop()
コード例 #6
0
 def testRead(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     self.assertEqual(testRoot.resolve('/_A1').read(1, 10), b"234567890a")
     self.assertEqual(testRoot.resolve('/////_A1').read(30, 6), b"uvwxyz")
     self.assertEqual(testRoot.resolve('_A2').readAll(), b'0123456789')
     mc.stop()
コード例 #7
0
 def testElementNote(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     self.assertEqual(testRoot.readNote(), "")
     testRoot.writeNote("Test Note")
     self.assertEqual(testRoot.readNote(), "Test Note")
     mc.stop()
コード例 #8
0
 def testClientNameDuplicated(self):
     mc1 = Session((MessageTransportTest.addr, MessageTransportTest.port), None, name="T2-ClientDuplicated")
     mc1.start()
     mc2 = Session((MessageTransportTest.addr, MessageTransportTest.port), None, name="T2-ClientDuplicated")
     self.assertRaises(ProtocolException, lambda: mc2.start())
     mc1.stop()
     time.sleep(0.5)
     mc2.blockingInvoker().connect(u"T2-ClientDuplicated")
     mc2.stop()
コード例 #9
0
 def testCreateDirectory(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     service.createDirectory("{}a2/NewDir".format(
         StorageServiceTest.testSpacePath))
     self.assertEqual(
         service.listElements("{}a2".format(
             StorageServiceTest.testSpacePath)), ["NewDir"])
     mc.stop()
コード例 #10
0
 def testNote(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     self.assertEqual(service.readNote(StorageServiceTest.testSpacePath),
                      u"")
     service.writeNote(StorageServiceTest.testSpacePath, u"Test Note")
     self.assertEqual(service.readNote(StorageServiceTest.testSpacePath),
                      u"Test Note")
     mc.stop()
コード例 #11
0
 def testElementMetaData(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     self.assertEqual(
         testRoot.resolve("a1").metaData(), {
             "Name": "a1",
             "Path": "{}a1".format(StorageServiceTest.testSpacePath),
             "Type": "Collection"
         })
     mc.stop()
コード例 #12
0
 def testCreateFile(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     testRoot.resolve('NewFile').createFile()
     testRoot.resolve('a2/NewFile').createFile()
     self.assertEqual(
         testRoot.listElements(),
         ["NewFile", "_A1", "_A2", "a1", "a2", "a3", "a4", "a5"])
     self.assertEqual(testRoot.resolve('a2').listElements(), ["NewFile"])
     mc.stop()
コード例 #13
0
 def testMetaData(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     self.assertEqual(
         service.metaData(u"{}a1".format(StorageServiceTest.testSpacePath)),
         {
             u"Name": u"a1",
             u"Path": u"{}a1".format(StorageServiceTest.testSpacePath),
             u"Type": u"Collection"
         })
     mc.stop()
コード例 #14
0
 def testRemoteInvokeAndAsync(self):
     client1 = Session((MessageTransportTest.addr, MessageTransportTest.port), None)
     f1 = client1.start()
     invoker1 = client1.asynchronousInvoker()
     future1 = invoker1.co()
     latch1 = threading.Semaphore(0)
     future1.onComplete(lambda: latch1.release())
     latch1.acquire()
     self.assertTrue(future1.isDone())
     self.assertFalse(future1.isSuccess())
     self.assertEqual(future1.exception().description, "Method not found: co.")
     client1.stop()
コード例 #15
0
 def testRead(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     self.assertEqual(
         service.read(u"{}_A1".format(StorageServiceTest.testSpacePath), 1,
                      10), b"234567890a")
     self.assertEqual(
         service.read(u"{}_A1".format(StorageServiceTest.testSpacePath), 30,
                      6), b"uvwxyz")
     self.assertEqual(
         service.readAll(u"{}_A2".format(StorageServiceTest.testSpacePath)),
         b'0123456789')
     mc.stop()
コード例 #16
0
 def testElementDelete(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     self.assertEqual(testRoot.listElements(),
                      ["_A1", "_A2", "a1", "a2", "a3", "a4", "a5"])
     testRoot.resolve('a1').delete()
     self.assertEqual(testRoot.listElements(),
                      ["_A1", "_A2", "a2", "a3", "a4", "a5"])
     testRoot.resolve('_A2').delete()
     self.assertEqual(testRoot.listElements(),
                      ["_A1", "a2", "a3", "a4", "a5"])
     mc.stop()
コード例 #17
0
 def testCreateFile(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     service.createFile("{}NewFile".format(
         StorageServiceTest.testSpacePath))
     service.createFile("{}a2/NewFile".format(
         StorageServiceTest.testSpacePath))
     self.assertEqual(
         service.listElements(StorageServiceTest.testSpacePath),
         ["NewFile", "_A1", "_A2", "a1", "a2", "a3", "a4", "a5"])
     self.assertEqual(
         service.listElements("{}a2".format(
             StorageServiceTest.testSpacePath)), ["NewFile"])
     mc.stop()
コード例 #18
0
 def testDelete(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     self.assertEqual(
         service.listElements(StorageServiceTest.testSpacePath),
         ["_A1", "_A2", "a1", "a2", "a3", "a4", "a5"])
     service.delete("{}a1".format(StorageServiceTest.testSpacePath))
     self.assertEqual(
         service.listElements(StorageServiceTest.testSpacePath),
         ["_A1", "_A2", "a2", "a3", "a4", "a5"])
     service.delete("{}_A2".format(StorageServiceTest.testSpacePath))
     self.assertEqual(
         service.listElements(StorageServiceTest.testSpacePath),
         ["_A1", "a2", "a3", "a4", "a5"])
     mc.stop()
コード例 #19
0
 def testAppend(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     service.append(u"{}_A1".format(StorageServiceTest.testSpacePath),
                    b"ABCDE")
     self.assertEqual(
         service.metaData(u"{}_A1".format(
             StorageServiceTest.testSpacePath)), {
                 u"Name": u"_A1",
                 u"Path": u"{}_A1".format(StorageServiceTest.testSpacePath),
                 u"Type": u"Content",
                 u"Size": 41
             })
     self.assertEqual(
         service.read(u"{}_A1".format(StorageServiceTest.testSpacePath), 35,
                      6), b"zABCDE")
     mc.stop()
コード例 #20
0
 def setUp(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     storage = mc.blockingInvoker(u"StorageService")
     if storage.exists(u"", StorageServiceTest.testSpacePath):
         storage.delete(u"", StorageServiceTest.testSpacePath)
     storage.createDirectory(u"", StorageServiceTest.testSpacePath)
     for i in range(1, 6):
         storage.createDirectory(
             u"", u"{}a{}".format(StorageServiceTest.testSpacePath, i))
     storage.createFile(u"",
                        u"{}_A1".format(StorageServiceTest.testSpacePath))
     storage.createFile(u"",
                        u"{}_A2".format(StorageServiceTest.testSpacePath))
     storage.write(u"", u"{}_A1".format(StorageServiceTest.testSpacePath),
                   b"1234567890abcdefghijklmnopqrstuvwxyz", 0)
     storage.write(u"", u"{}_A2".format(StorageServiceTest.testSpacePath),
                   b"0123456789", 0)
     mc.stop()
コード例 #21
0
 def testWrite(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     service = StorageService(mc)
     service.write(u"{}_A1".format(StorageServiceTest.testSpacePath),
                   b"ABCDE", 10)
     self.assertEqual(
         service.metaData(u"{}_A1".format(
             StorageServiceTest.testSpacePath)), {
                 u"Name": u"_A1",
                 u"Path": u"{}_A1".format(StorageServiceTest.testSpacePath),
                 u"Type": u"Content",
                 u"Size": 36
             })
     self.assertEqual(
         service.readAsString(
             u"{}_A1".format(StorageServiceTest.testSpacePath), 0, 16),
         u"1234567890ABCDEf")
     self.assertEqual(
         service.readAllAsString(u"{}_A1".format(
             StorageServiceTest.testSpacePath)),
         u"1234567890ABCDEfghijklmnopqrstuvwxyz")
     service.write(u"{}_A1".format(StorageServiceTest.testSpacePath),
                   b"defghi", 39)
     self.assertEqual(
         service.metaData(u"{}_A1".format(
             StorageServiceTest.testSpacePath)), {
                 u"Name": u"_A1",
                 u"Path": u"{}_A1".format(StorageServiceTest.testSpacePath),
                 u"Type": u"Content",
                 u"Size": 45
             })
     self.assertEqual(
         service.readAsString(
             u"{}_A1".format(StorageServiceTest.testSpacePath), 35, 10),
         u"z\0\0\0defghi")
     self.assertEqual(
         service.readAsString(
             u"{}_A1".format(StorageServiceTest.testSpacePath), 0, 16),
         u"1234567890ABCDEf")
     mc.stop()
コード例 #22
0
 def testElementListMetaData(self):
     mc = Session((StorageServiceTest.addr, StorageServiceTest.port), None)
     mc.start()
     testRoot = StorageService(mc).getElement(
         StorageServiceTest.testSpacePath)
     elements = testRoot.listElements(True)
     expected = [["_A1", "_A1", "Content"], ["_A2", "_A2", "Content"],
                 ["a1", "a1", "Collection"], ["a2", "a2", "Collection"],
                 ["a3", "a3", "Collection"], ["a4", "a4", "Collection"],
                 ["a5", "a5", "Collection"]]
     self.assertEqual(len(elements), len(expected))
     for i in range(0, len(expected)):
         exp = expected[i]
         res = elements[i]
         self.assertEqual(res.get("Name"), exp[0])
         self.assertEqual(res.get("Path"),
                          StorageServiceTest.testSpacePath + exp[1])
         self.assertEqual(res.get("Type"), exp[2])
     self.assertEqual(elements[0].get("Size"), 36)
     self.assertEqual(elements[1].get("Size"), 10)
     mc.stop()
コード例 #23
0
 def testConnectionOfSession(self):
     # mc = Session((MessageTransportTest.addr, 10211), None)
     # self.assertRaises(ConnectionRefusedError, mc.start)
     mc = Session((MessageTransportTest.addr, MessageTransportTest.port), None)
     mc.start()
     mc.stop()
コード例 #24
0
import sys
from Pydra import Message, ProtocolException, Session
import socket
import threading
import time
from Services.Storage import StorageService, HBTFileElement
import random
import math

if __name__ == '__main__':
    mc = Session(("192.168.25.27", 20102), None)
    mc.start()
    service = StorageService(mc)
    hbtFile = service.getElement('HBTChartTest.hbt').toHBTFileElement()
    hbtFile.initialize([["Column 1", HBTFileElement.BYTE],
                        ["Column 2", HBTFileElement.SHORT],
                        ["Column 3", HBTFileElement.INT],
                        ["Column 4", HBTFileElement.LONG],
                        ["Column 5", HBTFileElement.FLOAT],
                        ["Column 6", HBTFileElement.DOUBLE]])
    for i in range(0, 10):
        d1 = i
        d2 = i * i
        d3 = -i
        d4 = i * i * i
        d5 = math.sin(i)
        d6 = math.exp(i)
        hbtFile.appendRow([d1, d2, d3, d4, d5, d6])
    mc.stop()