Exemple #1
0
  @Test
  public void testRun_OneItem() throws NoSuchPool, EmptyPool, TException, InterruptedException {

    when(mockFactory.createClient(HOSTNAME, PORT)).thenReturn(mockClient);

    // Set message on the queue
    when(mockClient.acquire(POOL))
        .thenReturn(new Job(utf8.encode(MESSAGE_ONE), utf8.encode(ID_ONE)))
        .thenReturn(new Job(utf8.encode(MESSAGE_TWO), utf8.encode(ID_TWO)))
        .thenThrow(new EmptyPool());

    LoggingTextConsumer consumer = new LoggingTextConsumer(HOSTNAME, PORT, POOL);

    // Run as background thread then tell to stop after processing documents.
    Thread t = new Thread(consumer);
    t.start();
    Thread.sleep(10); // Could in case this if it starts to be a problem.
    consumer.stop();

    // Check it gets messages
    assertEquals(2, consumer.count);
    assertEquals(Arrays.asList(MESSAGE_ONE, MESSAGE_TWO), consumer.messages);

    verify(mockClient).purge(POOL, utf8.encode(ID_ONE));
    verify(mockClient).purge(POOL, utf8.encode(ID_TWO));
  }
Exemple #2
0
 @After
 public void tearDown() {
   ClientFactory.setInstance(null);
 }
Exemple #3
0
 @Before
 public void setUp() throws Exception {
   ClientFactory.setInstance(mockFactory);
 }