Esempio n. 1
0
  @Test
  public void testUpdateDriverStatusRetriesExhaust() throws LensException {
    Configuration conf = new Configuration();
    List<LensDriver> drivers = MockQueryContext.getDrivers(conf);
    MockQueryContext ctx =
        new MockQueryContext("simulate status failure", new LensConf(), conf, drivers);
    BackOffRetryHandler waitingHandler =
        new FibonacciExponentialBackOffRetryHandler(10, 10000, 1000);
    BackOffRetryHandler noWaitingHandler = new FibonacciExponentialBackOffRetryHandler(10, 0, 0);
    for (int i = 0; i < 18; i++) {
      if (i % 2 == 0) {
        ctx.updateDriverStatus(noWaitingHandler);
      } else {
        ctx.updateDriverStatus(waitingHandler);
      }
    }

    // retries should be exhausted and update should fail.
    try {
      ctx.updateDriverStatus(noWaitingHandler);
      fail("Should throw exception");
    } catch (LensException e) {
      // pass
    }
  }
Esempio n. 2
0
  @Test
  public void testUpdateDriverStatusRetries() throws LensException {
    Configuration conf = new Configuration();
    List<LensDriver> drivers = MockQueryContext.getDrivers(conf);
    MockDriver selectedDriver = (MockDriver) drivers.iterator().next();
    MockQueryContext ctx =
        new MockQueryContext("simulate status retries", new LensConf(), conf, drivers);
    BackOffRetryHandler waitingHandler =
        new FibonacciExponentialBackOffRetryHandler(10, 10000, 1000);
    BackOffRetryHandler noWaitingHandler = new FibonacciExponentialBackOffRetryHandler(10, 0, 0);
    // do first update
    ctx.updateDriverStatus(waitingHandler);
    assertEquals(selectedDriver.getUpdateCount(), 1);

    // try another update, update should be skipped
    ctx.updateDriverStatus(waitingHandler);
    assertEquals(selectedDriver.getUpdateCount(), 1);

    // update without delays
    ctx.updateDriverStatus(noWaitingHandler);
    ctx.updateDriverStatus(noWaitingHandler);
    ctx.updateDriverStatus(noWaitingHandler);
    ctx.updateDriverStatus(noWaitingHandler);
    assertEquals(selectedDriver.getUpdateCount(), 5);

    // update with delays, update should be skipped
    ctx.updateDriverStatus(waitingHandler);
    assertEquals(selectedDriver.getUpdateCount(), 5);

    // update succeeds now.
    ctx.updateDriverStatus(noWaitingHandler);
    // all next updates should succeed, as retries should be cleared
    ctx.updateDriverStatus(waitingHandler);
    assertEquals(selectedDriver.getUpdateCount(), 7);
  }