Ejemplo n.º 1
0
 def request(self, serviceID, dataProduct):
     reqPB = PythonTestPB()
     dataProduct.populateMessage(reqPB)
     reqPB.count += 1
     gdp = GravityDataProduct("ServiceTestResponse")
     gdp.data = reqPB
     return gdp
Ejemplo n.º 2
0
 def requestFilled(self, serviceID, requestID, response):
     testPB = PythonTestPB()
     response.populateMessage(testPB)
     Log.message("made it to request filled with request GDP ID = "+response.dataProductID +" and count = " + str(testPB.count))
     self.reqCount = testPB.count
     if self.reqCount < 5:
         gdp = GravityDataProduct("ServiceRequest")
         gdp.data = testPB
         self.gravityNode.request("ServiceTest", gdp, self)
Ejemplo n.º 3
0
    def request(self, serviceID, dataProduct):
        Log.message("made it to my request!")
        Log.message("for serviceID = "+serviceID)
        operands = MultiplicationOperandsPB()
        Log.message(str(type(operands)))
        dataProduct.populateMessage(operands)
        Log.message("have operands = "+str([operands.multiplicand_a, operands.multiplicand_b]))

        multResponse = MultiplicationResultPB()
        multResponse.result = operands.multiplicand_a * operands.multiplicand_b
        gdp = GravityDataProduct("MultResponse")
        gdp.setData(multResponse)
        Log.message("returning response with result = "+str(multResponse.result))
        return gdp
Ejemplo n.º 4
0
def testServiceTimeout(gravityNode):
    createTempService()
    
    myReq = MyRequestHandler(gravityNode)
    testPB = PythonTestPB()
    testPB.count = 0
    gdp = GravityDataProduct("ServiceRequest")
    gdp.data = testPB
    gravityNode.request("TempService", gdp, myReq, "", 2000)
    
    time.sleep(3)
    
    if myReq.timeoutCount == 0:
        return 1
    return 0
Ejemplo n.º 5
0
def testService(gravityNode):
    testProv = TestProvider()
    gravityNode.registerService("ServiceTest", gravity.TCP, testProv)

    myReq = MyRequestHandler(gravityNode)
    testPB = PythonTestPB()
    testPB.count = 0
    gdp = GravityDataProduct("ServiceRequest")
    gdp.data = testPB
    if gravityNode.request("jaskhf", gdp, 2) is not None:
        Log.critical("Request to non-existing service should return None")
        return 1
    gravityNode.request("ServiceTest", gdp, myReq)

    # test async
    loopCount = 0
    while myReq.reqCount < 5 and loopCount < 5:
        loopCount += 1
        time.sleep(1)

    if myReq.reqCount < 5:
        Log.critical(
            "Asynchronous Service Request failed, expected {} on counter, but was {}"
            .format(5, myReq.reqCount))
        return 1

    # test sync
    testPB.count = 0
    gdp.data = testPB
    responsePB = PythonTestPB()
    for i in range(0, 5):
        responseGDP = gravityNode.request("ServiceTest", gdp)
        responseGDP.populateMessage(responsePB)
        if responsePB.count != testPB.count + 1:
            Log.critical(
                "Incorrect return value, got {} but expected {}".format(
                    responsePB.count, testPB.count + 1))
            return 1
        else:
            Log.message(
                "Received return value {} on synchronous request".format(
                    responsePB.count))
        testPB.count += 1
        gdp.data = testPB

    return 0
Ejemplo n.º 6
0
def testPubSub(gravityNode):
    gravityNode.registerDataProduct("PubTest", gravity.TCP)
    mySub = MySubscriber()
    gravityNode.subscribe("PubTest", mySub)
    
    pubPB = PythonTestPB()
    pubPB.count = 0
    pubPB.message = ""
    gdp = GravityDataProduct("PubTest")
    while mySub.subCount < 5 and pubPB.count < 10:
        pubPB.count += 1
        gdp.setData(pubPB)
        gravityNode.publish(gdp)
        time.sleep(.1)
        
    if mySub.subCount < 5:
        Log.critical("Pub/Sub failed")
        return 1
    return 0
