List of usage examples for org.apache.commons.collections.buffer BlockingBuffer decorate
public static Buffer decorate(Buffer buffer)
From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java
public Object makeObject() { return BlockingBuffer.decorate(new MyBuffer()); }
From source file:edu.illinois.imunit.examples.apache.collections.TestBlockingBuffer.java
/** * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)}. */// w w w. j a va2 s .c o m @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.enforcemop.examples.apache.collections.TestBlockingBuffer.java
/** * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)}. *///from ww w . j av a 2s. 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.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 2 s . c o m*/ @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.imunit.examples.apache.collections.TestBlockingBuffer.java
/** * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add(Object)}. *///w ww . j a v a2 s. co m @Test @Schedule("[beforeRemove]@main->beforeAdd@addThread") public void testRemoveWithAdd() { 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("beforeRemove"); assertSame(obj, blockingBuffer.remove()); fireEvent("afterRemove"); }
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 ww .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:edu.illinois.imunit.examples.apache.collections.TestBlockingBuffer.java
/** * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}. *//*from w w w . j a v a 2 s .c o m*/ @Test @Schedule("[beforeRemove]@main->beforeAddAll@addThread") public void testRemoveWithAddAll() { Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer()); Object obj = new Object(); new NonDelayedAddAll(blockingBuffer, obj, "addThread").start(); // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer . fireEvent("beforeRemove"); assertSame(obj, blockingBuffer.remove()); fireEvent("afterRemove"); }
From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java
/** * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add(Object)}. *//* w ww .java 2s . co m*/ @Test // @Schedules({ // @Schedule(name = "RemoveWithAdd", sequence = "[beforeRemove:afterRemove]@main->beforeAdd@addThread") }) public void testRemoveWithAdd() { 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("beforeRemove")*/ assertSame("RemoveWithAdd", obj, blockingBuffer.remove()); /* @Event("afterRemove")*/ }
From source file:edu.illinois.imunit.examples.apache.collections.TestBlockingBuffer.java
/** * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)} using multiple read * threads./*from ww w . j av a 2s . c o m*/ * <p/> * Two read threads should block on an empty buffer until one object is added then both threads should complete. */ @Test @Schedules({ @Schedule(name = "BlockedGetWithAdd", value = "[beforeGet:afterGet]@readThread1->beforeAdd@main," + "[beforeGet:afterGet]@readThread2->beforeAdd@main," + "afterGet@readThread1->afterAdd@main," + "afterGet@readThread2->afterAdd@main") }) public void testBlockedGetWithAdd() throws InterruptedException { Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer()); Object obj = new Object(); // run methods will get and compare -- must wait for add Thread thread1 = new ReadThread(blockingBuffer, obj, "BlockedGetWithAdd", "readThread1"); Thread thread2 = new ReadThread(blockingBuffer, obj, "BlockedGetWithAdd", "readThread2"); thread1.start(); thread2.start(); // give hungry read threads ample time to hang try { // Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } // notifyAll should allow both read threads to complete fireEvent("beforeAdd"); blockingBuffer.add(obj); // allow notified threads to complete // Thread.sleep(100); fireEvent("afterAdd"); // There should not be any threads waiting. // if(thread1.isAlive() || thread2.isAlive()) { // fail("Live thread(s) when both should be dead."); // } }
From source file:edu.illinois.enforcemop.examples.apache.collections.TestBlockingBuffer.java
/** * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}. *//* w w w . j a v a 2 s.com*/ @Test // @Schedules({ // @Schedule(name = "RemoveWithAddAll", sequence = "[beforeRemove:afterRemove]@main->beforeAddAll@addThread") }) public void testRemoveWithAddAll() { Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer()); Object obj = new Object(); new NonDelayedAddAll(blockingBuffer, obj, "addThread").start(); // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer . /* @Event("beforeRemove")*/ assertSame("RemoveWithAddAll", obj, blockingBuffer.remove()); /* @Event("afterRemove")*/ }