Ejemplo n.º 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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
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()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()
Ejemplo n.º 9
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()
Ejemplo n.º 10
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()
Ejemplo n.º 11
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()
Ejemplo n.º 12
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()
Ejemplo n.º 13
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()
Ejemplo n.º 14
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()
Ejemplo n.º 15
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()
Ejemplo n.º 16
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()
Ejemplo n.º 17
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()
Ejemplo n.º 18
0
__author__ = 'Hwaipy'

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()
Ejemplo n.º 19
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()