コード例 #1
0
  /** Test that wrapping an object that violates our wrapping conditions fails */
  public void testBadWrap() {
    BadMockWrappedInterface mw = new BadWrapObjectImpl();

    CircuitBreakerWrapper cbw = CircuitBreakerWrapper.getCircuitBreakerWrapperInstance();
    try {
      mw = cbw.wrap(mw, BadMockWrappedInterface.class, new BaseCircuitBreakerPolicyImpl(1, 1, 10));
    } catch (CircuitBreakerWrappingException e) {
      return;
    }
    fail();
  }
コード例 #2
0
  /**
   * Test method for {@link
   * com.hubspot.utils.circuitbreaker.CircuitBreakerWrapper#wrap(java.lang.Object, java.lang.Class,
   * com.hubspot.utils.circuitbreaker.CircuitBreakerPolicy)}.
   */
  public void testWrap() throws Exception {
    MockWrappedInterface mw = new MockWrappedInterfaceImpl();

    CircuitBreakerWrapper cbw = CircuitBreakerWrapper.getCircuitBreakerWrapperInstance();
    try {
      mw = cbw.wrap(mw, MockWrappedInterface.class, new BaseCircuitBreakerPolicyImpl(1, 1, 10));
    } catch (Exception e) {
      fail();
    }
    assertNotNull(mw);
    assertEquals(mw.doSomething("HELLO"), "HELLO");
  }
コード例 #3
0
  /** Test that we can't double wrap an object */
  public void testDoubleWrapIsBadWrap() {
    MockWrappedInterface mw = new MockWrappedInterfaceImpl();
    CircuitBreakerWrapper cbw = CircuitBreakerWrapper.getCircuitBreakerWrapperInstance();
    try {
      mw = cbw.wrap(mw, MockWrappedInterface.class, new BaseCircuitBreakerPolicyImpl(1, 1, 10));
    } catch (CircuitBreakerWrappingException e) {
      fail();
    }

    // try wrapping the object in a circuit breaker one more time--should fail
    try {
      mw = cbw.wrap(mw, MockWrappedInterface.class, new BaseCircuitBreakerPolicyImpl(1, 1, 10));
    } catch (CircuitBreakerWrappingException e) {
      return;
    }

    fail();
  }
コード例 #4
0
 /**
  * Test method for {@link
  * com.hubspot.utils.circuitbreaker.CircuitBreakerWrapper#getCircuitBreakerWrapperInstance()}.
  */
 public void testGetCircuitBreakerWrapperInstance() {
   CircuitBreakerWrapper w = CircuitBreakerWrapper.getCircuitBreakerWrapperInstance();
   assertNotNull(w);
 }