Package org.commoncrawl.rpc

Examples of org.commoncrawl.rpc.UnitTestStruct1


     * int intType = 1; long longType = 2; ustring stringType = 3;
     * vector<ustring> vectorOfStrings = 4; }
     *
     * }
     * */
    UnitTestStruct1 inputStruct = new UnitTestStruct1();
    UnitTestStruct1 outputStruct = new UnitTestStruct1();

    inputStruct.setIntType(10);
    inputStruct.setLongType(20);
    inputStruct.setStringType("one");
    inputStruct.setFieldDirty(UnitTestStruct1.Field_VECTOROFSTRINGS);
    inputStruct.getVectorOfStrings().add(new TextBytes("one"));
    inputStruct.getVectorOfStrings().add(new TextBytes("two"));
    inputStruct.getVectorOfStrings().add(new TextBytes("three"));

    OutgoingMessageContext<UnitTestStruct1, UnitTestStruct1> request = new OutgoingMessageContext<UnitTestStruct1, UnitTestStruct1>(
        "testService", "testMethod", inputStruct, outputStruct, null);

    request.setRequestId(10);
   
    encoder.encodeRequest(request);

    // stream the data in one byte at a time
    while (output.available() != 0) {

      ByteBuffer buffer = output.read();

      input.getWriteBuf().put(buffer.get());
      input.flush();
      if (buffer.remaining() != 0) {
        output.putBack(buffer);
      }
      // validate that the decoder doesn't return the frame until the
      // appropriate time
      if (output.available() != 0)
        assertTrue(decoder.getNextRequestFrame() == null);
    }

    RPCFrame.IncomingFrame incomingFrame = decoder.getNextRequestFrame();
    // at this point the frame should be available ...
    assertTrue(incomingFrame != null);

    // check frame header values ...
    assertTrue(incomingFrame._service.equals("testService"));
    assertTrue(incomingFrame._method.equals("testMethod"));
    assertTrue(incomingFrame._requestId == 10);
    assertTrue(incomingFrame._type == RPCFrame.MSG_TYPE.REQUEST.ordinal());

    // deserialize the input struct
    outputStruct.deserialize(new DataInputStream(incomingFrame._payload),
        new BinaryProtocol());

    // validate values of deserialized struct against original (input) struct

    assertTrue(outputStruct.getIntType() == inputStruct.getIntType());
    assertTrue(outputStruct.getLongType() == inputStruct.getLongType());
    assertTrue(outputStruct.getStringType().equals(inputStruct.getStringType()));
    assertTrue(outputStruct.getVectorOfStrings().size() == inputStruct
        .getVectorOfStrings().size());
    assertTrue(outputStruct.getVectorOfStrings().get(0).equals(
        inputStruct.getVectorOfStrings().get(0)));
    assertTrue(outputStruct.getVectorOfStrings().get(1).equals(
        inputStruct.getVectorOfStrings().get(1)));
    assertTrue(outputStruct.getVectorOfStrings().get(2).equals(
        inputStruct.getVectorOfStrings().get(2)));

  }
View Full Code Here


    clientChannel.open();
   
    AsyncStub stub = new AsyncStub(clientChannel,eventLoop);

    UnitTestStruct1 input = new UnitTestStruct1();

    for (int i = 0; i < 1000; ++i) {

      input.setStringType("hello" + Integer.toString(i));
      input.setIntType(i);

      System.out.println("Sending Request:" + i);
      stub.hello(input, new Callback<UnitTestStruct1, UnitTestStruct1>() {

        public void requestComplete(
View Full Code Here

              else
                localChannel = localActor.createChannel(sourceExecutor);
             
              RPCTestService.AsyncStub stub = new RPCTestService.AsyncStub(localChannel,outerEventLoop);
             
              UnitTestStruct1 struct1 = new UnitTestStruct1();
              struct1.setIntType(i);
              System.out.println("Sending Request:" + struct1.getIntType() + " From Thread:" + Thread.currentThread().getId());
              stub.hello(struct1,new Callback<UnitTestStruct1, UnitTestStruct1>() {
                public void requestComplete(org.commoncrawl.rpc.OutgoingMessageContext<UnitTestStruct1,UnitTestStruct1> request) {
                  System.out.println("Received Request Complete for Request:" + request.getRequestId() + " Thread:" + Thread.currentThread().getId());
                 
                  if (request.getOutput().getLongType() == 1) {
View Full Code Here

TOP

Related Classes of org.commoncrawl.rpc.UnitTestStruct1

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.