Example usage for org.apache.commons.collections Buffer get

List of usage examples for org.apache.commons.collections Buffer get

Introduction

In this page you can find the example usage for org.apache.commons.collections Buffer get.

Prototype

Object get();

Source Link

Document

Gets the next object from the buffer without removing it.

Usage

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBoundedBuffer.java

@Test
// @Schedule(name = "addToFullBufferWithTimeout", sequence = "[beforeAdd:afterAdd]@main->beforeRemove@removeThread,afterRemove@removeThread->afterAdd@main")
public void testAddToFullBufferWithTimeout() {
    final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
    bounded.add("Hello");
    new NonDelayedRemove(bounded, 100, "removeThread").start();
    /* @Event("beforeAdd")*/
    bounded.add("World");
    /* @Event("afterAdd")*/
    assertEquals(1, bounded.size());/* w  ww. j  ava  2  s  .c o  m*/
    assertEquals("World", bounded.get());
    try {
        bounded.add("!");
        fail();
    } catch (BufferOverflowException e) {
    }
}

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBoundedBuffer.java

/**@TO-DO How do we handle timed events? */
@Test/* w w  w .j  a  v a  2 s . com*/
//  @Schedule(name = "addToFullBufferRemoveViaIterator", sequence = "[beforeAdd:afterAdd]@main->beforeRemove@removeThread")
public void testAddToFullBufferRemoveViaIterator() {
    final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
    bounded.add("Hello");
    new NonDelayedIteratorRemove(bounded, 100, "removeThread").start();
    /* @Event("beforeAdd")*/
    bounded.add("World");
    /* @Event("afterAdd")*/
    assertEquals(1, bounded.size());
    assertEquals("World", bounded.get());

}

From source file:edu.illinois.imunit.examples.apache.collections.TestBlockingBuffer.java

/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)}.
 *//*from   ww  w  .j  av  a  2s . com*/
@Test
@Schedule("[beforeGet]@main->beforeAdd@addThread")
public void testGetWithAdd() {
    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    new NonDelayedAdd(blockingBuffer, obj, "addThread").start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    fireEvent("beforeGet");
    assertSame(obj, blockingBuffer.get());
    fireEvent("afterGet");
}

From source file:edu.illinois.imunit.examples.apache.collections.TestBlockingBuffer.java

/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}.
 */// w w  w  . j a  v a  2s  .  c om
@Test
@Schedule("[beforeGet]@main->beforeAddAll@addAllThread")
public void testGetWithAddAll() {
    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    new NonDelayedAddAll(blockingBuffer, obj, "addAllThread").start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    fireEvent("beforeGet");
    assertSame(obj, blockingBuffer.get());
    fireEvent("afterGet");
}

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java

/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)}.
 *//*from  ww w.  j  a  v  a  2  s  .  c om*/
@Test
// @Schedules({
//   @Schedule(name = "GetWithAdd", sequence = "[beforeGet:afterGet]@main->beforeAdd@addThread") })
public void testGetWithAdd() {
    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    new NonDelayedAdd(blockingBuffer, obj, "addThread").start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    /* @Event("beforeGet")*/
    assertSame("GetWithAdd", obj, blockingBuffer.get());
    /* @Event("afterGet")*/
}

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java

@Test
// @Schedules({/* ww  w.ja v a  2  s. co  m*/
//   @Schedule(name = "GetWithAddTimeout", sequence = "[beforeGet:afterGet]@main->beforeAdd@addThread") })
public void testGetWithAddTimeout() {
    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer(), 500);
    Object obj = new Object();
    new DelayedAdd(blockingBuffer, obj, 100).start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    /* @Event("beforeGet")*/
    assertEquals("GetWithAddTimeout", obj, blockingBuffer.get());
    /* @Event("afterGet")*/
}

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java

@Test
// @Schedules({/*from   w  w  w  . jav a2s.  co m*/
//   @Schedule(name = "GetWithAddAllTimeout", sequence = "[beforeGet: afterGet]@main->beforeAddAll@addAllThread") })
public void testGetWithAddAllTimeout() {
    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer(), 500);
    Object obj = new Object();
    new DelayedAddAll(blockingBuffer, obj, 100).start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    /* @Event("beforeGet")*/
    assertSame("GetWithAddAllTimeout", obj, blockingBuffer.get());
    /* @Event("afterGet")*/
}

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java

/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}.
 *//*from  w w  w . j a  v a 2 s  .  c  o  m*/
@Test
// @Schedules({
//   @Schedule(name = "GetWithAddAll", sequence = "[beforeGet:afterGet]@main->beforeAddAll@addAllThread") })
public void testGetWithAddAll() {
    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    new NonDelayedAddAll(blockingBuffer, obj, "addAllThread").start();

    // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
    /* @Event("beforeGet")*/
    assertSame("GetWithAddAll", obj, blockingBuffer.get());
    /* @Event("afterGet")*/
}

From source file:org.xwiki.ircbot.internal.BrokenLinkEventListenerTest.java

@Test
public void onEventWhenSeveralInvalidURLEventSavesOnlyLastFour() throws Exception {
    // First one will be ejected by the 5th one since only last 4 broken links are saved
    sendInvalidURLEvent("testurl1", null);
    sendInvalidURLEvent("testurl2", null);
    sendInvalidURLEvent("testurl3", null);
    sendInvalidURLEvent("testurl4", null);
    sendInvalidURLEvent("testurl5", null);

    Buffer buffer = ((BrokenLinkEventListener) getMockedComponent()).getLastBrokenLinks();
    Assert.assertEquals(4, buffer.size());

    // Get the latest item from the buffer and verify its url is "testurl2" and not "testurl1", thus proving
    // that the first item has been ejected.
    Map<String, Object> source = (Map<String, Object>) buffer.get();
    Assert.assertEquals("testurl2", source.get("url"));
}