Examples of RpcResponseCallback


Examples of org.apache.spark.network.client.RpcResponseCallback

    doAnswer(new Answer<Void>() {
      @Override
      public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
        BlockTransferMessage message = BlockTransferMessage.Decoder.fromByteArray(
          (byte[]) invocationOnMock.getArguments()[0]);
        RpcResponseCallback callback = (RpcResponseCallback) invocationOnMock.getArguments()[1];
        callback.onSuccess(new StreamHandle(123, blocks.size()).toByteArray());
        assertEquals(new OpenBlocks("app-id", "exec-id", blockIds), message);
        return null;
      }
    }).when(client).sendRpc((byte[]) any(), (RpcResponseCallback) any());

    // Respond to each chunk request with a single buffer from our blocks array.
    final AtomicInteger expectedChunkIndex = new AtomicInteger(0);
    final Iterator<ManagedBuffer> blockIterator = blocks.values().iterator();
    doAnswer(new Answer<Void>() {
      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        try {
          long streamId = (Long) invocation.getArguments()[0];
          int myChunkIndex = (Integer) invocation.getArguments()[1];
          assertEquals(123, streamId);
          assertEquals(expectedChunkIndex.getAndIncrement(), myChunkIndex);

          ChunkReceivedCallback callback = (ChunkReceivedCallback) invocation.getArguments()[2];
          ManagedBuffer result = blockIterator.next();
          if (result != null) {
            callback.onSuccess(myChunkIndex, result);
          } else {
            callback.onFailure(myChunkIndex, new RuntimeException("Failed " + myChunkIndex));
          }
        } catch (Exception e) {
          e.printStackTrace();
          fail("Unexpected failure");
        }
View Full Code Here

Examples of org.apache.spark.network.client.RpcResponseCallback

    handler = new ExternalShuffleBlockHandler(streamManager, blockManager);
  }

  @Test
  public void testRegisterExecutor() {
    RpcResponseCallback callback = mock(RpcResponseCallback.class);

    ExecutorShuffleInfo config = new ExecutorShuffleInfo(new String[] {"/a", "/b"}, 16, "sort");
    byte[] registerMessage = new RegisterExecutor("app0", "exec1", config).toByteArray();
    handler.receive(client, registerMessage, callback);
    verify(blockManager, times(1)).registerExecutor("app0", "exec1", config);
View Full Code Here

Examples of org.apache.spark.network.client.RpcResponseCallback

  }

  @SuppressWarnings("unchecked")
  @Test
  public void testOpenShuffleBlocks() {
    RpcResponseCallback callback = mock(RpcResponseCallback.class);

    ManagedBuffer block0Marker = new NioManagedBuffer(ByteBuffer.wrap(new byte[3]));
    ManagedBuffer block1Marker = new NioManagedBuffer(ByteBuffer.wrap(new byte[7]));
    when(blockManager.getBlockData("app0", "exec1", "b0")).thenReturn(block0Marker);
    when(blockManager.getBlockData("app0", "exec1", "b1")).thenReturn(block1Marker);
View Full Code Here

Examples of org.apache.spark.network.client.RpcResponseCallback

    assertFalse(buffers.hasNext());
  }

  @Test
  public void testBadMessages() {
    RpcResponseCallback callback = mock(RpcResponseCallback.class);

    byte[] unserializableMsg = new byte[] { 0x12, 0x34, 0x56 };
    try {
      handler.receive(client, unserializableMsg, callback);
      fail("Should have thrown");
View Full Code Here

Examples of org.apache.spark.network.client.RpcResponseCallback

  }

  @Test
  public void handleSuccessfulRPC() {
    TransportResponseHandler handler = new TransportResponseHandler(new LocalChannel());
    RpcResponseCallback callback = mock(RpcResponseCallback.class);
    handler.addRpcRequest(12345, callback);
    assertEquals(1, handler.numOutstandingRequests());

    handler.handle(new RpcResponse(54321, new byte[7])); // should be ignored
    assertEquals(1, handler.numOutstandingRequests());
View Full Code Here

Examples of org.apache.spark.network.client.RpcResponseCallback

  }

  @Test
  public void handleFailedRPC() {
    TransportResponseHandler handler = new TransportResponseHandler(new LocalChannel());
    RpcResponseCallback callback = mock(RpcResponseCallback.class);
    handler.addRpcRequest(12345, callback);
    assertEquals(1, handler.numOutstandingRequests());

    handler.handle(new RpcFailure(54321, "uh-oh!")); // should be ignored
    assertEquals(1, handler.numOutstandingRequests());
View Full Code Here

Examples of org.apache.spark.network.client.RpcResponseCallback

  public void start() {
    if (blockIds.length == 0) {
      throw new IllegalArgumentException("Zero-sized blockIds array");
    }

    client.sendRpc(openMessage.toByteArray(), new RpcResponseCallback() {
      @Override
      public void onSuccess(byte[] response) {
        try {
          streamHandle = (StreamHandle) BlockTransferMessage.Decoder.fromByteArray(response);
          logger.trace("Successfully opened blocks {}, preparing to fetch chunks.", streamHandle);
View Full Code Here

Examples of org.apache.spark.network.client.RpcResponseCallback

    final RpcResult res = new RpcResult();
    res.successMessages = Collections.synchronizedSet(new HashSet<String>());
    res.errorMessages = Collections.synchronizedSet(new HashSet<String>());

    RpcResponseCallback callback = new RpcResponseCallback() {
      @Override
      public void onSuccess(byte[] message) {
        res.successMessages.add(new String(message, Charsets.UTF_8));
        sem.release();
      }
View Full Code Here

Examples of org.apache.spark.network.client.RpcResponseCallback

    respond(new ChunkFetchSuccess(req.streamChunkId, buf));
  }

  private void processRpcRequest(final RpcRequest req) {
    try {
      rpcHandler.receive(reverseClient, req.message, new RpcResponseCallback() {
        @Override
        public void onSuccess(byte[] response) {
          respond(new RpcResponse(req.requestId, response));
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.