Ejemplo n.º 7
0
def testPubSub(gravityNode):
    gravityNode.registerDataProduct("PubTest", gravity.TCP)
    mySub = MySubscriber()
    gravityNode.subscribe("PubTest", mySub)
    Log.warning("ref count = {}".format(sys.getrefcount(mySub)))
    if sys.getrefcount(mySub) != 2 + 1:  # +1 for temp reference in call
        raise AssertionError(
            "Ref count didn't increment properly on subscribe")

    pubPB = PythonTestPB()
    pubPB.count = 0
    pubPB.message = ""
    gdp = GravityDataProduct("PubTest")
    while mySub.subCount < 5 and pubPB.count < 10:
        pubPB.count += 1
        gdp.data = pubPB
        gravityNode.publish(gdp)
        time.sleep(.1)

    if mySub.subCount < 5:
        Log.critical("Pub/Sub failed")
        return 1
    # make sure ref count doesn't change when unsubscribe called with params we didn't use for subscribe
    gravityNode.unsubscribe("PubTest", mySub, "aFilterNotUsedAbove")
    if sys.getrefcount(mySub) != 2 + 1:  # +1 for temp reference in call
        raise AssertionError(
            "Ref count didn't decrement properly on unsubscribe with different params"
        )
    # make sure ref count decrements when unsubscribe with same params
    gravityNode.unsubscribe("PubTest", mySub)
    if sys.getrefcount(mySub) != 1 + 1:  # +1 for temp reference in call
        raise AssertionError(
            "Ref count didn't decrement properly on unsubscribe with same different params"
        )
    # make sure ref count doesn't dec a second time
    gravityNode.unsubscribe("PubTest", mySub)
    if sys.getrefcount(mySub) != 1 + 1:  # +1 for temp reference in call
        raise AssertionError(
            "Ref count didn't decrement properly on second unsubscribe call")

    return 0
Ejemplo n.º 8
0
if len(sys.argv) > 1:
    anomaly_point = int(sys.argv[1])

gn = GravityNode()
while gn.init(name) != gravity.SUCCESS:
    Log.warning("failed to init, retrying...")
    time.sleep(1)

inc1 = gn.getFloatParam("increment1", 0.05)
inc2 = gn.getFloatParam("increment2", 0.05)
channel = gn.getStringParam("subscription_name", "channel")
gn.registerDataProduct(channel, gravity.TCP)

pointPB1 = DataPointPB()
pointPB1.name = "Pub1"
gdp1 = GravityDataProduct(channel)

pointPB2 = DataPointPB()
pointPB2.name = "Pub2"
gdp2 = GravityDataProduct(channel)

sample_num = 0
p1 = p2 = 0
while True:
    pointPB1.value = np.sin(p1)
    p1 += inc1
    pointPB1.timestamp = int(datetime.now().timestamp() * 1000000)
    gdp1.data = pointPB1
    gn.publish(gdp1)

    pointPB2.value = np.cos(p2)
Ejemplo n.º 9
0
        return gdp


gn = GravityNode()
while gn.init("PyRequest") != gravity.SUCCESS:
    Log.warning("failed to init, retrying...")
    time.sleep(1)

requestorProvider = MyRequestorProvider()
gn.registerService("Multiplication", gravity.TCP, requestorProvider)

# Async request
operands = MultiplicationOperandsPB()
operands.multiplicand_a = 3
operands.multiplicand_b = 4
gdp = GravityDataProduct("MultRequest")
gdp.data = operands
gn.request("Multiplication", gdp, requestorProvider)

while not done:
    time.sleep(1)

# Sync request
operands.multiplicand_a = 5
operands.multiplicand_b = 6
gdp.data = operands
gdpResp = gn.request("Multiplication", gdp)
Log.message("received GDP response")
multResponse = MultiplicationResultPB()
gdpResp.populateMessage(multResponse)
Log.message("made it to request filled with request GDP ID = " +
Ejemplo n.º 10
0
    # on each parent.
    def __init__(self):
        GravitySubscriber.__init__(self)

    def subscriptionFilled(self, dataProducts):
        counterPB = BasicCounterDataProductPB()
        for gdp in dataProducts:
            gdp.populateMessage(counterPB)
            Log.message("received counter with value = " +
                        str(counterPB.count))


mySub = MySubscriber()

gn = GravityNode()
while gn.init("PyPub") != gravity.SUCCESS:
    Log.warning("failed to init, retrying...")
    time.sleep(1)
gn.registerDataProduct("PythonGDP", gravity.TCP)
gn.subscribe("PythonGDP", mySub)

counterPB = BasicCounterDataProductPB()
gdp = GravityDataProduct("PythonGDP")
for i in range(1, 50):
    counterPB.count = i
    gdp.data = counterPB
    gn.publish(gdp)
    time.sleep(1)

gn.waitForExit()
Ejemplo n.º 11
0
        Log.message("returning response with result = "+str(multResponse.result))
        return gdp

gn = GravityNode()
while gn.init("PyRequest") != gravity.SUCCESS:
    Log.warning("failed to init, retrying...")
    time.sleep(1)

myProv = MyProvider()
gn.registerService("Multiplication", gravity.TCP, myProv)

# Async request
operands = MultiplicationOperandsPB()
operands.multiplicand_a = 3
operands.multiplicand_b = 4
gdp = GravityDataProduct("MultRequest")
gdp.setData(operands)
myReq = MyRequestor()
gn.request("Multiplication", gdp, myReq)

while not done:
    time.sleep(1)

# Sync request
operands.multiplicand_a = 5
operands.multiplicand_b = 6
gdp.setData(operands)
gdpResp = gn.request("Multiplication", gdp)
Log.message("received GDP response")
multResponse = MultiplicationResultPB()
gdpResp.populateMessage(multResponse)