Ejemplo n.º 1
0
  @Test
  public void testIsAvailableSubjectExperation() throws Exception {
    when(webclient.invoke(eq("HEAD"), isNull())).thenReturn(response);
    when(mockSecurity.getExpires(subject))
        .thenReturn(new Date(System.currentTimeMillis() + 600000L))
        .thenReturn(new Date(System.currentTimeMillis() + 600000L))
        .thenReturn(new Date());
    sendEvent.setSubject(subject);
    boolean available = false;
    while (!sendEvent.ping()) {}

    long lastPing = sendEvent.getLastPing();
    // sleep incase the test runs too fast we want to make sure their is a time difference
    Thread.sleep(1);
    // run within the expiration period of the assertion
    available = sendEvent.ping();
    assertTrue(available);
    assertEquals(lastPing, sendEvent.getLastPing());
    // sleep incase the test runs too fast we want to make sure their is a time difference
    Thread.sleep(1);
    // run with expired assertion
    available = sendEvent.ping();
    assertTrue(available);
    assertNotEquals(lastPing, sendEvent.getLastPing());
  }
Ejemplo n.º 2
0
  @Test
  public void testIsAvailableNoExperation() throws Exception {
    long lastPing = sendEvent.getLastPing();
    when(webclient.invoke(eq("HEAD"), isNull())).thenReturn(response);
    boolean available = false;
    while (!sendEvent.ping()) {}

    assertNotEquals(lastPing, sendEvent.getLastPing());
    lastPing = sendEvent.getLastPing();
    Thread.sleep(1);
    // run within the expiration period of the assertion
    available = sendEvent.ping();
    assertTrue(available);
    assertEquals(lastPing, sendEvent.getLastPing());
  }
Ejemplo n.º 3
0
 @Test
 public void testIsAvailableRetryBackoff() throws Exception {
   when(webclient.invoke(eq("HEAD"), isNull())).thenThrow(new RuntimeException("test"));
   sendEvent.setSubject(subject);
   long lastPing = sendEvent.getLastPing();
   boolean available = true;
   // loop until we get to a backoff that will be long enough not to cause intermitent test
   // failures
   while (sendEvent.getRetryCount() < 7) {
     available = sendEvent.ping();
   }
   assertFalse(available);
   assertNotEquals(lastPing, sendEvent.getLastPing());
   lastPing = sendEvent.getLastPing();
   Thread.sleep(1);
   // run again this time within a backoff period and verify that it doesn't retry this is
   available = sendEvent.ping();
   assertFalse(available);
   assertEquals(7, sendEvent.getRetryCount());
   assertEquals(lastPing, sendEvent.getLastPing());
 }