// @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()); } }