public void testSendMessage() throws Exception {

    final Address address = channels[1].getAddress();
    Message message = new Message(address);

    // Validate normal dispatchers
    Object response = dispatchers[0].sendMessage(message, RequestOptions.SYNC());

    Assert.assertEquals(response, "dispatcher[1]");

    // Validate muxed dispatchers
    for (int j = 0; j < muxDispatchers[0].length; ++j) {

      response = muxDispatchers[0][j].sendMessage(message, RequestOptions.SYNC());

      Assert.assertEquals(response, "muxDispatcher[1][" + j + "]");
    }

    // Filter testing is disabled for now pending filter improvements in JGroups 3

    //        // Validate muxed rpc dispatchers w/filter
    //
    //        RspFilter filter = new RspFilter() {
    //
    //            @Override
    //            public boolean isAcceptable(Object response, Address sender) {
    //                return !sender.equals(address);
    //            }
    //
    //            @Override
    //            public boolean needMoreResponses() {
    //                return true;
    //            }
    //        };
    //
    //        response = muxDispatchers[0][0].callRemoteMethod(address, method,
    // RequestOptions.SYNC.setRspFilter(filter));
    //
    //        Assert.assertNull(address);
    //
    //        // Validate stopped mux dispatcher response is auto-filtered
    //        muxDispatchers[1][0].stop();
    //
    //        response = muxDispatchers[0][0].callRemoteMethod(address, method,
    // RequestOptions.SYNC.setRspFilter(null));
    //
    //        Assert.assertNull(address);
    //
    //        // Validate restarted mux dispatcher functions normally
    //        muxDispatchers[1][0].start();
    //
    //        response = muxDispatchers[0][0].callRemoteMethod(address, method,
    // RequestOptions.SYNC.setRspFilter(null));
    //
    //        Assert.assertEquals(response, "muxDispatcher[1][0]");
  }
Esempio n. 2
0
  /**
   * If the coordinator of the lock locks the lock and then send a message, the receiver will wait
   * for ever in tryLock. However, castMessage will return after a while because of the default
   * settings of RequestOptions.SYNC().
   */
  public void testCoordSendFirst() throws Exception {
    System.out.println("Running testCoordSendFirst");

    // ===========================================================================
    if (lock_a.tryLock()) {
      try {
        System.out.println("A aquired the lock, about to send message to B");
        String rsp =
            disp_a.sendMessage(
                new Message(b.getAddress(), "bla"), RequestOptions.SYNC().setTimeout(60000));
        if (rsp == null) {
          System.err.println("ERROR: didn't return correctly");
          Assert.fail("Didn't return correctly");
        } else System.out.println("Returned: " + rsp);

      } finally {
        lock_a.unlock();
      }
    } else {
      Assert.fail("The lock was already locked");
      System.out.println("A failed to aquire the lock");
    }
    // ===========================================================================

    System.out.println();
  }
Esempio n. 3
0
 void setReadPercentage() throws Exception {
   double tmp = Util.readDoubleFromStdin("Read percentage: ");
   if (tmp < 0 || tmp > 1.0) {
     System.err.println("read percentage must be >= 0 or <= 1.0");
     return;
   }
   disp.callRemoteMethods(null, new MethodCall(SET_READ_PERCENTAGE, tmp), RequestOptions.SYNC());
 }
 public void testMethodReturningException() throws Exception {
   Object retval =
       disp.callRemoteMethod(
           channel.getAddress(), "returnException", null, null, RequestOptions.SYNC());
   System.out.println("retval: " + retval);
   assertNotNull(retval);
   assert retval instanceof IllegalArgumentException;
 }
 // @Test(expectedExceptions=IllegalArgumentException.class)
 public void testMethodWithException2() throws Exception {
   try {
     disp.callRemoteMethod(channel.getAddress(), "foobar", null, null, RequestOptions.SYNC());
   } catch (Throwable t) {
     System.out.println("t = " + t);
     assert t instanceof InvocationTargetException;
     assert t.getCause() instanceof IllegalArgumentException;
   }
 }
 @Test(expectedExceptions = TimeoutException.class)
 public void testMethodWithExceptionWithoutWrapping() throws Exception {
   disp.wrapExceptions(false);
   try {
     disp.callRemoteMethod(channel.getAddress(), "bar", null, null, RequestOptions.SYNC());
   } finally {
     disp.wrapExceptions(true);
   }
 }
