@Override
    public void initialize() throws EventHubException {
      if (curInitFaults < initFaultCount) {
        curInitFaults++;
        isFault = true;
        throw new EventHubException("Simulate fault in initialize()");
      }

      // after recovery, forget all the faults
      initFaultCount = 0;
      curInitFaults = 0;
      receiveFaultOffset = -1;
      isFault = false;
      isReceiveNull = false;
      curOffset = -1;

      if (lastMessage != null) {
        String tmpOffset = EventHubMessage.parseAmqpMessage(lastMessage).getOffset();
        // make sure filter is updated
        EventHubOffsetFilter tmpFilter = new EventHubOffsetFilter(tmpOffset);
        assertEquals(filter.getFilterString(), tmpFilter.getFilterString());
        // update curOffset
        curOffset = Long.parseLong(tmpOffset);
      }
    }
 @Test
 public void testSuccessfulPath() {
   TestableResilientEventHubReceiver receiver =
       new TestableResilientEventHubReceiver("connectionString", "name", "0", null, -1, null);
   receiver.receive(5000);
   receiver.receive(5000);
   String offset = EventHubMessage.parseAmqpMessage(receiver.receive(5000)).getOffset();
   assertEquals("2", offset);
 }
 @Test
 public void testRecoveryBadDelays() {
   TestableResilientEventHubReceiver receiver =
       new TestableResilientEventHubReceiver("connectionString", "name", "0", null, -1, null);
   receiver.setReceiveDelay(10);
   receiver.setReceiveNull(true);
   receiver.receive(5000); // receive null and delay is too short, recover
   receiver.receive(5000); // receive message 0
   String offset = EventHubMessage.parseAmqpMessage(receiver.receive(5000)).getOffset();
   assertEquals("1", offset);
 }
 @Test
 public void testRecovery() {
   TestableResilientEventHubReceiver receiver =
       new TestableResilientEventHubReceiver("connectionString", "name", "0", null, -1, null);
   receiver.setReceiveFaultOffset(1);
   receiver.receive(5000); // receive message 0
   receiver.receive(5000); // receive message 1, fault, then recovered
   receiver.receive(5000); // receive message 1
   String offset = EventHubMessage.parseAmqpMessage(receiver.receive(5000)).getOffset();
   assertEquals("2", offset);
 }