Example usage for java.util.concurrent SynchronousQueue add

List of usage examples for java.util.concurrent SynchronousQueue add

Introduction

In this page you can find the example usage for java.util.concurrent SynchronousQueue add.

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Usage

From source file:org.springframework.xd.shell.command.JobCommandTests.java

@Test
public void testLaunchJobTwiceWhereMakeUniqueIsFalse() throws Exception {
    logger.info("Launch batch job (makeUnique=false) twice");
    String jobName = generateJobName();
    // Batch 3.0 requires at least one parameter to reject duplicate executions of an instance
    String myJobParams = "{\"-param(long)\":\"12345\"}";
    JobParametersHolder.reset();// ww w  . j av  a 2s.  c o  m
    final JobParametersHolder jobParametersHolder = new JobParametersHolder();

    executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=false");
    checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=false", true);
    executeJobLaunch(jobName, myJobParams);
    assertTrue("The countdown latch expired and did not count down.", jobParametersHolder.isDone());

    final SynchronousQueue<Message<?>> rendezvous = new SynchronousQueue<Message<?>>();
    MessageHandler handler = new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            rendezvous.add(message);
        }
    };
    getErrorChannel().subscribe(handler);
    executeCommand("job launch --name " + jobName + " --params " + myJobParams);
    Message<?> error = rendezvous.poll(5, TimeUnit.SECONDS);
    getErrorChannel().unsubscribe(handler);
    assertNotNull("expected an error message", error);
    Object payload = error.getPayload();
    assertTrue("payload should be a MessagingException", payload instanceof MessagingException);
    assertEquals(JobInstanceAlreadyCompleteException.class,
            ((MessagingException) payload).getCause().getClass());
}