Package org.springframework.core.task

Examples of org.springframework.core.task.MockRunnable


    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
    assertNotNull(RequestContextHolder.getRequestAttributes());
    assertEquals("value",
        RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
    MockRunnable runnable = new MockRunnable();
    RequestContextHolder.getRequestAttributes().registerDestructionCallback(
        "test", runnable, RequestAttributes.SCOPE_REQUEST);

    listener.requestDestroyed(new ServletRequestEvent(context, request));
    assertNull(RequestContextHolder.getRequestAttributes());
    assertTrue(runnable.wasExecuted());
  }
View Full Code Here


    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
    assertNotNull(RequestContextHolder.getRequestAttributes());
    assertEquals("value",
        RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
    MockRunnable runnable = new MockRunnable();
    RequestContextHolder.getRequestAttributes().registerDestructionCallback(
        "test", runnable, RequestAttributes.SCOPE_REQUEST);

    request.clearAttributes();
    listener.requestDestroyed(new ServletRequestEvent(context, request));
    assertNull(RequestContextHolder.getRequestAttributes());
    assertTrue(runnable.wasExecuted());
  }
View Full Code Here

    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
    assertNotNull(RequestContextHolder.getRequestAttributes());
    assertEquals("value",
        RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
    MockRunnable runnable = new MockRunnable();
    RequestContextHolder.getRequestAttributes().registerDestructionCallback(
        "test", runnable, RequestAttributes.SCOPE_REQUEST);

    // Execute requestDestroyed callback in different thread.
    Thread thread = new Thread() {
      public void run() {
        listener.requestDestroyed(new ServletRequestEvent(context, request));
      }
    };
    thread.start();
    try {
      thread.join();
    }
    catch (InterruptedException ex) {
    }
    // Still bound to original thread, but at least completed.
    assertNotNull(RequestContextHolder.getRequestAttributes());
    assertTrue(runnable.wasExecuted());

    // Check that a repeated execution in the same thread works and performs cleanup.
    listener.requestInitialized(new ServletRequestEvent(context, request));
    listener.requestDestroyed(new ServletRequestEvent(context, request));
    assertNull(RequestContextHolder.getRequestAttributes());
View Full Code Here

    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
    assertNotNull(RequestContextHolder.getRequestAttributes());
    assertEquals("value",
        RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
    MockRunnable runnable = new MockRunnable();
    RequestContextHolder.getRequestAttributes().registerDestructionCallback(
        "test", runnable, RequestAttributes.SCOPE_REQUEST);

    listener.requestDestroyed(new ServletRequestEvent(context, request));
    assertNull(RequestContextHolder.getRequestAttributes());
    assertTrue(runnable.wasExecuted());
  }
View Full Code Here

    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
    assertNotNull(RequestContextHolder.getRequestAttributes());
    assertEquals("value",
        RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
    MockRunnable runnable = new MockRunnable();
    RequestContextHolder.getRequestAttributes().registerDestructionCallback(
        "test", runnable, RequestAttributes.SCOPE_REQUEST);

    request.clearAttributes();
    listener.requestDestroyed(new ServletRequestEvent(context, request));
    assertNull(RequestContextHolder.getRequestAttributes());
    assertTrue(runnable.wasExecuted());
  }
View Full Code Here

    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
    assertNotNull(RequestContextHolder.getRequestAttributes());
    assertEquals("value",
        RequestContextHolder.getRequestAttributes().getAttribute("test", RequestAttributes.SCOPE_REQUEST));
    MockRunnable runnable = new MockRunnable();
    RequestContextHolder.getRequestAttributes().registerDestructionCallback(
        "test", runnable, RequestAttributes.SCOPE_REQUEST);

    // Execute requestDestroyed callback in different thread.
    Thread thread = new Thread() {
      @Override
      public void run() {
        listener.requestDestroyed(new ServletRequestEvent(context, request));
      }
    };
    thread.start();
    try {
      thread.join();
    }
    catch (InterruptedException ex) {
    }
    // Still bound to original thread, but at least completed.
    assertNotNull(RequestContextHolder.getRequestAttributes());
    assertTrue(runnable.wasExecuted());

    // Check that a repeated execution in the same thread works and performs cleanup.
    listener.requestInitialized(new ServletRequestEvent(context, request));
    listener.requestDestroyed(new ServletRequestEvent(context, request));
    assertNull(RequestContextHolder.getRequestAttributes());
View Full Code Here

TOP

Related Classes of org.springframework.core.task.MockRunnable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.