Пример #1
0
 /**
  * runs all "error" filters. These are called only if an exception occurs. Exceptions from this
  * are swallowed and logged so as not to bubble up.
  */
 public void error() {
   try {
     runFilters("error");
   } catch (Throwable e) {
     logger.error(e.getMessage(), e);
   }
 }
Пример #2
0
    @Test
    public void testUnsubscribeAfterTake() {
      Subscription s = mock(Subscription.class);
      TestObservable w = new TestObservable(s, "one", "two", "three");

      @SuppressWarnings("unchecked")
      Observer<String> aObserver = mock(Observer.class);
      Observable<String> take = Observable.create(take(w, 1));
      take.subscribe(aObserver);

      // wait for the Observable to complete
      try {
        w.t.join();
      } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
      }

      System.out.println("TestObservable thread finished");
      verify(aObserver, times(1)).onNext("one");
      verify(aObserver, never()).onNext("two");
      verify(aObserver, never()).onNext("three");
      verify(aObserver, times(1)).onCompleted();
      verify(s, times(1)).unsubscribe();
      verifyNoMoreInteractions(aObserver);
    }
Пример #3
0
 /**
  * runs all "pre" filters. These filters are run before routing to the orgin.
  *
  * @throws ZuulException
  */
 public void preRoute() throws ZuulException {
   try {
     runFilters("pre");
   } catch (Throwable e) {
     if (e instanceof ZuulException) {
       throw (ZuulException) e;
     }
     throw new ZuulException(e, 500, "UNCAUGHT_EXCEPTION_IN_PRE_FILTER_" + e.getClass().getName());
   }
 }
Пример #4
0
 /**
  * https://github.com/ReactiveX/RxJava/issues/198
  *
  * <p>Rx Design Guidelines 5.2
  *
  * <p>"when calling the Subscribe method that only has an onNext argument, the OnError behavior
  * will be to rethrow the exception on the thread that the message comes out from the Observable.
  * The OnCompleted behavior in this case is to do nothing."
  */
 @Test
 @Ignore("Subscribers can't throw")
 public void testErrorThrownWithoutErrorHandlerSynchronous() {
   try {
     Observable.error(new RuntimeException("failure")).subscribe();
     fail("expected exception");
   } catch (Throwable e) {
     assertEquals("failure", e.getMessage());
   }
 }
Пример #5
0
 @Test
 public void testRouteProcess() {
   FilterProcessor processor = new FilterProcessor();
   processor = spy(processor);
   try {
     processor.route();
     verify(processor, times(1)).runFilters("route");
   } catch (Throwable e) {
     e.printStackTrace();
   }
 }
Пример #6
0
    @Test
    public void testProcessZuulFilter() {
      FilterProcessor processor = new FilterProcessor();
      processor = spy(processor);
      try {
        processor.processZuulFilter(filter);
        verify(processor, times(1)).processZuulFilter(filter);
        verify(filter, times(1)).runFilter();

      } catch (Throwable e) {
        e.printStackTrace();
      }
    }
Пример #7
0
    @Test
    public void testProcessZuulFilterException() {
      FilterProcessor processor = new FilterProcessor();
      processor = spy(processor);

      try {
        ZuulFilterResult r = new ZuulFilterResult(ExecutionStatus.FAILED);
        r.setException(new Exception("Test"));
        when(filter.runFilter()).thenReturn(r);
        when(filter.filterType()).thenReturn("post");
        processor.processZuulFilter(filter);
        assertFalse(true);
      } catch (Throwable e) {
        assertEquals(e.getCause().getMessage(), "Test");
      }
    }
Пример #8
0
 public void testStandAloneClient() throws Exception {
   testParallel(10, false, 2, 4, 2, 4, 100);
   Client client = new Client(LongWritable.class, conf);
   InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10);
   try {
     client.call(new LongWritable(RANDOM.nextLong()), address, null, null);
     fail("Expected an exception to have been thrown");
   } catch (IOException e) {
     String message = e.getMessage();
     String addressText = address.toString();
     assertTrue("Did not find " + addressText + " in " + message, message.contains(addressText));
     Throwable cause = e.getCause();
     assertNotNull("No nested exception in " + e, cause);
     String causeText = cause.getMessage();
     assertTrue("Did not find " + causeText + " in " + message, message.contains(causeText));
   }
 }
Пример #9
0
  public void testErrorClient() throws Exception {
    // start server
    Server server = new TestServer(1, false);
    InetSocketAddress addr = NetUtils.getConnectAddress(server);
    server.start();

    // start client
    Client client = new Client(LongErrorWritable.class, conf);
    try {
      client.call(new LongErrorWritable(RANDOM.nextLong()), addr, null, null);
      fail("Expected an exception to have been thrown");
    } catch (IOException e) {
      // check error
      Throwable cause = e.getCause();
      assertTrue(cause instanceof IOException);
      assertEquals(LongErrorWritable.ERR_MSG, cause.getMessage());
    }
  }
Пример #10
0
    @Test
    public void testErrorHttpException() {
      HttpServletRequest request = mock(HttpServletRequest.class);
      HttpServletResponse response = mock(HttpServletResponse.class);
      RequestContext.getCurrentContext().setRequest(request);
      RequestContext.getCurrentContext().setResponse(response);

      FilterProcessor processor = new FilterProcessor();
      processor = spy(processor);
      try {
        when(processor.runFilters("error")).thenThrow(new ZuulException("test", 400, "test"));
        when(filter.filterType()).thenReturn("post");
        processor.error();
        assertTrue(true);
      } catch (Throwable e) {
        e.printStackTrace();
        assertFalse(true);
      }
    }
