Package org.jboss.internal.soa.esb.command

Examples of org.jboss.internal.soa.esb.command.InMemoryCommandQueue


import org.jboss.soa.esb.helpers.ConfigTree;

public class InMemoryCommandQueueUnitTest extends TestCase {

  public void test_args() throws CommandQueueException {
    InMemoryCommandQueue commandQueue = new InMemoryCommandQueue();
   
    try {
      commandQueue.open(null);
      fail("Expected IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
      // OK
    }

    ConfigTree config = new ConfigTree("config");
    try {
      commandQueue.open(config);
      fail("Expected CommandQueueException.");
    } catch (CommandQueueException e) {
      // OK
    }
  }
View Full Code Here


    }
  }
 
  public void test_queue_open_close() throws CommandQueueException {
    ConfigTree config = new ConfigTree("config");
    InMemoryCommandQueue commandQueue = new InMemoryCommandQueue();

    config.setAttribute(InMemoryCommandQueue.COMMAND_QUEUE_NAME, "test-queue");
    assertEquals(null, InMemoryCommandQueue.getQueue("test-queue"));
    commandQueue.open(config);
    assertEquals(commandQueue, InMemoryCommandQueue.getQueue("test-queue"));
    commandQueue.close();
    assertEquals(null, InMemoryCommandQueue.getQueue("test-queue"));
  }
View Full Code Here

    assertEquals(null, InMemoryCommandQueue.getQueue("test-queue"));
  }
 
  public void test_queue_receive() throws CommandQueueException, InterruptedException {
    ConfigTree config = new ConfigTree("config");
    InMemoryCommandQueue commandQueue = new InMemoryCommandQueue();

    // receive should fail if the queue hasn't been opened yet...
    try {
      commandQueue.receiveCommand(0);
      fail("Expected CommandQueueException.");
    } catch (CommandQueueException e) {
      // OK
    }
   
    config.setAttribute(InMemoryCommandQueue.COMMAND_QUEUE_NAME, "test-queue");
    commandQueue.open(config);
   
    // Start the consumer thread - it will receive the commands from the queue.
    CommandConsumerThread consumerThread = new CommandConsumerThread(commandQueue);
    consumerThread.start();
   
    // Make sure the thread is running.
    assertTrue(consumerThread.isRunning);
   
    commandQueue.addCommand("command1");
    assertCommandReceived(consumerThread, "command1", 0);
    commandQueue.addCommand("command2");
    assertCommandReceived(consumerThread, "command2", 1);
    commandQueue.addCommand("command3");
    assertCommandReceived(consumerThread, "command3", 2);
   
    // Stop the queue thread...
    commandQueue.addCommand("stop");
    Thread.sleep(50);
    assertTrue(!consumerThread.isRunning)// this flag being reset proves the stop command was consumed and so the queue is really working
    assertEquals(4, consumerThread.unblockCount); // Should have unblocked 4 times - once for each command.
   
    // receive should fail if the queue has been closed...
    commandQueue.close();
    try {
      commandQueue.receiveCommand(0);
      fail("Expected CommandQueueException.");
    } catch (CommandQueueException e) {
      // OK
    }
  }
View Full Code Here

TOP

Related Classes of org.jboss.internal.soa.esb.command.InMemoryCommandQueue

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.