// @Test
  public void rawEpochStealing() throws Exception {
    RealEventHubUtilities utils = new RealEventHubUtilities();
    utils.setup(-1);

    int clientSerialNumber = 0;
    while (true) {
      Thread[] blah = new Thread[Thread.activeCount() + 10];
      int actual = Thread.enumerate(blah);
      if (actual >= blah.length) {
        System.out.println("Lost some threads");
      }
      int parkedCount = 0;
      String selectingList = "";
      boolean display = true;
      for (int i = 0; i < actual; i++) {
        display = true;
        StackTraceElement[] bloo = blah[i].getStackTrace();
        String show = "nostack";
        if (bloo.length > 0) {
          show = bloo[0].getClassName() + "." + bloo[0].getMethodName();
          if (show.compareTo("sun.misc.Unsafe.park") == 0) {
            parkedCount++;
            display = false;
          } else if (show.compareTo("sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0") == 0) {
            selectingList += (" " + blah[i].getId());
            display = false;
          }
        }
        if (display) {
          System.out.print(" " + blah[i].getId() + ":" + show);
        }
      }
      System.out.println("\nParked: " + parkedCount + "  SELECTING: " + selectingList);

      System.out.println("Client " + clientSerialNumber + " starting");
      EventHubClient client =
          EventHubClient.createFromConnectionStringSync(utils.getConnectionString().toString());
      PartitionReceiver receiver =
          client
              .createEpochReceiver(
                  utils.getConsumerGroup(), "0", PartitionReceiver.START_OF_STREAM, 1)
              .get();

      boolean useReceiveHandler = false;

      if (useReceiveHandler) {
        Blah b = new Blah(clientSerialNumber++, receiver, client);
        receiver.setReceiveHandler(b).get();
        // wait for messages to start flowing
        b.waitForReceivedMessages().get();
      } else {
        receiver.receiveSync(1);
        System.out.println("Received a message");
      }

      // Enable these lines to avoid overlap
      /* */
      try {
        System.out.println("Non-overlap close of PartitionReceiver");
        if (useReceiveHandler) {
          receiver.setReceiveHandler(null).get();
        }
        receiver.close().get();
      } catch (InterruptedException | ExecutionException e) {
        System.out.println(
            "Client "
                + clientSerialNumber
                + " failed while closing PartitionReceiver: "
                + e.toString());
      }
      try {
        System.out.println("Non-overlap close of EventHubClient");
        client.close().get();
      } catch (InterruptedException | ExecutionException e) {
        System.out.println(
            "Client "
                + clientSerialNumber
                + " failed while closing EventHubClient: "
                + e.toString());
      }
      System.out.println("Client " + clientSerialNumber + " closed");
      /* */

      System.out.println("Threads: " + Thread.activeCount());
    }
  }
Exemplo n.º 2
0
 /**
  * This method is here to try and isolate the Azure related code as the PartitionReceiver cannot
  * be mocked with PowerMock due to it being final. Unfortunately it extends a base class and does
  * not implement an interface so even if we create a MockPartitionReciver, it will not work as the
  * two classes are orthogonal.
  *
  * @param context - The processcontext for this processor
  * @param partitionId - The partition ID to retrieve a receiver by.
  * @return - Returns the events received from the EventBus.
  * @throws ProcessException -- If any exception is encountered, receiving events it is wrapped in
  *     a ProcessException and then that exception is thrown.
  */
 protected Iterable<EventData> receiveEvents(
     final ProcessContext context, final String partitionId) throws ProcessException {
   final PartitionReceiver receiver;
   try {
     receiver = getReceiver(context, partitionId);
     return receiver.receive(100).get();
   } catch (final IOException
       | ServiceBusException
       | ExecutionException
       | InterruptedException e) {
     throw new ProcessException(e);
   }
 }
Exemplo n.º 3
0
  @OnStopped
  public void tearDown() throws ProcessException {
    for (final PartitionReceiver receiver : partitionToReceiverMap.values()) {
      if (null != receiver) {
        receiver.close();
      }
    }

    partitionToReceiverMap.clear();
    try {
      if (null != eventHubClient) {
        eventHubClient.closeSync();
      }
    } catch (final ServiceBusException e) {
      throw new ProcessException(e);
    }
  }