Пример #11
0
 @Test
 public void variableAtShouldCallResolveObject() {
   try {
     PrimObject primObject = new PrimObject();
     PrimObjectClass primObjectClass = mock(PrimObjectClass.class);
     when(primObjectClass.indexOfVariable("Thing")).thenReturn(0);
     primObject.cls(primObjectClass);
     PrimObject spy = spy(primObject);
     spy.variableAt("Thing");
     verify(spy).resolveObject("Thing");
   } catch (Throwable e) {
     try {
       PrintStream f =
           new PrintStream(new FileOutputStream("c:\\Users\\7\\redline-smalltalk\\x2.txt"));
       e.printStackTrace(f);
     } catch (FileNotFoundException h) {
       throw new RuntimeException(h);
     }
     throw new RuntimeException("in variableAtShouldCallResolveObject");
   }
 }
Пример #12
0
    @Test
    public void testPostProcessHttpException() {
      HttpServletRequest request = mock(HttpServletRequest.class);
      HttpServletResponse response = mock(HttpServletResponse.class);
      RequestContext.getCurrentContext().setRequest(request);
      RequestContext.getCurrentContext().setResponse(response);

      FilterProcessor processor = new FilterProcessor();
      processor = spy(processor);
      try {
        when(processor.runFilters("post")).thenThrow(new ZuulException("test", 400, "test"));
        when(filter.filterType()).thenReturn("post");
        processor.postRoute();
      } catch (ZuulException e) {
        assertEquals(e.getMessage(), "test");
        assertEquals(e.nStatusCode, 400);
      } catch (Throwable e) {
        e.printStackTrace();
        assertFalse(true);
      }
    }
Пример #13
0
  @Test
  public void testRequestedClaimsSelectNoScope() throws Exception {
    // Given
    Bindings variables =
        testBindings(
            asSet("openid"), Collections.singletonMap("given_name", asSet("fred", "george")));
    when(identity.getAttribute("cn")).thenReturn(asSet("Joe Bloggs"));

    // When/Then
    try {
      scriptEvaluator.evaluateScript(script, variables);
    } catch (Throwable e) {
      Throwable last = null;
      while (last != e) {
        if (e.getClass().equals(RuntimeException.class)) {
          break;
        }
        last = e;
        e = e.getCause();
      }
      assertThat(e.getMessage())
          .isEqualTo("No selection logic for given_name defined. Values: [george, fred]");
    }
  }
Пример #14
0
  /**
   * Processes an individual ZuulFilter. This method adds Debug information. Any uncaught Thowables
   * are caught by this method and converted to a ZuulException with a 500 status code.
   *
   * @param filter
   * @return the return value for that filter
   * @throws ZuulException
   */
  public Object processZuulFilter(ZuulFilter filter) throws ZuulException {

    RequestContext ctx = RequestContext.getCurrentContext();
    boolean bDebug = ctx.debugRouting();
    final String metricPrefix = "zuul.filter-";
    long execTime = 0;
    String filterName = "";
    try {
      long ltime = System.currentTimeMillis();
      filterName = filter.getClass().getSimpleName();

      RequestContext copy = null;
      Object o = null;
      Throwable t = null;

      if (bDebug) {
        Debug.addRoutingDebug(
            "Filter " + filter.filterType() + " " + filter.filterOrder() + " " + filterName);
        copy = ctx.copy();
      }

      ZuulFilterResult result = filter.runFilter();
      ExecutionStatus s = result.getStatus();
      execTime = System.currentTimeMillis() - ltime;

      switch (s) {
        case FAILED:
          t = result.getException();
          ctx.addFilterExecutionSummary(filterName, ExecutionStatus.FAILED.name(), execTime);
          break;
        case SUCCESS:
          o = result.getResult();
          ctx.addFilterExecutionSummary(filterName, ExecutionStatus.SUCCESS.name(), execTime);
          if (bDebug) {
            Debug.addRoutingDebug(
                "Filter {"
                    + filterName
                    + " TYPE:"
                    + filter.filterType()
                    + " ORDER:"
                    + filter.filterOrder()
                    + "} Execution time = "
                    + execTime
                    + "ms");
            Debug.compareContextState(filterName, copy);
          }
          break;
        default:
          break;
      }

      if (t != null) throw t;

      usageNotifier.notify(filter, s);
      return o;

    } catch (Throwable e) {
      if (bDebug) {
        Debug.addRoutingDebug(
            "Running Filter failed "
                + filterName
                + " type:"
                + filter.filterType()
                + " order:"
                + filter.filterOrder()
                + " "
                + e.getMessage());
      }
      usageNotifier.notify(filter, ExecutionStatus.FAILED);
      if (e instanceof ZuulException) {
        throw (ZuulException) e;
      } else {
        ZuulException ex =
            new ZuulException(
                e, "Filter threw Exception", 500, filter.filterType() + ":" + filterName);
        ctx.addFilterExecutionSummary(filterName, ExecutionStatus.FAILED.name(), execTime);
        throw ex;
      }
    }
  }