Esempio n. 7
0
 void setAnycastCount() throws Exception {
   int tmp = Util.readIntFromStdin("Anycast count: ");
   View view = channel.getView();
   if (tmp > view.size()) {
     System.err.println(
         "anycast count must be smaller or equal to the view size (" + view + ")\n");
     return;
   }
   disp.callRemoteMethods(null, new MethodCall(SET_ANYCAST_COUNT, tmp), RequestOptions.SYNC());
 }
 // @Test(expectedExceptions=InvocationTargetException.class)
 public void testMethodWithException() throws Exception {
   try {
     disp.callRemoteMethod(channel.getAddress(), "bar", null, null, RequestOptions.SYNC());
     assert false : "method should have thrown an exception";
   } catch (Exception ex) {
     assert ex instanceof InvocationTargetException;
     Throwable cause = ex.getCause();
     assert cause instanceof TimeoutException;
   }
 }
  public void testCastMessage() throws Exception {

    Message message = new Message();

    // Validate normal dispatchers
    Map<Address, Rsp<Object>> responses =
        dispatchers[0].castMessage(null, message, RequestOptions.SYNC());

    Assert.assertEquals(responses.size(), 2);

    for (int i = 0; i < dispatchers.length; ++i) {

      verifyResponse(responses, channels[i], "dispatcher[" + i + "]");
    }

    // Validate muxed dispatchers
    for (int j = 0; j < muxDispatchers[0].length; ++j) {

      responses = muxDispatchers[0][j].castMessage(null, message, RequestOptions.SYNC());

      Assert.assertEquals(responses.size(), 2);

      for (int i = 0; i < dispatchers.length; ++i) {

        verifyResponse(responses, channels[i], "muxDispatcher[" + i + "][" + j + "]");
      }
    }

    final Address address = channels[0].getAddress();

    RspFilter filter =
        new RspFilter() {

          public boolean isAcceptable(Object response, Address sender) {
            return !sender.equals(address);
          }

          public boolean needMoreResponses() {
            return true;
          }
        };

    // Validate muxed rpc dispatchers w/filter
    responses =
        muxDispatchers[0][0].castMessage(null, message, RequestOptions.SYNC().setRspFilter(filter));

    Assert.assertEquals(responses.size(), 2);
    verifyResponse(responses, channels[0], null);
    verifyResponse(responses, channels[1], "muxDispatcher[1][0]");

    muxDispatchers[1][0].stop();

    // Validate stopped mux dispatcher response is auto-filtered
    responses =
        muxDispatchers[0][0].castMessage(null, message, RequestOptions.SYNC().setRspFilter(null));

    Assert.assertEquals(responses.size(), 2);
    verifyResponse(responses, channels[0], "muxDispatcher[0][0]");
    verifyResponse(responses, channels[1], null);

    // Validate stopped mux dispatcher response is auto-filtered and custom filter is applied
    responses =
        muxDispatchers[0][0].castMessage(null, message, RequestOptions.SYNC().setRspFilter(filter));

    Assert.assertEquals(responses.size(), 2);
    verifyResponse(responses, channels[0], null);
    verifyResponse(responses, channels[1], null);

    muxDispatchers[1][0].start();

    // Validate restarted mux dispatcher functions normally
    responses =
        muxDispatchers[0][0].castMessage(null, message, RequestOptions.SYNC().setRspFilter(null));

    Assert.assertEquals(responses.size(), 2);
    verifyResponse(responses, channels[0], "muxDispatcher[0][0]");
    verifyResponse(responses, channels[1], "muxDispatcher[1][0]");
  }
Esempio n. 10
0
 void setMessageSize() throws Exception {
   int tmp = Util.readIntFromStdin("Message size: ");
   disp.callRemoteMethods(null, new MethodCall(SET_MSG_SIZE, tmp), RequestOptions.SYNC());
 }
Esempio n. 11
0
 void setNumMessages() throws Exception {
   int tmp = Util.readIntFromStdin("Number of RPCs: ");
   disp.callRemoteMethods(null, new MethodCall(SET_NUM_MSGS, tmp), RequestOptions.SYNC());
 }
Esempio n. 12
0
 void setSenderThreads() throws Exception {
   int threads = Util.readIntFromStdin("Number of sender threads: ");
   disp.callRemoteMethods(null, new MethodCall(SET_NUM_THREADS, threads), RequestOptions.SYNC());
 }
Esempio n. 13
0
  public void eventLoop() throws Throwable {
    int c;

    while (true) {
      c =
          Util.keyPress(
              "[1] Send msgs [2] Print view [3] Print conns "
                  + "[4] Trash conn [5] Trash all conns"
                  + "\n[6] Set sender threads ("
                  + num_threads
                  + ") [7] Set num msgs ("
                  + num_msgs
                  + ") "
                  + "[8] Set msg size ("
                  + Util.printBytes(msg_size)
                  + ")"
                  + " [9] Set anycast count ("
                  + anycast_count
                  + ")"
                  + "\n[o] Toggle OOB ("
                  + oob
                  + ") [s] Toggle sync ("
                  + sync
                  + ") [r] Set read percentage ("
                  + f.format(read_percentage)
                  + ")"
                  + "\n[q] Quit\n");
      switch (c) {
        case -1:
          break;
        case '1':
          try {
            startBenchmark();
          } catch (Throwable t) {
            System.err.println(t);
          }
          break;
        case '2':
          printView();
          break;
        case '3':
          printConnections();
          break;
        case '4':
          removeConnection();
          break;
        case '5':
          removeAllConnections();
          break;
        case '6':
          setSenderThreads();
          break;
        case '7':
          setNumMessages();
          break;
        case '8':
          setMessageSize();
          break;
        case '9':
          setAnycastCount();
          break;
        case 'o':
          boolean new_value = !oob;
          disp.callRemoteMethods(null, new MethodCall(SET_OOB, new_value), RequestOptions.SYNC());
          break;
        case 's':
          boolean new_val = !sync;
          disp.callRemoteMethods(null, new MethodCall(SET_SYNC, new_val), RequestOptions.SYNC());
          break;
        case 'r':
          setReadPercentage();
          break;
        case 'q':
          channel.close();
          return;
        case '\n':
        case '\r':
          break;
        default:
          break;
      }
    }
  }